0
Fork 0
mirror of https://github.com/mastra-ai/mastra.git synced 2026-11-17 08:44:46 +00:00
Commit graph

23,473 commits

Author SHA1 Message Date
Eric Pinzur
e728d57993 fix(observability): expose root context and omit unused trace details 2026-11-17 07:52:28 +01:00
Eric Pinzur
84ac77505e fix(observability): preserve trace page execution diagnostics 2026-11-17 07:33:02 +01:00
Eric Pinzur
54dc2e471f test(client-js): include SDK suite in root discovery
Rename the config to the extension scanned by root Vitest discovery so paging runtime and parity regressions run in CI. Preserve all five configured type-test files.

Review: https://github.com/mastra-ai/mastra/pull/30512#pullrequestreview-5925420901
2026-11-17 04:26:38 +01:00
Eric Pinzur
8872af9e8f docs(core): clarify unsigned trace continuation trust
Address finding 12: fingerprints detect changes, not forgery. Keep independent scope enforcement and decoded-request validation explicit.

Review: https://github.com/mastra-ai/mastra/pull/30512#pullrequestreview-5925420901
2026-11-17 04:24:46 +01:00
Eric Pinzur
d8de2a6630 test(core): assert trace cursor character budget
Address finding 11: check the 60000-character cursor cap separately from the request body byte budget for a maximum-size multibyte ID batch.

Review: https://github.com/mastra-ai/mastra/pull/30512#pullrequestreview-5925420901
2026-11-17 04:24:46 +01:00
Eric Pinzur
44ff0668cb docs(core): describe experimental browse depth default
Address finding 10 in schema metadata without defaulting a field that must stay absent for search and explicit-ID validation.

Review: https://github.com/mastra-ai/mastra/pull/30512#pullrequestreview-5925420901
2026-11-17 04:24:46 +01:00
Eric Pinzur
5327ff3fbf fix(core): require search for ancestor selection
Address finding 9: reject ignored ancestors options in browse and continuation requests while retaining both search modes.

Review: https://github.com/mastra-ai/mastra/pull/30512#pullrequestreview-5925420901
2026-11-17 04:24:45 +01:00
Eric Pinzur
65ff2506c2 fix(client-js): preserve legacy trace URL behavior
Address finding 8 by removing the unrelated getTrace encoding change. The new getTracePage method continues to encode its trace ID.

Review: https://github.com/mastra-ai/mastra/pull/30512#pullrequestreview-5925420901
2026-11-17 04:23:42 +01:00
Eric Pinzur
3ca8d25adf refactor(core): clarify internal trace page integration
Address finding 7 by marking the experimental reader and source internal while preserving Platform runtime exports; remove the unused Core SDK argument alias.

Review: https://github.com/mastra-ai/mastra/pull/30512#pullrequestreview-5925420901
2026-11-17 04:23:32 +01:00
Eric Pinzur
bab98ea875 perf(core): count trace page payload bytes incrementally
Address finding 4 by serializing each candidate node once and counting array separators separately from the changing response envelope. Preserve exact byte limits and continuation rewind.

Review: https://github.com/mastra-ai/mastra/pull/30512#pullrequestreview-5925420901
2026-11-17 04:23:31 +01:00
Eric Pinzur
ac9aa37902 test(client-js): detect optional trace page field drift
Address finding 6 with response and node key equality alongside assignability. Removing details or adding an optional response field fails the configured type suite.

Review: https://github.com/mastra-ai/mastra/pull/30512#pullrequestreview-5925420901
2026-11-17 04:23:14 +01:00
Eric Pinzur
377df55946 test(core): cover trace page guards and byte boundaries
Address finding 5 with topology limits, forged cursor validation, selection disappearance, and exact UTF-8 response budgets. Nine targeted guard mutations fail these regressions.

Review: https://github.com/mastra-ai/mastra/pull/30512#pullrequestreview-5925420901
2026-11-17 04:22:16 +01:00
Eric Pinzur
34a00ffd3b fix(client-js): retry experimental trace page reads
Address finding 3: preserve the read retry policy for initial pages and continuations, with real HTTP regressions for transient and terminal failures.

Review: https://github.com/mastra-ai/mastra/pull/30512#pullrequestreview-5925420901
2026-11-17 04:21:14 +01:00
Eric Pinzur
d0482ccf06 fix(observability): align trace page capabilities and contract checks 2026-11-17 04:16:27 +01:00
Eric Pinzur
9d3e0be7cb refactor(observability): keep trace page endpoint in Platform only 2026-11-17 04:16:27 +01:00
Eric Pinzur
57bb835fc8 refactor(observability): use trace page subresource 2026-11-17 04:16:27 +01:00
Eric Pinzur
0123f28fb8 fix(observability): bound trace reads to selected pages
Require explicit backend support, separate topology from page projection, and pre-page requested IDs. Restrict continuation invalidation to selected context and align identifier validation, tenant capabilities, and error mapping.
2026-11-17 04:16:27 +01:00
Eric Pinzur
dccb714a48 fix(observability): remove redundant trace request version 2026-11-17 04:16:27 +01:00
Eric Pinzur
caf8fbee62 chore: remove trace navigation docs and trim changesets 2026-11-17 04:16:27 +01:00
Eric Pinzur
3728e230c7 fix(observability): separate versioned trace page API
Use /observability/v2/traces/:traceId and getTracePage() to preserve legacy routing and inferred getTrace return types.

Reviews: https://github.com/mastra-ai/mastra/pull/30512#discussion_r4585617255 https://github.com/mastra-ai/mastra/pull/30512#discussion_r4585617185
2026-11-17 04:16:27 +01:00
Eric Pinzur
e661823f24 fix(server): preserve unsupported trace navigation responses
Allow requests through validation when older Core lacks the schema, so the handler returns 501. Reproduced with the adapter body parser.

