mirror of
https://github.com/mastra-ai/mastra.git
synced 2026-11-17 08:44:46 +00:00
23,414 commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
68f6924bf7 | Merge main into security/agent-browser-cli | ||
|
|
d929736435 |
fix(core): use one stream bus for durable agents (#30229)
Durable agents now use the wrapped Agent's stream bus instead of
constructing a second one. An Agent-level pubsub carries both run frames
and thread events, including after registration and forks; evented
execution still uses Mastra's shared transport. Standalone durable
agents remain observable, and plain-run records and abort checks stay
separate from durable execution.
Previously, observing across replicas required repeating the pubsub on
the durable wrapper. This now works with the Agent configuration alone:
```ts
const agent = createDurableAgent({
agent: new Agent({ id: 'assistant', name: 'Assistant', instructions, model, pubsub }),
});
```
Inngest explicitly exposes its detached-streaming capability without
migrating its bus. The server retains the `isDurableAgentLike` fallback
in `hasResumableStreams` for compatibility with older Inngest wrappers:
their proxy can inherit `false` from a plain Agent or lack the method
entirely. Server and Inngest versions are not coupled, so removing the
fallback would silently turn HTTP disconnects into run cancellation on
supported mixed-version installs. This is a deliberate, user-approved
exception to the ticket's shortcut-removal bullet; no peer-dependency
bump is needed while the fallback remains. Regression coverage exercises
capability `true`, `false`, and missing; the latter two fail without the
fallback.
Server branch audit (`packages/server/src/server/handlers/agents.ts`):
`validateDurableToolCallAccess` (line 298) remains because approvals
need durable workflow snapshots; `authorizeRunAccess` (2676) remains
because durable ownership uses workflow rows/local and replay owners
rather than plain run records (COR-1542). The two abort-route branches
(2724 and 2742) retain durable cancellation support and its
missing/finished-run acknowledgement semantics, not separate transports.
The observe-route branch (3141) remains for generation-fenced
`__subscribeToRunStream` and the Inngest adapter's `pubsub` fallback;
consolidating observation is COR-1541, and migrating Inngest's bus is
COR-1539. The recover-route guard (3746) remains because only durable
execution has recoverable workflow snapshots. None of these remaining
branches requires a second stream bus on core DurableAgent.
The Mastra-fallback regression also runs through a fork created after
registration, both with and without resolving the bus before
registration. Another replica must receive replay plus live tail through
finish, and the terminal frame must be published on Mastra's transport.
The latest targeted rerun passed 33 tests, including cache-policy
warnings and plain-publisher isolation across both durable storage
variants; core typecheck, targeted lint, formatting and diff checks
passed.
Verified with 1,643 core durable/stream tests, 78 AIMock parity tests,
292 server handler tests (including the mixed-version capability cases),
119 Inngest tests, and six real Redis cross-server cases covering live
observation, thread events and HTTP Stop. Typechecks, lint and
formatting pass. The Agent-pubsub regression failed before the fix; a
built-package red/green demo also confirms the transport change. An
earlier approval-resume timing failure passed in isolation and on the
final full rerun.
Fixes COR-1540
## Transport precedence and upgrade scope
Default-engine durable run transport precedence is now: explicit
`createDurableAgent` pubsub → wrapped Agent pubsub → Mastra pubsub.
Evented runs retain Mastra's shared transport. Mastra-only
configurations are unchanged.
If the wrapped Agent already specifies a different transport from Mastra
and the wrapper has no override, this fix changes the effective
run-frame and remote Stop transport. To preserve routing across an
upgrade, explicitly pass the previous transport to `createDurableAgent`
or align the Agent and Mastra transports. The wrapper configures the
shared stream bus, so its override also affects resumable streams from
direct calls on the wrapped Agent. The core changeset includes this
upgrade note.
A local investigation used separately built pre-change main
(`
|
||
|
|
775e0fe328 |
chore(deps): remove pnpm override floors that no longer match any dependency (#30521)
## Summary `pnpm-workspace.yaml` has 119 security floors of the form `pkg@<x: x`. Vanta and Dependabot remediation passes added them over Sept–Nov. A floor only rewrites versions below its vulnerable cutoff. Once every consumer asks for a patched version, the floor does nothing except hold packages on its exact version. This PR removes the 75 floors that no longer match any request in the dependency tree. The comments that only described them go too. ## How the dead floors were found 1. In a scratch copy, remove **all** floor overrides, delete `pnpm-lock.yaml`, and resolve from scratch (`pnpm install --lockfile-only`). 2. For each floor, check whether any resolved version of that package falls in its vulnerable range. - **75 match nothing.** Every consumer already requests a fixed version. `simple-git` and `@tootallnate/once` are no longer in the tree. - **44 still match.** A third-party parent pins or caps a vulnerable version, for example `lodash`, `axios`, `ws`, `undici`, `uuid` <11, `@modelcontextprotocol/*` 2.0.0 and `zod` 4.1.8. These floors stay. Removed floors include `brace-expansion` (3), `fast-uri`, `form-data`, `@noble/hashes`, `postcss-selector-parser` (2 each), `js-yaml` 3.x/5.x, `hono`, `@hono/node-server` (both), `@modelcontextprotocol/sdk`, `vitest`, `postcss`, `tar`, `dompurify`, `mermaid`, `proxy-addr`, `compression`, `ioredis`, `valibot`, `handlebars`, `follow-redirects`, `systeminformation`, and `@ai-sdk/provider` v3 (every consumer requests 3.0.19 since #30518), plus others. ## Effect on the lockfile No new package versions are added. `hono@4.13.16` and `uuid@13.0.1` leave the lockfile. Every consumer that changes moves onto a version already in the lockfile: | Package | Change | Consumers | Why | |---|---|---|---| | `hono` | 4.13.16 → 4.13.17 | 5 (`@hono/node-server`, `@modelcontextprotocol/node`/`sdk`) | the floor had held them on its exact version | | `@modelcontextprotocol/sdk` | 1.32.1 → 1.32.2 | 2 (`@anthropic-ai/claude-agent-sdk`, `@google/genai`) | same | | `browserslist` | 4.28.7 → 4.29.5 | 11 (`@babel/helper-compilation-targets`, cssnano/postcss plugins) | same | | `uuid` | 13.0.1 → 11.1.1 | 1 (`mermaid@11.17.2`) | mermaid declares `^11.1.0 \|\| ^12 \|\| ^13 \|\| ^14.0.0`; pnpm dedupes it onto 11.1.1, the patched version the kept `uuid@<11.1.1` floor already installs | ## Test plan - `pnpm install --frozen-lockfile` passes the lockfile supply-chain policy check. - A diff of the resolved package set before and after shows only the changes listed above. - `pnpm turbo build --filter @mastra/mcp...` builds all 19 tasks. - `unit:packages/mcp` passes 83 of 84 files. `server-http-body-size.test.ts` fails locally with `write ECONNRESET`, and it fails the same way on main without this change. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> **ELI5:** The project kept a list of version "floors" that force some packages to at least a safe version. Many floors no longer matched any package request, so this change deletes them. The floors that still match vulnerable versions stay in place. ## Summary of changes **Files changed:** 2 (`pnpm-lock.yaml`, `pnpm-workspace.yaml`). Total: 222 insertions, 387 deletions. ### `pnpm-workspace.yaml` (5 insertions, 96 deletions) The diff removes `pkg@<range>: version` override entries and the comments that described them. Examples of removed entries: - `@better-auth/drizzle-adapter@<1.7.7`, `js-yaml@>=5.0.0 <5.4.1`, `langsmith@<0.6.0`, `simple-git@<3.36.0`, `webpack-dev-server@<5.2.5`, `fast-uri` (3.x and 4.x), `form-data`, `brace-expansion`, `immer`, `multer`, `hono@<4.13.13`, `@hono/node-server@<1.19.15`, `mermaid`, `vitest@>=2.1.0 <4.1.12`, `@modelcontextprotocol/sdk@>=1.0.0 <1.32.0`, `@hono/node-server@>=2.0.0 <2.1.3`, `compression`, `@grpc/grpc-js`, `ioredis`, `systeminformation`, `onnxruntime-node`, and others. - Entries for `postcss-selector-parser` (`>=6.1.0 <6.1.3` and `>=7.1.0 <7.1.6`) and `source-map-js`. - Entries for `modern-tar`, `smol-toml`, `http-cache-semantics`, `handlebars`, and `follow-redirects`. - Entries for `js-yaml@>=3.0.0 <3.15.2` and `@ai-sdk/provider@>=3.0.0 <3.0.19`. The diff makes these changes to retained entries: - The `uuid@<11.1.1` comment is rewritten. It no longer mentions `tar`. - The `js-yaml` comment now refers to 4.x consumers only. The remaining floor is `js-yaml@>=4.0.0 <4.3.2: 4.3.2`. - The `@ai-sdk/provider` comments now refer to the ai v7 bundle. The 3.x floor is removed. Retained entries appear as unchanged context in the diff. They include `body-parser`, `inngest`, `fast-xml-parser`, `lodash`, `prismjs`, `serialize-javascript`, `axios`, `minimatch`, `ws`, `qs`, `jose`, `katex`, `adm-zip`, `@opencode-ai/plugin>effect`, `@modelcontextprotocol/node` and `@modelcontextprotocol/sdk` routing to `@hono/node-server` 2.1.6, and the `@ai-sdk/*` floors. The diff adds no new floors. Some of the added lines are reworded comments or moved entries. ### `pnpm-lock.yaml` (217 insertions, 291 deletions) The lockfile changes 508 lines. The author reports these resolved version changes. This review did not verify them: - `hono` 4.13.16 → 4.13.17 - `@modelcontextprotocol/sdk` 1.32.1 → 1.32.2 - `uuid` 13.0.1 → 14.0.3 for `mermaid` ## Validation All results below are author-reported. This review did not re-run them. - `pnpm install --frozen-lockfile` passes the lockfile supply-chain policy check. - A resolved-package-set diff shows only the described changes. - `pnpm turbo build --filter @mastra/mcp...` builds all 19 tasks. - `unit:packages/mcp` passes 83 of 84 files. - `server-http-body-size.test.ts` fails locally with `write ECONNRESET`. The author reports the same failure on `main` without this change. The author reports 74 floors removed and 44 matching floors retained. Four `@ai-sdk/*` floors are excluded because PR `#30518` rewrites them. This review did not confirm these counts. No CI results were available for this review. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Co-authored-by: mastracode <284800079+mastra-platform[bot]@users.noreply.github.com> |
||
|
|
da04116579 |
feat(factory): let a person's reply wake a card's session while automated runs hold every slot (#30307)
## What
When a trusted collaborator comments on or reviews a card's GitHub pull
request or issue, Factory wakes the card's session even while automated
runs hold every run slot. Before, those replies were
`sendMessage`/`signalActivity` decisions that counted against the single
automated cap (`dispatcher.maxInFlight`, default 10), so a reply could
sit behind multi-hour triage runs.
## How
- **Provenance.** GitHub rule actors gain `human: true` when the webhook
`sender.type` is `User`. Bots, and Factory's synthetic reconciler events
(no `sender.type`), get `human: false`.
- **Classification** (`isInteractiveDecision`, `rules/dispatcher.ts`): a
decision is a reply only if it's `sendMessage` or `signalActivity`,
would wake the session (`idleBehavior` isn't `persist`), has an empty
causal chain (no rule passed it along, e.g. not a transition's message),
and its actor is a GitHub human who is trusted and not Factory.
Everything else stays automated. GitLab, Linear, Jira and incident.io
activity stays automated because those sources give no reliable
bot/human signal.
- **Lane.** Each process keeps a reserve of reply slots
(`dispatcher.maxInteractiveInFlight` /
`MASTRACODE_DISPATCH_MAX_INTERACTIVE_IN_FLIGHT`, default `2`, `0`
allowed). Claim order per tick: pending manual starts → replies (reserve
first, then borrowing free automated slots) → automated runs. The claim
filter now receives the row's `actor` and `causalChain` as well as the
decision payload, so no schema change.
- **Honest bounds.** The caps limit dispatcher slot occupancy, not total
running agents: `signalActivity` frees its slot once the session accepts
it, and UI/Slack messages plus approval notices to following sessions go
to the session directly and never wait for a slot. The README says so.
- **Run-queue API (additive).** Entries gain `lane`; the response gains
`queuedByLane`, and `slots` gains `interactive: { inUse, cap }`.
Existing fields keep their meaning. `position` now counts within a lane.
The board's queue menu lists waiting replies first, with a reply-slot
footer.
## Testing
- Dispatcher (LibSQL + throwaway Postgres): with automated cap 1 held by
a hanging run, a trusted person's PR reply (`sendMessage`) and issue
comment (`signalActivity`) are claimed and delivered. Automated runs,
bot replies, untrusted replies, Factory-authored replies, actors with no
`human` flag, rule-passed messages and `persist` activity all stay
pending. Other cases: the reserve caps at its size, replies borrow a
free automated slot ahead of automated runs, and the default reserve is
2. Red proof: disabling the classification fails 3 of the 4 lane tests.
- GitHub rules: `issue_comment` and `pull_request_review` from a User →
`human: true`; from a Bot or without `sender.type` → `human: false`.
- Approval notice to a following session commits nothing to the run
queue.
- MSW: queue menu groups replies apart from automated runs and shows
both slot footers.
- Gates: factory `check`, oxlint and oxfmt clean. Factory suites on
LibSQL: 942 passed. factory-ui typecheck and lint clean; unit tests 696
passed. The full MSW suite has 21 failures, the same as on main
(AppStartup, OMSection, MemorySettings, NewSessionStarters,
ThreadPageTeammateSession, TranscriptMessageMeta). `mastracode/web`
index.test.ts has 2 failures that are also on main. Postgres runs of the
full dispatcher suite at `--maxWorkers=3` show the timing flakes main
already has; every test that failed passes on its own.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->
**ELI5:** When a trusted person replies to a GitHub issue or pull
request, that reply gets its own reserved run slots. It no longer waits
behind routine automated runs.
## Overview
This change adds an interactive lane to the Factory decision dispatcher.
Trusted GitHub human replies can wake a card's session while automated
runs hold the automated slots. The run-queue API changes are additive.
## Classification
`isInteractiveDecision` in `mastracode/factory/src/rules/dispatcher.ts`
marks a decision as interactive only when all of these hold:
- The decision is `sendMessage` or `signalActivity`.
- The decision wakes the session.
- The causal chain is empty.
- The decision does not persist.
- The actor is a trusted GitHub human.
- The actor is not Factory-authored.
All other decisions use the automated lane. This includes bot actors,
untrusted actors, Factory events, and activity from GitLab, Linear,
Jira, and incident.io.
## GitHub actor changes
- `mastracode/factory/src/rules/types.ts` adds optional `human?:
boolean` to the GitHub variant of `FactoryRuleActor`.
- `mastracode/factory/src/integrations/github/rules.ts` sets `human` to
`true` only when the webhook sender type is exactly `User`.
- Trust lookup and its failure handling are unchanged. A lookup error
still marks the actor untrusted.
## Dispatcher behavior
- The default interactive reserve is 2 slots per process.
- `dispatcher.maxInteractiveInFlight` in
`mastracode/factory/src/factory.ts` and
`MASTRACODE_DISPATCH_MAX_INTERACTIVE_IN_FLIGHT` in
`mastracode/web/src/mastra/index.ts` set the reserve.
- A value of `0` disables the reserve. Invalid values use the default of
2.
- Each tick claims in this order: pending manual starts, then
interactive decisions, then automated deferred runs.
- Interactive decisions can use free automated slots.
- `runSlots()` returns overall `inUse` and `cap`, plus `interactive: {
inUse, cap }`.
- The caps limit dispatcher-held slots. They do not limit all running
agents.
- Pull-request activity releases its slot when the session accepts it.
- Direct session messages and approval notices do not wait for a slot.
## Storage
- `FactoryDeferredDecisionClaimInput.decisionFilter` receives a second
argument, `provenance`.
- The new `FactoryDecisionProvenance` type contains `actor` and
`causalChain`.
- No schema change is made. Invalid stored actor JSON parses to `null`.
Invalid causal-chain JSON parses to an empty array.
## Run-queue API (additive)
- `runQueueResponseSchema` in
`mastracode/factory/src/routes/contracts.ts` adds:
- `slots.interactive: { inUse, cap }`
- `queuedByLane: { automated, interactive }`
- Each queue entry has a `lane` field with the value `automated` or
`interactive`.
- `position` counts within a lane.
- The listing limit of 50 entries is unchanged. Waiting replies are
listed before automated runs.
- The `runSlots` types in `routes/surface.ts` and `routes/work-items.ts`
include the interactive pool.
## Board UI
- `RunQueueIndicator.tsx` lists waiting replies before automated runs.
- Each nonempty group has a label.
- The menu shows reply-slot usage next to overall slot usage.
- The tooltip fallback reads "Runs waiting for a run slot."
- `msw-server.ts` and `BoardPageRunQueue.msw.test.tsx` add lane fixtures
and a test for a waiting reply.
## Documentation and release notes
- `mastracode/factory/README.md`,
`docs/src/mastra-code/configuration.mdx`, and two changesets describe
the reserve, its default, the `0` behavior, the queue fields, and the
board ordering.
- The `mastra` changeset is a patch. The `@mastra/factory` changeset is
a minor release.
## Tests
Added or updated tests cover:
- GitHub actor `human` classification for issue comments and PR reviews,
for `User`, `Bot`, and missing sender types.
- Dispatcher reserve use, interactive cap overflow, borrowing of free
automated slots, and exclusions. Exclusions include automated, bot,
untrusted, Factory-authored, untyped, causally moved, and persisted
messages.
- The default interactive cap of 2.
- The polling-loop claim count, which changes from two to three per
tick.
- Factory config forwarding in
`mastracode/web/src/mastra/index.test.ts`, which now expects
`maxInteractiveInFlight: 0` when the environment variable is `0`.
- Clearing `MASTRACODE_DISPATCH_MAX_INTERACTIVE_IN_FLIGHT` in
sandbox-provider tests.
- No deferred decisions recorded after approval-notification delivery,
in `approval-answer-resume.test.ts`.
## Validation (author-reported)
The PR objectives report the following results. They were not checked
against completed CI checks on the current head.
- Dispatcher tests were run on LibSQL and throwaway Postgres. Full
Postgres dispatcher runs at `--maxWorkers=3` showed timing flakes. The
author reports that each failing test passes when run alone.
- Factory suites on LibSQL report 942 passing tests.
- Factory `check`, oxlint, and oxfmt are reported clean.
- factory-ui unit tests report 696 passing tests.
- The author reports 21 full MSW suite failures and 2 `mastracode/web`
`index.test.ts` failures. The author states these also occur on `main`.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: mastracode <284800079+mastra-platform[bot]@users.noreply.github.com>
|
||
|
|
bb9845508a |
fix(factory): avoid provisioning a second Gateway key for keyed deploys (#30193)
## Summary Factory should use the Mastra Gateway API key supplied automatically by the Mastra platform when one is available, rather than asking the user to connect and creating a second key. - With an injected key (`MASTRA_GATEWAY_API_KEY`), Gateway is available in both company and personal setup without the **Connect Mastra Gateway** button. The server also skips key creation if an older client calls the connect endpoint. - Without an injected key, the button and existing connection flow stay available. - Previously saved company and personal keys keep their existing precedence. ## Testing and validation **Factory configuration routes: 117 tests passed.** Coverage includes: - An injected Gateway key reports the provider as connected, with a deployment source and no connect button. - Previously saved company and personal keys retain their precedence while the server key remains available as a fallback. - Calling the connect endpoint with an injected key creates no additional key and stores no new credential, for either company or personal scope. - Without a server key, the existing connect and key-provisioning flow still works. These tests explicitly pin the server key so a developer's local environment or credential store cannot affect the results. **Onboarding UI: 40 tests passed.** The two injected-key cases now exercise the current one-page onboarding flow, replacing coverage for the wizard removed on `main`. They verify that both company and personal setup can select Gateway, load a model, and submit the setup without opening a key dialog or calling the connect endpoint. The suite also covers the existing connect-button flow when no injected key is available. The UI tests ran with temporary source aliases because local dependency build artifacts were missing. They use the real hooks and React Query, with HTTP requests mocked through MSW. The aliases were used only for local validation and are not included in the PR. Formatting and lint checks passed for the migrated onboarding tests. |
||
|
|
7517474b39 |
fix(studio): load Gateway v2 models and skip v1 memory calls (#29445)
## Why Studio currently shows Gateway models from a bundled registry and sends memory requests to the Gateway v1 API whenever a Gateway key exists. A deployed project using Gateway v2 can therefore offer unsupported models and receive 404s from the v1-only memory endpoints. ## Design When the deployment sets `MASTRA_GATEWAY_VERSION=v2`, fetch the authenticated `/v1/models` catalog from the configured Gateway and offer only models with a chat endpoint through Mastra's chat model selector. If catalog loading fails, do not fall back to the v1 model list. Treat the Gateway memory client as unavailable in v2 mode so memory handlers use the agent's own memory configuration. V1 behavior remains unchanged. The Platform runtime signal is introduced by [platform#4329](https://github.com/mastra-ai/platform/pull/4329); deploying that PR alone will not change Studio until these Mastra packages are released and the project is redeployed. ## Validation - Focused core Gateway tests: 9 passed, including live model filtering and catalog failure behavior. - Focused server Gateway memory test: 1 passed. - `git diff --check` passed. - A live deployed Studio smoke test is still needed after the updated packages are published and deployed. Full package typechecks were unavailable in the isolated worktree because its linked local dependency builds are older than this checkout. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## ELI5 When Gateway v2 is on, Studio lists only the chat models from the live Gateway catalog. It also stops calling the Gateway v1 memory API. A resolved agent without memory now shows no memory data, not shared-storage data. ## Changes - In v2 mode, `MastraGateway.fetchProviders()` requests `/v1/models` with authentication and a 10-second timeout. It keeps only models that have a string `id` and a `chat` endpoint. - If the catalog request fails or returns an invalid response, the call throws. It does not fall back to the v1 model list. - The provider list skips the bundled `mastra` registry entry in v2 mode. This prevents stale model IDs from appearing. - Other Gateway versions keep the OpenRouter model list. - In v2 mode, `getGatewayClient()` returns `null`. Memory handlers then use the agent's own memory configuration. - For a resolved v2 Gateway agent without memory: - Thread listing returns "Memory is not initialized". - Message listing returns empty `messages` and `uiMessages` arrays. - Unresolved agents keep the storage fallback. - v2 detection uses `isGatewayV2()`. It returns true when any of these conditions holds: - `MASTRA_GATEWAY_VERSION` is `v2`. - The API key starts with `msk-gateway-` or `mskv2_`. - A registered `mastra` gateway instance reports `isV2()` as true. `MastraGateway.isV2()` is a new public method. This check covers gateways configured with a v2 key and no matching environment variables. - Added patch changesets for `@mastra/core` and `@mastra/server`. ## Testing and rollout - Completed CI results are not available for this review. - The author reports that focused core Gateway tests, a focused server memory test, and `git diff --check` passed. These results were not verified here. - Full package typechecks were not run in the author's isolated worktree. - A deployed Studio smoke test is still needed. It requires the updated Mastra packages to be published and the project to be redeployed. - The Platform runtime signal depends on platform#4329. Deploying that change alone does not affect Studio. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Taofeeq Oluder <oluderutaofeeq@gmail.com> Co-authored-by: mastracode <284800079+mastra-platform[bot]@users.noreply.github.com> |
||
|
|
92f3c5ba4f |
fix(cli): keep the key id of a Gateway v2 key from create-mastra (#30457) | ||
|
|
88f94f237a |
chore(deps): use the latest @ai-sdk/provider-utils and @ai-sdk/provider patch in each major (#30518)
Co-authored-by: mastracode <284800079+mastra-platform[bot]@users.noreply.github.com> |
||
|
|
7a8d1a4f05 |
feat(factory): let hosts set the commit co-author (#30485) | ||
|
|
11c2d1dcea |
test(inngest): verify OM resuspension on PostgreSQL with a separate worker (#30492) | ||
|
|
b9d2f1d085 |
feat(factory): refuse a person's move into a run-starting phase while the card is busy (#30513)
Co-authored-by: mastracode <284800079+mastra-platform[bot]@users.noreply.github.com> |
||
|
|
36eb75bb01 |
feat(factory): let the agent choose a card's repository instead of a picker (#30506)
Co-authored-by: mastracode <284800079+mastra-platform[bot]@users.noreply.github.com> |
||
|
|
a5859ee2b9 |
chore: version packages (alpha) (#30430)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> |
||
|
|
44cece6f36 |
refactor(factory): stop storing sandbox_provider on project repositories (#30508)
Co-authored-by: mastracode <284800079+mastra-platform[bot]@users.noreply.github.com> |
||
|
|
cd2a326988 |
fix(libsql): stop background task writes stalling shutdown, and fix backend timing flakes (#30504)
Co-authored-by: mastracode <284800079+mastra-platform[bot]@users.noreply.github.com> |
||
|
|
0f360e20d1 |
chore(factory): remove provider list routes nothing calls (#30489)
Co-authored-by: mastracode <284800079+mastra-platform[bot]@users.noreply.github.com> |
||
|
|
b739dd45db |
test(playground): stop jsdom teardown leaks from failing whole test shards (#30502)
Co-authored-by: mastracode <284800079+mastra-platform[bot]@users.noreply.github.com> |
||
|
|
4809a81ba5 |
test(ui): fix main-red autosave test and flaky UI Retry/theme tests (#30500)
Co-authored-by: mastracode <284800079+mastra-platform[bot]@users.noreply.github.com> |
||
|
|
8759d3ab63 |
test: keep real network calls out of unit test projects (#30498)
Co-authored-by: mastracode <284800079+mastra-platform[bot]@users.noreply.github.com> |
||
|
|
88b4a97042 |
refactor(factory): skip legacy migration tables on new databases (#30488)
Co-authored-by: mastracode <284800079+mastra-platform[bot]@users.noreply.github.com> |
||
|
|
6c647e6fae |
refactor(factory): stop creating columns and tables nothing reads (#30495)
Co-authored-by: mastracode <284800079+mastra-platform[bot]@users.noreply.github.com> |
||
|
|
1034a4e41f |
feat(json-render): add @mastra/json-render so agents can compose json-render interfaces (#29914)
(starts after a few seconds, white screens stays a bit) https://github.com/user-attachments/assets/27f91819-b4ad-41b5-b743-6de6e5690099 ## Description Adds `@mastra/json-render`, a new integration that lets Mastra agents compose [json-render](https://json-render.dev) interfaces from a component catalog you define. json-render owns the spec format, the prompt and the rendering. Mastra handles streaming, memory and validation. The catalog lists the components and actions the model may use. It has no React in it, so the server (prompt, validation) and the client (rendering) share the same file: ```ts // src/catalog.ts import { defineCatalog } from '@json-render/core'; import { schema } from '@json-render/react/schema'; import { z } from 'zod'; export const catalog = defineCatalog(schema, { components: { Stack: { description: 'Lays out its children vertically', props: z.object({ gap: z.number().optional() }) }, Card: { description: 'A card with a title', props: z.object({ title: z.string() }) }, Text: { description: 'A line of text', props: z.object({ text: z.string() }) }, Button: { description: 'A button that runs an action on press', props: z.object({ label: z.string() }) }, }, actions: { ask: { description: 'Send a follow-up prompt to the agent', params: z.object({ prompt: z.string() }), }, }, }); ``` The Zod schemas describe each component's props in the prompt, and the processor validates every spec against them before saving it. The agent gets its instructions from the catalog and runs the processor on both sides: ```ts // src/mastra/agents/ui-agent.ts import { Agent } from '@mastra/core/agent'; import { JsonRenderProcessor } from '@mastra/json-render'; import { Memory } from '@mastra/memory'; import { catalog } from '../../catalog'; const ui = new JsonRenderProcessor({ catalog }); const agent = new Agent({ id: 'ui-agent', name: 'UI Agent', model: 'openai/gpt-6.1-sol', instructions: catalog.prompt({ mode: 'inline', editModes: ['patch'], system: 'You are a travel assistant. Prefer showing an interface over describing it.', customRules: ['Wrap everything in a Stack root.'], }), inputProcessors: [ui], outputProcessors: [ui], maxProcessorRetries: 2, memory: new Memory(), }); ``` `system` holds the agent's own instructions and replaces json-render's default intro at the top of the prompt. `customRules` adds rules at the end. The catalog's component list and output format go in between. **What it does** - **Streams interfaces.** The model writes spec blocks in json-render's inline format. The processor turns them into `data-spec` parts, so the interface streams to the client while the reply's text keeps only the prose. The client renders them with `useJsonRenderMessage()` from `@json-render/react`. - **Saves interfaces in memory.** The `data-spec` parts are stored with the message, so interfaces render again after a reload. - **Edits interfaces in later turns.** Mastra drops data parts when it builds the prompt, so on its own the model would forget the interface it wrote. Before each model call, the processor replays the latest interface into the reply that wrote it, in the prompt only, without changing the stored thread. The model can then edit that interface with a few patches. - **Keeps what the user set.** The client sends the interface's state, such as ticked checkboxes or selected filters, under the `JSON_RENDER_STATE` request context key. The model sees it, and edits keep it. - **Validates specs.** Each spec is checked against the catalog, including props inside repeated elements and duplicate repeat keys. An invalid spec goes back to the model to fix before it's saved. Tools can show their own interface by writing `data-spec` parts, and later turns can edit those too. **Docs:** adds a new page under Agentic UI (`integrations/agentic-ui/json-render`). **Studio:** unchanged. Studio keeps showing only the prose of these replies. `examples/agent` adds a `gen-ui-agent` with its own catalog to try the processor. **Known limitation:** in json-render `0.22`, `buildSpecFromParts()` changes the parts it applies, so rebuilding from the same parts repeats list items. The processor works around this on the server. On the client, apps should pass `useJsonRenderMessage()` a copy of the parts. The docs page covers this. ## Related issue(s) <!-- TODO: link issue --> ## Type of change - [ ] Bug fix (non-breaking change that fixes an issue) - [x] New feature (non-breaking change that adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [x] Documentation update - [ ] Code refactoring - [ ] Performance improvement - [ ] Test update ## Test plan - `integrations/json-render`: 32 tests pass. They run a real `Agent` with `Memory` and a mocked model. They cover streaming, reload from memory, edits, replay into the prompt, user state, tool-written interfaces, validation retries, patches that cannot be applied, repeated elements, duplicate keys, and JSON Patch examples in other code blocks staying as prose. A React test drives `useChat` and json-render's `Renderer` through MSW. - `tsc`, oxlint, prettier and the package builds pass. - The docs page passes `pnpm check`. Its code examples typecheck against the real packages. - Tested by hand in a Vite + React example app with Playwright: weather interface from a tool result, streamed itinerary with Stop mid-stream, dashboard filters followed by "which filters did I pick?" (answered in plain text, no new interface), follow-up action buttons, a large composed board, an edit that keeps ticked items, editing a tool-written interface, and reloading a long thread. ## Checklist - [ ] I have linked the related issue(s) in the description above - [x] I have made corresponding changes to the documentation (if applicable) - [x] I have added tests that prove my fix is effective or that my feature works - [x] I have addressed all Coderabbit comments on this PR <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> **ELI5:** This PR adds a package that lets an AI agent send small interface layouts, such as cards and metrics, to a web app. The app draws them as real UI. The package also checks each layout against a list of allowed parts, so the model can fix mistakes. ## Summary This PR adds `@mastra/json-render`. The package connects json-render interfaces with Mastra agents. The package provides: - `JsonRenderProcessor`, which works as an agent input and output processor. - `JSON_RENDER_STATE`, a key for sending interface state to the agent. - Support for streamed `data-spec` message parts. - Saved interfaces that render again after a page reload. - Edits to saved interfaces. The processor replays prior interfaces by message order. - Validation of each assistant interface against the catalog. The processor retries the model when the interface fails validation. Studio rendering is not part of this PR. A later commit removed it. The README no longer documents the Studio catalog setup or its component limits. ## Changes by area **Package (`integrations/json-render`)** - Adds the package manifest, with ESM and CommonJS entry points. - Sets the peer dependencies: `@json-render/core` `^0.22.0`, `@mastra/core` `>=1.83.0-0 <2.0.0-0`, and Zod `>=3.25.0 || >=4.0.0`. - Adds the build, lint, and test setup: `tsconfig.json`, `tsconfig.build.json`, `tsdown.config.ts`, `turbo.json`, `vitest.config.ts`, and `lint-staged.config.js`. - Re-exports `JSON_RENDER_STATE`, `JsonRenderProcessor`, and the `JsonRenderProcessorOptions` type from `src/index.ts`. - Adds `src/processor.ts`, which: - Converts ` ```spec ` blocks and eligible JSON Patch lines into `data-spec` parts. - Keeps prose in the text stream. - Accepts patches outside a spec fence only for `/root`, `/elements`, and `/state`. - Rebuilds the latest spec from saved parts and adds it to the prompt. - Aborts with a retry at output-step completion when the spec has validation errors, unknown components, invalid props, duplicate repeat keys, or an unappliable patch. **Tests** - `src/processor.test.ts` covers stream splitting, validation and retry, patch edits, state handling, and conversation context. - `src/react-chat.test.tsx` is a jsdom suite. It covers rendering from a streamed response, rendering from saved messages, and sending state with an action. - `src/__tests__/test-utils.ts` adds shared catalog, spec, model, and agent helpers. **Documentation** - `README.md` covers installation, processor setup, rendering `data-spec` parts, sending `JSON_RENDER_STATE`, and calling `buildSpecFromParts()`. - `.changeset/json-render-processor.md` adds a minor changeset. - `CHANGELOG.md` adds a heading for `@mastra/json-render`. **Example agent (`examples/agent`)** - Adds `gen-ui-catalog.ts`, which defines `genUICatalog` with eight components: `Stack`, `Grid`, `Card`, `Heading`, `Text`, `Badge`, `Metric`, and `Notice`. The catalog has no actions. - Adds `gen-ui-agent.ts`, which defines `genUIAgent`. The agent uses the catalog in inline mode with patch edits, the `openai/gpt-5.4-mini` model, the JSON-render processors, two retries, and memory. - Registers `genUIAgent` in `src/mastra/index.ts`. - Adds the `@json-render/core` and `@json-render/react` dependencies at `^0.22.0`, and `@mastra/json-render` at `latest`. Adds a pnpm override that links `@mastra/json-render` to `../../integrations/json-render`. - Updates `README.md` to require `pnpm setup` from the repository root before installing dependencies. ## Validation The author reports these results. They are not verified in this summary. - 41 of 41 json-render tests pass. - 59 of 59 playground-ui `message-row` tests pass. - TypeScript and oxlint report no errors. The author reports one open CI check: "New packages exist on npm." This check needs an npm admin to reserve the `@mastra/json-render` name. Completed CI results for the current head are not available. ## Scope The diff has 22 changed files, with 1658 lines added and 3 removed. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: mastracode <284800079+mastra-platform[bot]@users.noreply.github.com> |
||
|
|
418fae64fc |
fix(factory-ui): keep a running reply's tool calls in place when the chat rejoins its stream (#30476)
**─────── TLDR ───────** > Coming back to a running Factory session, or opening one mid-run, now draws the reply in flight whole: every tool call once, in order, with the text it wrote while you were away. A tab hidden for more than 30 seconds releases its stream, and the server sends no backlog when the tab comes back. The reply in flight was then drawn from its stored copy, which holds `step-start` and workspace data parts the stream never sends, so the stream's part indexes no longer matched what was on screen; and anything the reply wrote while the tab was away was simply missing. Every stream opens on a `display_state_changed` snapshot whose `currentMessage` is the row in flight, laid out the way the stream indexes it; the transcript now redraws that row from the snapshot whenever what is on screen has drifted from it or fallen behind it, and leaves it alone otherwise. ### Behavior changed a reply that started while the tab was away calls another tool ├─ **was** — that call drawn twice, React warns about a duplicate key └─ **now** — each call once, in order a reply already streaming when you left keeps going while you are away ├─ **was** — the calls it made while you were away never show up └─ **now** — they show up as soon as the tab is back a reply writes text while you are away ├─ **was** — the words written while away are missing, the next words land after the old text └─ **now** — the full text opening a thread, or navigating back to it, while a reply is in flight ├─ **was** — the next call drawn twice └─ **now** — each call once ### Decisions - **heal on every running snapshot, not only a stream's first** — keeps the fix in the reducer, no flag threaded through three hooks; a matching snapshot returns the same state, so no re-render - **"caught up" uses the rule the window adoption already uses** — text must hold the live prefix, a call must not lag a live result, other parts must match; a call already settled from storage never forces a redraw - **a snapshot of another thread's reply is ignored** — the session's stream can still be on that thread while the route switches ### Not verified - [ ] the fix in a real browser against a running session — reproduced and checked through MSW only - [ ] what aborted the run in the report — the kickoff block that repeats in the screenshot is the dispatcher's retry of that aborted run, stored twice; this PR does not touch it --- > █████████████████ **tests** `+337` — 85% of the additions > ███ **source** `+61` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> **ELI5:** When a chat tab comes back to a reply that is still running, tool steps could show up twice or go missing. This change redraws the running reply from the server's latest snapshot when the on-screen parts no longer match the live stream. If they match, it leaves the reply alone. ## Summary This PR changes how the Factory transcript handles an assistant reply that is still running when a user returns to a session, opens it mid-run, or navigates back to it. It adds handling for `display_state_changed` events and adds MSW tests for these cases. ### Changes **`mastracode/factory-ui/src/ui/domains/chat/services/transcript.ts` (+49/−12)** - `applyEvent` handles `display_state_changed` by calling `followLiveRow(state, event.displayState, viewerId)`. - `followLiveRow` returns the state unchanged when: - `isRunning` is false, or - `currentMessage` is missing or is not an assistant message, or - both `currentMessage.threadId` and `state.threadId` are nonempty and differ. - Otherwise, it finds the transcript entry whose `id` or `message.id` matches the live message ID. - If the entry already follows the stream (per `followsStream`), the state is unchanged. - If not, it calls `upsertMessage` with the live message. The entry keeps its `streaming` flag when that flag is `true`. - `followsStream` maps each displayed part to its stream index. The index comes from `sourcePartIndexes`, or from the part's position when `sourcePartIndexes` is absent. It returns true only when: - every live part is either covered by the displayed part at its index (checked with `partCovers`), or is a tool call listed in `toolCallIdsDrawnElsewhere`, and - every displayed part whose stream index falls outside the live message is a `tool-invocation` part. - `windowCopyCovers` now delegates its per-part comparison to a new helper, `partCovers(copy, part)`. The comparison logic is unchanged. The length check that rejects shorter persisted copies already existed. **`mastracode/factory-ui/src/ui/pages/__tests__/ThreadPageRunInFlight.msw.test.tsx` (+337)** - Adds an MSW streaming harness and a `describe` block for `ThreadPage` joining a run in flight. The block has five tests: 1. Each call is drawn once when the tab returns to a reply that began while it was away. 2. Calls that a streaming reply made while the tab was away are shown. 3. Each call is drawn once when the thread opens on a reply in flight. 4. Words that a reply wrote while the tab was away are kept. 5. A reply in flight on another thread in the session is left out. ### Public API No exported or public declarations change. ### Scope and limits - Stored message copies can contain parts that the stream does not send, such as `step-start` and workspace data parts. Stream indexes count only streamed parts. - The author states that validation used MSW only. The fix was not verified in a real browser against a running session. - The repeated kickoff block, which the author attributes to a dispatcher retry of an aborted run, is not addressed by this PR. <!-- end of auto-generated comment: release notes by coderabbit.ai --> |
||
|
|
49de7780aa |
fix(convex): apply every operator in a vector filter field condition (#30469) | ||
|
|
20a1a404fd |
fix(pinecone): keep other filter conditions next to $all (#30468) | ||
|
|
e8ef0c928f |
fix(factory-ui): tidy sidebar actions, the locked model picker and branch copying (#30471)
**─────── TLDR ───────**
> Five small fixes to controls in Factory's sidebar, composer and
session panel.
Four of them had their own styling instead of reusing the control beside
them. They reuse it now, and the two components that only existed for
the locked model control are gone. The fifth lets a card's description
show more before you expand it.
### Behavior changed
Hovering a board row in the sidebar
├─ **was** — the configure link was a ghost icon button with
its own hover reveal
└─ **now** — the same row action as every other sidebar row
The sidebar command header
├─ **was** — its buttons stopped 6px short of the nav rows'
right edge
└─ **now** — flush with the rows' right edge
Steering a teammate's session, the composer's model control
├─ **was** — a separate model + thinking button pair, styled
unlike the picker
└─ **now** — the usual picker trigger, disabled; hover says
who can change it
Copying a session's branch in the workspace panel
├─ **was** — a separate copy icon button after the branch
name
└─ **now** — click the branch icon or name; a copy icon
shows on hover
A card's description in the session panel overview
├─ **was** — clipped at 72px, with Show more on its own row
below
└─ **now** — clipped at 100px, Show more floats centered
over the fade
### Decisions
- **copy icon keeps a reserved slot at the end of the name** —
overlaying it would hide the end of a truncated branch; one class away
- **no tooltip on the branch button** — the hover icon and the toast
already say it copies; a truncated name is no longer readable on hover
- **`unavailableReason` is a minor bump** — new optional prop, same name
and role as `ThinkingLevelPicker`'s
### Shape changed
| | | |
|---|---|---|
| **−** | `LockedModelButton` | the locked state is now the shared
picker, disabled |
| **−** | `ModelThinkingGroup` | the thinking level now lives in the
disabled trigger's accessible name |
| **~** | `Button` rendered as a link | drops `type`, the configure link
was rendering `<a type="button">` |
new on `@mastra/playground-ui`
`ModelPicker` `unavailableReason?: string`
One test in `ThreadPageTeammateSession` ("says a teammate when the owner
has no profile") fails locally on `main` too when the whole file runs,
and passes alone. `EmptyThreadState` shows the owner's `userId` as the
resource ID. I left it out of this PR.
### Not verified
- [ ] the five changes in a running browser; the layout is from reading
the classes
---
> ██████████████████ **source** `+160 −105` — net +55, two components
deleted
> ███ **changeset** `+21`
> █ **tests** `+12 −5`
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->
**ELI5:** This change fixes several small Factory UI details. Sidebar
buttons line up with their rows, a locked model shows a disabled picker
with a reason tooltip, and a session branch copies when clicked. Session
descriptions also show more text before they are clipped.
## Overview
The change updates 15 files. It adds 193 lines and removes 110. It
changes two packages:
- `@mastra/playground-ui`: adds the `unavailableReason` prop to
`ModelPicker`, changes `Button` link rendering, and adjusts sidebar
command-header padding.
- `mastracode/factory-ui`: removes two session model-status components
and updates the board, workspace, session-description, and model-status
UI.
## Changes
### Playground UI package
- **`ModelPicker`
(`packages/playground-ui/src/domains/llm/model-picker.tsx`):** Adds
optional `unavailableReason?: string` to `ModelPickerProps`. When set,
the trigger renders disabled and shows the reason in a tooltip.
Otherwise, the popover or drawer picker renders as before.
- **`Button`
(`packages/playground-ui/src/ds/components/Button/Button.tsx`):** When a
button renders as a link, the cloned element sets `type` to `undefined`.
Link-rendered buttons no longer put `type` on the anchor. This allows
`Sidebar.NavAction` links to render a valid `<a>`.
- **`SidebarCommandHeader`
(`packages/playground-ui/src/ds/components/Sidebar/header/sidebar-command-header.tsx`):**
Uses `pr-0.5` instead of `pr-2` when the sidebar is not collapsed. The
collapsed padding stays `px-3`.
- **Changesets:** A minor changeset documents `unavailableReason`. A
patch changeset documents the `Sidebar.CommandHeader` alignment and the
`Button` link fix.
### Factory UI: model status
- **Removed:** `LockedModelButton.tsx` and `ModelThinkingGroup.tsx`.
- **`ModelPicker.tsx`:** `ModelMenuProps` accepts `unavailableReason?:
string`, and `ModelMenu` passes it to the shared picker. A new
`LockedModelMenu` renders the session owner's credential and the shared
model menu. Its trigger is disabled and shows the locked reason. Its
accessible label includes the thinking summary. When a session has a
locked model and a selected model ID, `ModelPicker` uses this menu. The
regular menu reuses the shared trigger content.
- **`SessionThinkingSettings.tsx` and `useSessionThinking.ts`:**
`useSessionThinking` returns a `summary` string. The summary is
`loading` or `unavailable` for those states. Otherwise, it is the label
that matches the effective level, or the level value if no label
matches. `SessionThinkingSettings` uses this summary in the group's
accessible label.
### Factory UI: board and sessions
- **`FactorySection.tsx`:** Board configuration actions use
`Sidebar.NavAction` instead of `Button`. The hover and focus group
selectors are updated. `FactoryLink` no longer adds the `group/board`
class when an action is present.
- **`CardDescription.tsx`:** Raises the collapsed height cap from 4.5rem
to 6.25rem. The description container is centered. The collapsed mask
starts at 50% instead of 30%. The "Show more" / "Show less" button
changes from `ghost` to `default` styling. While collapsed, the button
sits over the bottom center of the description. When expanded, that
positioning is removed.
### Factory UI: workspace branch
- **`WorkspaceSection.tsx`:** Replaces `CopyButton` with a local
`BranchCopyButton`. Clicking the branch icon or name copies the branch
name. The button shows a checkmark after copying. The copy icon appears
on hover or keyboard focus. The loading and unavailable states are
unchanged.
## Tests
- **`WorkspaceFiles.msw.test.tsx`:** The focus assertion in "opens the
overview immediately" now expects the `Copy branch factory/issue-1`
button instead of `Copy branch name`.
- **`ThreadPageTeammateSession.msw.test.tsx`:** The disabled model
button's accessible name now includes the thinking level. The test
checks that the session owner's OpenAI credential is shown. It keeps the
locked-reason tooltip check and asserts that clicking the model button
does not open a dialog. It no longer asserts that the thinking-level
control is disabled.
## Known issues and limits
- The author reports that the test "says a teammate when the owner has
no profile" fails when the full `ThreadPageTeammateSession` file runs on
`main`. It passes when run alone. This PR does not address that failure.
- The author did not verify the five UI changes in a running browser.
- CI and test results: not available.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
|
||
|
|
7da6593acb |
ci(test-tiers): let the daily update finish (#30467) | ||
|
|
9b9240047b |
feat(factory-ui): add a stage bar, dock the session panel, and find any workspace file (#30388)
**─────── TLDR ───────**
> Card session pages now show the card's stage in the header and its
links, changes and files in a panel docked beside the conversation.
Before, a review session listed its pull requests twice, and each
surface judged a pull request's status its own way. Now each fact has
one home, and the panel gives way before the conversation does.
### Behavior changed
a card session's header
├─ **was** — a breadcrumb: board, card, then the session's
context
└─ **now** — a stage bar: arrows move the card, or say why
they can't
the session panel as the window narrows
├─ **was** — under the header, the conversation squeezed
beside it
└─ **now** — beside the header; narrows, then folds in step
with the sidebar
Go to file in a session
├─ **was** — no search: a file was reached by opening its
folders one by one
└─ **now** — typing a name finds any workspace file,
multi-repo roots included, changed first
a pull request's status icon on the board, in the sidebar and the panel
├─ **was** — each surface read the state its own way
└─ **now** — one rule: merged sticks, a close holds until
the card reopens
a pull request closed, then reopened
├─ **was** — on GitHub every card holding it stayed closed;
on GitLab, its own card
└─ **now** — every card that holds it reads open again
### Shape changed
| | | |
|---|---|---|
| **−** | `WorkspaceOverview`, `WorkspaceFilesSurface` | replaced by
`WorkspaceSection` and the docked card |
| **−** | `FactoryReviewPullRequestLinks`, `PullRequestLinks` | the
links live in the panel overview |
| **−** | `GlobalSearchButton` | search lives in the sidebar |
| **−** | `useWorkspacePullRequestStatuses` | its 5-second poll goes;
`useSessionPullRequestSubscriptions` reads on the feed |
| **~** | `usePullRequestSubscriptions` | split into
`useThreadSubscriptions` and `useRefreshThreadSubscriptions` |
new surface the panel relies on
`GET /web/workspace/files?workspacePath=`
returns `{ workspacePath, available, paths, truncated }` · `updatedAt`
on GitHub and GitLab subscriptions · `CodeDiff` paints on the card
surface, Studio included · the dock is an `aside` landmark named Session
panel
### Decisions
- **no breadcrumb** — the sidebar, panel and stage bar each name one
part; one component to restore it
- **search only in the sidebar, phones included** — the header button
duplicated it; Cmd/Ctrl+K still opens it
- **the client still picks between card and subscription state** —
either can lag today; I move that to the server next
### Tradeoff
The sidebar stops asking for each visible session's pull request status
every 5 seconds. The board's live feed now triggers that read, and a
re-read every 60 seconds is the floor. For ten visible sessions with an
open pull request and nothing happening, that is about 10 reads a minute
where main made 120 (computed from the intervals, not measured). A busy
board refreshes at most every 5 seconds, so it never reads more often
than main's poll, and like that poll it re-reads only a pull request
whose subscription is open. The price: a status that changes without a
card write can show up to 60 seconds late, against 5 on main. With the
stream down, it reads every 5 seconds as before.
### Not verified
- [ ] the panel folding and unfolding in Safari and Firefox — checked in
Chromium only
- [ ] the file index on busybox sandboxes — its script relies on `grep
-z` and `xargs -0`
- [ ] a pull request reopened on a real GitHub or GitLab repository —
the reopen sync ran against test storage only
- [ ] the file index refusing a symlinked checkout on a Linux sandbox —
it ran on a macOS host only, and a single-repository workdir that is
itself a symlink is not checked
- [ ] the `mastra-studio-preview` build on Vercel — it fails generating
`@mastra/connect` provider docs (`oxfmt-mdx` not found), in files this
PR does not touch
- [ ] `CodeDiff` in Studio's memory observations — it shares the
component, and I only looked at it in Factory
- [ ] a sidebar toggle that leaves the conversation within 10px of the
dock threshold — the fold starts about 70ms after the sidebar there
---
> ██████████████████ **ui source** `+3583 −1446`
> █████████████ **ui tests** `+2586 −611` — with e2e and server tests,
49% of the additions
> ████ **e2e** `+777 −2` — a 556-line heavy-session fixture
> ██ **server tests** `+401 −22`
> ██ **server source** `+352 −16` — the file index route and the reopen
sync on GitHub and GitLab
> █ **changesets** `+46`
> █ **design system** `+4` — `CodeDiff` on the card surface
---------
Co-authored-by: Damien Schneider <damienschneider@damiens-MacBook-Pro.local>
Co-authored-by: Damien Schneider <damienschneider@mac.lan>
|
||
|
|
a1c11c5b11 |
chore(deps): update better-auth monorepo to v1.7.22 (#30464)
This PR contains the following updates: | Package | Type | Update | Change | Pending | |---|---|---|---|---| | [@better-auth/drizzle-adapter@<1.7.7](https://www.better-auth.com/docs/adapters/drizzle) ([source](https://redirect.github.com/better-auth/better-auth/tree/HEAD/packages/drizzle-adapter)) | pnpm-workspace.overrides | patch | [`1.7.18` → `1.7.22`](https://renovatebot.com/diffs/npm/@better-auth%2fdrizzle-adapter/1.7.18/1.7.22) | `1.7.25` (+2) | | [better-auth](https://better-auth.com) ([source](https://redirect.github.com/better-auth/better-auth/tree/HEAD/packages/better-auth)) | pnpm-workspace.overrides | patch | [`^1.7.18` → `^1.7.22`](https://renovatebot.com/diffs/npm/better-auth/1.7.18/1.7.22) | `1.7.25` (+2) | | [better-auth](https://better-auth.com) ([source](https://redirect.github.com/better-auth/better-auth/tree/HEAD/packages/better-auth)) | dependencies | patch | [`^1.7.18` → `^1.7.22`](https://renovatebot.com/diffs/npm/better-auth/1.7.18/1.7.22) | `1.7.25` (+2) | --- > [!WARNING] > Some dependencies could not be looked up. Check the [Dependency Dashboard](../issues/9505) for more information. --- ### Release Notes <details> <summary>better-auth/better-auth (@​better-auth/drizzle-adapter@<1.7.7)</summary> ### [`v1.7.22`](https://redirect.github.com/better-auth/better-auth/blob/HEAD/packages/drizzle-adapter/CHANGELOG.md#1722) [Compare Source](https://redirect.github.com/better-auth/better-auth/compare/v1.7.21...v1.7.22) ##### Patch Changes - [#​12333](https://redirect.github.com/better-auth/better-auth/pull/12333) [`6536174`]( |
||
|
|
536faa6508 |
fix(mongodb): retire older live observational memory records when startup races a rollover (#30452)
MongoDB's startup cleanup could leave an extra observational memory record live. At startup, the store finds threads that have more than one live record (older adapter versions never marked replaced records) and retires all but the current one. A rollover first marks the current record as replaced, then inserts the new one. If startup cleanup checked in between, the thread showed only one live record, the older one, and was skipped. Once the new record landed, both were live. Reads still picked the right record, but writes aimed at the older id still landed on it until the next startup. Startup cleanup now also counts the record being rolled over, so the thread is processed, the rollover is completed and the older record is retired. There's no schema or API change. ## Test plan - New test in `om-lifecycle-concurrency.test.ts` that pins the race: the rollover marks the record just before cleanup's check and inserts the new one just after. With the old code it fails 10/10 with two live records; with the fix it passes. - The existing randomized race test (25 races per run) passes 50/50 runs with the fix. The window is rare locally: 0 of 50 runs failed on main. - The observational memory lifecycle tests pass 26/26 against real MongoDB 7. Typecheck, lint and formatting are clean. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ELI5: When the database starts, it cleans up old memory records. A timing bug could leave an old record active next to its replacement. This change makes startup cleanup count the record that is being replaced, so the old record gets retired. ## Summary This change fixes a MongoDB startup-cleanup race in observational memory. Cleanup could skip a thread when it ran after a record was fenced for rollover but before its successor was inserted. The older record then stayed live until the next startup. ## Changes - `stores/mongodb/src/storage/domains/memory/index.ts`: The duplicate-live-document aggregation in `#maintainSupersededBy` now matches documents where `supersededBy` is null or `pendingSuccessor` exists. A fenced head therefore counts as live during grouping. The code comment explains the window. - `.changeset/quiet-owls-roll.md`: Adds a patch changeset for `@mastra/mongodb`. - `stores/mongodb/src/storage/domains/memory/om-lifecycle-concurrency.test.ts`: Adds a deterministic test. It fences the head while the backfill groups live documents. It then checks that the head has `generationCount` 2 and is the only live record. ## Diff scope Three files changed, with 47 lines added and 1 removed. ## Verification The PR description reports these results. I did not run them. - The deterministic test passes with the fix and fails 10/10 on the old code. - The randomized race test passed 50/50 with the fix. None of 50 runs failed on main. - Observational memory lifecycle tests passed 26/26 against MongoDB 7. - Typecheck, lint, and formatting were reported clean. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Co-authored-by: remy-builder[bot] <324360501+remy-builder[bot]@users.noreply.github.com> |
||
|
|
12f79652cf |
feat(playground-ui): pick every remaining interface icon from Central Icons (#30438) | ||
|
|
1137e804e9 |
ci(test-tiers): retry a connection GitHub closes before responding (#30453) | ||
|
|
adc0a70bf8 |
fix(memory, couchbase): check semantic recall scope in Memory and warn on ignored Couchbase filters (#30446) | ||
|
|
d1d736db29 |
test(memory): pin attachment token counts in the #29851 image test (#30415) | ||
|
|
c8a35ac624 |
fix(memory): keep Observational Memory local when the gateway has no memory API (#30414)
> Opened by @abhiaiyer91 > Opened by @factory-project:7d5175c3-3a20-42ac-aba9-756f183136f4 ## Summary Keep Observational Memory local for agents using `mastra/<provider>/<model>` with gateway organization keys (`msk-gateway-*` and `mskv2_*`), because those keys do not provide gateway-managed memory. Gateway project keys (`msk_*`) continue to use gateway-managed memory. Finish an open local turn before switching to gateway-managed memory. Credential ownership checks report local memory only for models that are not on the Mastra gateway. A credential the gateway cannot resolve — including one it reports as missing — is thrown instead of read as local ownership: guessing local ownership can cause both the gateway and local store to persist the same thread, because the model call resolves the same credential again. The Observational Memory processor also propagates ownership-check errors. Older models that cannot report gateway memory ownership retain their previous behavior. Docs explain the gateway-key distinction and the paired `@mastra/core` and `@mastra/memory` upgrade. Project keys routed BYOK or with gateway memory disabled remain outside this change's scope. ## Verification (head ` |
||
|
|
c51c601813 |
ci(test-tiers): retry gh api calls on transient GitHub errors (#30451)
## What The daily test-tier updater (`scripts/test-tiers/update.mjs`) calls `gh api` for every failed PR run, job log and compare in its 14-day window. The helper made each call exactly once, so a single GitHub server error ended the whole update. The scheduled run has failed this way on both days since tiers went live, most recently on one `HTTP 502`. This wraps every `gh api` call in a retry: - Retries GitHub 5xx and 429 responses, rate-limit errors, and dropped or timed-out connections, waiting 5, 20 and 60 seconds between tries. - Fails at once, as before, on errors that won't change on retry: 404, 422, permission 403, unknown flags. - Repeats a paginated call from the start, so pages from two attempts are never mixed. - After the last try it throws the original error. The run fails and writes nothing, as it does today. ## Testing - New `node:test` cases drive the retry with a stand-in `gh` executable that fails like the real one: recovers after one 502, gives up after four 503s, doesn't retry a 404 or an unknown flag, and classifies a table of transient and permanent errors. - End to end with a fake `gh` that returns 502 on the first call: before, `update.mjs daily` exits 1 after one call and leaves the tier file unchanged. After, it retries, exits 0 and updates the tier file. - `node --test scripts/test-tiers/*.test.mjs`: 53 passed. oxfmt and oxlint clean. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> **ELI5:** The daily job that updates test tiers calls GitHub. GitHub sometimes fails for a short time, and the job then stopped. This change makes the job wait and try again for those short failures. Errors that do not go away on their own still stop the job at once. ## Summary This PR adds retry logic to each `gh api` call in `scripts/test-tiers/update.mjs`. ### Changes in `scripts/test-tiers/update.mjs` (+32/-1) - `isTransientGhError(error)` classifies a failed call as retryable. It checks `stderr` and `message` for these indicators: - HTTP 5xx and HTTP 429 - rate limit - timeout (`timed out`, `timeout`, `time out`) - `ETIMEDOUT`, `ECONNRESET`, `ECONNREFUSED`, `EAI_AGAIN` - `connection reset`, `unexpected EOF` - `GH_RETRY_DELAYS_MS` is `[5_000, 20_000, 60_000]`. - `retryTransient(fn, delays, sleep)` calls `fn`. If `fn` throws a transient error, it logs a warning, waits, and calls `fn` again. It allows one initial call and three retries. After the last retry, it throws the original error. A non-transient error throws at once. - The wait uses `Atomics.wait`, so it blocks the process synchronously. - The `gh` wrapper runs each `gh api` call through `retryTransient`. A `--paginate` call restarts from the first page on each retry. This prevents mixing pages from two attempts. Errors such as 404, 422, 403 permission errors, and unknown flags do not match the classifier. These errors fail immediately. ### Tests - `scripts/test-tiers/update.test.mjs` (+89/-0, per the change summary) adds tests for retry timing, retry exhaustion, immediate failure for permanent errors, and the transient and permanent classifications. I did not inspect this file. - The PR author reports these results. I did not run them: - An end-to-end run with a fake `gh` that returns 502 on the first call now retries, exits with status 0, and updates the tier file. Before the change, it exited with status 1 and left the file unchanged. - `node --test scripts/test-tiers/*.test.mjs` passed 53 tests. - oxfmt and oxlint reported no issues. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Co-authored-by: remy-builder[bot] <324360501+remy-builder[bot]@users.noreply.github.com> |
||
|
|
4224ee32d3 |
fix(code-sdk): show plugin signal provider startup failures in the TUI (#30428)
## Summary Plugin signal providers start while Mastra Code boots, before the TUI subscribes to plugin errors. A provider whose `start()` failed then reached only `console.warn`, printed before the UI took over the terminal, so the user never saw it. Reload failures already show in the session (#30412); startup failures now do too. - `PluginManager` keeps the most recent errors (up to 20) reported while nobody listens and hands them to the first `onPluginError` listener when it subscribes. They still go to `console.warn` when reported, so headless embedders keep their trace. Later listeners only receive new errors. - The TUI subscribes once the startup thread is on screen, because rendering it clears notices shown earlier. Errors reported before then are held by the manager. ## Testing - New TUI E2E `plugins-signal-provider-start-failure`: boots with a local plugin whose signal provider's `start()` rejects and waits for the error on screen. It fails without the change. - New `PluginManager` tests: errors reported before anyone listens reach the first listener once, and only the most recent 20 are kept. - Ran `manager`, `signal-lane`, `loader` and SDK `index` tests, the plugin E2E scenarios (start failure, reload failure, hot reload, GitHub poll update, local tool), and `tsc` for `@mastra/code-sdk` and `mastracode`. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> **ELI5:** Some plugins can fail when they start. Before this change, the error only printed in the console, so users could miss it. Now the app keeps those early errors and shows them in the chat screen once the screen is ready. ## Overview This change shows plugin signal provider startup failures in the Mastra Code TUI. A provider can fail before the TUI subscribes to plugin errors. Before this change, those failures appeared only through `console.warn`, which prints before the UI takes over the terminal. ## Changes - **`PluginManager` (`mastracode/sdk/src/plugins/manager.ts`)** - Retains up to 20 plugin errors reported when no listener is subscribed. - Evicts the oldest error when the limit is exceeded. - Delivers the buffered errors to the first listener that subscribes, then clears the buffer. - Sends each error to `console.warn` when it is reported. - Sends later listeners only new errors. - Catches and logs listener exceptions separately, so one failing listener does not stop notification of the others. - **TUI (`mastracode/tui/src/tui/mastra-tui.ts`)** - Moves the plugin error subscription in `init` to after existing messages and tasks render. - Subscribes only when a plugin manager exists and no listener is already registered. - Returns from `init` without subscribing if the TUI stops while the startup thread renders. - Shows each plugin error through `showError`. - Subscribes after rendering because rendering clears earlier notices. Buffered startup errors then reach the listener and appear on screen. - **Tests** - `mastracode/sdk/src/plugins/__tests__/manager.test.ts` adds tests for: - Warning immediately on report. - Queuing the error for the first listener. - Delivering the error once to that listener. - Retaining only the latest 20 errors while no listeners exist. - `mastracode/tui/src/tui/__tests__/mastra-tui-init-stop.test.ts` adds tests for `MastraTUI` init and stop: - Normal init subscribes to plugin errors and starts the update-check timer. `stop()` clears the timer. - If `stop()` runs during startup rendering, init does not subscribe to plugin errors, does not call `checkForUpdate`, and leaves no update-check timer. - `mastracode/tui/e2e/tui/plugins.ts` adds the `pluginsSignalProviderStartFailureScenario` E2E scenario. The scenario creates a local plugin whose signal provider throws `e2e provider start broke` during startup. It waits up to 10 seconds for the startup-failure message in the TUI. - `mastracode/tui/e2e/tui/index.ts` registers the scenario as `plugins-signal-provider-start-failure`. - `mastracode/tui/e2e/tui/types.ts` adds `'plugins-signal-provider-start-failure'` to the `ScenarioName` union. - **Changesets** - `.changeset/plugin-errors-before-listener.md` declares a patch for `@mastra/code-sdk`. - `.changeset/plugin-startup-failure-notice.md` declares a patch for `mastracode`. ## Public API No exported declarations change. The only declaration change is the `ScenarioName` union in the E2E test types. ## Scope - 9 files changed. - 254 lines added and 14 lines removed. ## Validation The PR objectives report these runs. This summary did not rerun them, and no CI results were inspected: - New `PluginManager` tests for first-listener delivery and the 20-error limit. - The `manager`, `signal-lane`, `loader`, and SDK `index` tests. - Plugin E2E scenarios for start failure, reload failure, hot reload, GitHub poll update, and local tool. - `tsc` for `@mastra/code-sdk` and `mastracode`. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: mastracode <284800079+mastra-platform[bot]@users.noreply.github.com> |
||
|
|
b666fdbf03 |
fix(client-js): stop retrying state-changing requests by default (#30434)
> Opened by @factory-project:7d5175c3-3a20-42ac-aba9-756f183136f4 The JavaScript client retried every HTTP method the same way, so a `POST`, `PUT`, `PATCH`, or `DELETE` that hit a server error was silently re-sent up to four times. When the server had already committed the work before failing, that replay duplicated side effects — agent generations, workflow starts, and similar writes. `BaseResource.request()` now resolves retries by method: `GET`, `HEAD`, and `OPTIONS` keep the default of three attempts, while every other method is attempted once unless the caller opts in with an explicit `retries` count on the client or the call. Requests that pass no method keep the previous read behavior. Four observability queries only read server state even though they travel as `POST`, so `aggregateTraces()`, `aggregateSpans()`, `queryTraceThreads()`, and `querySpans()` keep the read default. An explicit `retries` on the client still wins. **Approved** — head ` |
||
|
|
54708eccf8 |
fix(mastracode): stop startup once the TUI is stopped part-way (#30431) | ||
|
|
0e4ccf0c03 |
fix(factory): show checkout-scoped plans in approval cards (#30436)
## Summary - Allow approved `.artifacts` roots inside a repository checkout to be listed and read by the session workspace routes. - Resolve submitted absolute plan paths against the matching checkout root in the approval card, while retaining path and symlink guards. - Cover multi-repository plan reads, unsafe symlink targets, and disabled approval when a plan cannot load. ## Test plan - `cd mastracode/factory && npm exec -- vitest run src/routes/fs.test.ts` (66 passed) - `cd mastracode/factory && npm run check` - `cd mastracode/factory-ui && npm exec -- vitest run src/hooks/__tests__/use-fs.msw.test.tsx src/ui/domains/chat/components/__tests__/SubmitPlanCard.msw.test.tsx` (38 passed) - `cd mastracode/factory-ui && npm run typecheck` - Type-aware Oxlint and Oxfmt checks on changed files Ref #30361 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> **ELI5:** Factory lets a user review a plan before approving it. Before this change, a plan stored inside one code project of a multi-project session could not be opened for that review. This change lets the app open those plans safely, and keeps the safety checks against unsafe file links and ignored files. ## Summary This change lets Factory show plan previews for plans inside a repository checkout in a multi-repository session. It has three parts: - **Server routes (`mastracode/factory/src/routes/fs.ts`):** - Rendered-root approval also accepts a repository-specific `<repo-prefix>.artifacts` root when the session has repositories. - Session rendered-path listing resolves the sandbox layout before it validates the root. - Session file reads treat paths under a repository's `.artifacts` directory as trusted. Other paths still go through ignored-file checks. - **Path handling (`mastracode/factory-ui/src/hooks/use-fs.ts`):** - `isPlanReadablePath` accepts `.artifacts/...` paths at the workspace root or under one checkout directory prefix. It rejects paths that contain `..`, backslashes, or NUL characters. - `normalizePlanPath` takes a new optional `root` argument. The default is `.artifacts`. - `normalizePlanPath` returns relative paths unchanged. It rewrites absolute paths under `rootPath` to the given root. It returns `undefined` for other relative paths, malformed input, absolute paths when the root is missing, and absolute paths outside `rootPath`. - The `planFileUrl` comment now describes the session file route as supporting `.artifacts` paths at the workspace root or inside a repository checkout. - **Approval card (`SubmitPlanCard.tsx`):** - When an absolute plan path cannot be normalized against the workspace `.artifacts` root, the card lists the checkout-specific `.artifacts` directory. It derives the checkout name from the `/<checkout>/.artifacts/<file>` path pattern. - The card uses that listing's root to normalize the path. Its pending state counts toward loading. - Loading no longer requires the initial listing to be error-free. ## Tests and changeset - `use-fs.msw.test.tsx` adds `normalizePlanPath` cases. Checkout-relative `.artifacts` paths pass through when the rendered root is unknown. An absolute path under the checkout normalizes to the checkout-relative path when the root and checkout prefix are given. - `SubmitPlanCard.msw.test.tsx` adds a test for a plan submitted from a checkout. It checks that the rendered-list lookup includes `mastra/.artifacts`. It checks that the plan is fetched with the workspace path and the normalized relative path. It checks that rejecting the plan sends the original absolute path, the title, and the body. - `fs.test.ts` adds live-session tests. They check that listing and reading `mastra/.artifacts` returns the plan file. They check that an unrelated repository's rendered root is rejected. They check that an artifact symlink to the checkout's `.env` file is refused. They also check that a symlinked checkout is unavailable when listing rendered artifacts. - `.changeset/factory-checkout-plan-preview.md` adds a patch changeset for `@mastra/factory`. It declares no public API changes. ## Public API No exported declarations are changed in the raw summary, except that `normalizePlanPath` gains an optional third parameter (`root = '.artifacts'`). Existing two-argument calls keep their behavior. ## Scope 7 files changed, +144 / −30 lines. ## Verification The author reports these results. They were not re-run against the current head for this summary: - `mastracode/factory`: `fs.test.ts`, 66 passed. `npm run check` was run. - `mastracode/factory-ui`: the two MSW test files, 38 passed. `npm run typecheck` was run. - Type-aware Oxlint and Oxfmt checks on the changed files. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: mastra-platform[bot] <mastra-platform[bot]@users.noreply.github.com> Co-authored-by: mastra-platform[bot] <284800079+mastra-platform[bot]@users.noreply.github.com> |
||
|
|
cac6299ae0 |
feat(playground-ui): reveal the mobile sidebar from under the page (#30440)
**─────── TLDR ───────** > On phones, the page now slides aside to reveal the sidebar underneath it. `takeover`, the default mobile mode of `Sidebar`, was a drawer covering the page. Now the `AppShell` content is the layer that moves, and the sidebar stays fixed below it, scaling up from 95% as it shows. It all lives in playground-ui, so Studio and Factory get it through `AppShell` with no change on their side. ### Behavior changed Opening navigation on a phone ├─ **was** — a drawer slid over the page, with a floating close button └─ **now** — the page slides right and the sidebar shows underneath Swiping the page ├─ **was** — only the open drawer could be swiped shut └─ **now** — right opens, left closes, the page tracks the finger both ways Letting go mid-swipe └─ **new** — finishes the way you last moved; under 40px it springs back Navigation open ├─ **new** — a tinted, framed strip of page: tap it, swipe it, or press <kbd>Esc</kbd> └─ **new** — <kbd>Tab</kbd> and <kbd>Shift</kbd>+<kbd>Tab</kbd> cycle inside the sidebar; the page and toasts are out of reach until it closes Resizing the sidebar on desktop └─ **unchanged** — same widths; the live value is now set on the panel ### Decisions - **drag progress in non-inherited properties on the three moving layers** — a scope variable restyled the whole page per touchmove, 2.16ms against 0.21ms - **live `--sidebar-width` on the panel, not the scope** — same restyle cost per desktop resize frame; every reader in this repo sits inside the panel - **past 40px, release follows the last direction moved, not "past halfway or a fast flick"** — halfway sent a slow close bouncing back open; one line in `release` to revert - **the open reveal makes everything outside itself inert, not `AppShell` its own content** — also covers toasts and portals mounted outside `AppShell`, and removing the sidebar while it's open can't leave the page stuck inert ### Watch > [!WARNING] > The gesture only moves elements marked as reveal layers, and only `AppShell` marks the page. <mark>A `takeover` sidebar outside `AppShell` has no page to slide</mark>: wrap it in `AppShell` or pass `mobileMode="drawer"`, like the agent builder does. The changeset spells this out. ### Not verified - [ ] real iOS Safari and Android Chrome, including iOS's edge back-swipe against swipe-to-open: checked only in Chromium and WebKit with synthetic touches, and in DevTools touch emulation - [ ] the platform app: not in this repo, so I couldn't check it renders the sidebar inside `AppShell` - [ ] one emulator run right after page load lost `touchend` and left the page mid-drag; two reruns didn't reproduce it --- > ███████████████████ **source** `+493 −42` — half of it the gesture hook > ████████████ **tests** `+322 −7` > █ **changeset** `+21` > █ **stories** `+10 −2` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> **ELI5:** On a phone, the menu now slides out from under the page, like pulling a drawer out from behind a curtain. You swipe or tap to open it, and you swipe, tap, or press Escape to close it. ## Summary This PR changes the default mobile and tablet `takeover` sidebar in `@mastra/playground-ui`. The `AppShell` page content slides aside to reveal the sidebar underneath. The reveal uses a scale and fade effect. - Swipe right opens the sidebar. Swipe left closes it. - On release, movement beyond 40px follows the last gesture direction. Shorter movements spring back to the starting state. - When open, a strip of the page stays visible. Tapping or swiping the strip closes the sidebar. Escape also closes it. - While open, focus stays in the sidebar. Tab and Shift+Tab cycle between the sidebar's first control and its close strip. The page and toasts are set to `inert` until the sidebar closes. - Desktop sidebar widths do not change. The live `--sidebar-width` value is set on the sidebar panel. - A `takeover` sidebar outside `AppShell` has no page to slide. Wrap the page in `AppShell`, or set `mobileMode="drawer"` on the sidebar. ## Changes by file - **`.changeset/rich-bats-hide.md`**: Adds a minor release note for `@mastra/playground-ui`. It describes the page-sliding and swipe behavior, focus handling, gesture exclusions, reduced-motion behavior, and the `AppShell` requirement. - **`sidebar-reveal.tsx`** (new): Adds the `SidebarReveal` component. It applies reveal styling, connects gestures to drawer state, and makes the panel a modal dialog while open. It focuses the panel on open and handles Escape. On cleanup, it removes inert marks and restores focus to the mobile trigger if focus was lost. While closed, the drawer is inert and hidden from accessibility APIs. A scrim click closes the drawer. - **`use-reveal-gesture.ts`** (new): Adds `useRevealGesture` and the exported `REVEAL_EASE` constant. The hook tracks one touch. It claims horizontal movement after an 8px threshold. It ignores gestures owned by a nested horizontal swipe. Release duration is velocity-matched and clamped to 120–400ms. Cancelled touches use zero velocity. Cleanup removes listeners and temporary CSS variables. - **`sidebar-reveal.css`** (new): Defines non-inherited custom properties for drag, duration, progress, and motion. Progress rests at 0 when closed and at 1 when open. The settle duration is 320ms closed and 400ms open. Reduced-motion preferences set layer motion to 0ms. The panel scales and fades, and the scrim translates and fades. When a mobile sidebar is present, the page is clipped, styled, and translated. - **`sidebar-panel.tsx`**: Renders mobile takeover mode through `SidebarReveal`. The mobile drawer always uses drawer mode, fixed drawer sizing, and `px-3` padding. The takeover-specific close button and conditional takeover styling are removed. The desktop panel applies its computed width through `SidebarPanelStyle` and attaches `panelRef`. - **`sidebar-provider.tsx`**: Adds a panel ref and exposes it through context. Writes the live `--sidebar-width` value to the panel, not the scope. Adds `data-sidebar-mobile-open`, set to `'true'` or `'false'` by drawer state. - **`sidebar-context.ts`**: Adds `scopeRef` and `panelRef` to `SidebarContextValue`. - **`sidebar-mobile-trigger.tsx`**: Removes the selector that hid the trigger when `data-sidebar-mobile-present="true"`. The selector for `data-sidebar-mobile="false"` remains. - **`app-shell.tsx`**: Adds `data-sidebar-reveal-layer="page"` to the content wrapper. Slot and layout classes are unchanged. - **`app-shell.css`**: Sets `overflow-x: clip` when a mobile sidebar is present and reveal state is active. - **`app-shell.stories.tsx`**: Adds a Storybook description of the mobile interactions to the `Mobile` story. - **`sidebar-layout.stories.tsx`**: Sets `mobileMode="drawer"` on the `Mobile` story's sidebar. - **`sidebar-reveal.test.tsx`** (new, 313 lines added): Tests opening by a rightward drag past halfway or by a fast flick. Tests that short or reversed drags stay closed. Tests that vertical scrolls and drags in horizontal scrollers do not open the sidebar. Tests closing by leftward swipe or Escape. Tests that Escape in a nested menu closes only that menu. Tests focus restoration, focus cycling, and inert behavior for the page and an outside toast. Tests that removing the sidebar while open leaves the page usable. - **`sidebar-root.test.tsx`**: Adds an `Element.prototype.getAnimations` fallback when the method is missing. The `widthOf` helper reads `--sidebar-width` from the panel. The mobile close test queries the button named "Close navigation menu". ## Public API changes - Added: `SidebarReveal` component. - Added: `useRevealGesture` hook and `REVEAL_EASE` constant. - Changed: `SidebarContextValue` gains `scopeRef` and `panelRef`. - Behavior change: The default mobile `takeover` sidebar slides the page. The previous takeover rendering is removed. ## Testing and verification - The author reports synthetic touch tests in Chromium and WebKit, and DevTools touch emulation. - Real iOS Safari and Android Chrome were not verified. iOS edge back-swipe behavior was not verified. - The platform app was not checked. - One emulator run lost `touchend` after page load and left the page mid-drag. Two reruns did not reproduce it. - CI results for this head: not available. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Damien Schneider <damienschneider@mac.lan> |
||
|
|
a48d697b35 |
feat(e2b): run commands as another OS user, and choose the owner of S3/GCS mounts (#30433)
> Opened by @factory-project:7d5175c3-3a20-42ac-aba9-756f183136f4
## Description
E2B sandboxes ran every agent command as the template's default OS user,
and S3/GCS FUSE mounts were always owned by that same user. That user
has to be privileged — mounting FUSE filesystems needs `sudo`, and the
staged s3fs credentials file (`/tmp/.passwd-s3fs-*`, mode 600) is only
readable by it — so an agent running shell commands as that user could
read bucket credentials or become root.
Two opt-in options fix that:
- **`E2BSandbox({ user })`** — every command the sandbox runs on the
agent's behalf runs as that OS user: `executeCommand`, background
processes, and the tree-kill script that takes their descendants down
(another user cannot signal them). Mounting still runs as the default
user, because it needs `sudo`.
- **`S3Filesystem({ owner })` / `GCSFilesystem({ owner })`** — `{ uid,
gid }` naming the owner of the files inside the FUSE mount, replacing
the `id -u && id -g` probe. This is what gives the command user read and
write access to the mount.
Both are additive and default to today's behavior. `owner` lives on the
filesystem options rather than the sandbox because the mount config is
produced by `filesystem.getMountConfig()`, which is what E2B's `mount()`
reads; `E2BSandboxOptions.user` reaches the provider through the shared
`CommandsApiProcessManager`, and the key is left off entirely when unset
so the SDK's own default user still applies. `owner` is validated as
non-negative integers before it is interpolated into a mount command.
The `user` must already exist in the sandbox template.
## Related issue(s)
Fixes #30349
## Type of change
- [ ] Bug fix (non-breaking change that fixes an issue)
- [x] New feature (non-breaking change that adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [x] Documentation update
- [ ] Code refactoring
- [ ] Performance improvement
- [ ] Test update
## Checklist
- [x] I have linked the related issue(s) in the description above
- [x] I have made corresponding changes to the documentation (if
applicable)
- [ ] I have addressed all Coderabbit comments on this PR
## Test plan
All checks run on this head (`dec4e6ec`):
- `packages/_internals/workspace`: 160 tests, including a new test that
the spawn and the kill script both carry the configured user, and one
that the key stays unset without a user.
- `@mastra/e2b` unit suite: 367 passed, 9 skipped (`validateOwner`
cases; S3 and GCS mounts using an explicit owner skip the `id -u && id
-g` probe and emit `uid=`/`gid=` and `--uid=`/`--gid=`; mounts without
an owner still probe).
- `@mastra/s3` 150 passed, `@mastra/gcs` 91 passed, including
`getMountConfig()` carrying `owner` when set and omitting it when not.
- Typecheck (e2b, s3, gcs, platform-workspace) clean; lint 0 warnings /
0 errors and builds clean for e2b, s3 and gcs.
- Each new test fails against the base source without the change (10 in
e2b, 1 internal, 1 s3, 1 gcs).
- Integration coverage: `index.integration.test.ts` gained a case
asserting an explicit owner yields `1234:1234` from `stat -c %u:%g`. It
needs `E2B_API_KEY`, so it does not run in CI — a manual run on a real
sandbox is the remaining gap.
## Follow-ups (not part of this change)
1. File-API writes (`sandbox.files`, `FilesApiFilesystem`) and code-mode
staging under `/home/user` still run as the default user, so with `user`
set, files written through file tools are not owned by the command user.
2. `E2BProviderConfig.configSchema` does not list `user` (it already
omits `workingDirectory`, `reattach` and `lifecycle`), so the Studio
provider form does not offer it even though the runtime forwards it.
3. `commands.list()` scope relative to the configured user is unverified
without an API key; tracked handles still surface.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->
**ELI5:** Agent commands in an E2B sandbox used to run as the same user
that mounts cloud storage. This PR lets you pick a separate,
less-privileged user for agent commands, and lets you set the file owner
for S3 and GCS mounts. Both options are off by default.
## Summary
This PR adds two opt-in E2B options, as described in issue `#30349`:
- **Command user.** `E2BSandbox({ user })` runs agent commands,
background processes, and descendant cleanup as the named OS user.
Mounting still uses the default user. The user must already exist in the
sandbox template.
- **Mount owner.** `S3Filesystem({ owner })` and `GCSFilesystem({ owner
})` accept `{ uid, gid }`. When set, the mount uses these IDs. When
unset, the existing `id -u && id -g` probe runs.
### Changes by area
- **Workspace process manager**
(`packages/_internals/workspace/src/commands-api-process-manager.ts`):
`CommandsApi.run` and `CommandsApiProcessManagerOptions` accept an
optional `user`. Spawned commands and descendant cleanup in `kill()` use
it.
- **E2B provider** (`workspaces/e2b/src/sandbox/`):
- `index.ts` adds `user?: string` to `E2BSandboxOptions`.
- `process-manager.ts` forwards `user` to the base class.
- `mounts/types.ts` adds `MountOwner` and `validateOwner`. Validation
requires non-negative integers for `uid` and `gid`.
- `mounts/s3.ts` and `mounts/gcs.ts` use a supplied owner. Otherwise,
they probe the default user.
- `index.ts` re-exports `MountOwner`.
- **S3 and GCS filesystems** (`workspaces/s3/src/filesystem/index.ts`,
`workspaces/gcs/src/filesystem/index.ts`): add `MountOwner`, an optional
`owner` option, and a `readonly owner` property. `getMountConfig()`
copies `uid` and `gid` into a plain object only when an owner is set.
This copy also handles owners whose fields are prototype getters. Both
packages re-export `MountOwner`.
- **Docs and changeset:** document both options. The changeset sets
minor releases for `@mastra/e2b`, `@mastra/s3`, and `@mastra/gcs`.
### Tests
- Workspace tests check that a configured user reaches spawned commands
and their kill commands. They also check that an unset user is passed as
`undefined`.
- E2B unit tests check owner validation and mount behavior with and
without an owner.
- S3 and GCS tests check `getMountConfig()` with and without an owner.
They also check that later changes to the input owner do not change the
config.
- An E2B integration test checks that an explicit owner of `1234` mounts
with ownership `1234:1234`. This test requires `E2B_API_KEY` and was not
run in CI.
The author reports passing workspace, E2B, S3, and GCS tests. The author
also reports clean typecheck, lint, and build results. These results are
not tied to a completed CI run on the current head. A manual run against
a real E2B sandbox is outstanding.
### Out of scope (per PR description)
- File-API writes and code-mode staging still use the default user.
- The Studio configuration schema does not expose `user`.
- The scope of `commands.list()` relative to the configured user is not
verified.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: mastra-platform[bot] <mastra-platform[bot]@users.noreply.github.com>
Co-authored-by: mastra-platform[bot] <284800079+mastra-platform[bot]@users.noreply.github.com>
|
||
|
|
82c98f9f1c |
fix(rag): keep long JSON string content when chunking JSON documents (#30407)
> Opened by @factory-project:7d5175c3-3a20-42ac-aba9-756f183136f4
JSON chunking (`MDocument.chunk({ strategy: 'json' })`) silently
discarded most of a long string value whenever the field's serialized
path was longer than 13 characters, or the value contained characters
that JSON escapes. The splitter budgeted a fixed 20-character overhead
regardless of the real field name, and then dropped every piece that
still exceeded `maxSize`. The result was silent data loss with no error,
no warning, and no config that avoided it — a 3000-character value under
a 16-character key kept 120 characters at `maxSize` 500, and a
14-character key at `maxSize` 21 produced zero chunks.
The fix sizes each piece from the value it is about to emit: it measures
the serialized envelope of the candidate piece and its full field path,
cuts only at code-point boundaries so astral characters are never split,
and never discards a completed piece. When a field path alone leaves no
room for a single character, the remainder is emitted as one oversized
chunk instead of being dropped.
**Result:** Approved — `
|
||
|
|
0170d700a4 |
feat(mcp): let MCPServer set maxRequestBodySize for HTTP requests (#30411)
> Opened by @factory-project:7d5175c3-3a20-42ac-aba9-756f183136f4
## Description
Every MCP HTTP request served by a Mastra `MCPServer` was capped at the
MCP SDK's fixed 4 MiB default. A client sending a larger `tools/call`
body received
```json
{"jsonrpc":"2.0","error":{"code":-32000,"message":"Payload Too Large: Request body must not exceed 4194304 bytes"},"id":null}
```
before the tool ever ran, with no way to raise the bound. That breaks
legitimate payloads — for example a Claude connector MCP App intake form
that submits a signed PDF and a photo of an ID in a single `tools/call`.
`MCPServer` now accepts an optional `maxRequestBodySize` (bytes) in its
config, next to `legacy`:
```typescript
const server = new MCPServer({
name: 'intake',
version: '1.0.0',
maxRequestBodySize: 16 * 1024 * 1024,
tools: { submitIntake },
});
```
The option is forwarded to both SDK layers that enforce the cap:
`createMcpHandler(...)` owns the handler's bound, and
`toNodeHandler(...)` owns an adapter-level bound —
`@modelcontextprotocol/node` buffers the Node request stream itself
before the handler sees it, and per its
`ToNodeHandlerOptions.maxRequestBodySize` docs "the adapter's bound
applies first". Passing it to only one layer leaves the other's 4 MiB
default in force.
Leaving the option unset keeps the SDK default of `4194304` (4 MiB), so
existing servers behave exactly as before, and an over-limit body is
still rejected with the same `413` before it is parsed. The option
applies to `startHTTP` only; `stdio` has no request bodies. Documented
in the `MCPServer` configuration table of
`docs/src/content/en/reference/tools/mcp-server.mdx`.
## Test plan
New `packages/mcp/src/server/server-http-body-size.test.ts` drives the
real `startHTTP` path through the shared harness:
- default server rejects a 5 MiB body with `413`, `-32000`, and the
default byte count in the message, without running the tool;
- `maxRequestBodySize: 8 MiB` accepts a 5 MiB body and the tool runs;
- `maxRequestBodySize: 1024` rejects a 2 KiB body with `413` naming the
configured limit;
- a body under the configured limit is accepted.
## Verification
| Category | Command | Result |
| --- | --- | --- |
| Package tests | `pnpm exec vitest run --project unit:packages/mcp
src/server` | ✅ 36 files, 669 passed, 8 skipped |
| Package tests | `pnpm exec vitest run --project unit:packages/mcp
src/client` | ✅ 34 files, 627 passed |
| Type check / build | `pnpm --filter @mastra/mcp build:lib` | ✅ Passed;
emits `maxRequestBodySize?: number` in `dist/server/server.d.ts` |
| Lint | `npx oxlint --type-aware <changed .ts>` | ✅ 0 warnings, 0
errors |
| Format | `npx oxfmt --check <changed .ts>` | ✅ Passed |
| New tests on base code | new tests against the pre-change `server.ts`
| ✅ 2 of 4 fail on base (`expected 413, received 200`), 4 of 4 pass on
head |
| Docs checks | `run-checks.sh --docs
docs/src/content/en/reference/tools/mcp-server.mdx` | ✅ format, remark,
validate pass |
| Public surface | scratch script importing the built `@mastra/mcp` | ✅
default → `413`, raised limit passes the size gate |
| Not run | Vale prose check | ⚠️ binary not installed, so prose was not
linted |
One full-suite run failed on `server-events.test.ts` (stdio events). The
same test also fails at the base commit under the same full-suite load
and passes on re-run and in isolation, so it is a pre-existing flake
rather than a regression; this change does not touch the `serveStdio`
path.
## Follow-ups (non-blocking)
- A non-positive or non-finite `maxRequestBodySize` is not validated at
construction; the SDK's `RangeError` surfaces on the first HTTP request
as a `500`. Constructor-time validation would fail faster.
- The built-in `/api/mcp` endpoint (`server.mcp` / `ServerMCPConfig`)
and adapter-level `MCPOptions` still expose no body-size option; this
change deliberately scopes to a user-instantiated `MCPServer`.
Fixes #30207
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->
ELI5: MCP servers reject requests bigger than 4 MB. This PR lets a
developer set a bigger limit for one server, so large uploads can reach
the tool.
## Summary
This PR adds an optional `maxRequestBodySize` setting to
`MCPServerConfig`. `MCPServer` stores the value and passes it to both
`createMcpHandler(...)` and `toNodeHandler(...)`. When the setting is
unset, the SDK default of 4 MiB (4194304 bytes) applies.
## Changes
- `packages/mcp/src/server/server.ts`: Adds `maxRequestBodySize?:
number` to `MCPServerConfig`. Adds a private readonly field and assigns
it from config. Passes the value to both HTTP handler layers. Adds 12
lines.
- `packages/mcp/src/server/server-http-body-size.test.ts`: Adds 109
lines and 4 test cases:
- A body over the default 4 MiB limit returns `413`, and the tool does
not run.
- A body larger than 4 MiB succeeds when `maxRequestBodySize` raises the
limit.
- A body over a lowered limit returns `413`, and the message includes
the configured limit.
- A body under the configured limit succeeds.
- `docs/src/content/en/reference/tools/mcp-server.mdx`: Documents the
option in the configuration table. Adds 7 lines.
- `.changeset/olive-pandas-carry.md`: Adds a minor release note for
`@mastra/mcp`. Adds 20 lines.
## Behavior
- The limit is in bytes.
- The documentation states that the value must be positive. The diff
does not validate this. The code stores any value it receives.
- An oversized body receives a `413` JSON-RPC error before it is parsed.
No tool runs.
- The limit applies only to bodies the server reads from the request
stream. When body-parsing middleware supplies the parsed body, the limit
does not apply. The documentation tells the user to set the limit on
that parser too.
- The setting does not apply to `stdio`.
## Scope
- The PR does not add constructor-time validation for non-positive or
non-finite values.
- The PR does not add body-size options to the built-in `/api/mcp`
endpoint or to adapter-level `MCPOptions`.
## Diff
4 files changed, 148 lines added, 0 removed.
## Verification
The PR author reports these results. This review did not run them.
- `vitest run --project unit:packages/mcp src/server`: 36 files, 669
passed, 8 skipped.
- `vitest run --project unit:packages/mcp src/client`: 34 files, 627
passed.
- `pnpm --filter @mastra/mcp build:lib`: passed.
- Vale prose check: not run. The binary was unavailable.
- One full-suite failure in `server-events.test.ts`. The author reports
the same failure on the base commit under full-suite load. The author
reports that it passes on rerun and in isolation.
## Linked issue
Issue `#30207` requests a per-server `maxRequestBodySize` on
`MCPServer`, passed to `createMcpHandler`. The PR adds the constructor
option and forwards it to both handler layers. The diff and test names
cover the requested behavior: the default is kept when unset, a `413` is
returned above the limit, and the setting applies per server.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: mastra-platform[bot] <284800079+mastra-platform[bot]@users.noreply.github.com>
Co-authored-by: mastra-platform[bot] <mastra-platform[bot]@users.noreply.github.com>
|
||
|
|
1072f7c626 |
fix(memory): reuse message embeddings across saves (#30429)
## Summary Saving messages with semantic recall embeds each message's text and writes a vector row for it. Since the message write path moved onto the shared row builder, Memory stopped reusing embeddings for text it had already embedded. The same text saved again (a repeated reply, a re-saved message, a cloned thread) went back to the embedder every time: three saves of the same 50 texts made 150 embedding calls instead of 50. This restores bounded reuse on the write path without changing how rows are written: - Vectors are cached per Memory instance in a bounded LRU, keyed by each message's exact prepared chunks, so chunk-size limits still apply and a different chunking is a miss. - The cache is emptied when the embedder or its options change. - Failed calls, and responses without exactly one embedding per chunk, are never kept. Concurrent writes of the same chunks share one call. - Reused vectors are not counted again in reported embedding usage. - Only vectors are cached. Every message still gets its own row with its own id and metadata, so there are no duplicate recall rows. The memory performance benchmark previously timed recalls without checking that anything had been indexed, so a writer that skipped embedding would pass it. It now checks that every message has a vector row and that each thread's semantic recall returns its own messages before timing. ## Test plan - New `semantic-recall-embedding-reuse.test.ts` (10 tests): repeated text, re-saved ids, usage on reuse, long-text reuse, invalid responses and changed embedder options fail before this change. Edited text, failed embeds, embedder swaps and raw-string content are covered as controls. - `@mastra/memory` unit suite: 2,689 pass + 1 todo. Typecheck, lint and format clean. - Real file-backed LibSQL, 3 saves × 50 messages: repeated text 150 → 50 embedding calls, re-saved ids 150 → 50. Stored rows unchanged (151 / 51 / 451 for long chunked text). Unique, raw-string and long-text call counts unchanged. - LibSQL performance benchmark (2,500 messages, FastEmbed) passes with the new check. The check fails when vector writes are disabled or recall returns nothing. - Local FastEmbed: repeated text ~7.6s → ~2.6s; unique text unchanged. Ref #29826 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ELI5: When a message is saved, Memory turns its text into numbers (an embedding). If the same text was already turned into numbers, this change reuses them instead of asking the embedding service again. Each message still gets its own stored row. ## Overview This change adds a bounded cache of message-chunk embeddings to `Memory`. The cache applies only to the message-vector write path. The change also adds checks to the LibSQL performance test, a patch changeset for `@mastra/memory`, and a new test file. Diff scope: 4 files changed, 350 lines added, 11 removed. ## Changes **`packages/memory/src/index.ts`** (+55 / -11) - Adds `chunkEmbeddingCache`, an LRU cache bounded by `DEFAULT_EMBEDDING_CACHE_MAX_SIZE`. It holds promises of vectors only. Keys are a hash of `JSON.stringify(chunks)`. - Adds `chunkEmbeddingCacheOwner`. It records the embedder and options that produced the cached vectors. - Adds `embedMessageChunks(chunks)`, which: - Snapshots `this.embedder` and `this.embedderOptions` before hashing. - Calls `embedValues` with the snapshot and skips the cache if the embedder or options change during hashing. - Clears the cache when the owner record differs from the snapshot. The clear happens at the next miss, not when the embedder changes. - Returns cached vectors on a hit. A hit returns no usage data. - On a miss, calls `embedValues` and stores the pending promise. Concurrent writes with the same chunks share that promise. - Evicts the entry when the call fails or returns a number of embeddings that differs from the number of chunks. - Returns usage only for the call that reached the embedder. - Changes `embedValues` to accept an optional `{ embedder, embedderOptions }` argument. The default is `this`, so other callers keep the current behavior. - Changes the message-vector row builder to call `embedMessageChunks` instead of `embedValues`. The diff for this file shows no change to the query or content embedding paths. **`packages/memory/src/semantic-recall-embedding-reuse.test.ts`** (+267) - Adds a new test file. It covers reuse across saves, one row per message on resave, re-embedding of edited or distinct text, usage counting, non-reuse of failed or mis-sized results, invalidation on embedder or option change, an embedder change during an in-flight save, raw-string content, and chunking within the embedder input limit. - The number of tests in this file is not verified from the diff. The PR reports 10. **`packages/memory/integration-tests/src/performance-testing/performance-tests.ts`** (+23) - Imports the `MastraVector` type. - Before timing, checks that indexed vector rows are at least `threadCount * messagesPerThread`. - Before timing, runs a thread-scoped semantic recall for each thread. Checks that results are nonempty and belong to that thread. - The timed query measurements and p95 threshold are not changed. **`.changeset/quiet-owls-reuse.md`** (+5) - Adds a patch changeset for `@mastra/memory`. It describes reuse of vectors for repeated or re-saved text and the exclusion of reused vectors from reported usage. ## Reported results These results come from the PR description. They are not verified by completed checks on the current head. - Three saves of 50 messages with repeated text: embedding calls fell from 150 to 50. Stored row counts are reported unchanged. - Repeated-text FastEmbed time: about 7.6 s before, 2.6 s after. - Unique, raw-string, and long-text call counts: reported unchanged. - `@mastra/memory` unit tests: 2,689 passing, 1 todo. - Typecheck, lint, and format: reported clean. - LibSQL benchmark with 2,500 messages: reported passing. ## Not verified - Test, typecheck, lint, format, and benchmark results. No completed check on the current head was available. - The test count in the new test file. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: remy-builder[bot] <324360501+remy-builder[bot]@users.noreply.github.com> |
||
|
|
1100a41fb7 |
feat(playground-ui): switch interface icons to Central Icons (#29934) | ||
|
|
33eaa293e2 |
fix(core): give unnamed sleeps the same step id in every process (#30397)
## Description
A `.sleep()` or `.sleepUntil()` declared without an `id` now gets the
same step ID in every process: `sleep_<workflowId>_<n>`, where `n`
starts at the number of sleeps declared before this one and moves up
past any ID already in use.
### Why
Each process generated a random ID for an unnamed sleep when it built
the workflow, and that ID is the key of the sleep's result in the stored
run. A process that restarts or time travels a run stored by another
process looked the sleep up under its own ID, found nothing, and the
step after the sleep got no input. On the evented engine a restart
failed the run with an input validation error (the step received
`undefined`). Time travel on either engine ran the step with `{}`.
Scheduled workflows were affected too: the schedule's definition hash
covers the serialized step graph, which includes the sleep IDs, so every
instance computed a different hash and the instances that hadn't
registered the schedule last refused to fire it.
### What changed
`packages/core/src/workflows/workflow.ts` uses the rule unnamed `.map()`
steps have used since #21222: a deterministic ID from the workflow ID
and an ordinal, unless the workflow is already registered with a Mastra
instance that has a custom ID generator when the sleep is declared, in
which case that generator still produces the part after `sleep_`.
`sleep` and `sleepUntil` share one count, since both use the `sleep_`
prefix. An ID already taken by an explicit one is skipped. An explicit
`id` is unchanged.
```ts
// before: sleep_3f2c9e1a-... (different in every process)
// after: sleep_my-workflow_0
createWorkflow({ id: 'my-workflow', ... }).then(a).sleep(5000).then(b).commit();
```
The `sleep` and `sleepUntil` reference pages now describe the default
ID.
### Known limits
- Adding or removing a sleep shifts the default IDs of later unnamed
sleeps. Pass `{ id }` to pin one.
- Runs stored before the upgrade keep their random sleep IDs and still
won't match after a restart or time travel, as before.
- A custom ID generator that returns random IDs still gives a different
ID per process.
### Tests
- New `packages/core/src/workflows/sleep-id-determinism.test.ts`: two
builds of the same workflow give the same IDs with one ordinal over
`sleep` and `sleepUntil` (without the fix: random `sleep_<uuid>` IDs);
an explicit ID that claims a default name is skipped (without the fix: a
random ID); a default-engine time travel past a sleep after the workflow
is rebuilt, on `InMemoryStore`, hands the next step its recorded input
(without the fix: the run ends `failed` with "Step input validation
failed", because the step got `{}`).
- `packages/core/src/workflows/evented/sleep-restart.test.ts`: the sleep
and `sleepUntil` restart cases now build the workflow once per runtime,
as a real restart does, and assert the step after the sleep receives its
input (without the fix: the run ends `failed` with
`WORKFLOW_STEP_INPUT_VALIDATION_FAILED`, input `undefined`).
## Related issue(s)
None
## Type of change
- [x] Bug fix (non-breaking change that fixes an issue)
- [ ] New feature (non-breaking change that adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Documentation update
- [ ] Code refactoring
- [ ] Performance improvement
- [ ] Test update
## Checklist
- [ ] I have linked the related issue(s) in the description above
- [x] I have made corresponding changes to the documentation (if
applicable)
- [x] I have added tests that prove my fix is effective or that my
feature works
- [ ] I have addressed all Coderabbit comments on this PR
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->
**ELI5:** When a workflow waits, it gives that wait a name. Before this
change, the name was random each time the code ran. Another process
could not find the saved wait, so a restarted or time-traveled run lost
its data. Now each unnamed wait gets a name based on its position in the
workflow, so every process uses the same name.
## Summary
Unnamed `.sleep()` and `.sleepUntil()` steps now get a deterministic ID.
The ID has the form `sleep_<workflowId>_<n>`. Both sleep types share one
counter. The counter skips IDs that already exist in the workflow's
steps. Explicit `{ id }` values are unchanged.
## Changes
- **`packages/core/src/workflows/workflow.ts`:** Adds a private
`#defaultSleepId(stepType)` helper. `sleep()` and `sleepUntil()` call it
when no explicit ID is given.
- With no custom ID generator on the Mastra instance, `n` equals the
number of earlier `sleep` and `sleepUntil` entries in `stepFlow`. The
helper increments `n` while `sleep_<workflowId>_<n>` already exists in
`steps`.
- With a custom ID generator, the helper calls `generateId` with the
workflow ID and the step type. It then prefixes the result with
`sleep_`. The generator supplies the suffix.
- The `crypto.randomUUID()` fallback is removed from both methods.
- **`.changeset/curly-pillows-argue.md`:** Adds a `@mastra/core` patch
changeset. It describes the fix and states these limits:
- Runs stored before this change keep their random IDs. They do not
match after a restart or time travel.
- Scheduled workflows with unnamed sleeps get the same definition hash
on each instance.
- Adding or removing a sleep changes the IDs of later unnamed sleeps.
Pass `{ id }` to keep an ID fixed.
## Documentation and tests
- The raw summary reports that the `sleep` and `sleepUntil` reference
pages describe the ID format, the counter, and the custom ID generator
behavior.
- The raw summary reports a new
`packages/core/src/workflows/sleep-id-determinism.test.ts`. It covers
stable IDs, the shared counter, explicit-ID collisions, and a
rebuild-and-time-travel case.
- The raw summary reports that `sleep-restart.test.ts` now creates a
separate workflow object for each runtime. It asserts that the
`afterSleep` step receives `{ value: 'persist me' }`.
- Verification status: the doc pages and test files were not inspected.
Test results are not available.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
|
||
|
|
d0f7dd3a80 |
chore: version packages (alpha) (#30420)
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and publish to npm yourself or [setup this action to publish automatically](https://github.com/changesets/action#with-publishing). If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. ⚠️⚠️⚠️⚠️⚠️⚠️ `main` is currently in **pre mode** so this branch has prereleases rather than normal releases. If you want to exit prereleases, run `changeset pre exit` on `main`. ⚠️⚠️⚠️⚠️⚠️⚠️ # Releases ## @mastra/factory@0.29.0-alpha.3 ### Minor Changes - Added opt-in health metrics to Factory, sent through `mastra.metrics`. Pick the groups you want, since every record counts towards observability usage: ([#30225](https://github.com/mastra-ai/mastra/pull/30225)) ```ts new MastraFactory({ // ... metrics: { groups: ['process', 'postgres', 'redis', 'sandbox', 'intake'] }, // or 'all' }); ``` Or set `FACTORY_METRICS=all` (or a list like `sandbox,intake`). `FACTORY_METRICS_INTERVAL_MS` (default 60s, minimum 15s) and `FACTORY_METRICS_MAX_PER_MIN` (default 500) tune how often records are sent and cap their volume. Metrics are named `mastra_factory_*` and labeled with `service` (`api`, `worker` or `all`) so split deployments can be told apart. ### Patch Changes - Fixed a pull request Factory opened for a card whose issue lives in Jira, Linear or incident.io getting a card of its own on GitHub. The pull request now attaches to that card and moves it to Review, as it already does on GitLab, so the work is no longer tracked on two cards while it is being reviewed. Fixes [#30358](https://github.com/mastra-ai/mastra/issues/30358). ([#30418](https://github.com/mastra-ai/mastra/pull/30418)) - Deliver Factory notifications when their bound session no longer exists, including concurrent notifications. Notifications for a role that has been handed off remain suppressed. ([#30422](https://github.com/mastra-ai/mastra/pull/30422)) - Updated dependencies [[`02dbde1`]( |
||
|
|
df8e02bbd5 |
fix(factory): recover stale session bindings before delivering notifications (#30422)
## Summary
- Recover the selected role binding when its bound controller session no
longer exists, before resolving the notification owner and delivering
the notification.
- Preserve safe retry behavior when there is no binding preparer; do not
create an unrelated session or repoint the card.
- Add regression coverage for successful recovery and the no-preparer
failure, including notification delivery and persisted binding state.
## Test plan
- Reproduction test failed before the fix (`prepareBinding` was never
called); both scenarios pass after the fix.
- Full Factory dispatcher suite: 222 passed.
- `pnpm run check` in `mastracode/factory`.
- Type-aware lint and formatting for changed files; `git diff --check`.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->
ELI5: The system sends a notification to a session for a role. Sometimes
that session no longer exists. Now the system first replaces the stale
role binding, then sends the notification. If another session has
already taken over the role, the notification is not sent, and the newer
session stays in charge.
## Summary
This change updates how the Factory dispatcher delivers `notify`
decisions when the selected role binding points to a missing controller
session. It also adds an expected-binding guard to run-start
preparation. The change touches 6 files: 348 lines added and 2 removed.
The change recovers the stale role binding before the notification owner
is resolved and the notification is delivered. When no binding preparer
is available, the change keeps retry behavior. It does not create an
unrelated session or repoint the card.
### Dispatcher (`mastracode/factory/src/rules/dispatcher.ts`, +43/-2)
- The `notify` path selects an active binding.
- If the decision's role was superseded, or the decision was overtaken,
the decision is marked `superseded`.
- The path then prepares or requires the role's binding. It checks that
the selected binding ID is still current.
- `#requireOrPrepareBinding` accepts an expected binding ID. If the
role's current binding differs from that ID, or is missing, it calls
`#sameRoleReplacement`.
- `#sameRoleReplacement` marks the decision `superseded` when:
- no replacement exists,
- the replacement is the expected binding,
- the role was superseded, or
- the decision was overtaken.
- Otherwise, `#sameRoleReplacement` requires that the replacement
session exists.
- Preparation receives the expected binding ID.
- A `FactoryRunBindingSupersededError` from preparation resolves to a
same-role replacement when an ID was expected. Otherwise, it marks the
decision `superseded`.
- Other preparation errors propagate.
- `FactoryBindingPreparationInput` gains an optional `expectedBindingId`
field.
### Run-start path
- `mastracode/factory/src/routes/surface.ts` (+1):
`prepareFactoryRuleBinding` forwards `input.expectedBindingId` to
`coordinator.prepare`.
- `mastracode/factory/src/rules/start-coordinator.ts` (+2):
`FactoryStartRequest` gains an optional `expectedBindingId`.
`FactoryStartCoordinator.prepare` forwards it to
`storage.prepareRunStart`.
- `mastracode/factory/src/storage/domains/work-items/base.ts` (+21):
- Adds the `FactoryRunBindingSupersededError` class.
- Adds an optional `expectedBindingId` to `PrepareFactoryRunStartInput`.
- When `expectedBindingId` is set, `prepareRunStart` requires:
- an existing work-item ID, and
- an active binding that matches the ID, organization, project, and
role.
- If a requirement fails, `prepareRunStart` throws
`FactoryRunBindingSupersededError` before it processes the pending
start.
### Tests (`mastracode/factory/src/rules/dispatcher.test.ts`, +276)
The added tests cover three cases:
- **Preparer available:** A preparer replaces the stale binding. The
notification is delivered as the owner of the replacement session.
Concurrent notifications that share the stale binding are both
delivered.
- **Successor during preparation:** A successor takes over the session
during preparation. The notification is not sent. The decision becomes
`superseded`. The successor binding stays active, and the stale role is
not restored.
- **No preparer:** The notification is not sent. The decision retries
with `session_unavailable`. The active binding is unchanged.
### Changeset (`.changeset/factory-stale-notification-binding.md`, +5)
Adds a patch changeset for `@mastra/factory`. It describes delivery of
notifications when a bound session no longer exists, including
concurrent notifications. It also describes suppression of notifications
for roles that have been handed off.
### Not verified
- The PR objectives report 222 passing Factory dispatcher tests, a
passing `pnpm run check` in `mastracode/factory`, and clean lint,
format, and `git diff --check` results. These results are
author-reported. This review did not run them.
- This review did not run the tests, type checks, or lint.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: mastra-platform[bot] <mastra-platform[bot]@users.noreply.github.com>
Co-authored-by: mastra-platform[bot] <284800079+mastra-platform[bot]@users.noreply.github.com>
|
||
|
|
7bc312b64b |
fix(factory): attach a Factory pull request to a Jira, Linear or incident.io card on GitHub (#30418)
> Opened by @factory-project:7d5175c3-3a20-42ac-aba9-756f183136f4
On GitHub, a pull request Factory opened for a card whose issue lives in
Jira, Linear or incident.io was filed on a card of its own. The source
card never gained a `pull-request` source, so it could not enter the
board's pull request review phase: the move is refused for a card with
no pull request attached ("holds only cards with a pull request").
GitLab already took such a card as the merge request's home, so the two
providers behaved differently for the same board.
`GithubRules.#pullRequestHome` decides which existing card a first-seen
pull request belongs with. Its `eligible` predicate required
`cardBelongsToRepository` for every card, which matches a card by its
GitHub issue/PR URL or an intake-stamped `githubRepositoryId` — neither
of which a Jira or Linear card carries, so the authoring card was never
eligible and no `attachTo` was emitted. `eligible` now requires
repository membership only for GitHub cards, mirroring GitLab's own
`eligibleHome`, which excludes GitHub cards in the same way. A card with
no source of its own still never takes a pull request, since it would
become the card's only source, and a GitLab card still keeps only merge
requests.
Regression tests cover a Jira, Linear and incident.io card (the pull
request joins the card, no second card, and the card reaches PR review),
plus the two negatives — a source-less card and a GitLab card — and the
GitHub control.
## Checks on `
|