Review: https://github.com/mastra-ai/mastra/pull/30512#discussion_r4585617220
2026-11-17 04:16:26 +01:00
Eric Pinzur
87ab76f950 chore: split trace navigation changesets by package 2026-11-17 04:16:26 +01:00
Eric Pinzur
87da733f1f feat(observability): add bounded trace navigation API 2026-11-17 04:16:26 +01:00
Damien Schneider
e22c5a7035
fix(factory): show the right status for person sessions, later threads and failed setups (#30627)
**─────── TLDR ───────**

> A session now shows Waiting on you, Working or Initializing when
that's actually true, for person sessions as well as card sessions.

Stacked on #30624. Three rules were wrong in the one server derivation
the sidebar and board read. A person session parked on a question showed
Working, because its parked state was never looked up. A run on any
thread but the session's first one went unseen. And Initializing only
checked whether setup had finished, so a session whose clone failed, or
that never ran at all, stayed Initializing for good. The client polled
`/sessions` every 15 s to work around that, so the poll goes too.

**Was**
  ├─ person session, agent asks a question: Working
  ├─ person clicks New thread and prompts: Idle the whole run
  ├─ Slack session running: Idle
  ├─ setup never finished, no run: Initializing forever
  ├─ card whose clone failed: Initializing, and held so no new
run could start
  └─ sessions list: refetched every 15 s while a session
looked unmaterialized

**Now**
  ├─ person session, agent asks a question: Waiting on you,
even before its sandbox came up
  ├─ person clicks New thread and prompts: Working
  ├─ Slack session running: Working
  ├─ setup never finished, no run: its normal status
  ├─ setup never finished, run waiting on it: Initializing, as
before
  ├─ card whose clone failed: its normal status, not held
  └─ sessions list: no poll

**Decisions**
- Person and card rows now go through the same `sessionStatus`. Person
rows still ignore a card's suggested run and settled state. Why: a
person session can be indexed next to a card, and those two facts belong
to the card's own sessions. Undo: give `userRow` its own status again.
- The parked set is the card sessions plus every session the reader can
see. Why: card sessions stay in so a card still reads parked for people
who can't see its private session row. Undo: go back to
`sessionIdsWhere(cards, isParked)`.
- A run counts for the session whose current thread it's on, read from
the live session registry in this process, like `activeRuns` already is.
Why: leaving a thread drops its run, so a run always lies on its
session's current thread, and this costs no database read, unlike the
thread stamp lookup. Undo: drop `sessionOnThread` from
`runningSessionIds`.
- Initializing needs a run waiting on setup. Why: `markMaterialized`
only runs at the end of the GitHub clone and the sandbox starts lazily,
so "not materialized" alone mostly meant "never ran". Undo: drop
`running &&` in `sessionStatus` and bring back the poll.
- Waiting on you now outranks Initializing. Why: a suspended run still
counts as running, so a lazy sandbox session asking its first question
read Initializing, and a run parked on a person can't be setting its
sandbox up. Undo: swap the first two checks in `sessionRowStatus`.

**Watch**
- A card whose session exists but whose run hasn't registered yet is no
longer held for that short window. I haven't seen it happen.
- The transcript's "Answered" receipt reads `parkedSessionIds`, so it
should now stay off while a person session still waits. Not tested.

**Known limit**
- With lazy sandbox start, a session whose run hasn't touched the
sandbox yet, like a chat-only turn, shows Initializing while it runs.
Nothing persisted says setup is in progress: `setSandbox` is written
after setup. It's still an in-flight status, and it no longer sticks
once the run ends.

**Not verified**
- [ ] Not checked in a browser against a live Factory
- [ ] A real suspended core run on a person session, end to end with a
lazy sandbox
- [ ] A Slack session's row going Working, end to end
- [ ] Playwright e2e not run

---

> source     ████ +38 −54
> tests       ████████ +115 −69
> changeset █ +6
> generated none



<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

**ELI5:** The Factory app showed the wrong status for some sessions.
This change fixes the status rules. It also stops the app from asking
the server for session updates every 15 seconds.

**Overview**

This change corrects how Factory derives session status for person
sessions and card sessions. It also moves card status and session holds
to server-derived session activity. The client no longer polls for
session updates.

**Status rules**

- Person rows and card rows use the same `sessionStatus` calculation.
- Person rows do not use a card's suggested-run or settled-state data.
- "Waiting on you" applies to parked sessions. The parked set includes
card sessions and sessions visible to the reader.
- "Initializing" applies only to a running session whose
`materializedAt` is null.
- "Waiting on you" takes precedence over "Initializing."
`sessionRowStatus` returns `ready` when `attention` is true, even if
initialization is also in progress.
- A failed clone or a session that has never run does not show
"Initializing" only because setup is incomplete.
- Factory sessions that await a person count as attention. Settled state
applies only to factory sessions.

**Run-to-session mapping**

- `LiveSession` exposes `thread.getId()`, which may return `null`.
- `LiveSessions.sessionOnThread(threadId)` returns the first tracked
session whose current thread matches. It returns `undefined` if none
matches.
- `RunReach` and `WorkItemRoutesDeps.liveSessions` now require
`sessionOnThread`.
- `runningSessionIds` includes runs by thread ID, optional resource ID,
and the session ID found for that thread. It still excludes runs with an
explicitly supplied unreachable resource ID.
- A run on a later thread, or a Slack run, can therefore map to its
session and show "Working."

**Polling removal**

- `sessionsRefetchInterval` is removed from
`mastracode/factory-ui/src/hooks/useWorkspaces.ts`.
- `workspacesQueryOptions` no longer sets a refetch interval.
- The previous helper returned 15 seconds while any session was
unmaterialized and updated in the last 10 minutes. Otherwise it returned
`false`.

**Contracts and routes**

- `sessionActivityResponseSchema` describes `parkedSessionIds` as
sessions whose run waits on a person. It no longer limits them to card
sessions.
- The `sessionHeldCardIds` description now refers to running or parked
sessions. It no longer includes "coming up."
- The `CardSessionStatus.held` comment no longer includes "coming up."

**Tests**

- `session-rows.test.ts` and `session-row-status.test.ts` add or update
cases for later-thread runs, parked user sessions, owner visibility,
unmaterialized sessions, and initialization.
- `live-sessions.test.ts` adds a real-controller test for
`sessionOnThread` on a second thread.
- Factory UI MSW tests cover initializing belts, active runs on
unmaterialized sessions, and sidebar visibility for sessions waiting on
setup.
- The polling tests in `useWorkspaces.test.ts` are removed.
- The e2e session-read fixture sets `sessionOnThread` to return
`undefined`.

**Changeset**

- `.changeset/spicy-peaches-crash.md` declares patch releases for
`@mastra/factory` and `mastra`.

**Verification status**

- Per the PR description, these were not performed:
  - Browser verification against a live Factory.
- End-to-end checks for a suspended person-session run with a lazy
sandbox.
  - End-to-end checks for a Slack session.
  - Playwright e2e tests.
- The transcript "Answered" receipt behavior was not tested.
- CI and test results for the current head are not available.

**Known limit**

- A chat-only turn can show "Initializing" while it runs, if it has not
touched the sandbox.

**Scope**

- 18 files changed.
- 169 lines added and 123 lines removed.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-16 19:02:18 -08:00
Damien Schneider
1b1f89c136
Factory: Work Intake brings in exactly the sources you select (#30625)
**─────── TLDR ───────**
> In Work Intake, the sources you select are exactly what comes in: the
per-service sync switches are gone, and GitHub issues and Vanta now
follow their lists.

Each service had a sync switch next to its source list, and the two
disagreed. A switched-off service kept a hidden selection, GitHub filed
issues from every linked repository whatever its list said, and Vanta
synced into every project with nothing selected. The list is now the
only control: a source in the list comes in, an empty list brings in
nothing.

### Behavior changed

a GitHub issue opens on a linked repository that is not in the GitHub
list
&nbsp;&nbsp;├─ **was** — filed as a card anyway
&nbsp;&nbsp;└─ **now** — ignored; pull requests from that repository
still come in

a repository is added to the GitHub list
&nbsp;&nbsp;├─ **was** — nothing until the next new issue
&nbsp;&nbsp;└─ **now** — its open issues are brought in

a repository is linked from the UI, API or CLI
&nbsp;&nbsp;├─ **was** — the UI added it to the list; API and CLI links
filed issues anyway
&nbsp;&nbsp;└─ **now** — the server adds it unless the link sends
`selectIntake: false`

Vanta connected, nothing selected
&nbsp;&nbsp;├─ **was** — every active vulnerability synced into every
project
&nbsp;&nbsp;└─ **now** — nothing syncs until the Vulnerabilities source
is selected

intake order and Not routed
&nbsp;&nbsp;├─ **was** — Settings › Work Intake
&nbsp;&nbsp;└─ **now** — Routing, in board settings; Settings keeps
connections and their sources

### Decisions

- **Dependabot keeps its switch** — it has no source list of its own to
stand in for one
- **a selection saved while switched off reads as empty** — showing it
would bring back the hidden state; the Linear repository mapping is kept
- **"Routing" names the board page** — "Intake" is already the first
phase's name in the same sidebar

### Watch

on deploy: two one-time steps run at boot. Every repository already
linked to a Factory joins its org's GitHub list, so no issue stops
arriving; a repository someone removed from the list earlier reappears.
Orgs whose Vanta switch was on with nothing selected get the
Vulnerabilities source selected. Both write a marker and never run
again; a failure logs and retries on the next boot.

### Not verified

- [ ] the Work Intake and Routing pages in a browser — covered by MSW
tests only
- [ ] the boot steps against Shipyard's data — run only on my local
database

---

> ██████████████████ **source** `+580 −328`
> █████████████████ **tests** `+565 −272`
> █ **changeset** `+10`
> █ **docs** `+4 −2`


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

ELI5: Work Intake now brings in only the sources a user selects. If a
list is empty, nothing comes in. Existing setups keep working because a
one-time update adds the sources they already used.

## Summary

Work Intake uses each source list as the control for intake. A source in
the list syncs. An empty list syncs nothing. Dependabot keeps its own
switch because it has no source list.

### Behavior changes

- **GitHub issues:** Only issues from repositories in the org's selected
list are ingested. Pull requests continue to come from every linked
repository.
- **GitHub linking:** Linking a repository through the link route adds
it to the selected list. The request can pass `selectIntake: false` to
skip this. Selecting a repository brings in its open issues.
- **Vanta:** Vulnerabilities do not sync until the Vulnerabilities
source is selected.
- **Linear:** A selection saved while the service is off is read as
empty. The Linear repository mapping is kept.
- **Routing:** Intake order and the Not routed list move from Settings
to a new board Routing page. Settings keeps connections and their
sources.
- **Settings UI:** Sources from all providers render in one "Sources"
subsection. The sync-switch controls are removed. Account-add actions
are ghost buttons (`AddPlatformAccountButton`,
`AddLinearWorkspaceButton`).

### Backend changes

- `IntakeStorage` adds `listConfigs`, `addSources`, and
`addSourcesOnce`. `addSourcesOnce` checks a named marker in the
`intake_data_migrations` table, runs in a serializable transaction, and
writes the marker on completion. `IntakeStorage.init` ensures that table
exists, independent of legacy binding detection.
- `MastraFactory.prepare()` runs two one-time migrations:
  - Seeds GitHub issue intake with linked repository slugs.
- Selects the Vanta Vulnerabilities source for orgs that have Vanta
enabled and no selected source.

  Each migration logs failures and retries on the next boot.
- GitHub rules return `ignored` for an `issueOpened` event when no item
was resolved and issue intake is not selected for the project and
repository.
- The GitHub issue reconciler checks issue-intake selection before
missed-open discovery. If a selection check fails, it skips discovery
for that repository and still reconciles existing cards.
- The intake PUT route calls the new `onSourcesSelected` callback for
newly selected source IDs. Selecting GitHub sources also ingests
backlogs for linked repositories that match the selected IDs.
Per-repository failures are logged.
- `parseRepositoryLinkInput` accepts `selectIntake` (default `true`) and
rejects non-boolean values. The link route adds the repository to GitHub
intake when this is true. Intake failures are logged and do not change
the link response.

### Routing and paths

- New `BoardIntakePage`. The router maps the Work board's intake URL and
any board's intake URL to it.
- New helpers in `boardConfigPaths.ts`: `boardIntakePath`,
`INTAKE_ORDER_ANCHOR`, `NOT_ROUTED_ANCHOR`. The two anchor constants are
removed from `settingsSections.ts`.

### Verification

- The author ran the one-time boot steps only against a local database,
not production data.
- The author did not verify the Work Intake and Routing pages in a
browser. Test coverage for those pages is MSW-based.
- CI and test results on the current head: not available.

### Scope

- 62 files changed, +1357 / −758 lines (merge base `c451f9c`).
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-16 18:47:06 -08:00
Arthur Fiorette
e110fa681a
fix(core): reload a run after restart() claims it (#30399)
## Description

On the default engine, `run.restart()` now reads the run again after it
has taken the run's lease, and acts on what it finds then. A restart
that races the end of a run returns the run's stored result instead of
running steps again.

### Why

`restart()` read the run, checked it wasn't finished, and only then took
the run's lease. A run that finished (or suspended) and released its
lease between that read and the claim was restarted from the stale
snapshot: `running` was written over `success`, and the steps that were
active at the stale read ran again.

### What changed

- The first read keeps its checks, so a run that isn't active never
touches the lease table.
- After the claim, the run is loaded again and handled exactly as a
first read would handle it: the stored result for a finished run, the
"This workflow run was not active" error for a suspended, canceled,
bailed or paused run, and "Snapshot not found" for a missing row. The
lease is released on every exit that doesn't restart.
- The restart's parameters, stored state and request context come from
that second read.
- The block that builds the stored result moved unchanged into a helper
both reads use.

### Cost

On storage v1 a restart reads the run's full snapshot once more than
before: a recovered run takes four reads where it took three (two in
`createRun()`, one before and one after the claim). On storage v2 the
count is unchanged, because the existing full load moved after the
claim.

### Known limits

- Runs whose lease does nothing (runs that aren't recoverable, nested
runs, runs that persist neither `running` nor `waiting`, stores without
run fencing, every evented run), and an owner whose lease lapsed while
it is still alive: the second read narrows the window, but nothing
enforces it.
- A run that finished but whose owner hasn't released its lease yet
still gets `WORKFLOW_RESTART_RUN_OWNED`.

### Tests

New cases in
`packages/core/src/mastra/restart-active-runs-ownership.test.ts`, run on
storage v1 and v2. Replica A runs the step up to a gate. Replica B calls
`restart()`, and just before B claims the lease, A passes the gate,
settles and releases its lease for real.

- Run finished: B's `restart()` returns A's `success` and result, the
step ran once (in A), the stored run is unchanged and the lease isn't
live. Without the fix the step runs a second time in B (`executions`
gains `B:<runId>`).
- Run suspended: B's `restart()` rejects with "This workflow run was not
active" and nothing runs in B. Without the fix B runs the step again and
the restart resolves `success`.

The read-count expectation in
`packages/core/src/mastra/test-utils/recovery-read-cases.ts` goes from
three snapshot reads to four for the restarted run, because of the v1
read after the claim.

## Related issue(s)

Related to #28060

## 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

- [x] I have linked the related issue(s) in the description above
- [ ] 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:** Two computers can work on the same saved task. If one computer
finishes or pauses the task while another computer is about to restart
it, the restart can use old information. This change makes the restart
check the task again after it takes ownership, so it uses the latest
saved state.

## Summary

This pull request fixes a race condition in `Run._restart` in
`packages/core/src/workflows/workflow.ts`. A replica can read a run.
Another replica can finish or suspend that run before the first replica
claims its lease. The restart then acts on a stale snapshot.

### Changes

- **First read kept.** `_restart` reads the run and returns the stored
result if the run is terminal. It then calls
`createRestartExecutionParams`, which throws for an inactive run. This
happens before the lease is claimed.
- **Stored-result helper.** A new private method,
`#storedRestartResult`, returns the stored result for `success`,
`failed`, and `tripwire` snapshots. It returns `undefined` for other
statuses. On the finished path, it calls `this.cleanup?.()`. The first
read and the second read both use this method.
- **Reload after claim.** After it claims the lease, `_restart` calls
`loadFull()` again. It applies the stored-result check and
`createRestartExecutionParams` to this second snapshot.
- **Restart inputs from the second read.** Restart parameters, state,
and request context come from the second snapshot.
- **Lease released on non-restart exits.** A `finally` block releases
the lease unless the restart proceeds. This covers a missing snapshot, a
finished run, and an inactive run found on the second read.
- **Inactive-run errors.** A run that is not active fails with "This
workflow run was not active." A missing run fails with "Snapshot not
found."

### Read count

- On storage v1, a restarted run performs four snapshot reads instead of
three. The extra read is the `loadFull()` call after the lease claim.
- On storage v2, the read count does not change. The earlier code
already performed a second `loadFull()` on this path.
- `packages/core/src/mastra/test-utils/recovery-read-cases.ts` changes
the expected read list to four `'stopped'` entries. Its comment now
states that `restart()` loads the snapshot before and after it claims
the run.

### Tests

- `packages/core/src/mastra/restart-active-runs-ownership.test.ts` adds
finish and suspension race tests for storage v1 and v2. These tests were
not inspected in this review.
- Test and CI results: not available. This summary does not record a
completed test run.

### Known limits

- The second read narrows the race. It does not enforce ownership in all
cases. The pull request description lists these cases: runs where the
lease has no effect, stores without run fencing, evented runs, and
owners whose lease lapses while still alive.
- A finished run whose owner has not released its lease still returns
`WORKFLOW_RESTART_RUN_OWNED`.

### Release note

`.changeset/quick-plums-flash.md` adds a patch changeset for
`@mastra/core`. The changeset states that `run.restart()` returns the
stored result for a finished run. It also states that `run.restart()`
fails with "This workflow run was not active" when a run suspends after
restart reads it and before restart takes ownership. The changeset file
was not part of the inspected diff.

### Scope

- 4 files changed.
- 177 lines added and 51 lines removed.
- No exported or public declarations changed.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-16 18:41:15 -08:00
Arthur Fiorette
d0a2fa4e34
fix(core): keep workflow sleeps longer than 2^31-1 ms asleep for the full duration (#30395)
## Description

A workflow `.sleep()` or `.sleepUntil()` longer than 2^31-1 ms (about
24.8 days) now waits its full duration on the default and evented
engines.

### Why

Each sleep armed a single `setTimeout`. Node and Bun turn a delay above
2^31-1 ms into 1 ms, so a sleep beyond that woke at once and the next
step ran immediately. For example, `.sleepUntil(new Date(Date.now() + 30
* 24 * 60 * 60 * 1000))` ran the following step about 1 ms later.

### What changed

A new internal helper, `setLongTimeout` in
`packages/core/src/workflows/utils.ts`, counts the duration down in
consecutive timers of at most 2^31-1 ms. It subtracts each timer's delay
from the remaining time and never reads the wall clock. `abortableSleep`
(the default engine's sleeps) and both evented sleep timers in
`evented/workflow-event-processor/sleep.ts` use it. A sleep up to the
limit arms exactly one timer, as before, and a duration that is zero,
negative or NaN still fires at once. `abortableSleep` keeps its abort
behavior: an abort clears whichever timer is armed and resolves.

Most of the `sleep.ts` diff is re-indentation from the formatter. In
each of the two timers the only change is `setTimeout(...)` to
`setLongTimeout(...)` and dropping the `duration < 0 ? 0 : duration`
guard, which the helper now handles.

### Known limits

- Retry delays (`retryConfig.delay`) still use a single timer.
- The scheduler's `tickIntervalMs` is unchanged.
- `sleep(Infinity)` now sleeps forever. Before, it woke after 1 ms.
- `sleepUntil` still measures the time left from when the sleep starts
and doesn't follow wall-clock changes.
- An evented sleep still lives in one process for its whole duration
(#30012).

### Tests

`packages/core/src/workflows/utils.test.ts` adds two `abortableSleep`
rows with fake timers and a duration of 2^31 + 60 s. The first checks
that the sleep is still pending after 2^31-1 ms and 1 ms before the end,
and resolves at the end. The second aborts after 2^31-1 ms + 1 s and
checks that it resolves with no timer left. Without the fix both fail
with `expected true to be false`, because the sleep had already
resolved.

The new
`packages/core/src/workflows/evented/workflow-event-processor/sleep.test.ts`
runs `processWorkflowSleep` with a 30-day duration and
`processWorkflowSleepUntil` with a date 30 days ahead, both through a
real `StepExecutor`. It checks that nothing is published to `workflows`
1 ms before 30 days, and that the next `workflow.step.run` is published
at 30 days. Without the fix both rows fail with `expected [ [
'workflows', { …(3) } ] ] to have a length of +0 but got 1`.

## 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
- [ ] 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

Workflows have a "sleep" step that pauses before the next step runs. For
very long sleeps, the computer's timer stops early, so the next step
runs too soon. This change makes long sleeps wait the full time.

## Summary

This change fixes workflow `.sleep()` and `.sleepUntil()` on the default
and evented engines. Sleeps longer than 2^31−1 ms (about 24.8 days)
ended early in Node and Bun. The runtime fired a single `setTimeout`
with an oversized delay after about 1 ms.

### Changes

- **`packages/core/src/workflows/utils.ts`**: Adds the internal
`setLongTimeout(callback, duration): () => void` helper. It counts down
with consecutive timers. Each timer is at most 2^31−1 ms.
  - Positive durations wait the full time.
  - Zero, negative, and `NaN` durations fire immediately.
  - `Infinity` never fires.
  - The returned function cancels the armed timer.
- `abortableSleep` now uses this helper. Aborting it clears the timer
and resolves the sleep.
-
**`packages/core/src/workflows/evented/workflow-event-processor/sleep.ts`**:
`sleep` and `sleepUntil` schedule their completion with `setLongTimeout`
instead of `setTimeout`. The completion logic and published events are
unchanged. The explicit clamp of negative durations to zero is removed.
Both helpers receive `duration` directly.
- **`packages/core/src/workflows/utils.test.ts`**: Adds `abortableSleep`
tests for durations above the timer limit. The tests check that the full
duration elapses before resolution. They also check that aborting after
the first timer chunk resolves the sleep and clears its timer.
-
**`packages/core/src/workflows/evented/workflow-event-processor/sleep.test.ts`**:
Adds fake-timer tests for evented `sleep` and `sleepUntil` steps
scheduled 30 days ahead. For both, no step publication occurs before 30
days. One publication occurs at 30 days with execution path `[2]`.
- **`.changeset/sour-cities-show.md`**: Adds a patch changeset for
`@mastra/core`.

### Scope and limits

- Retry delays are unchanged.
- The scheduler's `tickIntervalMs` is unchanged.
- `sleepUntil` measures the time remaining when the sleep starts. It
does not track wall-clock changes.
- Evented sleeps remain in one process for their full duration.
- No public API declarations changed.

### Diff size

- 5 files changed, 245 lines added, 106 lines removed.

### Verification

- Test results and CI status: not available.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-16 18:41:00 -08:00
Damien Schneider
b90d0ecd41
fix(factory): show the sidebar's card session status on the board (#30624)
**─────── TLDR ───────**

> The board now shows each card's session status as the sidebar does,
because both read it from the server.

A card's session status showed up in four places that disagreed: the
sidebar card row, the board card marker, the stage bar and the activity
band. The server already worked out the sidebar's answer. The board
worked out its own on the client. Now the server sends its answer to all
four, and the client stops guessing.

**Was**
&nbsp;&nbsp;├─ suggested run + running session: sidebar says waiting on
you, board says working
&nbsp;&nbsp;└─ one working session + one starting session: sidebar says
working, board says starting

**Now**
&nbsp;&nbsp;├─ suggested run + running session: waiting on you in both,
and the suggested run stays named but disabled until the session ends
&nbsp;&nbsp;└─ one working session + one starting session: working in
both

**Decisions**
- The marker and the hold are two facts. `cardStatuses` drives the
marker. `sessionHeldCardIds` says a session is starting, running or
parked on a person, so no rival run should start. Why: the server's
`waiting` also covers a suggested run or failed effect next to an idle
session, and using it as the hold would have disabled "Start suggested
run" and hidden Retry on those cards. Both come from the same
`factoryStatus`, so it's one derivation. Undo: drop `sessionHeldCardIds`
and hold on the status again.
- A held card with a suggested run shows the run disabled instead of
hiding it. Why: approving it doesn't go through the server's busy-card
guard, so the button is the only thing stopping a second run (#23083,
#25836). Dismiss stays in the menu. Undo: return `[]` for a held card in
`cardActions`.
- Another person's private card session no longer marks or holds the
card for you. Why: the board now uses the sidebar's visibility filter,
which already hid that session's row. Undo: skip `isSeenBy` in
`cardStatuses`.

**Shape changed**
&nbsp;&nbsp;`GET …/session-activity` adds `cardStatuses` and
`sessionHeldCardIds`
&nbsp;&nbsp;removed: `initializingSessionIds` from session-activity,
`runningSessionIds` and `parkedSessionIds` from board phases and the
work-item list, `useItemSessionStatuses`, `itemAwaitsPerson`

The activity read now also loads the board catalog and one page of
decisions (50) per request, the same reads the rows route makes.

**Not verified**
- [ ] Not checked in a browser against a live Factory
- [ ] Didn't confirm the new regression tests fail on `main`
- [ ] `packages/cli` api tests still use opaque `runningSessionIds`
fixtures; left as they are

---

> source &nbsp;&nbsp;&nbsp;&nbsp;████████████████ +211 −219
> tests &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;██████████████████ +217 −275
> changeset █ +6
> generated ██ +23 −34


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

**ELI5:** The board shows a small status mark and a stage bar for each
work card. Before this change, the web app worked out those marks on its
own, using different data than the sidebar. Now the server calculates
the status once, and the board reads it, so the board and sidebar show
the same status.

## Summary

This change moves card status and session-hold calculation from the
client to the server. The server now returns these values from `GET
…/session-activity`:

- `cardStatuses`: a map from card ID to sidebar status.
- `sessionHeldCardIds`: the IDs of cards held by a session.

The server derives both values from the same rows and visibility filter
that the sidebar uses. A private session that belongs to another person
does not mark or hold a card.

### Server (`mastracode/factory`)

- `session-rows.ts` (helper): adds `SessionStatusViewer`,
`CardSessionStatus`, `SessionRowIndex.cardStatuses(viewer)`, and
`isInFlight`. Factory-row and card-row status logic moves into
`factoryStatus` and `cardStatus`.
- `session-row-view.ts`: `sessionActivity` accepts `cardStatuses`. It
returns in-flight card statuses and held card IDs. It no longer returns
`initializingSessionIds`.
- `session-rows.ts` (route): loads sessions, cards, boards, and one page
of 50 deferred decisions together. The session-rows and session-activity
routes both use the same index and viewer state.
- `contracts.ts`: removes `runningSessionIds` and `parkedSessionIds`
from the board phases response. Removes `initializingSessionIds` from
session activity and adds `cardStatuses` and `sessionHeldCardIds`.
- `work-items.ts`, `board-snapshot.ts`: stop returning running and
parked session IDs. `boardSnapshot` and `scopedSnapshot` lose their
session-ID parameters. `WorkItemRoutesDeps.liveSessions` no longer
requires `isRunning`.
- `board-snapshot.ts`: fixes the JSON output for an empty metadata
object.

### Client (`mastracode/factory-ui`)

- `useSessionRows.ts`: adds `CardSessions` and
`useCardSessions(factoryProjectId)`. It returns the status map and the
held-ID set from session activity.
- `BoardContent.tsx`, `CardStageBar.tsx`: read status and hold state
from `useCardSessions`.
- `useItemSessionStatuses.ts`: deleted.
- `boardCardState.ts`: the `BoardCardOwner` session variant no longer
carries a status. `BoardCardStateInput` adds `sessionHolds`. The session
owner applies when `sessionHolds` is true. `itemAwaitsPerson` is
removed.
- `cardPrimaryAction.ts`: `freeCardActions` receives the full card
state. A session owner gets a disabled suggested run only when the
status is `waiting`. Otherwise it gets no actions. Waiting-status
labeling moves into `suggestedRun`.
- `cardControls.ts`, `WorkItemCard.tsx`: `sessionStatus` is documented
as the sidebar marker. `sessionHolds` is added and passed through.
- `WorkItemMenuItems.tsx`: adds `ownerCurrent`. The suggested-run
approval action is disabled when runs are blocked or the owner is not
current.
- `workItems.ts`, `useWorkItems.ts`: `BoardSnapshot` contains only
`workItems` and optional `total`. Running and parked session IDs are
removed from the board phase snapshot.
- Test fixtures and MSW mocks: remove `runningSessionIds`,
`parkedSessionIds`, and `initializingSessionIds`. Add `cardStatuses` and
`sessionHeldCardIds` where session activity is mocked.
- `e2e/ui/board-reads.ts`, `e2e/ui/session-reads.ts`: stubbed projects
drop running and parked ID lists. The session-activity stub derives card
statuses and held IDs.

### Behavior changes

- A card with a held session keeps its suggested run visible. The run is
disabled while the card is held. Dismiss remains available.
- A card with a running session shows as working, even when another of
its sessions is not yet materialized.
- A card with a retryable failure shows as ready, not working. Retry
stays hidden.
- A card with a live session that has an active run shows its session as
ready, not working.
- While the session-activity read is pending or a refresh has failed,
the board treats the hold as unknown. Moves go to the server. Suggested
runs stay disabled on the card and in its menu.
- The status marker and the session hold are separate values. The hold
does not use `waiting`.

### Removed API surface

- Session activity: `initializingSessionIds`.
- Board phases and work-item list: `runningSessionIds`,
`parkedSessionIds`.
- Client: `useItemSessionStatuses`, `itemAwaitsPerson`.
- Server: the `liveSessions.isRunning` requirement in work-item routes.

### Scope

- 46 files changed, +540 and −534 lines, against merge base `2d53b04`.
- A changeset (`.changeset/slimy-teeth-sell.md`) declares patch releases
for `@mastra/factory` and `mastra`.

### Verification status

- CI and test results: not available for the current head.
- Browser check against a live Factory: not performed, per the PR
author.
- New regression tests failing on `main`: not confirmed, per the PR
author.
- `packages/cli` API tests: still use opaque `runningSessionIds`
fixtures. This PR does not update these fixtures.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-16 18:40:57 -08:00
Arthur Fiorette
464810dcf8
fix(pg): keep PgVector startup warmup from caching a dropped index (#30578)
## Description

A `PgVector` instance no longer caches what its startup warmup read for
an index that `deleteIndex()` or an index rebuild invalidated while the
warmup was running. Before this change, two things could go wrong. The
next `upsert()` or `query()` on that index could fail with `Vector table
"<name>" does not exist`, even after the table had been created again. A
later `createIndex()` could also skip its work and keep the index's
previous metric.

The test `PgVector > Namespace isolation > lazy migration without
createIndex > invalidates readiness after deletion and raw recreation`
failed intermittently in CI with:

```
Error: Vector table "test_namespace_lazy_migration" does not exist
 ❯ PgVector.describeIndexMetadata src/vector/index.ts:1822:27   (MASTRA_VECTOR_PG_DESCRIBE_INDEX_FAILED)
Caused by: Error: Vector table "test_namespace_lazy_migration" does not exist
 ❯ PgVector.describeIndexMetadata src/vector/index.ts:1745:15
```

### Cause

The constructor starts a cache warmup and does not await it
(`stores/pg/src/vector/index.ts`, `cacheWarmupPromise`). The warmup
calls `listIndexes()`, then `getIndexMetadata()` for each listed table,
and that call stores its in-flight promise in `indexMetadataCache`. Then
it writes the index's cache key to `createdIndexes`. The failing
sequence in CI:

1. `new PgVector(...)`: the warmup's `listIndexes()` reads the catalog
and sees the table.
2. `deleteIndex()` drops the table and clears `indexMetadataCache`.
3. `listIndexes()` returns its earlier result. The warmup calls
`getIndexMetadata()`, which caches a new `describeIndexMetadata()`
promise for the dropped table.
4. That read runs before the table exists again and fails at
`describeIndexMetadata` (`:1745`).
5. The table is created again, and `upsert()` calls `getIndexMetadata()`
while the warmup's promise is still in the cache, so it gets the
warmup's rejection (`:1822`).

A second sequence uses the same warmup:

1. The warmup reads the metadata of a cosine HNSW index.
2. `deleteIndex()` clears the caches.
3. `createIndex()` recreates the index with the euclidean metric.
4. The warmup finishes and writes the cosine cache key to
`createdIndexes`.
5. A later `createIndex({ metric: 'cosine' })` matches that key, takes
the cached fast path and leaves the euclidean index in place.

### Changes

- The constructor creates a set of invalidated index names for the
warmup. While the warmup runs, `invalidateIndexCaches()` (called by
`deleteIndex()` and by the index rebuild in `setupIndex()`) adds the
index to it.
- The warmup skips an index in that set before it reads its metadata,
and again before it writes `createdIndexes` and `indexVectorTypes`. That
index is read on its first real use instead.
- The set is released once every metadata read of the warmup has
settled, whether the warmup succeeded or failed. `cacheWarmupPromise`,
which `disconnect()` awaits, now also waits for those reads.

### Known limits

- Only operations on the same instance invalidate its caches. When
another instance or process drops or rebuilds a table, this instance's
warmup, or any metadata read it has in flight, can still cache what it
read. This PR does not change that.
- `setupIndex()` invalidates the caches after `DROP INDEX` and before it
creates the new index, and nothing invalidates them afterwards. A
`query()` that reads the metadata in that window caches the index as
`flat` with the default `cosine` metric until the next invalidation.
Separately, `buildIndex()` with other parameters doesn't update
`createdIndexes`, which still holds the key `createIndex()` stored. A
later `createIndex()` with the original parameters then takes the cached
fast path and leaves the rebuilt index as it is. Both exist before this
PR, which does not change them.
- A warmup that finishes during a rebuild with no `deleteIndex()` before
it can still leave a stale key. `createIndex()` with other parameters
stores its key and then awaits catalog reads in `setupIndex()`. A warmup
that finishes during that wait writes the old key, and the rebuild that
follows invalidates the metadata caches without storing the key of the
index it built. A later `createIndex()` with the old parameters then
takes the cached fast path and leaves the rebuilt index as it is. Here
the warmup writes before the invalidation, so the invalidated set can't
stop it. The same sequence fails before this PR, and it shares its cause
with the `buildIndex()` case above: a rebuild never stores the key of
what it built.

### Tests

There are two new tests in `stores/pg/src/vector/index.test.ts`. Each
first checks that the warmup's listing saw the table, and holds the
listing or one of the warmup's catalog queries with a deferred promise.

- `upserts after deletion and raw recreation while the startup warmup is
still running` holds the warmup's `listIndexes()` until `deleteIndex()`
has run. It then holds the warmup's metadata read of the dropped table
(if one starts) until `upsert()` has been called on the recreated table,
and asserts the upserted row is stored. On the code before this change
it fails every run with the error above.
- `rebuilds with the requested metric after deletion while the startup
warmup is still running` holds the warmup after it has read a cosine
HNSW index's definition. It runs `deleteIndex()` and `createIndex()`
with the euclidean metric, lets the warmup finish, then calls
`createIndex()` with the cosine metric and asserts through
`describeIndex()` that the index is cosine. Without the second check it
fails every run with `metric: 'euclidean'`.

The existing test is unchanged. The vector test file passed 5 runs with
the CI vitest config.

## 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
- [ ] 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 database index is deleted and rebuilt while the app is
starting, the app can save the old index details in its cache. This
change stops the startup check from saving those old details, so later
saves and searches use the current index.

## Summary

This change fixes stale cache entries in `PgVector` startup warmup. The
constructor starts a background warmup. The warmup lists indexes and
reads each index's metadata. If `deleteIndex()` or an index rebuild runs
during that time, the warmup can cache metadata for an index that
changed or no longer exists.

The change in `stores/pg/src/vector/index.ts` does the following:

- Adds a `warmupInvalidations` field, typed `Set<string> | null`. Warmup
creates a new set when it starts. The field is set to `null` when warmup
finishes.
- `invalidateIndexCaches()` adds the index name to this set when the set
is not `null`.
- Warmup skips an index that is already in the set before it reads
metadata.
- Warmup checks the set again before it writes `createdIndexes` and
`indexVectorTypes`.
- Warmup collects the per-index read promises. Its `finally` block waits
for all of them with `Promise.allSettled`. Then it sets the field to
`null`.

The `finally` block keeps tracking active until every started read
settles. A single rejected read does not end tracking early. The
`cacheWarmupPromise` assignment is not changed in this diff. Its async
body now waits for the reads, so `disconnect()`, which waits for
`cacheWarmupPromise`, also waits for those reads.

Expected effects, as stated in the changeset:

- `upsert()` and `query()` do not fail with "Vector table ... does not
exist" after an index is deleted and created again during startup.
- `createIndex()` does not keep the previous metric when an index is
deleted and recreated, or rebuilt, during startup.

Invalidation applies only to operations on the same `PgVector` instance.
Changes made by another instance or process are not covered.

The change adds a patch changeset for `@mastra/pg` that describes both
fixes.

The PR also adds two tests to `stores/pg/src/vector/index.test.ts`.
According to the file summary, one covers upsert after delete and
recreate during warmup. The other covers metric and index type after
delete, recreate, and rebuild during warmup. The test file contents were
not inspected in this review. No test results were available.

**Scope:** 3 files changed, 132 lines added, 2 lines removed.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-16 18:40:43 -08:00
Ward Peeters
0ed63d7308
perf(server): stop deep-copying agent controller display state for every SSE client (#30615)
A long-running Factory server ("shipyard") grows from about 2 GB to
about 7 GB of memory over six hours, and garbage collection rises from
13% to about 42% of its busy CPU time, with event-loop stalls of up to 2
s. Its top allocation site is the agent controller SSE stream. Every
`display_state_changed` event was `structuredClone`d once for each
connected client in `toWireDisplayState`, then JSON-serialized again
once for each client by the server adapter. `structuredClone` copies
every string, so the current message text and every completed tool
result were duplicated in every snapshot, for every client, on every
update. Any frame waiting in a slow client's queue held its own full
copy.

This PR changes only `@mastra/server`. Nothing changes in `@mastra/core`
or the wire format.

**One snapshot per update.** The session bus hands every stream the same
event object in one synchronous dispatch. The stream handler now builds
one snapshot for that event and gives it to every stream of the session.
A single slot keyed by event identity is cleared in a microtask, so a
held event that is emitted again later gets a fresh snapshot.

**Strings are shared, not copied.** `snapshotForWire` copies the state
the way `JSON.stringify` would read it at that moment. It copies every
object and array, because the reducer updates tool status and results,
input buffers, file operations and subagent progress in place. It
resolves `toJSON` (Dates become ISO strings, as on the wire). It shares
strings and other primitives, which can't change. Shared and circular
references are kept the same way `structuredClone` kept them.

**Serialized once.** When a second stream takes the same frame,
`shareStreamChunk` marks it, and `serializeStreamChunk` caches its JSON
in a `WeakMap`. Every client of the session reuses one string. A lone
client never creates a cache entry.

With no clients connected the bus already does no snapshot work, so
`SessionBus` and its ordering guarantees (a pending coalesced snapshot
is flushed before the next non-coalescible event) are untouched.

**Test plan**

New tests in `agent-controller.test.ts` run through a real session bus,
the real stream route and the real `redactStreamChunk` +
`serializeStreamChunk`, then parse the bytes back.

A slow client with every frame queued before it reads still sees each
step of the turn as it was when emitted. For example, a tool is
`running` before it is `completed`, input-buffer text grows, and file
operations go from 1 to 2. Two clients of one session get identical
frames, and a client of another session sees only its own state.
Re-emitting a held `display_state_changed` event sends the current
state, not the cached frame. A parsed tool result with an own
`__proto__` key arrives unchanged.

Each test fails when the matching piece is broken on purpose: a shallow
copy, a never-cleared slot, a frame shared across events, or plain
assignment of `__proto__`. The first three tests also pass on the old
`structuredClone` code, so they check what clients receive, not how it
is built.

Suites run:
- `packages/server`: full suite 3574 passed. `tsc --noEmit`, lint and
prettier are clean.
- `packages/core`: `display-state.test.ts` 106 passed, including the
coalesced-flush ordering test.
- `server-adapters/hono`: 3524 tests passed. Four files didn't load
locally because `@mastra/client-js` and `@mastra/duckdb` weren't built.

`packages/server/scripts/bench-agent-controller-stream.ts` drives a real
session and the real stream route through one turn. The turn is 500 text
deltas spaced past the 16 ms coalescing window, plus one 100 KB tool
result, giving 1018 frames per client. Each client redacts, serializes,
frames and encodes every frame the way the adapters do. `allocated`
comes from one heap-sampling run and counts collected objects. The other
columns are medians of 7 runs, against `origin/main`:

| clients | allocated | time inside `session.emit` | CPU | GC |
| --- | --- | --- | --- | --- |
| 0 | 1.7 → 1.6 MB | 11 → 16 ms | 48 → 62 ms | 3× / 0.7 ms → 2× / 0.9 ms
|
| 1 | 174.8 → 122.0 MB | 73 → 62 ms | 301 → 341 ms | 7× / 9.7 ms → 14× /
10.1 ms |
| 5 | 851.7 → 349.2 MB | 112 → 50 ms | 1320 → 756 ms | 22× / 39.3 ms →
10× / 19.3 ms |

The benchmark hashes every client's full byte stream. The hash is
`aa4b36c9b3ae0e21` before and after, for both 1 and 5 clients. A
separate one-off run with awkward values was also byte-identical. The
values were Dates, nested Map/Set, shared and circular references,
BigInt, `NaN`, `-0`, sparse and typed arrays, class instances,
integer-like keys, U+2028 and lone surrogates.

For one client, allocation drops by about 30%. The 0-client row runs no
changed code, so its differences are noise. CPU and GC moved both ways
across runs: over about 8 paired runs CPU was 293–416 ms before and
281–390 ms after, and GC time stays flat, so I'd call it neutral. The
gain grows with every extra client on a session.

**Decision needed.** Values that `structuredClone` mishandles now
serialize the same way JSON serializes them, which is how every other
stream event is already sent:
- A function or symbol anywhere in display state used to make
`structuredClone` throw. The stream listener then unsubscribed and the
client silently stopped getting events. Now the value is dropped and the
stream keeps going.
- A class instance with `toJSON` used to arrive as its own fields, for
example `{"cents":150}`. It now sends its `toJSON` output, for example
`"$1.50"`.
- An `Error` with custom enumerable fields used to arrive as `{}`. It
now keeps those fields, for example `{"statusCode":403}`.

The run engine turns tool errors into message strings, so I don't expect
the last two in practice. Please confirm this is acceptable.

**Open risks and questions**

Sharing depends on a convention: once a frame is marked shared it must
not be mutated. No adapter mutates chunks (`redactStreamChunk` returns
`display_state_changed` as-is), and the frames are not frozen. A custom
adapter that mutated a chunk would leak the change to other clients of
the session. In-process consumers of the route also now receive the same
frame object as the other streams of that session.

If one client drains a shared frame quickly and another is stalled, the
cached JSON stays alive until the stalled client reads the frame. Each
queued frame then pins about one serialized frame. That is roughly the
size the old per-client clone held, so not worse, but a stalled client
still costs memory per queued frame.

I haven't reproduced the production growth itself. This PR removes the
per-client clone, the duplicated strings and the repeated stringify. It
doesn't address two other things:
- **Unbounded queues.** The stream handler enqueues without checking
`desiredSize`, so a client that stops reading can make its queue grow
without limit. I haven't checked how each adapter handles a slow socket.
- **Full snapshots.** Every snapshot still carries the full state,
including every completed tool result.

Either could account for part of the 2 → 7 GB growth.

If the handler and an adapter were ever loaded from different builds
(ESM and CJS), they would hold separate caches. Clients would still get
correct bytes, just without the shared serialization. In the current
`dist`, both import `serializeStreamChunk` from the same chunk.

Each adapter still builds and encodes `data: ${json}\n\n` for every
client. That is most of the remaining per-client cost, about 58 MB per
client in the benchmark. Caching encoded frames would mean touching
every adapter, so I left it out.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

## ELI5

The server sends the same agent status updates to many viewers. Before
this change, it made a full copy of each update for every viewer. Now it
makes one snapshot per update and reuses the serialized result for
viewers that receive the same update. This uses less memory and less
processing.

## Summary

This change affects only `@mastra/server`. It does not change
`@mastra/core` or the wire format.

The change does the following for `display_state_changed` events:

- Creates one snapshot per dispatched event for all streams in a
session.
- Shares strings and other primitives. Copies objects and arrays.
- Marks a frame as shared when several streams use it. Caches its
serialized JSON so clients reuse one serialization. A single-client
stream does not create a cache entry.
- Clears the snapshot slot in a microtask. A later re-emission of the
same event gets a new snapshot.

The change does not alter `SessionBus` or its ordering guarantees.

## Changes by file

- `.changeset/modern-regions-lead.md` (+5): Adds a patch changeset for
`@mastra/server`.
- `packages/server/src/server/handlers/agent-controller.ts` (+87/-13):
Builds the display-state snapshot. Recursively copies objects and
arrays. Preserves shared and circular references. Resolves `toJSON`.
Unboxes `Number`, `String`, and `Boolean` objects. Clones typed-array
views. Keeps an own `__proto__` key as a data property. Converts
Map-valued fields to records. Reuses one serialized frame for streams
that receive the same event during one synchronous dispatch.
- `packages/server/src/server/server-adapter/serialize.ts` (+23/-2):
Adds `shareStreamChunk<T extends object>(chunk: T): T`, which marks an
object for shared serialization. `serializeStreamChunk` reuses the first
result for marked objects, including failures. Unmarked chunks serialize
on each call. The cache uses weak object keys.
- `packages/server/src/server/handlers/agent-controller.test.ts` (+234):
Adds wire-level tests. The tests cover:
  - Queued frames that keep the state from their emission time.
  - Identical frames for multiple clients of one session.
  - Isolation between sessions.
  - Tool results with an own `__proto__` key.
  - Boxed primitive values.
- Refreshed state when a held `display_state_changed` event is
re-emitted.
- `packages/server/scripts/bench-agent-controller-stream.ts` (+263):
Adds a benchmark. It drives a session through the stream route with a
set number of clients. It reports CPU time, synchronous `session.emit`
time, GC activity, sampled allocations, wire size, frame count, and
per-client wire hashes.

## Behavior changes

- Clients receive identical bytes for a shared event.
- Message text and tool results are shared, not copied.
- An unclonable value no longer closes the stream. Functions and symbols
are dropped.
- Class instances serialize through `toJSON`.
- Enumerable custom fields on `Error` objects are kept.
- An own `__proto__` key is kept as a data property.
- Boxed `Number`, `String`, and `Boolean` values are unwrapped, as in
JSON serialization.

## Testing (author-reported, not verified here)

- `packages/server`: 3,574 tests passed. `tsc --noEmit`, lint, and
Prettier passed.
- `packages/core` `display-state.test.ts`: 106 tests passed, including
the coalesced-flush ordering test.
- `server-adapters/hono`: 3,524 tests passed. Four files did not load
because `@mastra/client-js` and `@mastra/duckdb` were not built.
- Benchmark, one client: allocation fell from 174.8 MB to 122.0 MB.
- Benchmark, five clients: allocation fell from 851.7 MB to 349.2 MB.
- Full-stream hashes matched before and after for one and five clients.
- CPU and GC results were reported as neutral. The 0-client row runs no
changed code and was reported as noise.
- CI status on the current head: not available.

## Open risks and review questions

- The author has not reproduced the production memory growth.
- Slow-client queues are unbounded.
- Snapshots still include full state.
- Shared frames are not frozen. A custom adapter that mutates a shared
frame could affect other streams in the session.
- Adapters still encode a separate SSE frame per client.
- The author asks reviewers to confirm that the JSON handling for values
that `structuredClone` mishandles is acceptable.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: mastracode <284800079+mastra-platform[bot]@users.noreply.github.com>
2026-11-16 18:40:25 -08:00
Tyler Barnes
4feafd33e1
feat(mastracode): export runTui so other programs can start the TUI with extra session options (#30371) 2026-11-16 19:34:58 -07:00
mastra-platform[bot]
c451f9c63a
fix(create-factory): stop scaffolding when a --tag registry lookup fails (#30614)
> Opened by @DSchau

Follow-up to #30598.

## Summary
`create-factory --tag <dist-tag>` looks up each `mastra`/`@mastra/*`
package's dist-tags with `npm view` and pins the package to that
version. Before this change, a failed lookup (for example a network
error or a registry 5xx) was handled the same way as a package that has
no release under the tag. If one lookup failed while the others
succeeded, the CLI kept the template's version for that package, showed
a "no release found" warning, and installed a project that mixed release
channels.

Now:
- **A lookup fails for any package:** the CLI stops before installing
and names the affected packages ("Could not look up the "alpha" versions
of @mastra/factory. Check your network connection and npm registry
access.").
- **A package has no release under the tag:** unchanged. The CLI keeps
the template's version and shows a warning.
- **No package has a release under the tag (e.g. a typo):** the CLI
stops with "No Mastra packages are published under the "<tag>" tag."

## Test plan
- [x] New test: one `npm view` fails while the others succeed. The
scaffold rejects, names the package, and never runs install.
- [x] New test: an unknown tag fails before install with the new
message.
- [x] Existing tests still pass, including the one where a package has
no release under the tag.
- [x] `vitest` 74/74, `tsc --noEmit`, `oxlint` all pass

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

**ELI5:** When you create a new Mastra project with a version tag, the
tool now stops if it cannot check a package's version. Before, it could
not tell a failed check apart from a package with no release under that
tag. Now it stops and tells you which package failed the check.

## Summary

This change updates how `create-factory --tag` handles npm registry
lookups for `mastra` and `@mastra/*` packages. It separates two cases:

- **Lookup failure.** The registry request throws. Scaffolding stops
before installation. The error names the packages whose lookup failed
and suggests an `npm view <package> dist-tags` check.
- **No release under the tag.** The registry responds, but the package
has no version for the tag. The package keeps its template version. A
warning is shown.

If no package resolves under the tag, scaffolding stops with the error
`No Mastra packages are published under the "<tag>" tag.`

## Changes

- `mastracode/mastra-factory/src/utils/versions.ts`
- `PinResult` gains a `failed` field that lists packages whose lookup
failed.
- `resolveDistTag` returns `{ version }` for a valid version, `{}` when
the tag has no valid version, and `{ failed: true }` when the lookup or
parsing throws.
- `pinMastraPackages` returns without writing `package.json` if any
lookup failed.
  - Packages with no version for the tag stay in `unresolved`.
- `mastracode/mastra-factory/src/create.ts`
- If `pinMastraPackages` throws, the pinning spinner stops with a
failure message. The error is rethrown.
- If any lookups failed, the spinner stops and the error names the
failed packages and includes a registry and tag check command.
- When no package pins and some packages are unresolved, the error
reports that no packages are published under the tag. It includes a
command to list available tags.
- `mastracode/mastra-factory/src/create.test.ts`
- New test: a tag with no published Mastra packages fails with the
tag-specific message. Installation does not run.
- Replaced test: a lookup failure for `@mastra/factory` fails with a
package-specific error. Other lookups return tag data. `@mastra/core`
remains at `latest`. Installation does not run.
- `.changeset/create-factory-tag-lookup-errors.md`
- Adds a `patch` changeset for `create-factory`. It describes the
lookup-failure and missing-release behavior.

Diff size: 4 files, +61 and -16 lines.

## Verification

The PR author reports that `vitest` (74/74), `tsc --noEmit`, and
`oxlint` pass. These results are not verified here. This summary is
based on the diff metadata and the supplied change summaries only.
<!-- 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>
2026-11-17 01:30:49 +00:00
Tyler Barnes
8847e06005
ci(test-tiers): name the merge that broke a skipped test and alert its author (#30606)
## Why

Test tiers skip test files and jobs on PRs when they haven't failed in
30 days. The full suite still runs on the alpha versioning PR
(`changeset-release/main`), so a merge that breaks a skipped test goes
green on its PR. The failure then turns up later on the versioning run,
with nobody pointed at it. That's what happened with #29370, which broke
`goal-step.test.ts`, and #30434, which broke the Playground autosave
test.

## What this does

When a versioning run fails in a file or job that tiers had skipped, the
tier update now passes those escapes to a new `attribute` job. That job:

1. Finds the last green versioning run (up to 72 hours back) and lists
the first-parent merges on `main` between it and the red head (at most
60).
2. Bisects those merges, running only the escaped test file at each
step. It checks out the commit, installs, builds the package and its
dependencies from the read-only Turbo cache, and runs Vitest across the
`unit`, `typecheck`, `e2e:packages/*` and `e2e:client-sdks/*` projects,
the same ones the PR jobs use.
3. Names a merge only when the file fails there twice and passes at its
parent. A file that passes at the red head is reported as not reproduced
(a flake). A file that also fails before the range, or can't be run, is
unconfirmed. Nobody is tagged in either case.

When a file is reported by more than one project, any failure wins. The
file passes only if every result passed, and a file with no result is
unconfirmed.

A separate `notify` job holds the Slack token and sends the messages. If
`attribute` fails or times out (45 minutes), `notify` sends the plain
fallback alert that `update` prepared. The escaped file goes back into
the PR tier for 30 days, as before.

### Who gets tagged

The message names the PR, its title and its author, tagged through
`.github/slack-users.json`. A login that isn't in the map is printed as
a plain `@login`.

When the PR was opened by a bot, the bot can't answer for it, so the
message tags a person instead and says who they are to the PR:

1. the human who merged it ("merged by"); otherwise
2. every human whose latest review approved it ("approved by");
otherwise
3. the human(s) credited on the most commits, counting commit authors
and `Co-authored-by` trailers with GitHub noreply addresses
("co-authored by"); otherwise
4. `@here`.

`@here` is for when we can't tell who the person is. It is not for a
person we know but who is missing from the Slack map: they still get a
plain `@login`. Reviews and commits are read across every page. A lookup
that fails, or a commit list at GitHub's 250-commit cap (which may be
cut off), counts as unknown, and that rung is skipped rather than
guessed from. PR titles are escaped, so a title can't inject `<!here>`
or other mentions.

## Testing

- `node --test scripts/test-tiers/*.test.mjs`: 96 pass on Node 22 and
24. The new tests fail with the attribution module removed. Each
stand-in rung, the title escaping, any-failure-wins aggregation, E2E
project selection and pagination fails its own test when that rule is
removed.
- Replays against real versioning runs, at the real commits:
- #29370 (`goal-step.test.ts`, run 43907413456): found merge `929c8ab`
over 3 merges in 182 s.
- #30434 (autosave test, run 43750070686): found merge `b666fdb` over 2
merges in 495 s. The PR was opened by a bot, so the message reads "by
mastra-platform[bot] (bot), merged by @abhiaiyer91".
- A flaky `execute-tool-core.test.ts` failure (run 43848445791): passed
at the red head, so not reproduced and no alert, in 64 s.
- The runner, run for real on `main`, passed a unit file and a package
E2E file and returned an error for a missing file. That took 51 s.
- `actionlint` reports only the custom runner label.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

ELI5: When a versioning test fails in a file that the test tiers had
skipped, this PR finds the code change that caused it. It then posts a
Slack message that names the likely author. If that search cannot
finish, it posts a simpler alert instead.

## Overview

This PR adds attribution for test failures from versioning runs. The
failing file or job was skipped by the test tiers. The PR adds a new
`attribute` job. The job searches for the failing commit range and
reports the merge that introduced the failure. A separate `notify` job
posts a fallback alert if attribution fails or times out.

## Changes

- **`scripts/test-tiers/attribute.mjs`** (new, +455): Main attribution
logic.
  - Finds files and jobs that moved from tier `out` to `in`.
- Selects the latest successful versioning run from the preceding 72
hours.
- Considers at most 60 first-parent merges between the green run and the
failing run.
  - Bisects those merges by running the escaped file.
- Reports a merge only when the file fails there twice and passes at its
parent.
  - Reports a file as not reproduced when it passes at the failing head.
- Reports a file as unconfirmed when it also fails before the range or
cannot run.
  - Resolves culprit PRs and selects stand-ins for bot-authored PRs.
  - Generates Slack messages with escaped mrkdwn.
- Runs the `unit`, `typecheck`, `e2e:packages/*`, and
`e2e:client-sdks/*` projects.
- Passes a remaining-time timeout to each command. The script defaults
`DEADLINE_MINUTES` to 38. The PR description states a 45-minute job
deadline. The source does not yet confirm how these two values relate.
- **`scripts/test-tiers/attribute.test.mjs`** (new, +518): Tests for the
functions above. Covers bisect steps, verdicts, stand-ins, alert
grouping, paginated lookups, and deadline-aware runner timeouts.
- **`scripts/test-tiers/update.mjs`** (+9/-1): Imports `escapedFiles`.
Adds an optional `--escapes-out=<file>` argument to the versioning
command. Snapshots tier data before applying failures. Writes the run ID
and escape details to the output file when the argument is set.
- **`.github/workflows/test-tiers.yml`** (+106/-2): Records escapes in
job outputs. Runs the `attribute` job when escapes exist. Posts
attribution results or the fallback `notify` alert. Documents the new
behavior.
- **`.github/slack-users.json`** (+1): Adds an empty JSON object.

## Alert behavior

- For human-authored PRs, the alert names the PR, title, and author.
- For bot-authored PRs, the alert names, in order:
  1. The human who merged the PR.
  2. If unavailable, the humans with the latest approving reviews.
  3. If unavailable, the most-credited commit authors.
  4. If none are available, `@here`.
- Unknown Slack mappings appear as plain `@login`.
- Titles are escaped to prevent injected mentions.

## Result semantics

- A file that fails in any project result is a failure.
- A file passes only when every project result passes.
- A file with no project result is unconfirmed.
- An escaped file returns to the PR tier for 30 days.

## Verification

- The PR author reports 96 passing tests on Node 22 and 24, using `node
--test scripts/test-tiers/*.test.mjs`. This was not verified in this
review.
- The PR author reports replays against two real versioning runs that
found the breaking merges. This was not verified in this review.
- The PR author reports a flaky failure that was not reproduced and did
not alert. This was not verified in this review.
- The PR author reports a real `main` runner check that passed unit and
package E2E files and errored on a missing file. This was not verified
in this review.

## Scope

- Total: 5 files changed, +1089 / -3 lines.
- No exported or public declarations were removed.
- New exported functions and constants are listed in the `attribute.mjs`
source.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: remy-builder[bot] <324360501+remy-builder[bot]@users.noreply.github.com>
2026-11-16 18:27:39 -07:00
Leo
b1ba914ea1
fix(connect): accept PostHog column type pairs in posthog_run_query (#30541)
## Summary

`posthog_run_query` in `@mastra/connect` failed provider-response
validation whenever PostHog returned column types, which it does for
every query with columns, even `select 1`: the schema expected `types`
as strings, and PostHog sends `[columnName, clickhouseType]` pairs such
as `[["1", "UInt8"]]`. Both schemas now accept those pairs, through a
generator override in `scripts/generate-provider.ts` like the Fireflies
and OpenAI ones. The pinned template commit returns 404 upstream, so the
override's output was applied to `tools/run-query.ts` by hand, and a
generator test proves it matches a regeneration byte for byte.

```diff
 // posthog/run-query, in both runQueryOutputSchema and ProviderResponseSchema
-types: z.array(z.string()).nullish()
+types: z.array(z.tuple([z.string(), z.string()])).nullish()
```

## Evidence

The new test `src/__tests__/posthog-run-query.test.ts` goes through the
public `tools()` resolver against a real localhost HTTP server; only the
PostHog response body is scripted, starting from the issue's `select 1`
payload.

- **Before** (main's generated tool): 4 of 9 fail. Three are the bug,
with the issue's error:
  ```
  × returns the rows and column types for select 1
  × returns a type pair per column for a grouped query
  × keeps column types for a query that returns no rows
ZodError: path ["types", 0]: Invalid input: expected string, received
array
  ```
The fourth, `rejects flat string types`, fails because main accepts flat
strings; it pins the new contract.
**After:** 9 of 9 pass. Pairs, multiple columns, zero rows, and `null`,
omitted or empty `types` are accepted; flat strings, a one-element entry
and a three-element entry are rejected.
- **Response shape:** PostHog's source fills `types` with pairs on every
path
([`query.py:140`](d4c65ec5da/posthog/hogql/query.py (L140))
`Sequence[tuple[str, str]]`, from
[`with_column_types=True`](d4c65ec5da/posthog/hogql/query.py (L1097));
[`direct_sql/adapter.py:63`](d4c65ec5da/posthog/hogql/direct_sql/adapter.py (L63))
`list[tuple[str, str]]`). The issue and triage suggested a union that
also keeps flat strings; it is left out because no PostHog path emits
them. Only `posthog_run_query` declared `types` as `string[]`;
`posthog_get_insight` and `posthog_list_insights` already use
`z.array(z.unknown())` and are unaffected.
- **Generator:** with the override off, the reconstructed template
regenerates main's `run-query.ts` byte for byte; with it on, it
regenerates the committed file byte for byte. Five drift cases stop
generation if the template changes shape. 40 of 40 pass.
- **Smoke step:** the live `run query` step now fails unless `types`
holds one name/type pair per returned column.
- `@mastra/connect` suite 531 of 531, `tsc --noEmit`, `oxfmt --check`
and `oxlint` pass (type-aware lint is left to CI).
- **Not checked:** a live PostHog query (no Platform credentials here)
and regeneration from the real pinned template (the commit returns 404).
The byte-for-byte match proves the reconstructed fixture generates
main's file, not that it equals the upstream source.

## Merge Danger

Low risk; reverting the PR undoes it. The output contract changes:
`types` goes from `string[]` to `[string, string][]`, which the
changeset states for anyone typed against the exported schema. Pair
responses used to fail and now pass; `null`, omitted and empty `types`
pass as before; flat strings, which PostHog never sends, are now
rejected. If PostHog ever changes the shape again, the whole call fails,
rows included. Only `posthog_run_query` changes. On main,
`src/providers/posthog/tools.ts` already differs from its manifest
checksum, so the next regeneration will rewrite it too; this PR does not
touch it.

## Council review

Rounds: 8 (stopped: stalled)

| Seat | R1 | R2 | R3 | R4 | R5 | R6 | R7 | R8 |
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
| Claude Opus 5.5 | not run | 8.5/10 | 9/10 | 9/10 | 9/10 | 9/10 | 9/10
| 9/10 |
| GPT-6.1 Sol | 9/10 | 9.3/10 | 9.5/10 | 9.4/10 | 9.5/10 | 9.5/10 |
9.5/10 | 9.5/10 |
| Grok 4.7 | empty seat | empty seat | empty seat | empty seat | empty
seat | empty seat | empty seat | empty seat |
| Kimi K3.1 | not run | not run | not run | 10/10 | 9.3/10 | 9.8/10 |
9.5/10 | 9.5/10 |
| DeepSeek V4.1 Flash | not run | not run | not run | 9/10 | 9/10 | 9/10
| 9/10 | 9/10 |

The bar was 9/10 in every category from every seat. Every seat scored
correctness and test proof at 9 or above in every full-panel round. The
last five rounds did not raise the median score, so the council stopped:
in round 8 Opus and DeepSeek scored scope 8.5 over the size of the
reconstructed generator fixture, which earlier rounds asked for, and
their remaining notes are polish.

Fixes #30528

Follow-up: fix the schema in the upstream PostHog run-query template,
then remove the override and replace the reconstructed test fixture with
the real template.

Created with Claude Opus 5.5 in T3 Code.

🤖 Generated with [Claude Code](https://claude.com/claude-code)


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

**ELI5:** PostHog now sends column types as pairs. Connect's query tool
expected a plain list of strings, so every successful query failed. This
change makes the tool accept PostHog's pair format and return it
unchanged.

## Overview

`posthog_run_query` now accepts `types` as arrays of `[columnName,
clickhouseType]` string pairs. The change applies to the provider
response schema and the tool output schema. It addresses issue `#30528`.
The issue asks for PostHog's pair format to validate. This change uses a
strict pair schema. It does not use the issue's suggested union or a
looser unknown-value schema.

## Changes by file

- `.changeset/posthog-query-column-types.md`: Adds a patch changeset for
`@mastra/connect` (+5).
- `packages/connect/src/providers/posthog/tools/run-query.ts`: Changes
`types` in the output schema and the provider response schema to arrays
of `[string, string]` tuples. Updates the output description to identify
each pair's contents. The file is edited by hand (+5/-2).
- `packages/connect/src/providers/posthog/.manifest.json`: Updates the
SHA-256 entry for `tools/run-query.ts` to match the hand edit (+1/-1).
- `packages/connect/scripts/generate-provider.ts`: Adds
`adaptPosthogRunQuery`. The adapter rewrites `types` in the output and
provider-response schemas to string-pair tuples. It also updates the
output description. Generation throws if an expected declaration or
pattern is missing. The override dispatcher applies this adapter to
`posthog/run-query` (+49).
- `packages/connect/src/__tests__/provider-commands.test.ts`: Adds a
reconstructed `run-query` template fixture. Adds a byte-for-byte test
that generation with the override off matches the pre-override tool.
Adds a byte-for-byte test that generation with the override on matches
the shipped tool and manifest checksum. Adds drift cases that expect
generation to reject changes to the response schema, the output `types`
schema, or the output description (+248).
- `packages/connect/src/__tests__/posthog-run-query.test.ts`: Adds a
`describe` block with seven cases. The cases cover `select 1`, a grouped
query, a query with no rows, `types: null`, an omitted `types` field, an
empty `types` list, and rejection of entries that are not name/type
pairs (+218).

Totals: 6 files changed, 526 lines added and 3 lines removed.

## Verification

These results are author-reported. They were not re-run for this
summary.

- The PR description reports the `@mastra/connect` suite (526 tests),
`tsc --noEmit`, `oxfmt --check`, and `oxlint` as passing.
- The PR description reports five passing `posthog-run-query` cases. The
test file contains seven cases. The reported count may predate the last
change.
- The PR description reports the PostHog generator suite as six tests.
The generator tests are in `provider-commands.test.ts`. That file
contains more than six cases, so the reported count may not cover the
full file.

## Not verified

- A live PostHog project was not tested. Platform credentials were
unavailable.
- Regeneration from the real pinned upstream template was not tested.
The upstream template commit could not be fetched. The generator tests
use a fixture rebuilt from the generated tool.

## Follow-up

- The generator override exists because the upstream template commit
could not be fetched. The manifest checksum and `run-query.ts` depend on
the hand edit until the upstream template is fixed and regenerated. The
override then needs removal.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 17:17:59 -08:00
Ward Peeters
2d53b0462d
fix(factory): delete an intake rule without renumbering the rules after it (#30613)
## Problem

On a deployment with a remote Postgres (e.g. Shipyard), `DELETE
/web/factory/projects/:id/intake-routes/:routeId` took very long, and
deleting a rule broke other admins' open rule edits.

The delete closed the position gap it left: it rewrote every rule after
the deleted one with two sequential UPDATEs each (park at a negative
position, then the final position — ~2N round trips inside one
transaction). Each rewrite also bumped the rule's revision, so an edit
another admin had open failed with a stale-revision 409 when saved.
Deleting a board compacted its surviving project's rules the same way.

## Fix

Stop compacting positions on delete. Gaps are safe: every reader sorts
by `position`, new rules insert at `max + 1`, and reorder / insert-ahead
renumber the whole list anyway. The single-rule delete and the board
delete now only remove the deleted rows — O(1) route-table writes, and
the surviving rules keep their positions, revisions and order. No schema
change; the UI already renders rules by list order.

## Tests

- New storage scenario (LibSQL + Postgres): rules over two boards,
delete one near the top → zero writes to the route table (spied), the
other rules keep order/revision/fields exactly, an edit loaded before
the delete still saves, and later insert + reorder still work over the
gap.
- New HTTP scenario (LibSQL + Postgres): delete a rule through the API →
remaining rules keep revision 1 and a PATCH holding a pre-delete
revision answers 200 instead of 409.
- Updated the board-delete scenario to pin that surviving rules keep
their positions/revisions, and removed assertions that pinned the old
contiguous renumbering.
- Both new scenarios were verified red on the previous code (8 route
writes / revision bumps / 409) and green on this change.
- Net test lines: +45 (81 insertions, 36 deletions across 4 test/source
files).

Gates: `build:lib`, `tsc --noEmit`, `oxlint --type-aware`, `oxfmt`,
focused intake/boards/dispatcher suites on LibSQL and a dedicated
postgres:16 container, CLI route metadata regenerated with no drift.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

**ELI5:** When someone deletes an intake rule, the app used to renumber
every rule below it. That caused slow writes on remote databases and
conflicts for editors who had a rule open. Now deletion removes only the
selected rule, and the other rules keep their positions and revisions.

## Summary

This change stops intake-rule deletion from renumbering surviving rules.
It applies to single-rule deletion and to board deletion. The change
also prevents board-scoped reorder and insert-ahead from renumbering or
revision-bumping rules that do not move.

Before this change, deletion closed the position gap by updating every
later rule. On remote Postgres, this added many route-table writes. It
also changed each survivor's revision. An editor who loaded a rule
before the delete then received a stale-revision conflict on save.

After this change:

- Deletion removes only the selected rows.
- Surviving rules keep their positions, revisions, and order.
- Position gaps are allowed. Readers sort by position.
- New rules use `max + 1`.
- Project-wide reorder still compacts positions.
- Board-scoped reorder assigns the board's rules only to position slots
that the board already holds. Other boards' rules keep their positions
and revisions.
- Insert-ahead uses a free gap before the catch-all when one exists.
Otherwise, it moves only the catch-all and the rules after it.
- Default seeding is unchanged. It places new defaults at the start of
the list.
- No schema change is included.

## Changes by file

- **`.changeset/purple-buckets-spend.md`**: Adds a patch changeset for
`@mastra/factory`. It describes the delete fix. (+5/−0)
- **`mastracode/factory/src/storage/domains/boards/base.ts`**: Removes
renumbering from intake-route and board deletion. Adds the gap-aware
insert-ahead and board-scoped reorder behavior. `placeIntakeRoutes`
delegates to `moveIntakeRoutes`, which leaves routes already in place
unchanged. (+45/−14)
-
**`mastracode/factory/src/storage/domains/boards/intake-routes.test.ts`**:
- The route-order helper accepts strictly increasing, distinct positions
with gaps.
  - `emptyProject` deletes seeded routes in listed order.
- A new test covers deletion of an early route. It checks that no
route-table updates run. It checks that other routes keep their order,
fields, and revisions. It checks that an edit using a previously read
revision succeeds, and that later insert and reorder work across the
gap.
- New tests cover board-scoped reorder across a gap and insert-ahead
across a gap.
- The concurrency test title and comments describe adding, deleting, and
editing routes. (+94/−22)
-
**`mastracode/factory/src/storage/domains/boards/intake-order.test.ts`**:
The board-deletion test expects surviving routes to keep their positions
and revisions. The title states that other boards' rules are unchanged.
(+5/−4)
- **`mastracode/factory/src/routes/intake-routes.test.ts`**: Test setup
deletes unseeded routes in listed order. A new regression test checks
that deleting one route leaves other revisions unchanged. It also checks
that an editor holding a pre-delete revision can update a later route
without a conflict. (+24/−2)

Totals: 5 files changed, +173 lines, −42 lines.

## Verification

The PR author reports these results. This review did not run them.

- New LibSQL and Postgres storage and HTTP scenarios fail on the
previous code and pass with this change. This includes the board-scoped
reorder and insert-ahead regression scenarios.
- Reported gates: `build:lib`, `tsc --noEmit`, `oxlint --type-aware`,
`oxfmt`, and focused intake, boards, and dispatcher suites on LibSQL and
a Postgres 16 container.
- CLI route metadata was regenerated with no drift.
- The author reports that all gates were rerun after the follow-up
changes and passed.

## Review notes

- Behavior change: deleted rules leave position gaps. Any reader that
assumes contiguous positions starting at zero will fail. The test helper
accepts gaps. Other readers were not checked in this review.
- Review severity counts: not available.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: mastracode <284800079+mastra-platform[bot]@users.noreply.github.com>
2026-11-16 16:45:21 -08:00
Damien Schneider
c638825c83
feat(factory): list each Connect connection's tools in Settings › Tools (#30610)
## Description

Stacked on #30607. Settings › Tools lists a project's Mastra Connect
connections, but not the tools sessions actually get from them, so
there's no way to check what a `tools` option narrows to (e.g.
`allowTools: ['posthog_get_*', 'posthog_list_*']`) without starting a
session.

New `GET /web/integrations/platform/connect-tools/tools` resolves the
tools a session started by the signed-in user would get: Factory's
default Connect tools, or whatever the `tools` option returns. Each tool
comes back with its description, whether it asks for approval and, for
default tools, whether Factory leaves it out because it deletes or
archives. GitHub/GitLab tools stay out, like their connections. If the
tools can't be resolved, it answers 502 `tools_unavailable` with the
reason, so the panel shows a retry instead of an empty list.

In `session-tools.ts` the unfiltered resolver is split from the session
wrapper, so sessions behave exactly as before (filtered, and an empty
set with a warning on failure) while the listing sees failures.

The panel shows "N tools" per connection and expands to the list,
matched to connections by Connect's `<integrationId>_` tool prefix. With
a `tools` option, a connection the code doesn't use shows "No tools",
and tools from no listed connection (MCP, custom tools) appear under
"Other tools from code". One caveat: a `tools` function that reads the
request sees the signed-in user's request here, not a session's.

**Default tools**: what sessions get, then what Factory leaves out:

![Default Connect tools with left-out
tools](https://raw.githubusercontent.com/mastra-ai/mastra/3f685d750cf1e8523836780c067d2728c654fcf6/.pr-assets/connect-tool-list/default-tools.png)

**Tools from code**: a `tools` option narrowing PostHog to read tools,
not using Linear, and adding one tool of its own:

![Tools from a tools option, per
connection](https://raw.githubusercontent.com/mastra-ai/mastra/3f685d750cf1e8523836780c067d2728c654fcf6/.pr-assets/connect-tool-list/tools-from-code.png)

Tests: `factory.test.ts` boots a real Factory against the Platform
stand-in and checks the listing matches what sessions get, including the
left-out Linear tools, for both the default and a narrowing
`connectTools()` option, plus the 502 when the Platform is down. Route
tests cover approval flags, custom tools not being filtered, missing
setup and signed-out callers. MSW tests cover counts, ordering, "No
tools", "Other tools from code" and the retry. Patch changesets for
`@mastra/factory` and `mastra`, plus README notes.

## Related issue(s)

Related to #30579 (fixed in #30607).

## 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)
- [ ] 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)
- [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

---
_Generated by [Claude
Code](https://claude.ai/code/session_01VhgyDVR9FKd4yzi7nnjSdi)_

---------

Co-authored-by: Damien Schneider <damien@mastra.ai>
2026-11-16 16:40:20 -08:00
Damien Schneider
a6dbd29a4e
fix(factory): list Connect connections in Settings › Tools when tools is set (#30607)
## Description

Settings › Tools said "Mastra Connect tools are off" whenever a Factory
set the `tools` option, even when that option was itself Connect tools,
e.g.:

```ts
tools: connectTools({ providers: ['posthog'], allowTools: ['posthog_get_*', 'posthog_list_*'] })
```

Sessions got the PostHog tools fine, but `factory.ts` dropped the
Connect project id as soon as `tools` was set, so `GET
/web/integrations/platform/connect-tools` answered 404
`connect_tools_off` and the panel showed it as off.

The project id is now resolved independently of `tools`. Whenever the
Factory has Platform credentials and `MASTRA_PROJECT_ID`, the route
lists the project's connections and returns `toolsSource: 'default' |
'custom'`. With `custom`, the panel keeps the list and says session
tools are set in code. When setup is missing, the 404 keeps the
`connect_tools_off` code (older CLIs still read it) and adds `reason:
'no_credentials' | 'no_project_id'`, so the panel names the one missing
piece instead of listing every cause. The route also checks sign-in
before answering, so signed-out callers can't read how the Factory is
set up.

What sessions get is unchanged: `tools` still replaces the default
Connect tools.

**Before**, a Factory narrowing Connect tools in `tools`:

![Before: Mastra Connect tools are
off](https://raw.githubusercontent.com/mastra-ai/mastra/cdf6eb7b8f5faca30a1cdb9231c0e9ba3cbe6d80/.pr-assets/connect-tools-panel/before.png)

**After**, same Factory:

![After: connections listed with a note that tools are set in
code](https://raw.githubusercontent.com/mastra-ai/mastra/cdf6eb7b8f5faca30a1cdb9231c0e9ba3cbe6d80/.pr-assets/connect-tools-panel/after-tools-in-code.png)

**After**, Platform credentials set but no `MASTRA_PROJECT_ID`:

![After: names the missing
MASTRA_PROJECT_ID](https://raw.githubusercontent.com/mastra-ai/mastra/cdf6eb7b8f5faca30a1cdb9231c0e9ba3cbe6d80/.pr-assets/connect-tools-panel/after-no-project-id.png)

Tests: route tests cover the custom source, each missing reason and
signed-out callers. A `factory.test.ts` case boots a real Factory with a
narrowing `connectTools()` against the Platform stand-in and reads the
route; it fails with the 404 without the fix. MSW tests cover the panel
states, including an older server that sends no reason. Patch changesets
for `@mastra/factory` and `mastra` (the Settings UI ships in the CLI),
plus a README note.

## Related issue(s)

Fixes #30579

## 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

- [x] 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

---
_Generated by [Claude
Code](https://claude.ai/code/session_01VhgyDVR9FKd4yzi7nnjSdi)_

---------

Co-authored-by: Damien Schneider <damien@mastra.ai>
2026-11-16 16:40:20 -08:00
Damien Schneider
46361a59f9
feat(factory): announce session writes so sidebars update live (#30617)
**─────── TLDR ───────**
> A session someone starts, renames, hides or follows to a card now
shows in every teammate's sidebar within a second, not up to a minute
later.

Session and follow writes never sent a feed frame, so other open
sidebars only caught up on the 60 s safety refetch, or on a 15 s
`settling` poll while a session was starting. Now every committed
session or follow write announces its project. Every replica forgets its
cached list for that project, and the feed frame makes the open tabs
reload.

### Behavior changed

a teammate starts, renames or makes a session private
&nbsp;&nbsp;├─ **was** — your sidebar caught up after 15 to 60 s
&nbsp;&nbsp;└─ **now** — it updates on the next feed frame

a session follows or stops following a card
&nbsp;&nbsp;├─ **was** — same 60 s delay
&nbsp;&nbsp;└─ **now** — same feed frame

a session is still starting in an open sidebar
&nbsp;&nbsp;├─ **was** — the sidebar polled `session-rows` every 15 s
&nbsp;&nbsp;└─ **now** — no poll; each write sends its own frame

the session list, on a sidebar reload with no write since the last one
&nbsp;&nbsp;├─ **was** — one probe query, then a full reload whenever
the probe moved
&nbsp;&nbsp;└─ **now** — kept in memory, no query for it

### Gain

> ██████████████████ **#30616** `8.5 queries`
> ██████████ **this PR** `4.5 queries`

Database queries per sidebar request, same bench as #30616: 50 viewers,
about 4,000 sessions, local Postgres. CPU for those 50 viewers went from
225 to 243 ms, which I read as noise but did not prove.

### Shape changed

| | | |
|---|---|---|
| **−** | `ProbedList`, `probeNewest` | a probe per read plus a 5 s
settle window |
| **−** | `settling`, `isSettling` | the poll they drove is gone |
| **+** | `AnnouncedLists` | list kept until a write announces it;
mirrors `KeptCards` |
| **+** | `shareSessionListChanges` | bus wiring; mirrors
`shareLinkedRepositoryChanges` |
| **~** | `unsubscribeFromWorkItem` | takes `factoryProjectId`, to
announce the right list |

removed from the wire
&nbsp;&nbsp;&nbsp;&nbsp;`settling` on `GET …/session-rows` · `settling`
on `GET …/session-activity`

### Decisions

- **one topic for sessions and follows, apart from board changes** — a
session write must not make `KeptCards` reread cards; merge topics if
you disagree
- **four one-shot writes moved to `updateAtomic`** — the announcement
needs the row's project; one transaction per session lifetime each
- **kept the `UNMATERIALIZED_POLL_MS` poll in `useWorkspaces`** — feed
frames don't refetch that query; out of this PR's scope

### Watch

> [!WARNING]
> A lost bus message leaves that replica's list <mark>stale for up to 60
s</mark>, the max age every kept list has. A replica that cannot
subscribe reads the database on every request instead.

on deploy: replicas still on the old build neither announce nor listen,
so their writes reach new replicas within 60 s until the rollout ends.

### Not verified

- [ ] a sidebar updating live in a browser, on two accounts

---

> ██████████████████ **source** `+264 −156` — net +108
> █████████████████ **tests** `+253 −277` — net −24
> █ **changeset** `+5`
> █ **generated** `+2 −10`
> █ **docs** `+1 −1`

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

**ELI5:** Teammates' open sidebars now update when someone changes a
session or a follow. Before, the sidebar asked the server again and
again. Now the server sends a message when something changes.

## Summary

This pull request changes how `@mastra/factory` reports session and
follow list changes to open sidebars. It replaces periodic sidebar
refetches with write-triggered feed frames.

### Behavior changes

- Session starts, renames, visibility changes, and follow changes
announce their project. `shareSessionListChanges` relays these
announcements across replicas and sends a frame on the project feed.
- The `settling` field is removed from the `session-rows` and
`session-activity` responses. The schemas, handlers, and
`sessionActivity` no longer use it or the `now` input for it.
- The `UNMATERIALIZED_POLL_MS` polling in `sessionRowsQueryOptions` and
`sessionActivityQueryOptions` is removed. Both keep
refetch-on-window-focus. The constant is no longer exported from
`useWorkspaces.ts`, but its value stays at 15,000 ms.
- `unsubscribeFromWorkItem` now requires `factoryProjectId`. Callers in
`session-tools.ts` and `work-item-tools.ts` pass the project scope.

### Storage changes

- `ProbedList` and `probeNewest` are removed, along with
`probed-list.ts` and its test file.
- `AnnouncedLists<T>` replaces them. It caches a project list in memory
until an announcement invalidates it, with a 60-second maximum age. It
holds at most 100 entries. When announcements are untrusted, reads call
the loader directly.
- `SourceControlStorage.projectSessions` and
`WorkItemsStorage.projectSubscriptions` are now public `AnnouncedLists`
instances. Session and subscription mutations announce their scope.
- Work-item deletion announces the project only when the card was
deleted and at least one subscription was removed.
- `MastraFactory` starts `shareSessionListChanges` and stores its
unsubscribe function. `shutdown()` calls it.

### Shared module

- `session-list-changes.ts` adds `SESSION_LIST_CHANGES_TOPIC` and
`shareSessionListChanges`.
- Each instance has a UUID so it ignores its own events.
- Incoming events are accepted only for the `sessions` and `follows`
lists with string scope IDs.
- If the subscription fails, the module logs a warning and stops
announcements. If it succeeds, it trusts announcements and distrusts
them on cleanup.

### Tests and docs

- New two-replica tests in `session-list-changes.test.ts` cover
shared-database updates, unsubscribed replicas, and a lost announcement.
The lost-announcement test expects the change after 60 seconds.
- Some `listByProject` tests in `source-control/base.test.ts` are
removed. The work-item subscription test now covers unsubscribing with
`factoryProjectId`.
- `test-utils.ts` uses a random Postgres schema per connection, or a
temporary LibSQL database. Postgres requires
`FACTORY_TEST_POSTGRES_URL`.
- MSW fixtures no longer include `settling`.
- The README and a new patch changeset for `@mastra/factory` describe
the new behavior.

### Stated results and limits

- The author reports a drop from 8.5 to 4.5 database queries per sidebar
request in the stated benchmark. CPU changed from 225 to 243 ms for 50
viewers. The author did not show that the CPU difference is more than
noise.
- If a bus message is lost, a replica's list can stay stale for up to 60
seconds.
- The author did not verify live browser behavior across two accounts.
- The `UNMATERIALIZED_POLL_MS` poll in `useWorkspaces` is out of scope.

### Scope

- 29 files changed, with 525 lines added and 444 removed, relative to
merge base `5e4645fd`.
- Review severity counts: not available.
- CI and test results: not available.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-16 16:35:01 -08:00
Damien Schneider
996966f0e6
perf(factory): build sidebar session rows once per change, not once per viewer (#30616)
**─────── TLDR ───────**
> Open sidebars now share one set of session rows per project, so
serving them takes about a third of the server CPU it did.

Every `session-rows` and `session-activity` request rebuilt the
project's rows from scratch, every session, card and follow, for one
viewer. With 50 sidebars open, that is 50 rebuilds of the same rows. Now
the part that doesn't depend on who's looking is built once per change
and shared, and each request only filters it for its viewer, visibility
first.

No behavior change: same rows, same order, same activity.

### Gain

> ██████████████████ **main** `689 ms`
> ██████ **this PR** `225 ms`

Server CPU for 50 viewers each loading rows and activity, in a project
of about 4,000 sessions on local Postgres, median of 7 rounds. The
rounds have no write in between, so the one rebuild a change costs is
not in the number. Part of the gain is the row sort: rows sort on ISO
timestamps, which now compare as plain strings instead of through
`localeCompare`. Queries per request stay at 8.5; #30617, stacked on
this one, brings them to 4.5.

### Shape changed

| | | |
|---|---|---|
| **+** | `SessionRowIndex` | row facts built once per change;
`rows(viewer)` filters first |
| **+** | `ProjectSessions` | the reader's shared result; `seenBy` and
`rowIndex` read it |
| **+** | `listSharedByProject` | every session of the project, frozen,
for the shared index |
| **+** | `isSeenBy` | the one visibility rule, for storage and the
index |
| **−** | `sessionRows` | replaced by `SessionRowIndex.rows` |
| **~** | `ProjectSessionsReader` | no `userId`; callers filter through
`seenBy(viewer)` |

### Decisions

- **owner names resolved for every owner in the project** — the index is
shared, so one owner set; differs only past the 100-owner cap
- **activity still names a card's sessions, private ones included** —
the board's card status reads them, same as main

### Not verified

- [ ] the gain on Shipyard itself: measured on local Postgres with
seeded data at Shipyard's size

---

> ██████████████████ **source** `+341 −172` — net +169
> ██████ **tests** `+107 −24`
> █ **changeset** `+5`

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

**ELI5:** The sidebar builds a list of work sessions for each person who
opens it. This change builds the shared project list once, then filters
it for each person. The sidebar loads faster, and each person still sees
only the sessions they are allowed to see.

## Overview

This change reduces repeated work in sidebar session-row generation.
Before this change, each `session-rows` and `session-activity` request
rebuilt rows for one viewer. The change builds viewer-independent
project data once per change, then filters it for each viewer.

The PR description reports a local Postgres measurement: median of seven
rounds, 225 ms versus 689 ms for 50 viewers loading rows and activity,
in a project with about 4,000 sessions. This measurement is the author's
report. It is not verified here. The gain on Shipyard was not verified.
Queries per request remain at 8.5. The description states that PR
`#30617` reduces this to 4.5.

## Changes by area

**Shared visibility and storage (`storage/domains/source-control/`)**
- `base.ts` adds `isSeenBy(session, viewerUserId)`. Non-private sessions
are visible to all viewers. Private sessions are visible only to their
owner.
- `base.ts` adds `NO_SESSIONS`, a shared frozen empty list.
- `base.ts` adds `sessions.listSharedByProject({ orgId, factoryProjectId
})`. It returns linked sessions without viewer filtering.
- `base.ts` changes `listByProject` to apply `isSeenBy` to the shared
result.
- `base.ts` caches project sessions by organization and project. It
caches filtered links by a sorted link-ID key.
- `inmemory.ts` implements `listSharedByProject`. `listByProject` now
uses `isSeenBy` in place of its inline private-session check.

**Project session reader (`routes/project-sessions.ts`)**
- `ProjectSessionsReader` no longer takes `userId`. It returns a
`ProjectSessions` collection instead of `ListedSession[]`.
- The reader loads shared sessions from each source-control provider and
project subscriptions concurrently. It resolves owner profiles and
attaches followed work-item IDs.
- `ProjectSessions` exposes `seenBy(viewerUserId)` and a cached row
index.
- The reader reuses a previous collection when list identities,
subscription identity, and owner profiles match.
- Adds the `SeenSessions` interface.

**Session rows (`session/session-rows.ts`)**
- Adds `SessionRowIndex`. The constructor indexes sessions and cards,
and caches card context. `rows(viewer)` applies viewer filtering and
builds rows.
- Replaces the `sessionRows(facts)` function with `SessionRowIndex`. The
function is removed.
- Renames `SessionRowFacts` to `SessionRowViewer`. The `sessions`,
`cards`, and `boards` fields move to the index.
- Changes `RunReach.visibleSessionIds` to `Pick<ReadonlySet<string>,
'has'>`.
- Precomputes serialized session data, board, settled state, update
time, card fields, card-context rank, phase label, and deduplicated
followed work-item IDs.
- A person session uses its own update time. Other sessions use the card
update time when present.

**Session-row routes (`routes/session-rows.ts`,
`routes/source-control-sessions.ts`)**
- `sessionFacts` loads sessions and cards concurrently. It derives the
viewer's seen sessions and passes their IDs as the visible set.
- Row generation uses `rowIndex`. Settling uses the viewer's seen
sessions.
- The session-activity route passes seen sessions to `sessionActivity`.
- The Factory-project sessions GET route calls the reader without
`userId`. It returns `sessions.seenBy(userId)`.

**Sorting (`session/session-row-view.ts`)**
- Adds a `newestFirst` comparator. It compares ISO timestamp strings
directly instead of using `localeCompare`. Activity, updated, and
created sort modes use it. Descending order is unchanged.

**Activity privacy**
- Activity still names sessions linked to a card, including private
sessions. The board uses these session IDs to compute card status.
- The commit history shows an intermediate change that hid private
sessions from activity. A later commit reverted it.

**Tests**
- `session-rows.test.ts` and `session-row-view.test.ts` build rows
through `SessionRowIndex`. `rowsOf` defaults cards to an empty array.
- `routes/session-rows.test.ts` adds `x-viewer` header support and
configurable authentication. It adds helpers for rows, activity, and
session-list endpoints. It checks private-session visibility for the
owner and for other viewers, with authentication on and off.
- `mastracode/factory-ui/e2e/ui/session-reads.ts` builds rows with
`SessionRowIndex`.

**Changeset**
- Adds a patch changeset for `@mastra/factory`. It states that sidebar
requests use about one-third of the prior server CPU. This claim comes
from the changeset text. No measurement in the supplied evidence
confirms it.

## Behavior notes

- Owner names are resolved for all project owners. The PR description
states one difference: owners beyond the 100-owner cap.
- Row ordering and activity output are stated to be unchanged.

## Test results

Test and CI results are not available in the supplied evidence.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-16 16:35:00 -08:00
Damien Schneider
944bb3ab0f
feat(factory): personal custom endpoints, added from the provider list (FACT-596) (#29879)
**─────── TLDR ───────**
> A custom OpenAI-compatible endpoint can now be saved just for you or
for your whole organization, and you add it from Add provider like any
other provider.

Fixes FACT-595 and FACT-596. Custom endpoints were org-wide only, any
member could change them, and they lived in their own Settings section
that the Add provider drawer didn't know about. An endpoint is now saved
at a scope, the same way a key is, and it only ever authenticates with
its own key.

### Before / after

**Settings › Models, seen by a member** — endpoints now sit in the
provider list of the scope they belong to, and the org one is read-only
for members

| Before | After |
|---|---|
| ![before: models
settings](https://raw.githubusercontent.com/mastra-ai/mastra/bf93941c211c79c0ea38ca79700817e1f261040a/.pr-screenshots/factory-custom-endpoints/before-settings.png)<br>![before:
custom providers
section](https://raw.githubusercontent.com/mastra-ai/mastra/bf93941c211c79c0ea38ca79700817e1f261040a/.pr-screenshots/factory-custom-endpoints/before-custom-section.png)
| ![after: models
settings](https://raw.githubusercontent.com/mastra-ai/mastra/bf93941c211c79c0ea38ca79700817e1f261040a/.pr-screenshots/factory-custom-endpoints/after-settings.png)
|

**Add provider drawer** — a custom endpoint is one of the options

| Before | After |
|---|---|
| ![before: add provider
drawer](https://raw.githubusercontent.com/mastra-ai/mastra/bf93941c211c79c0ea38ca79700817e1f261040a/.pr-screenshots/factory-custom-endpoints/before-add-provider.png)
| ![after: add provider
drawer](https://raw.githubusercontent.com/mastra-ai/mastra/bf93941c211c79c0ea38ca79700817e1f261040a/.pr-screenshots/factory-custom-endpoints/after-add-provider.png)
|

Real app on Vite in Chromium, with Playwright answering the API.

### Behavior changed

a personal custom endpoint
&nbsp;&nbsp;└─ **new** — only its owner sees it, their personal sessions
run on it

an org-wide endpoint, in a personal session
&nbsp;&nbsp;├─ **was** — offered and used
&nbsp;&nbsp;└─ **now** — not offered, personal work uses personal
endpoints only

a member adds, edits or removes an org-wide endpoint
&nbsp;&nbsp;├─ **was** — allowed
&nbsp;&nbsp;└─ **now** — 403, and read-only in Settings like org keys

an endpoint named like a built-in provider, with no key of its own
&nbsp;&nbsp;├─ **was** — called with the key saved for that provider
&nbsp;&nbsp;└─ **now** — called with no key, and that name is refused
for new ones

editing an endpoint without retyping its key
&nbsp;&nbsp;├─ **was** — the saved key was wiped
&nbsp;&nbsp;└─ **now** — kept on the same host, asked for again on
another host

an endpoint on `localhost`, a private address or plain HTTP, on a hosted
Factory
&nbsp;&nbsp;├─ **was** — saved and called from the Factory server
&nbsp;&nbsp;└─ **now** — refused on save; one saved earlier shows "URL
not allowed" and its models are not offered

a custom endpoint that answers with a redirect
&nbsp;&nbsp;├─ **was** — followed, carrying the request and its key
&nbsp;&nbsp;└─ **now** — refused, the call fails

the same endpoint on a local or self-hosted Factory
&nbsp;&nbsp;└─ **unchanged** — Ollama or vLLM on the machine or network
still works

Adding an endpoint under a name already in use used to replace it
silently; it is now refused, and so is renaming onto a taken name. Names
that already mean something are refused too: built-in providers (even
when the catalog failed to load), their sign-in ids such as "OpenAI
Codex", older ids such as "Kimi for Coding", and the gateways' own
("Mastra", "Mastra Gateway", "MastraCode"). An endpoint without a key
now works when sign-in is on, where it used to fail with "no
credential". A `mastra/…` model never runs on a custom endpoint, with or
without a gateway key; mastra-ai/mastra#29183 added the same guard in
`resolveLanguageModel`, and this PR folds it into the one lookup. A save
no longer empties the endpoint list for runs already using it while the
list reloads.

### Shape changed

| | | |
|---|---|---|
| **+** | `#customProvider(id)` | one gateway lookup replaces four, own
key or none |
| **+** | `customProviderOwner(tenant)` | one rule for which list a
request uses, everywhere |
| **+** | `user_custom_providers` | the org table's unique index can't
be relaxed |
| **+** | `storedScopeFor` · `runScopeFor` | one map between
`user`/`org` and `user`/`factory` |
| **+** | `isReservedProviderId` | every id model resolution or the
pickers already use |
| **+** | `customEndpointUrlProblem(url)` | one hosted URL rule, read by
save, gateway, catalogs and the org key gate |
| **~** | `upsert` → `create` · `update` | add never replaces; an edit
decides the key inside its atomic write |
| **−** | `orgForTenant` | replaced by `customProviderOwner` |
| **−** | `CustomProvidersSection` | endpoints are rows in the provider
list now |

what callers now live with
&nbsp;&nbsp;&nbsp;&nbsp;`scope` (`user` by default, or `org`) on `POST
/web/config/custom-providers` and `DELETE …/:id?scope=` · `scope` on
each `GET` row · `previousId` means edit, its absence means add ·
`urlProblem` on a `GET` row the server refuses to call · 409
`provider_name_taken`, 404 `custom_provider_not_found`, 400
`api_key_required`, 400 `custom_endpoint_url_refused`
removed: "Update key" and "Remove key" on custom rows

### Decisions

- **two tables, not a nullable `user_id`** — the old unique index would
block two members using one name; one table would need a copy on boot
- **scopes are exclusive, like keys, for every account** — accounts
without an organization included; an admin switch to share an org
endpoint is a follow-up if needed
- **a host change needs the key again** — compared by URL origin, so a
path change on the same host keeps it
- **hosted means `MASTRA_DEPLOYMENT_ID` is set** — the platform stamps
it on every deploy and local `factory dev` never sets it;
`MASTRA_PLATFORM_ACCESS_TOKEN` is skipped when observability is off, so
it would fail open
- **the gateway snapshot is the line that holds** — save, catalogs and
the org key gate filter too, but a missed filter there only means a
failed call, not a request out
- **redirects refused for every custom endpoint** — the SDK can't tell
hosted from local, and following one hands the key to another address

### Watch

> [!WARNING]
> New Factories default to `hybrid`, where interactive sessions are
personal. <mark>Org-wide endpoints stop appearing in those
sessions</mark>, so anyone using one there has to add it again as
personal.

### Not verified

- [ ] saving, editing and removing endpoints against a real server — the
screenshots and component tests answer the API with stubs
- [ ] how many orgs on `hybrid` use an org-wide endpoint today
- [ ] a public hostname whose DNS points at a private address — the rule
checks the URL, not what it resolves to
- [ ] whether Railway exposes a metadata address to Factory containers
at all
- [ ] hosted rows named like a built-in provider — they still take over
that provider's models, now without its key, until an admin removes or
renames them

---

> ███████████████████ **tests** `+1570 −398` — 59% of the additions
> █████████████ **source** `+1046 −524`
> █ **changeset** `+39`


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

ELI5: Custom AI model servers can now be added for just one person or
for the whole organization. Each server appears only where its owner can
use it. Hosted Factories block server addresses that point to private or
local networks.

## Overview

This change makes custom OpenAI-compatible endpoints scoped providers.
An endpoint can be personal (`user`) or organization-wide (`org`). The
change covers storage, API routes, the SDK model resolution, and the
settings UI. The diff touches 47 files, with 2655 lines added and 922
removed.

## Behavior

- Personal endpoints are visible only to their owner. They are used in
personal sessions.
- Organization endpoints are not offered in personal sessions. Only
organization admins can add, edit, or remove them.
- Custom endpoints appear in the provider list and the Add provider
drawer.
- The settings page no longer renders the separate organization "Custom
providers" section. The `CustomProvidersSection` component and its test
are deleted.
- Adding an endpoint no longer overwrites an existing name.
- Editing an endpoint keeps its saved key when the URL origin is
unchanged.
- Editing an endpoint to a different origin requires a new key.
- Reserved provider IDs are refused for new endpoints. Reserved IDs
include built-in, catalog, and gateway provider IDs.
- A custom endpoint without its own key does not use a built-in
provider's key.
- Model IDs in the `mastra/...` namespace are not sent to custom
endpoints. They route to the Mastra gateway.
- Custom endpoint requests do not follow redirects.
- Endpoint lists stay available to runs during reloads.
- Hosted Factories (`MASTRA_DEPLOYMENT_ID` set) reject local, private,
link-local, and plain-HTTP endpoint URLs. Hosted Factories skip stored
rows with such URLs in the gateway, catalog, and organization-key-gate
paths. The settings UI flags these rows.
- Local and self-hosted Factories accept these URLs.

## API changes

- Create and delete routes accept `scope` (`user` or `org`). Any value
other than `org` defaults to `user`.
- Each GET row returns `scope`.
- Edits use `previousId` to identify the existing provider.
- Save calls `update` when `previousId` is set. Otherwise it calls
`create`.
- Error responses:
  - 409 `provider_name_taken`
  - 404 `custom_provider_not_found`
  - 400 `api_key_required`
- Delete returns 404 when no record is removed.
- Successful writes and deletes notify the host and clear the
available-model cache.

## Storage changes

- `CustomProvidersStorage.upsert` is removed.
- `create({ owner, createdBy, input })` refuses duplicate IDs with
`name_taken`.
- `update({ owner, providerId, input })` changes only the owner's
provider. It returns `not_found` for a missing row and
`api_key_required` for a cross-origin change with no new key.
- `list(owner)` returns owner-scoped rows.
- `listForOrg(orgId)` returns organization and member rows.
- `delete({ owner, providerId })` is owner-scoped.
- Records include `userId: string | null`. A `null` value means
organization ownership.
- Organization and member providers use separate collections with
owner-specific uniqueness.

## Server and SDK changes

- `customProviderOwner(...)` selects the owner from the tenant identity
and credential scope.
- `OrgCustomProvidersSnapshot` stores organization and per-user lists.
It skips rows with invalid endpoint URLs.
- `customEndpointUrlProblem(url)` returns a problem string for hosted
deployments. It is used in the org-key gate and the custom-provider
source.
- `storedScopeFor` and `runScopeFor` map between run credential scopes
and stored scopes.
- The SDK gateway `handlesModel` claims a matching custom-provider ID
even without a key.
- `getApiKey` parses the gateway-qualified model ID.
- `resolveModelForRequest` passes an empty custom-provider list for
`mastra/` models.

## UI changes

- `CustomProviderDialog` adds or edits an endpoint. It uses the saved
scope when editing.
- `CustomProviderRow` shows the name, URL, model count, and key status.
It also shows a URL problem warning when one exists. The menu offers
edit and remove.
- `ProviderList` loads custom providers separately from built-in
providers. It filters rows by credential scope.
- `AddProviderDrawer` shows a custom endpoint option outside the search
results. It takes an `onAddCustomProvider` callback.
- `ProviderRows` adds shared row components and `ProviderIcon`. It adds
`CustomEndpointIcon`.
- `useRemoveCustomProvider` sends `scope` with the delete request.
- Provider connection state treats a custom provider as connected when
it has no URL problem.
- The onboarding picker disables custom-provider add when the current
scope is not writable. It shows an organization-admin explanation.
- The memory model picker queries models with `scope: 'user'`.

## Documentation and tests

- Two changesets are added: a patch for `@mastra/code-sdk` and a minor
changeset for the Factory feature.
- Tests cover scope isolation, name conflicts, key retention, hosted URL
rejection, and 404 on missing rows.
- SDK tests cover gateway routing, redirects, and keyless custom
endpoints.
- The MSW server adds a default `GET */web/config/custom-providers`
handler that returns an empty list.
- The following test files were added, changed, or deleted:
`CustomProvidersSection.msw.test.tsx` (deleted),
`ProviderList.msw.test.tsx`, `ProviderListScopes.msw.test.tsx`,
`custom-endpoint-url.test.ts`, `custom-provider-auth.test.ts`, and
`base.test.ts`.

## Upgrade notes

- Custom providers that relied on another provider's saved key must set
`apiKey` directly.
- Hosted Factory rows with local or plain-HTTP URLs are skipped. They
must be changed to public HTTPS URLs to work again.

## Not verified

The PR author reports these items as not verified:

- Saving, editing, and removing endpoints against a real server.
- Current use of organization-wide endpoints in hybrid sessions.
- Behavior of hosted rows named like built-in providers. Such rows may
still take over those providers' models without their keys until they
are removed or renamed.

No CI or test run results were supplied for this summary. Review finding
counts were not supplied and are not available.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Damien Schneider <damienschneider@damiens-MacBook-Pro.local>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 16:13:28 -08:00
mastra-platform[bot]
93b823a847
fix(deps): patch @opentelemetry/resources (GHSA-qrww-3xmv-qhgm) (#30580)
## Summary

Fixes the open dependency advisories from the Security board in the
mastra monorepo (outside templates). After checking every lockfile in
the repo, only one advisory was still open; the other three already
resolve to fixed versions on `main`.

### Advisories

| Item | Package | Advisory | Status |
| --- | --- | --- | --- |
| SEC-323 | `@opentelemetry/resources` <2.12.1 / >=3.0.0 <3.1.1 |
GHSA-qrww-3xmv-qhgm | **Fixed in this PR** |
| SEC-262 | `fastify` 5.12.6 → 5.12.8 | AIKIDO-2026-576509 | Already
fixed on `main`. Every lockfile resolves `fastify@5.12.8` and the direct
specifiers are `^5.12.7` / `5.12.8` |
| SEC-243 | `@opentelemetry/core` 1.30.1 → 2.8.0 | GHSA-8988-4f7v-96qf |
Already fixed on `main`. No lockfile has `@opentelemetry/core@1.x`; only
2.9.0+/2.12.x/3.x are present, all at or above the fixed 2.8.0, so no
major bump is needed |
| SEC-252 | `follow-redirects` 1.16.1 → 1.16.2 | — | Already fixed on
`main`. Only `follow-redirects@1.16.2` is present outside templates |

`hono` and `templates/template-mongodb-bedrock-agent` are out of scope
because other sessions are handling them.

### Changes (SEC-323)

- **Direct bumps:** `@opentelemetry/resources` `^2.12.0` → `^2.12.1` in
`@mastra/arize`, `@mastra/laminar` and `@mastra/otel-exporter`.
- **Root overrides** (`pnpm-workspace.yaml`), scoped to the affected
ranges: `@opentelemetry/resources@>=2.0.0 <2.12.1 → 2.12.1` and
`@opentelemetry/resources@>=3.0.0 <3.1.1 → 3.1.1`. Older OTel SDK lines
(0.207 / 0.211 / 0.220 / 0.300, via third-party deps) pin `resources` to
an exact version, and both fixes are patch releases in the same major.
- **Nested example lockfiles** get the same scoped overrides:
- `observability/_examples/otel-bridge/agent-hub`: also changes the
pinned direct `2.10.0` to `2.12.1`.
- `observability/_examples/otel-bridge/hono-multi`: also raises
`instrumentation`'s `^2.0.1` to `^2.12.1`.
- `examples/durable-agents`: added to `package.json` `pnpm.overrides`,
because this project runs pnpm 10.
- As a side effect, `@opentelemetry/core` moves to 2.12.1 / 3.1.1, the
versions those `resources` releases depend on. No other resolutions
changed.
- A changeset for the three published packages.

## Test plan

- [x] `pnpm why @opentelemetry/resources -r`: only `2.12.1` and `3.1.1`
remain (previously 2.2.0, 2.5.0, 2.9.0, 2.12.0, 3.0.0).
- [x] Nested lockfiles (`durable-agents`, `agent-hub`, `hono-multi`) now
resolve only `@opentelemetry/resources@2.12.1`.
- [x] `pnpm turbo build --filter=@mastra/arize...
--filter=@mastra/laminar... --filter=@mastra/otel-exporter...`: 19/19
tasks pass.
- [x] Tests pass: `@mastra/arize` (27), `@mastra/laminar` (6),
`@mastra/otel-exporter` (187), `@mastra/otel-bridge` (52, a transitive
consumer).

Fixes SEC-323
Ref SEC-262
Ref SEC-243
Ref SEC-252


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

**ELI5:** Some tools send app performance data with an OpenTelemetry
library that has a known security bug. This change updates those tools
and example projects to fixed versions, so the bug no longer applies.

## Summary

This change updates `@opentelemetry/resources` to address advisory
GHSA-qrww-3xmv-qhgm. It changes 15 files, with 581 lines added and 355
removed.

### Published packages

Four published packages receive patch changesets: `@mastra/arize`,
`@mastra/arthur`, `@mastra/laminar`, and `@mastra/otel-exporter`.

- `@mastra/arize` raises `@opentelemetry/core`,
`@opentelemetry/resources`, and `@opentelemetry/sdk-trace-base` from
`^2.12.0` to `^2.12.1`. It raises the OTLP trace exporter from
`^0.223.0` to `^0.223.1`.
- `@mastra/laminar` sets `@opentelemetry/resources` and
`@opentelemetry/sdk-trace-base` to `^2.12.1`. It sets
`@opentelemetry/exporter-trace-otlp-proto` to `^0.223.1`.
- `@mastra/otel-exporter` raises the core, resources, trace SDK, and
Zipkin packages from `^2.12.0` to `^2.12.1`. It raises the logs SDK and
OTLP log and trace exporters from `^0.223.0` to `^0.223.1`.
- `@mastra/arthur` raises `@opentelemetry/core` and
`@opentelemetry/sdk-trace-base` from `^2.12.0` to `^2.12.1`. It raises
`@opentelemetry/exporter-trace-otlp-proto` from `^0.223.0` to
`^0.223.1`.
- `.changeset/otel-resources-sec-323.md` contains the patch changesets
for these four packages. It states the minimum raised versions. It says
that older SDK or OTLP exporter versions can resolve to
`@opentelemetry/resources` 2.12.0, which GHSA-qrww-3xmv-qhgm affects. It
advises projects with direct OpenTelemetry dependencies to check for
`@opentelemetry/resources` 2.12.1 or later on the 2.x line, or 3.1.1 or
later on the 3.x line.

### Root workspace

- `pnpm-workspace.yaml` adds two overrides:
- `@opentelemetry/resources` versions `>=2.0.0 <2.12.1` resolve to
`2.12.1`.
- `@opentelemetry/resources` versions `>=3.0.0 <3.1.1` resolve to
`3.1.1`.

### Example projects

- `examples/durable-agents/package.json` adds the same two version
constraints under `pnpm.overrides`. The existing `glob` override is
unchanged.
- `observability/_examples/otel-bridge/agent-hub/`:
- `package.json` changes `@opentelemetry/resources` from `2.10.0` to
`2.12.1`.
- `pnpm-workspace.yaml` adds the same two overrides, with a comment that
cites the advisory.
- `observability/_examples/otel-bridge/hono-multi/`:
- `instrumentation/package.json` changes `@opentelemetry/resources` from
`^2.0.1` to `^2.12.1`.
- `pnpm-workspace.yaml` adds the same two overrides, with a dated
security comment.

### Lockfiles

- The root `pnpm-lock.yaml` and the nested lockfiles for
`durable-agents`, `agent-hub`, and `hono-multi` change to match these
ranges and overrides.
- The author reports that `@opentelemetry/core` also moves to 2.12.1 and
3.1.1. The lockfile contents were not inspected for this summary.

## Validation

The author reports these results. This review did not rerun them. No
completed CI results were available for this review.

- `pnpm why @opentelemetry/resources -r` shows only `2.12.1` and
`3.1.1`.
- Nested lockfiles for `durable-agents`, `agent-hub`, and `hono-multi`
resolve only `2.12.1`.
- `pnpm turbo build` for the published packages and their dependencies
passed 19/19 tasks.
- Tests passed for `@mastra/arize` (27), `@mastra/laminar` (6),
`@mastra/otel-exporter` (187), and `@mastra/otel-bridge` (52).

## Scope notes

- The author reports that the `fastify` (SEC-262), `@opentelemetry/core`
(SEC-243), and `follow-redirects` (SEC-252) advisories were already
resolved on `main`. This change does not address them.
- The `hono` project and `templates/template-mongodb-bedrock-agent` are
out of scope.
<!-- 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>
Co-authored-by: shreyas-mastra <shreyas@mastra.ai>
2026-11-16 18:33:08 -05:00
Damien Schneider
4dc0519fec
feat(factory-ui): a card opens its session, or a draft that starts one (#30481)
**─────── TLDR ───────**
> Clicking a card now opens its session, or a draft page built like one
when the card has none; the expanded card view is gone.

Stacked on #30475. Before, clicking a card grew it into an expanded copy
over the board (a details dock beside the list), and the card carried
Open session or Start session pills. Now the card is a link: to the
thread of the session it shows, else to `/cards/:id`, which opens a
fresh draft with the card's stage bar, its suggested next steps and the
composer. The draft creates nothing until the first message or a
suggested step.

### Behavior changed

clicking a card, on the board, in the list or in the search palette
&nbsp;&nbsp;├─ **was** — opened the expanded card or the details dock;
from search, an unstarted card moved into its next phase or created a
session straight away
&nbsp;&nbsp;└─ **now** — opens the thread of the card's session; a card
without one opens the card draft, and nothing moves or starts

the card draft
&nbsp;&nbsp;└─ **new** — the session page's layout: the card's title,
its stage bar in the header, its suggested steps as buttons
(Investigate, Accept, Move to…) and the repository picker when the card
could live in several, naming the provider when two share a name; the
first message creates a session bound to the card, then opens its
thread; a failed start keeps the message on the draft, and the next send
reuses the session it left; a missing model or credential shows the same
guard as New session

the card's badge row
&nbsp;&nbsp;├─ **was** — Open session or Start session pills, and the
source links only in the expanded card
&nbsp;&nbsp;└─ **now** — no session pills; the card's own issue or pull
request and each attached one lead the row, and a `Session` badge marks
a card that holds one

Back from a session to a cached board
&nbsp;&nbsp;├─ **was** — the board could show empty: its groups mounted
before the scroll surface they measure against
&nbsp;&nbsp;└─ **now** — the cards show at once

list rows
&nbsp;&nbsp;├─ **was** — a details button swapped in on hover, and a
wide gap sat between the avatar and the time
&nbsp;&nbsp;└─ **now** — the title is the link, and the time column fits
"just now", left-aligned

### Shape changed

| | | |
|---|---|---|
| **−** | `WorkItemDetailsPanel` · `CardDetailsPanel` ·
`BoardDetailsDock` · `WorkItemTray` · `CardSessions` ·
`WorkItemDescription` · `WorkItemExternalLink` · `cardMorph.css` | the
expanded card and the list's details dock |
| **−** | `useCardMorph` · `useOpenCardState` · `BoardOpenCardContext` ·
`BoardRowDetailsContext` · `BoardDetailsDockContext` ·
`useBoardScrollRef` | which card was open, and the scroll ref |
| **−** | `useBoardRuns` · `useStartFactoryRun` · `sessionLink` ·
`onCreateSession` | starting a session from the board; the draft starts
it now |
| **−** | `openCard` on `useBoardPhasesQuery` | the board no longer
reads an open card out of a deep phase |
| **−** | `cardSessionPath` · `CardSourceDescription` · `timelineEvents`
| helpers only the expanded card used, or a second copy of `threadPath`
|
| **+** | `CardDraftPage` · `CardDraftActions` ·
`useStartCardSessionFromDraft` · `useCardSessionRepository` ·
`DraftSessionStartContext` | the card draft and its start |
| **+** | `cardSessionRepository` | where a session can start: resolved,
a choice, or unavailable with why |
| **+** | `cardControls` | a card's state and buttons, shared by the
board card and the draft |
| **+** | `WorkItemUpstreamLinks` · `SessionBadge` | the badge row's
links, minus a pull request a related card already links, and the badge
|
| **+** | `workItemQueryOptions` · `queryKeys.workItem` | one card by
id, for the draft |
| **+** | `cardPath` · `cardDraftPath` · `threadPath` | the card and
thread URLs; every thread link but `attention.ts`'s encoded one now goes
through `threadPath` |
| **+** | `cardSourceMetadata` | the provider's facts over the card's
own, used by every repository choice |
| **~** | `DraftStart` · `useDraftModelGuards` | moved out of `NewPage`,
so both drafts show the same guards |
| **~** | `Composer` · `ChatSessionProvider` · `ModelPicker` | treat a
card draft as a draft, not only a person's own |
| **~** | `BoardScrollContext` | holds the scroll element in state
instead of a ref: the groups render again once it attaches |
| **~** | `SessionChatSurface` | owns the chat column class, and a
notice no longer ends the empty state: an empty thread keeps its
greeting, the draft its card and steps |
| **~** | `FactoryGlobalSearchContent` | selecting a card opens it; no
move or busy refusal on select |

- `mastracode/factory-ui/src/ui/`
- └─ `router.tsx` — `cards/:workItemId` redirects to
`cards/:workItemId/new/:draftSessionId`, a new draft each visit
  - └─ `pages/CardDraftPage.tsx` — the draft
  - └─ `domains/chat/components/DraftStart.tsx` — out of `NewPage.tsx`

### Decisions

- **a card without a session opens a draft, not a session** — a click no
longer creates a sandbox nobody asked for; the draft waits for a message
or a step. Undo: point `cardPath` at a start.
- **the card's session starts before its thread opens** — the draft
waits for the create and the start, then opens the thread of the session
the server returned. The server reuses a person's session on the card's
branch, so the id is known only after the create; New session still
opens its thread first. Undo: open the thread first again once one
server request finds or creates the card's session and binds it.
- **the expanded card's description and session list stay in the
session** — the session's panel shows the description and its header
menu switches between the card's sessions; a card without a session has
neither on its draft. Undo: render `CardDescription` in the draft.

### Watch

> [!WARNING]
> A GitHub or GitLab card filed by someone without write access
<mark>can't start its session from the draft</mark>, on main too:
creating the session puts its thread on the Factory's memory, so binding
the untrusted card throws `UntrustedSharedSessionError`, an uncaught
500. The draft shows the error and keeps the message. Reproduced against
the start coordinator in a throwaway scenario test. Not fixed here: the
fix is one server request that finds or creates the card's session and
binds it.

### Not verified

- [x] the draft rendered in the e2e harness, light and dark, with one
and two repositories
- [x] Back onto a cached board, in a throwaway Playwright repro
- [ ] starting a session from the card draft against a running Factory;
covered by the MSW suite only
- [ ] screenshots

---

> ████████████████████ **source** `+1354 −1970` — the expanded card and
the board's session start are most of the deletions
> █████████████ **tests** `+674 −1464` — the expanded-card,
start-from-board and move-from-search tests left with that code
> ██ **styles** `+42 −230` — `cardMorph.css` out, the pill stack's CSS
in its own file
> █ **e2e** `+3 −26`


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

ELI5: Clicking a card now opens that card's chat session. If the card
has no session yet, the click opens a new draft page. The draft starts a
session after the user sends a message or picks a suggested step.

## Overview

This change makes card clicks open a session or a draft. It removes the
expanded card view and the board-based session start.

- Card click opens the card's existing session. If none exists, it opens
a draft page at `cards/:workItemId/new/:draftSessionId`.
- The draft starts a session only after a message or a suggested step.
- After a successful start, the draft opens the thread that the server
returns.
- If a start fails, the draft keeps the first message. A later send
reuses the session from the failed attempt.
- The draft uses the session page layout. It shows the card title, stage
bar, suggested steps, and a repository picker when needed.
- Missing-model and missing-credential guards are shared with New
session (`useDraftModelGuards`, `DraftStart`).
- Card badge rows link to the card's own and attached upstream items
(`WorkItemUpstreamLinks`). A `Session` badge appears when a session
exists.

## Main changes

- **Routing:** `router.tsx` adds the draft route and lazy-loads
`CardDraftPage`. `routeLoaders.ts` adds `prefetchCardDraft`.
`factoryPaths.ts` adds `threadPath`, `cardDraftPath`, and `cardPath`.
- **Draft page:** `CardDraftPage.tsx` is new. It redirects to an
existing session for the current stage. Otherwise it shows the guarded
draft start.
- **Draft start:** `useStartCardSessionFromDraft.ts` is new. It resolves
the repository, creates a session on the item branch, starts a chat
work-item run, and navigates to the returned thread.
- **Repository resolution:** `boardRepository.ts` adds
`cardSessionRepository` and `firstEnvironmentRepository`.
`useCardSessionRepository.ts` is new.
- **Chat:** `Composer.tsx`, `ChatSessionProvider.tsx`, `Chat.tsx`, and
`DraftSessionStartContext.ts` treat card drafts as drafts.
`DraftStart.tsx` is new. `SessionChatSurface.tsx` and `ModelPicker.tsx`
change accordingly.
- **Card state:** `cardControls.ts` is new. `cardPrimaryAction.ts` drops
session-link inputs and actions. It returns `undefined` when no action
applies.
- **Board UI:** `WorkItemCard.tsx`, `WorkItemListRow.tsx`,
`BoardListRow.tsx`, and `WorkItemCardRows.tsx` use card URLs and a
card-level overlay link. They drop the details-panel flow.
- **Data:** `useWorkItems.ts` drops the `openCard` parameter. It adds
`workItemQueryOptions` and `useWorkItemQuery`. `keys.ts` adds
`queryKeys.workItem`.
- **Scroll:** `BoardScrollContext` now holds an element.
`useBoardScrollElement.ts` is new. `boardVirtualScroll` takes an
element.

## Removed

- Details and session UI: `CardDetailsPanel`, `WorkItemDetailsPanel`,
`WorkItemTray`, `WorkItemDescription`, `WorkItemExternalLink`,
`CardSessions`, `BoardDetailsDock`, and `cardMorph.css`.
- Open-card state: `BoardOpenCardContext`, `BoardRowDetailsContext`,
`useBoardOpenCard`, `useBoardRowDetails`, `useOpenCardState`,
`useBoardScrollRef`, and `useCardMorph`.
- Board-based session start: `useStartFactoryRun.ts` and
`useBoardRuns.ts`.
- Helpers: `sessionLink` and `timelineEvents`.
- Tests: MSW tests for the removed flows. Several remaining tests now
assert links, labels, or the draft route instead of the details dialog.

## Verification status

- The author reports that the draft rendered in the e2e harness in light
and dark themes, with one and two repositories.
- The author reports that returning to a cached board was checked in a
throwaway Playwright repro.
- Starting a session from the draft against a running Factory was not
verified. Screenshots were not taken.
- Session start is covered only by the MSW suite.
- CI status: not available.

## Known unresolved issue

- A card filed by a user without write access can fail to start a
session. Binding the card raises `UntrustedSharedSessionError`.
- The draft shows the error and keeps the message.
- The author reproduced this in a throwaway scenario test. This PR does
not fix it.

## Scope

- Diff: 91 files changed, +2009 / -3715 lines.
- Commit messages describe follow-up handling for deleted sessions and
cards in related links and board rows. They also describe keeping
renames and deletions visible while sorting, and resetting sidebar
session-window depth on factory switch or board-setting change.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-16 15:23:56 -08:00
Tyler Barnes
55010c0670
test(mongodb): pin store-test MongoDB back to 7.0.45 so it starts on CI runners (#30597)
## Summary

Every `Combined Store Tests / test (mongodb)` job is failing before any
test runs. The `mongo:9.0.8` container exits on startup:

> MongoDB cannot start: Linux kernel versions 6.19.0 through 7.0.13 have
a known incompatibility with this version of MongoDB. See
https://jira.mongodb.org/browse/SERVER-121912

The CI runners now run Linux kernel 6.19.14 (reported by mongod in the
job log). MongoDB's compatibility matrix in
[SERVER-125742](https://jira.mongodb.org/browse/SERVER-125742) lists
only 7.0 as supported on kernels 6.19 to 7.0.13. Of the later lines,
8.0.0–8.0.20 crash after about a minute; 8.0.21+, 8.3.x and 9.0.x exit
at startup. 8.2 has no startup check but crash-loops on 6.19
([SERVER-122741](https://jira.mongodb.org/browse/SERVER-122741)).

`stores/mongodb/docker-compose.yaml` was already pinned to
`mongo:7.0.45` for this reason, with a comment saying not to move back
to 8.x. The Docker images update in #19788 bumped it to 9.0.8 before the
runners reached the affected kernel.

## Changes

- `stores/mongodb/docker-compose.yaml`: `mongodb-storage` and
`mongodb-fidelity` go back to `mongo:7.0.45`.
- `renovate.json`: a rule keeps the Docker `mongo` image below 8, so the
next Docker images update does not undo the pin. Remove it once MongoDB
ships a release that starts on these kernels.

The `mongodb-vector` service (`mongodb/mongodb-atlas-local:8.2`) is
unchanged. The vector tests rely on its features. It may still be
affected on these kernels: in the failing run it started but was torn
down within a second, so its behaviour under a full run is unverified.

## Test plan

- `pnpm test` in `stores/mongodb` against `mongo:7.0.45`: 15 files
passed, 5 skipped (1,186 tests passed, 314 skipped). The fidelity suite
passed 2 files (62 tests passed, 1 skipped).
- Not reproduced locally: the local Docker kernel is 7.0.14, outside the
affected range. The red evidence is the CI job log.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

ELI5: The MongoDB test database was set to a version that does not start
on the CI computers. This change sets it back to an older version that
does start. It also adds a rule so automatic updates do not move it
forward again.

## Summary

This pull request pins the MongoDB store-test images to `mongo:7.0.45`.
It also adds a Renovate rule that keeps the `mongo` Docker image below
version 8. The `mongodb-vector` service is not changed.

### Changes

- `stores/mongodb/docker-compose.yaml`:
- Changes the image for `mongodb-storage` and `mongodb-fidelity` from
`mongo:9.0.8` to `mongo:7.0.45`.
- Renames the `mongodb-storage` data volume from `mongodbdata-v7` to
`mongodbdata-mongo7`. The comment states that mongod 7.x cannot open a
data directory from a newer major version. The old volume may hold 9.0.8
data. The new name avoids a "Wrong mongod version" failure. The change
does not delete existing data.
- Adds a named volume, `mongodbfidelity-mongo7`, for `mongodb-fidelity`
at `/data/db`. Before this change, that service used an anonymous
volume, which could reuse data from a 9.0.8 container.
- Updates the comment above `mongodb-storage`. It states that MongoDB
8.x refuses to start on Linux kernel 6.19+ (SERVER-121912). It also
states that the image must not return to 8.x until MongoDB ships a
patched TCMalloc.
- Replaces the top-level `mongodbdata-v7` volume entry with
`mongodbdata-mongo7` and adds `mongodbfidelity-mongo7`.
- `renovate.json`: Adds a package rule for datasource `docker` and
package name `mongo` with `allowedVersions: "<8"`. The rule description
states that MongoDB 8.x and 9.0.8 do not start on Linux kernel 6.19.0
through 7.0.13 (SERVER-121912). It also states that the rule should be
removed when MongoDB ships a release that starts on those kernels.

Diff size: 2 files changed, 18 lines added, 6 lines removed.

### Context

The commit message states that a Renovate Docker major-version update
replaced the `mongo:7.0.45` pin with `9.0.8`. This change restores the
pin and adds the Renovate rule so the next Docker update does not undo
it.

### Test results

The PR author reports these results. They were not run as part of this
review:

- `pnpm test` in `stores/mongodb` on `mongo:7.0.45`: 15 files passed
(1,186 tests), 5 files skipped (314 tests).
- Fidelity suite: 2 files passed (62 tests), 1 test skipped.

The author did not reproduce the failure locally. The local Docker
kernel is 7.0.14, which is outside the affected range. The reported
failure evidence is the CI job log. The behavior of `mongodb-vector`
during a full run on affected kernels is not verified.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: remy-builder[bot] <324360501+remy-builder[bot]@users.noreply.github.com>
2026-11-16 16:02:59 -07:00
mastra-platform[bot]
208cbc218c
feat(create-factory): add --tag to pin Mastra packages to an npm dist-tag (#30598)
> Opened by @DSchau

## Summary

The Factory templates (`template-factory`,
`template-factory-self-hosted`) list `mastra` and `@mastra/*` under the
`latest` dist-tag. Because of that, `create-factory` had no way to
scaffold a project on prerelease packages.

This PR adds a `--tag <dist-tag>` option. It pins every `mastra` /
`@mastra/*` dependency in the scaffolded `package.json` to the exact
version that npm dist-tag points to. It works with any tag: `alpha`,
`latest` (gives exact stable versions instead of the floating `latest`
spec), `beta`, and so on.

```sh
npx create-factory@latest my-factory --tag alpha
```

How it works: the template is cloned and renamed as before. Then each
Mastra package's dist-tags are fetched in parallel with `npm view <pkg>
dist-tags --json`, and the exact versions are written into
`package.json`. This happens before install. Templates don't need any
changes, and custom `--template` repos work too.

- If a package has no release under the tag, it keeps the template's
version spec and you get a warning.
- If none of the packages resolve (for example, the tag doesn't exist or
the registry can't be reached), the run fails before install with a
clear error.
- **npm + prerelease versions:** when any pinned version is a
prerelease, an npm project also gets `legacy-peer-deps=true` in its
`.npmrc`. Without it, npm rejects the install. Under semver's prerelease
rules, a peer range like `>=1.83.0-0 <2.0.0-0` (from
`@mastra/pg@1.37.0-alpha.1`) does not match
`@mastra/core@1.84.0-alpha.3`. pnpm only warns about this, so pnpm
projects don't get the `.npmrc` line.

Analytics records the tag as `version_tag`: `latest` and `alpha` are
sent as-is, and any other tag is sent as `custom`. Custom tags are also
redacted from failure telemetry.

## Test plan

- [x] Unit tests in `src/create.test.ts`:
- pinning with the `alpha`, `latest`, and custom (`beta`) tags; only
Mastra packages are looked up
  - pinning happens before install
- a package with no release under the tag keeps its template spec, with
a warning
  - no lookups happen without `--tag`
  - the run fails before install when nothing resolves
  - `.npmrc` is written only for npm with prerelease pins
- [x] `pnpm test` (70 passed), `tsc --noEmit`, `oxlint`, and `--help`
output checked
- [x] Ran `pinMastraPackages` against the real registry on the
self-hosted template's `package.json`:
- `alpha` → `@mastra/core@1.84.0-alpha.3`,
`@mastra/factory@0.29.0-alpha.4`, `mastra@1.39.1-alpha.3`, …
- `latest` → stable versions; `npm install --package-lock-only` succeeds
- `alpha` fails with `ERESOLVE` under plain npm and resolves with
`legacy-peer-deps`

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

**ELI5:** Projects made with `create-factory` can now get Mastra
packages at the exact versions from a chosen npm tag, such as `alpha` or
`latest`. This lets users try a specific release channel without editing
the project by hand.

## Overview

This change adds a `--tag <dist-tag>` option to `create-factory`. When
the option is set, the tool pins each `mastra` and `@mastra/*`
dependency to the version published under that npm dist-tag. The pinning
runs after the template is cloned and renamed. It runs before
dependencies are installed.

## Behavior

- Only `mastra` and `@mastra/*` entries in `dependencies`,
`devDependencies`, and `optionalDependencies` change.
- Only own properties of these entries are replaced.
- Each distinct matching package is resolved once, in sorted order.
- Version lookups run `npm view` from the scaffolded project directory.
They use the same npm configuration and registry as installation.
- Lookups use a 15-second timeout. Lookup, parse, and command failures
count as unresolved.
- A package with no release under the tag keeps its template version.
The tool reports it as unresolved and issues a warning.
- If no packages resolve and at least one is unresolved, the run fails
before installation.
- `package.json` is rewritten with two-space indentation and a trailing
newline.
- If the project uses npm and any pinned version contains `-` (a
prerelease), the tool appends `legacy-peer-deps=true` to `.npmrc`.
Existing content is kept. pnpm projects do not receive this setting.
- Without `--tag`, template versions stay unchanged and no lookup runs.
- The CLI trims the tag value. An empty value is treated as not set.
- Analytics records `latest` and `alpha` as given. Other tags are
recorded as `custom`. Custom tag names are redacted from failure
telemetry. The start event uses the same tag-normalization helper as
command telemetry, so raw custom tag names are not sent to analytics.

## Changed files

- `mastracode/mastra-factory/src/utils/versions.ts`: adds
`isMastraPackage`, the `PinResult` interface, `versionTagForAnalytics`,
and `pinMastraPackages`.
- `mastracode/mastra-factory/src/create.ts`: adds `versionTag?: string`
to `CreateArgs`, calls pinning before install, and adds the `.npmrc`
update.
- `mastracode/mastra-factory/src/index.ts`: adds the `--tag` CLI option
and the analytics and redaction handling.
- `mastracode/mastra-factory/src/create.test.ts`: adds tests for
pinning, lookup scope, install ordering, unresolved packages, failure
before install, `.npmrc` handling, and the no-tag path.
- `mastracode/mastra-factory/README.md`: documents `--tag` and shows an
`alpha` example.
- `.changeset/create-factory-tag-flag.md`: adds a minor changeset for
`create-factory`.

Six files changed, with 326 lines added and none removed.

## Validation

The following results are reported by the author. They were not re-run
for this summary:

- Unit tests covering tag pinning, fallback and failure behavior, lookup
timing, and `.npmrc` handling.
- `pnpm test`: 70 passed.
- `tsc --noEmit` and `oxlint`.
- A check of `--help` output.
- Real-registry check: `alpha` fails with `ERESOLVE` under plain npm and
resolves when `legacy-peer-deps` is set.

Review severity counts: not available.
<!-- 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>
2026-11-16 22:48:25 +00:00
dane-ai-mastra[bot]
3c7d26e6ab
chore: version packages (alpha) (#30516)
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

> The changelog information of each package has been omitted from this
message, as the content exceeds the size limit.

## @mastra/factory@0.29.0-alpha.5


## mastra@1.40.0-alpha.4


## @mastra/core@1.84.0-alpha.4


## @mastra/playground-ui@69.1.0-alpha.4


## @mastra/libsql@1.31.0-alpha.2


## @mastra/pg@1.37.0-alpha.2


## @mastra/client-js@1.60.1-alpha.4


## @mastra/react@1.15.1-alpha.4


## @mastra/deployer-cloud@1.84.0-alpha.4


## @mastra/longmemeval@1.1.43-alpha.4


## @mastra/opencode@0.1.43-alpha.4


## create-factory@0.4.4-alpha.4


## @mastra/code-sdk@1.19.1-alpha.5


## mastracode@0.50.1-alpha.5


## @mastra/deployer@1.84.0-alpha.4


## @mastra/mcp-apps-components@0.1.1-alpha.1


## @mastra/mcp-docs-server@1.3.14-alpha.4


## @mastra/server@1.84.0-alpha.4


## @mastra/redis-streams@0.9.0-alpha.2


## @mastra/elysia@0.1.24-alpha.4


## @mastra/express@1.5.28-alpha.4


## @mastra/fastify@1.5.28-alpha.4


## @mastra/hono@1.7.26-alpha.4


## @mastra/koa@1.7.28-alpha.4


## @mastra/nestjs@0.3.1-alpha.4


## @mastra/next@0.2.42-alpha.4


## @mastra/tanstack-start@0.2.42-alpha.4


## @mastra/convex@1.9.1-alpha.2


## @mastra/turso@0.1.22-alpha.2


## @mastra/inngest@1.11.3-alpha.0


## @mastra/temporal@0.6.1-alpha.4


## @mastra/platform-workspace@1.13.1-alpha.0


## create-mastra@1.40.0-alpha.4


## @internal/playground@1.40.0-alpha.4

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-11-16 23:44:41 +01:00
mastra-platform[bot]
9d22ca2813
fix(factory): harden board cache validators and clone checks (#30596)
<!-- CURSOR_AGENT_PR_BODY_BEGIN -->
## Description

Board listing and activity responses now name their cache validators
with SHA-256. A client that still holds an older validator reloads the
board once.

Sandbox clone, checkout, environment sync, push, and merge-request
refresh now refuse a repository name or clone URL whose path would
resolve to a different repository. They also refuse a default branch
that is not a valid git ref. Session checkout already used those ref
rules.

## Testing

- `mastracode/factory/src/routes/board-snapshot.test.ts` checks that
listing and activity validators match SHA-256 of the response body, and
that a change in session activity changes the validator.
- `mastracode/factory/src/integrations/github/sandbox.test.ts` checks
that clone, checkout, environment sync, push, and merge-request refresh
refuse a repository path or clone URL that would resolve to a different
repository. The rest of that file still passes, including self-hosted
GitLab subgroup clones.
- `pnpm --filter ./mastracode/factory check` passes.

## Type of change

- [x] Bug fix (non-breaking change that fixes an issue)

## Checklist

- [x] I have added tests that prove my fix is effective or that my
feature works
<!-- CURSOR_AGENT_PR_BODY_END -->

<div><a
href="https://cursor.com/agents/bc-540db48d-d0e6-535c-8c67-0a103289f04a?cursor_ref=pr_footer&cursor_cta=open_in_web"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/open-in-web-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/open-in-web-light.png"><img
alt="Open in Web" width="114" height="28"
src="https://cursor.com/assets/images/open-in-web-dark.png"></picture></a>&nbsp;<a
href="https://cursor.com/background-agent?bcId=bc-540db48d-d0e6-535c-8c67-0a103289f04a&cursor_ref=pr_footer&cursor_cta=open_in_cursor"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/open-in-cursor-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/open-in-cursor-light.png"><img
alt="Open in Cursor" width="131" height="28"
src="https://cursor.com/assets/images/open-in-cursor-dark.png"></picture></a>&nbsp;</div>



<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

ELI5: The change makes two things safer. Board pages now use a stronger
checksum to tell if their data changed. Sandbox Git actions now refuse
repository names and clone URLs that point to a different repository
than the one requested.

## Overview

This change updates board cache validators and sandbox repository checks
in `mastracode/factory`. It changes 6 files: +199 lines and −19 lines.
It also adds a patch changeset for `@mastra/factory`.

## Board cache validators

- `mastracode/factory/src/routes/board-snapshot.ts` replaces the
exported `sha1` function with `etagDigest`. `etagDigest` uses SHA-256
and encodes the result as base64url.
- `scopedSnapshot`, `hashedBody`, `namedBody`, and `snapshot` now call
`etagDigest` for their ETags.
- `mastracode/factory/src/routes/work-items.ts` imports `etagDigest`
instead of `sha1`. It uses the function to compute cached wire versions
for work-item cards.
- Clients with older validators receive a new validator. They reload the
board once.

## Sandbox repository checks

`mastracode/factory/src/integrations/github/sandbox.ts` adds these
helpers:

- `pathHasDotSegment(value)` returns true when a repository name or
clone URL contains a `.` or `..` path segment, after percent-decoding.
It also returns true for any backslash.
- `assertRepositoryLocator(repoFullName, cloneUrl, code)` checks a
repository name and a clone URL. It throws `MaterializeError` with the
operation's failure code when a check fails.

The helper runs in these paths:

- Materialization (clone). It replaces the earlier inline
repository-name regex. The default branch now uses `isValidGitRef`
instead of the older character-class regex.
- Environment sync (`syncEnvironmentRepository`). It uses the
`pull-failed` code.
- Merge-request refresh (`refreshMergeRequestCheckout`). It validates
`access.cloneUrl` and uses the `pull-failed` code.
- Session checkout (`checkoutSessionBranchImpl`). It uses the
`clone-failed` code.
- Push helpers (`pushBranch` and `pushRepositoryBranch`). They use the
`push-failed` code. They replace the inline repository-name regex.

## Tests

- `board-snapshot.test.ts` (+51 lines) adds tests for `hashedBody`. The
tests check the weak SHA-256 ETag, the matching of validators with or
without the weak prefix, and the change of the ETag when the body
changes. They also check that scoped listing ETags change with session
activity.
- `sandbox.test.ts` (+87 lines) adds tests for these cases:
  - Materialization rejects default branches that begin with `-`.
- Materialization rejects repository paths that normalize to a different
repository.
- Materialization rejects clone URLs with traversal or backslash
segments before any sandbox command runs.
- Checkout, environment sync, merge-request refresh, and both push
helpers reject mismatched repository paths or clone URLs before they run
commands.

The PR author reports that `pnpm --filter ./mastracode/factory check`
passes. The author also reports that the rest of `sandbox.test.ts`
passes, including self-hosted GitLab subgroup clones. This review did
not run these checks.

## Compatibility

The exported `sha1` function is removed. The new export is `etagDigest`.
The change alters ETag values for all board and work-item responses.
Clients that cache validators will reload once.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->


Supersedes #30208 (reopened by the Factory bot so the original author
can review).

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: shreyas-mastra <shreyas@mastra.ai>
2026-11-16 17:27:01 -05:00
Caleb Barnes
d7d735fbff
fix(factory): stop review sessions recording the same verdict in a loop (#30559)
## What this fixes

A session reviewing a pull request could record its verdict, then record
the same verdict again and again on the same commit until the run ended
without output. The card never moved on.

## Why it happened

Recording a verdict changes the card. When a card changes, Factory sends
the session a fresh copy of the card before its next step. That copy
described the verdict the session had just recorded as "the previous
pass", announced a new review pass, and asked for a verdict on the same
commit. The session did as asked, which changed the card again.

## What changed

When the run in progress has already recorded a verdict that covers the
current commit, the card copy now says the pass is complete instead of
announcing a new one.

A verdict call that failed does not count, so the reviewer is still
asked for a verdict. A step that arrives without its tool results still
counts through the call itself.

Anything that starts a new run still reads as a new pass: a new commit,
a re-requested review, or a person replying to dispute a finding. Those
can all end in a different verdict.

A re-requested review on the same commit changes nothing on the card, so
the session used to keep the "pass is complete" copy and stop without
reviewing. The next run is now sent the card again. On an unchanged
commit it tells the reviewer to read the newest comments and reviews on
the pull request before deciding whether its verdict still stands.

## Test plan

- `work-item-state-processor.test.ts`: records a verdict with the real
tool, re-renders the card, and checks no new pass is announced in that
run. It also checks a later run on the same commit is still told to
review and record a verdict. It covers a failed verdict call and a step
missing its tool results too. Fails without the fix.
- Same file: after a recorded verdict, a new run with no change to the
card is sent the card once, with the new-pass wording. Fails without the
fix.
- Local Factory, before the re-request change: one review of this pull
request recorded one verdict and the run ended.
- Factory `tsc --noEmit`, `oxlint`, and the rules, session and GitHub
integration tests pass.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

**ELI5:** A review helper kept saying "start a new review" for the same
code, so the reviewer kept giving the same verdict. This change tells
the reviewer when its review is already done. It also tells the reviewer
to re-check the newest pull request comments when a review is requested
again on the same commit.

## Overview

This change stops review sessions from recording the same verdict
repeatedly on the same commit. Before the change, recording a verdict
updated the work-item card. The card went back to the session as if a
new review pass had started.

Diff size: 3 files, +159 lines, -9 lines.

## Behavior changes

**`mastracode/factory/src/session/work-item-state-processor.ts`**

- `FactoryWorkItemStateProcessor` checks the current run's steps for
successful `factory_record_review_verdict` calls.
- A call counts as successful unless a matching part is:
  - a `tool-error`, or
  - a `tool-result` whose output type is `error-text` or `error-json`.
- A call with no result still counts.
- The verdict status is part of the snapshot cache key. It is also
passed to work-item rendering as review guidance.
- When all of the following hold, `headLine` reports that the pass is
complete:
  - a verdict was recorded in this run,
  - the reviewed head is known,
  - the current head is absent or equals the reviewed head.
- In that state, `headLine` allows another verdict only if the head
moves or a person asks for reconsideration.
- On a later run with a matching recorded head, the guidance tells the
reviewer to read the newest comments and reviews. The reviewer then
decides whether its verdict still stands.

**`mastracode/factory/src/session/work-item-state-processor.test.ts`**

- Adds a test helper that returns the processor, work-item storage,
request context, and cache key with the rendered content.
- Adds tests that cover:
- recording a verdict through the transition tool marks the pass
complete in the same run,
  - a failed call does not count,
- a successful call still counts when another call in the same step
fails,
  - a later run starts a new pass,
- a re-requested review sends the card once before it suppresses an
unchanged signal.

**`.changeset/calm-verdicts-rest.md`**

- Adds a patch changeset for `@mastra/factory`.

## Public API

No exported or public declarations change.

## Validation

Not available. This summary does not include results from completed
checks on the current head.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: CalebBarnes <CalebBarnes@users.noreply.github.com>
Co-authored-by: mastracode <284800079+mastra-platform[bot]@users.noreply.github.com>
2026-11-16 15:24:36 -07:00
Justin Levine
7a2076d2fc
Open Knowledge pages in a panel instead of replacing the graph (#30588)
## Description

Opening a Knowledge page now shows it in a panel beside the Pages tree,
on the graph's black canvas, instead of swapping the graph out for a
full-width page. The graph stops drawing while the page is open, so
nothing renders or fetches behind it; closing the panel returns to the
graph with the page still selected. The small grey metadata line under
the title moves into a Details list in the right column, and that column
now shows at a narrower width so it fits the panel. Phones keep the
full-screen page.

| | Before | After |
| --- | --- | --- |
| Light | ![Knowledge page view before, full-width page beside the
tree](https://github.com/user-attachments/assets/732c9b98-7193-4161-9f8b-547265a9fc53)
| ![Knowledge page view after, page in a panel with a Details
list](https://github.com/user-attachments/assets/4fe41990-ad38-45ca-b7a2-c1295d815189)
|
| Dark | ![Knowledge page view before in dark
mode](https://github.com/user-attachments/assets/8075bf7d-5a91-42e2-a8c5-612891e97865)
| ![Knowledge page view after in dark
mode](https://github.com/user-attachments/assets/ef12082f-eb18-4ab5-8962-c24d087cd307)
|

Verified: playground-ui knowledge tests (314, including a new
close-the-panel test), typecheck, oxlint and prettier pass; checked the
Page and GraphWithDrawer stories in both themes.

## Related issue(s)

PLTFRM-3713

## Type of change

- [x] New feature (non-breaking change that adds functionality)

## Checklist

- [x] I have linked the related issue(s) in the description above
- [x] I have added tests that prove my fix is effective or that my
feature works


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

**ELI5:** Knowledge pages now open beside the page list, not in place of
the graph. Page details move to a side column, so you can see the page
and the graph layout together.

## Overview

This change updates how the Knowledge explorer shows a selected page in
`@mastra/playground-ui`. It touches 7 files, with 117 lines added and 47
removed.

## Behavior changes

- **Wide screens:** A selected page opens in a "Page" panel over the
graph. The panel sits beside the Pages tree. The graph stays rendered
but is hidden while the panel is open. Closing the panel returns to the
graph with the page still selected.
- **Narrow screens:** The selected page keeps its full-screen layout.
The overlay-specific frame wrapper (`frameSurfaceStyle`) is removed from
the page view.
- **Graph container:** Its background changes from `bg-background` to
`bg-sidebar`.
- **Page detail layout:** The two-column breakpoint changes from `@4xl`
to `@3xl`.
- **Metadata:**
- In compact mode, version, scope (for non-scope pages), and update time
appear as compact metadata.
- In non-compact mode, a **Details** section lists scope (for non-scope
pages), updated time, author, creation time, and version.

## Files

- `.changeset/eleven-rockets-melt.md`: Adds a minor changeset for
`@mastra/playground-ui`.
- `KnowledgePageDetail.tsx`: Imports `DataKeysAndValues`. Adds the
compact and non-compact metadata layouts and the Details section.
Changes the breakpoint.
- `KnowledgePageExplorer.tsx`: Adds `pageOverGraph` to control the
overlay. Removes `frameSurfaceStyle`. Changes the graph container
background.
- `__tests__/KnowledgePageExplorer.drawers.test.tsx`: Removes the
assertion that the graph container is absent for the initial page
selection. The page tree and details drawer assertions remain.
- `__tests__/KnowledgePageExplorer.page.test.tsx`: Expects the selected
page in a drawer over the graph. Checks that closing the drawer returns
to graph view. Checks the Scope, Updated, By, Created, and Version terms
and their values.
- `__tests__/KnowledgePageTree.test.tsx`: Expects the home-scope name
"Acme" inside the Details region.
-
`packages/playground/src/pages/knowledge/__tests__/index.msw.test.tsx`:
The linked-page test checks for the "Updated" label inside the Details
region. It verifies that no React Flow graph renders. It replaces the
previous version-label and graph-container assertions.

## Verification

- The author reports that 314 playground-ui Knowledge tests passed,
including a new panel-close test. The author also reports passing
typecheck, oxlint, and prettier. These results were not checked against
the current head in this review.
- The author reports checking the Page and GraphWithDrawer stories in
light and dark themes. This was not verified in this review.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-16 14:16:03 -08:00
Justin Levine
39243f21cb
feat(playground-ui): size Central icons to match Lucide, with an optical inset (#30555)
## Description

Follow-up to #30542. Central icons read smaller than the Lucide icons
they replaced, because Central leaves more room around each drawing.
This grows the four icon sizes by 2px so an icon in the same slot draws
at the size people are used to, and documents how icon sizing works.

- Icon sizes go from 12/14/16/20px to 14/16/18/22px (CSS and the
TypeScript scale). After the bump, Central icons land at their Lucide
size: median 1.0 across 286 icons.
- Things that already fill their box keep their drawn size: product
icons draw on a 1/8 larger canvas, and the remaining Lucide icons,
provider logos, product marks and the toast close button sit 1px in from
each edge. The `xs` and `inline` avatars get their own size tokens
instead of borrowing the icon sizes.
- A few Central shapes run edge to edge and drew about 20% larger than
the rest of the set, like the ↗ in a large button. `opticalInset` in
`central-icons.json` pads those families inside the same box (plain
arrows, dots, menu bars, undo, percent, bar chart, infinity, graduation
cap, laptop, toggle). The generator validates it, bakes it into each
icon, and thickens those icons' stroke by the same factor so every icon
keeps the same line weight. A test keeps the table, the inset and the
line weight in sync. Boxes and layout are untouched.
- Containers that sized icons with literal classes now use the icon
tokens, so they follow the bump.
- The Icons docs page and the README cover sizing, the lint rule, and
the optical inset.

Rows keep their height almost everywhere because controls are taller
than icons. Across 1,336 stories, 29 got taller, 12 of them icon
showcase pages; the rest are `EmptyState` (+2px), provider logo lists,
the permission and session pages, and one rich tooltip.

| Button sizes | Before | After |
| --- | --- | --- |
| Light | ![Buttons with plus and arrow icons before the size bump,
light](https://github.com/user-attachments/assets/7830b87d-be31-4efa-a930-a8bab52947cb)
| ![Buttons with plus and arrow icons at Lucide size,
light](https://github.com/user-attachments/assets/ba891420-e22a-436c-965a-df54bada6b5d)
|
| Dark | ![Buttons with plus and arrow icons before the size bump,
dark](https://github.com/user-attachments/assets/19806658-7d55-47ee-b7ab-2b60f2ae9a27)
| ![Buttons with plus and arrow icons at Lucide size,
dark](https://github.com/user-attachments/assets/64c8bacd-2a2a-4ee4-9623-a2e5e3492115)
|

| Sidebar | Before | After |
| --- | --- | --- |
| Light | ![Sidebar nav before the size bump,
light](https://github.com/user-attachments/assets/9a10b939-a818-45d1-b9b5-9cc27c595950)
| ![Sidebar nav with 2px larger Central icons,
light](https://github.com/user-attachments/assets/c2e0f10a-f5eb-4b75-a8e9-bea13608443d)
|
| Dark | ![Sidebar nav before the size bump,
dark](https://github.com/user-attachments/assets/da0faf17-38e2-4871-8278-73913e39bc09)
| ![Sidebar nav with 2px larger Central icons,
dark](https://github.com/user-attachments/assets/1e33138a-63ce-494f-81c4-e2a77223a636)
|

| Toolbars | Before | After |
| --- | --- | --- |
| Light | ![Filter toolbars before the size bump,
light](https://github.com/user-attachments/assets/ee5baea2-073a-4ee8-9816-bf6ad2adcb5c)
| ![Filter toolbars after the size bump,
light](https://github.com/user-attachments/assets/24aeac17-4471-4d2c-b762-486104dad06e)
|
| Dark | ![Filter toolbars before the size bump,
dark](https://github.com/user-attachments/assets/15477837-207e-4555-a904-31f9bee32e31)
| ![Filter toolbars after the size bump,
dark](https://github.com/user-attachments/assets/08a86d6e-64ec-4600-8636-3579f1e0f935)
|

Verified: lint, format, and typecheck pass in playground-ui, Studio, and
Factory UI. Tests pass in playground-ui (8,216) and Studio (3,088) on
the merged branch. Factory UI's failures are the same ones on main.
Reviewed on localhost.

## Related issue(s)

PLTFRM-2484

## 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)
- [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: The PR makes the design system's icons a little bigger so they
match the size of the Lucide icons they replace. Some Central icon
shapes that run edge to edge get extra inner padding, so they do not
look too large.

## Summary

This PR changes the Central icon sizes and the icon size tokens in
`@mastra/playground-ui`. It also adds optical insets for selected
Central icons. A changeset declares a minor release for
`@mastra/playground-ui` and a patch release for `mastra`.

### Size token changes
- `packages/playground-ui/src/ds/tokens/sizes.ts` and `theme/scale.css`
change the icon sizes from 12/14/16/20px to 14/16/18/22px for
`xs`/`sm`/`md`/`lg`.
- New avatar tokens are added: `avatar-xs` (12px) and `avatar-inline`
(16px).
- `avatar-size.ts` and `avatar-group.tsx` use the avatar tokens for `xs`
and `inline`.

### Optical insets
- `central-icons.json` adds `opticalInset` values (2 or 3) for 18 icons.
- `scripts/central-icons.mjs` reads these values. It validates that each
entry names a known icon and is a finite positive number. It scales
numeric `strokeWidth` values by `(24 + 2 * inset) / 24`, rounded to four
decimals.
- `create-central-icon.tsx` accepts an optional `opticalInset` argument
(default `0`). It uses the inset to compute the `viewBox`.
- Generated Central icon files change their `viewBox` and stroke widths.
Examples include `IconArrowDown` (`strokeWidth` 2 to 2.5) and
`IconChart6` (2 to 2.3333).
- `central-icons.test.tsx` adds tests for the inset table. The tests
check the viewBox padding and the scaled stroke width.

### Icon size class migration
- Many components replace fixed `size-3`, `size-3.5`, `size-4`, and
`size-5` classes with `size-icon-*` tokens. Examples are in
`ds/components/*`, `domains/traces/*`, `domains/scores/*`, and
`domains/experiments/*`.
- `ProviderLogo` and `ProductAvatar` add `p-px` padding to icon classes.
- `:where(svg.lucide)` in `components.css` and the toaster close button
get `padding: 1px`.
- Several hand-written icons in `ds/icons/` change their SVG dimensions
and `viewBox` values. Examples include `AgentIcon`, `SearchIcon`, and
`TrashIcon` (to 18px). `ProcessorIcon` and `PromptIcon` change their
default size to 18.

### Documentation and lint guidance
- `icons.mdx` and `packages/playground-ui/README.md` describe the new
size tokens. They also describe the
`playground-ui/icon-size-from-parent` lint rule and optical insets.
- The README removes `CirclePause`, the `Loader2` spinner, and filled
stars from the `lucide-react` exception list.

### Factory UI and playground
- Files under `mastracode/factory-ui` and `packages/playground` switch
icon size classes to `size-icon-*` tokens. These changes follow the same
pattern as the playground-ui changes.

### Not covered by this summary
- The PR description reports lint, format, and typecheck results, and
test counts (8,216 in playground-ui and 3,088 in Studio). These results
come from the PR author. They were not verified against completed checks
on the current head.
- The PR description includes screenshots. This summary does not
describe them.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-16 16:54:04 -05:00
mastra-platform[bot]
8ed3cd8680
fix(factory): open the repo picker on recent repos and search the rest (#30345)
## Summary

The Factory repository picker loaded every repository the GitHub App can
see before showing anything. For accounts with 500+ repositories the
Platform listing took longer than the Factory's 15s request timeout, so
onboarding failed with **"Failed to list repos (500)"**.

The picker now loads optimistically:

- **On open** it asks for the **8 most recently pushed** repositories.
Installs that grant only a few repositories still show all of them.
- **Once you type** it searches by name on the server (up to 50 results)
instead of filtering a full list in the browser.

Changes:
- `/web/github/repos` accepts `limit` (max 100), passes `q`/`limit` to
each installation, and returns the merged matches most recently pushed
first.
- The Platform-backed integration requests the narrowed listing from the
Platform (uncached). Single-repo lookups (`getInstallationRepo`) search
by name when no full listing is cached, instead of listing everything.
- The direct (self-hosted) integration narrows its own listing the same
way.
- All pickers sharing `useGithubReposQuery` send the limit.

Depends on mastra-ai/platform#4882, which adds `q`/`limit`/`pushedAt` to
the Platform repositories endpoint. Merge order does not matter: an
older Platform ignores the params and returns the full list, which the
Factory route still filters and caps. The 500 goes away once both are
deployed.

## Test plan
- New route test: `q`/`limit` reach every installation and the merged
list keeps the most recently pushed.
- New Platform integration tests: narrowed listing sends `q`/`limit` and
does not poison the full-listing cache; `getInstallationRepo` searches
by name when nothing is cached.
- New picker MSW test: opens with `limit=8`, then searches with
`q`/`limit=50` after typing.
- Factory: 416 tests across GitHub/platform/factory suites pass; `tsc
--noEmit` clean. Factory UI: 756 workspace/settings tests pass,
typecheck and oxlint clean.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

**ELI5:** When you open the Factory repo picker, it now shows your most
recently pushed repos. When you type, it searches your repos by name on
the server. This keeps the picker fast for accounts with hundreds of
repos.

## Summary

This change updates the Factory repository picker. On open, it requests
a short list of the eight most recently pushed repositories. After the
user types, it searches by name on the server and requests up to 50
results. It also adds a `limit` option to the Factory API and the
Platform integration. The change addresses a failure for accounts with
more than 500 repositories. Loading the full list could exceed the
15-second request timeout and return "Failed to list repos (500)".

## Changes

- **Changeset:** Adds a patch changeset for `@mastra/factory`. It
describes the recent-repos picker, the name search, and the new `limit`
behavior. It also records the earlier failure for GitHub accounts with
hundreds of repositories.
- **Picker query
(`mastracode/factory-ui/src/hooks/useGithubRepos.ts`):**
`useGithubReposQuery` requests 8 repositories when no query is set. It
requests 50 when a query is set. The refresh mutation uses the same
limit and keeps `refresh: true`. It exports `RECENT_REPOSITORY_LIMIT =
8`.
- **Client service
(`mastracode/factory-ui/src/ui/domains/workspaces/services/github.ts`):**
`GithubRepo` gains an optional `pushedAt` field. `listGithubRepos`
accepts an optional `limit` option and adds it to the request query
string when set.
- **Add-repository picker (`AddRepositoryPicker.tsx`):** Treats the
recent list as capped when its length is at least
`RECENT_REPOSITORY_LIMIT`. When no query is entered and no available
repositories remain, a capped list shows a message that asks the user to
search for others. Otherwise, the existing "no more repositories"
message appears.
- **Workspace VCS step (`VcsFactoryStep.tsx`):** During a connected
GitHub repository refresh, the component records the prior repository
IDs, the query update time, and the installation count. After a
successful refresh, when `githubCallbackAwaitsAccess` is true, it clears
the pending GitHub App approval notice if either of these is true:
  - The installation count increased.
- The refreshed list contains a repository that was not listed before
and was not pushed after the captured update time.

A repository that is only newer by `pushedAt` does not clear the notice.
This replaces the earlier rule, which cleared the notice only when the
list length grew.
- **Factory route
(`mastracode/factory/src/integrations/github/routes.ts`):** The
repository listing route trims and lowercases `q`. It accepts a positive
integer `limit`, capped at 100, and passes the limit to each
installation. After filtering and deduplicating, it sorts limited
results by descending `pushedAt` and truncates them to the limit.
Without a valid limit, the existing behavior applies.
- **Core GitHub integration
(`mastracode/factory/src/integrations/github/integration.ts`):**
- `RepoSummary` gains optional `pushedAt`, which is `null` when GitHub
omits it.
  - New exported `RepoListOptions` type (`fresh`, `query`, `limit`).
- New exported `narrowRepos` function. It filters by case-insensitive
substring, orders by most recent push, and applies an optional limit.
- `listInstallationRepos` accepts `RepoListOptions`. It applies
narrowing only when `query` or `limit` is set.
- **Platform GitHub integration
(`mastracode/factory/src/integrations/platform/github/integration.ts`):**
- When `query` or `limit` is set, `listInstallationRepos` sends `q`
(truncated to 100 characters) and `limit` to the Platform repositories
endpoint. It returns results with `installationId` added. It does not
store the narrowed result as the TTL full-list cache.
- If `fresh` is also set on a narrowed request, it deletes the cached
full listing for that installation. The stated reason is that a granted
repository may have changed.
- Unfiltered listings keep the TTL cache. `fresh` bypasses the cache
read and clears the entry before refetching.
- `getInstallationRepo` uses the cached full listing when it is
unexpired. Otherwise, it searches by the last path segment of
`repoFullName` with a limit of 100. It then matches the exact full name.

## Tests

- **Factory route tests (`routes.test.ts`):** Adds a test. It checks
that a case-insensitive `q=Agent` reaches each installation as `query:
'agent'` with `limit: 2`. It also checks that merged results sort by
`pushedAt` and return the two newest. Two existing session-title tests
are reformatted. Their assertions are unchanged.
- **Platform integration tests
(`platform/github/integration.test.ts`):** Adds tests for uncached
single-repository lookup. Adds tests for narrowed listings. They check
that the limit is sent, that `pushedAt` is returned, and that the
narrowed result is not cached as the full listing. They also cover a
fresh narrowed refresh that finds a newly granted repository.
- **Picker MSW test (`VcsFactoryStep.msw.test.tsx`):** Adds a test. It
checks that the initial request uses `limit=8`. After the user types
`old`, it checks that the request uses `q=old` and `limit=50` and shows
the filtered result. Adds a refresh test. It checks that a pending
approval notice clears when the refreshed list includes a newly granted
repository. It also checks that the notice remains when the new
repository is only newer by `pushedAt`.
- **Settings MSW test (`RepositoriesSection.msw.test.tsx`):** Adds a
test for the case where all eight recent repositories are already
linked. It checks that the add-repository drawer prompts the user to
search and does not state that no repositories remain.

The author reports these results. They were not verified in this review:
- 416 Factory tests passing across GitHub, Platform, and Factory suites.
- 756 Factory UI workspace and settings tests passing.
- `tsc --noEmit`, typecheck, and oxlint clean.

## Dependencies and deployment

The change depends on mastra-ai/platform#4882. That change adds `q`,
`limit`, and `pushedAt` to the Platform repositories endpoint. An older
Platform can ignore these parameters. In that case, the Factory route
still filters and caps results. The "Failed to list repos (500)" error
stops only after both changes deploy.
<!-- 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>
2026-11-16 13:47:09 -08:00