mirror of
https://github.com/mastra-ai/mastra.git
synced 2026-11-17 08:44:46 +00:00
23,467 commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
bb6c76b52e | style(factory): restore repository formatting | ||
|
|
ad80361768 | Merge branch 'fix/gateway-v2-studio-errors' into fix/factory-gateway-errors | ||
|
|
d390b2e410 | Merge branch 'fix/gateway-v2-client' into fix/gateway-v2-studio-errors | ||
|
|
0a8c60e9fc | chore(core): merge main and format gateway tests | ||
|
|
31f1b765c3 |
fix(factory): stamp a session's first events once and stop redoing session work (#30648)
**─────── TLDR ───────** > A session's first-event times now survive concurrent LibSQL writers, and the server stops redoing session work it already had. Two LibSQL processes stamping the same session could both write, so a later write replaced the first and inflated latency metrics such as `materialize_s`. Projects without a GitHub connection evicted each other's session index on every poll, and session activity sorted every card status to report the few in flight. The one-request rows and activity read and the shared owner lookup from the first push are reverted: each carried a trade-off, so they wait until after the release. The platform GitHub backlog test, red on `main` since #30625 made issue intake follow the selected repositories, now selects its repository first. ### Behavior changed two LibSQL processes stamp the same session's first message ├─ **was** — both could write, and the later time replaced the first └─ **now** — the `IS NULL` check runs inside the update; the first write stays two projects with no GitHub connection, polled in turn ├─ **was** — each read evicted the other's session index └─ **now** — each project keeps its own until its sessions change ### Gain > ██████████████████ **session activity, before** `3.1 ms` > █ **session activity, after** `0.11 ms` Per call on 2,850 card statuses with 30 in flight, from a throwaway bench that is not committed; the output is identical. Postgres already serialized the stamps with `SELECT … FOR UPDATE`, so there the change only trades a dedicated connection running five statements for two statements. --- > ██████████████████ **tests** `+98 −1` — 75% of the additions > ████ **source** `+24 −40` — net −16 > ██ **changeset** `+9` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> **ELI5:** When two copies of the app share one database, each can record when a session started. This change makes sure only the first recorded time is kept. The app also avoids some repeated work when it loads session lists for projects that have no GitHub connection. ## Summary This change covers six files: 131 lines added and 41 removed. ### Changes by file - **`mastracode/factory/src/storage/domains/source-control/base.ts`** (+17/-36): - Removes the `NO_SESSIONS` constant. - When `linkedProjectSessions` finds no connections, it continues to the repository-link lookup and the cached session read and filter path. It no longer returns the shared empty constant. This stops projects without a GitHub connection from evicting each other's session indexes. - The three session timestamp methods call a new `#stampOnce` helper. The helper updates only rows whose selected timestamp is null. If no row changes, it returns without announcing. Otherwise, it reloads the row and announces it when the row exists. - **`mastracode/factory/src/session/session-row-view.ts`** (+7/-4): `sessionActivity` filters card-status entries to in-flight statuses before it builds the sorted `cardStatuses` list and the working and waiting counts. Held-card IDs still come from all card-status entries and are sorted. - **`mastracode/factory/src/storage/domains/source-control/base.test.ts`** (+69/-1): Adds a test. It opens two `LibSQLFactoryStorage` instances on one temporary file database. It creates a session and calls `markMaterialized` from both instances concurrently. Over 10 attempts, it asserts that the project is announced exactly once. - **`mastracode/factory/src/routes/project-sessions.test.ts`** (+28/-0): Adds a test for `createProjectSessionsReader`. It creates two projects without a repository. It checks that repeated reads for each project return the same object instance. - **`mastracode/factory/src/integrations/platform/github/integration.test.ts`** (+1/-0): The linked-repository backlog import test saves an enabled GitHub intake configuration for `acme/app` before it builds the integration context and runs the import. This fixes a test that failed on `main` after issue intake began to follow selected repositories. - **`.changeset/funky-bears-know.md`** (+9/-0): Adds a patch changeset for `@mastra/factory`. It describes reduced work during session sidebar and board updates. It also describes one-time recording of session timestamps when Factory processes share a LibSQL database. ### Scope notes - The PR objectives state that the one-request rows and activity read, and the shared owner lookup, were reverted from the first push. The six changed files do not include them. - The objectives report that session activity reads take 0.11 ms, down from 3.1 ms, on 2,850 card statuses with 30 in flight. This figure comes from an uncommitted throwaway benchmark. The output was identical. - On Postgres, the objectives state that the stamp path already used `SELECT … FOR UPDATE`. The change reduces that path from five statements on a dedicated connection to two statements. This diff does not show a Postgres test. ### Verification No CI, build, or test results were available for this review. <!-- end of auto-generated comment: release notes by coderabbit.ai --> |
||
|
|
7518c05d6f |
feat(core): add knowledge.movePage() to move a page without losing its notes or pins (#30631) | ||
|
|
8cc2b95344 |
fix(factory): unload idle and released sessions from server memory (#30612)
## Description
A long-running Factory server keeps every agent session it has ever
opened in memory. In production that adds up to roughly 2 GB growing to
7 GB over six hours, with GC climbing from about 13% to 42% of busy CPU
until the next redeploy. The core `AgentController` holds sessions until
the host deletes them, and Factory only deleted them from the explicit
delete routes. Each session kept its display state, tool results,
workspace caches and subscriptions.
Factory now unloads a session from memory in two cases. The first is
when it stops or releases the session's sandbox: a card leaving a
context, a card finishing, or a retired session. The second is after 30
minutes without activity, checked every minute. A session stays loaded
while it has a run in flight, a pending approval or
`ask_user`/`submit_plan` wait, an active thread stream, or a browser tab
following its event stream. Busy sessions released by a sandbox stop get
unloaded on the first sweep after their work ends. Before unloading,
Factory waits for run-end audit writes, then drops its per-session
workspace caches. It does not stop or destroy the sandbox VM. The
thread, messages, session row, sandbox and work-item bindings all stay,
so the next message, dispatched run, deferred wake or reopened tab loads
the session again from storage. No `@mastra/core` changes.
```ts
new MastraFactory({
// defaults shown; `idleMs: 0` only unloads on sandbox release, `false` never unloads
idleSessionUnload: { idleMs: 30 * 60_000, sweepIntervalMs: 60_000 },
});
```
Unloading drops in-memory state that isn't persisted: `session.state`
that isn't mirrored to thread metadata, auto-approvals granted for the
session, and past bus events. The UI rebuilds the transcript from stored
messages.
I'd like reviewers to weigh in on some risks. There's a small window
where the sweep can unload a session that the start coordinator just got
back from `createSession` but hasn't touched yet. The re-checks right
before `deleteSession` shrink that window but don't close it, and owner
takeover and route deletes have the same gap today.
`mastra_factory_sandboxes_active` counts memoized sandboxes, so it
undercounts VMs whose session idled out while the VM kept running (a
restart already does the same). Without `auth`, a deferred wake for an
unloaded session waits until something else loads it, same as after a
restart. Unloading is per replica: a replica only unloads sessions it
holds itself, and every replica runs its own sweep. I also haven't
measured heap in a long-running process. The tests prove the controller
drops the session and Factory clears its caches, but not that RSS
flattens in production.
Test plan: new tests run on a real `AgentController` with
`InMemoryStore`, a mock language model and a real Hono server
(`session/session-unloader.test.ts`). They cover idle unload, a running
turn, a parked `ask_user`, an open SSE tab, rehydration with history and
the row owner, release-then-sweep, the timer, and settings validation.
`sandbox/context-sandboxes.test.ts` covers unload when a card leaves a
context or finishes, over libsql and pg. `workspace.test.ts` checks that
invalidation drops caches without stopping or destroying the sandbox.
Mutation checks showed the new tests fail when the unload hook, watcher
check, busy check, timer or run-audit settle is removed. The focused
Factory suites pass (41 files, 1111 tests), along with `tsc --noEmit`
and oxlint. In the full Factory suite, the only failures are the 13 that
also fail on untouched `main` in this environment (config, fs,
session-model-catalog and session-tools route tests that pick up local
provider credentials).
## Related issue(s)
No public issue. This was reported from the production Factory
deployment.
## 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)
- [x] Documentation update
- [ ] Code refactoring
- [x] Performance improvement
- [ ] Test update
## Checklist
- [ ] I have linked the related issue(s) in the description above
- [x] I have made corresponding changes to the documentation (if
applicable)
- [x] I have added tests that prove my fix is effective or that my
feature works
- [ ] I have addressed all Coderabbit comments on this PR
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->
ELI5: When a Factory session is no longer needed, the server removes it
from memory. The saved session data stays on disk, so the session loads
again when someone uses it.
## Summary
This PR adds session unloading to `@mastra/factory`. The server removes
a session from memory in these cases:
- Its sandbox is stopped or released.
- It has been idle for 30 minutes. The default sweep runs every minute
per process.
A session stays loaded while any of these hold:
- A run is active.
- An approval or user answer (`ask_user` or `submit_plan`) is pending.
- A browser event stream is open.
- Its running sandbox reports a tracked background process.
For an idle session with a running process, the idle clock resets for
another idle timeout. Only sandboxes with status `running` are queried
for processes. Released sessions are not queried, because their sandbox
has already stopped. A busy session that is released unloads on a later
sweep, after it becomes idle.
Before unloading, the factory waits for run-end audit writes to finish.
It then clears the session's cached workspace entry. It does not stop or
destroy the sandbox VM.
Threads, messages, session rows, sandboxes, and work-item bindings stay
stored. A later request reloads the session. In-memory-only state,
session auto-approvals, and past bus events are dropped.
The PR also changes the following:
- **Default model on unloaded sessions:** When a bound session is not
loaded, the default-model apply job calls `setThreadModel`. It counts
the binding as applied, not skipped.
- **Untrusted-checkout posture on prompt creation:**
`restorePromptCheckoutTrust` consults a session's run-binding history,
including revoked bindings, even when a binding is active. It marks the
checkout untrusted when bindings span multiple projects or when a
trusted binding's item cannot be verified. Reopened review sessions load
`AGENTS.md` and `CLAUDE.md` from the base branch, or no instructions
when the trusted branch cannot be determined.
- **Process listing failures:** A failed sandbox process listing keeps
the session loaded.
### Key changes
- **`session/session-unloader.ts` (new):** Adds `SessionUnloader`,
`sessionHoldsWork`, `createSessionActivityMiddleware`, and the
`IdleSessionUnloadOptions`, `UnloadableSession`, `UnloadableController`,
and `SessionUnloaderOptions` interfaces. Negative or non-finite idle
values and non-finite or non-positive sweep intervals throw errors.
`unloadReleased` returns `not-loaded`, `unloaded`, or `deferred`. A run
that starts during release cancels the pending unload.
- **`factory.ts`:** Adds `idleSessionUnload?: false |
IdleSessionUnloadOptions` to `MastraFactoryConfig`. The factory creates
the unloader unless the option is `false`. It starts the unloader in
`finalize()` and stops it in `shutdown()`. It adds a `setThreadModel`
callback to the controller wiring. `hostInstructions` calls
`restorePromptCheckoutTrust`.
- **`sandbox/session-retirement.ts`:** Adds an optional `unloadSession`
callback. The coordinator calls it after sandbox stop or release. Unload
errors are logged and not propagated.
- **`rules/dispatcher.ts`:** Uses `sessionHoldsWork(session)` to decide
whether to keep a stale run binding.
- **`rules/binding-context.ts`:** Adds `restorePromptCheckoutTrust`. It
classifies review-context and pull-request items as untrusted.
- **`storage/domains/work-items/base.ts`:** Adds an index on `(org_id,
session_id)` and `listRunBindingsForSession`. The method returns all
bindings for a session, including revoked ones, oldest first.
- **`session/run-audit.ts`:** Changes `waitForSessionRunAudit` to accept
`object` instead of `RunEndCaptureSession`.
- **`routes/projects.ts`:** `ModelApplyController` now requires
`setThreadModel`.
- **Docs and changesets:** `mastracode/factory/README.md` adds an
"Unloading idle sessions" section. The changesets mark a minor
`@mastra/factory` release and a patch release for reopened review trust.
- **Tests:** Adds `session/session-unloader.test.ts` (443 added lines).
Updates the context-sandbox, workspace, default-model scenario,
source-control session, and projects tests. Several controller mocks now
include `onSessionDeleted` and return unsubscribe functions.
The PR changes 23 files, with 1,433 lines added and 82 removed.
### Configuration
- `idleSessionUnload` is enabled by default.
- `idleMs: 0` disables idle unloading. Released-session unloading still
runs.
- `false` disables all unloading.
### Known limitations
- A deferred wake without `auth` does not reload an unloaded session.
The session loads when another event loads it, as after a restart.
- Whether a remote sandbox provider's process listing reports processes
after reload is not verified.
- Production heap or RSS improvement was not measured.
- The risks the author lists include a race between session creation and
sweeping, possible undercounting by `mastra_factory_sandboxes_active`,
and per-replica unloading.
### Verification
The author reports these results. They were not re-run for this summary.
- 41 focused Factory test files with 1,111 tests pass.
- After the later trust fix, `source-control-sessions.test.ts`,
`src/rules`, and `src/session` pass (1,344 tests).
- `tsc --noEmit` and oxlint pass.
- 13 full-suite Factory failures occur. The same failures occur on
untouched `main` in the author's environment.
### Review status
- Review finding 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>
Co-authored-by: Damien Schneider <74979845+damien-schneider@users.noreply.github.com>
|
||
|
|
76069d5b99 |
fix(factory): follow a card when a chat approves or retries its run (#30637)
## Description Stacked on mastra-ai/mastra#30628. When a session moves a card, it follows it, so the run's report (done, failed, blocked, waiting for approval) reaches that session and it can pass the outcome on in its chat. Approving a held run with `factory_resolve_proposal` (as the person), or retrying a failed one with `factory_retry_decision` (which keeps the run's original approver), also starts a run from the session, but didn't follow the card. That matches what happened in Slack on Nov 16: asked to "start the automated review on the board" for #30578, Shipyard approved the held review run, said "I'm following the card and will post here when the review finishes", and never posted, although the review finished and was approved on GitHub. The card's run-end report goes only to the card's followers (`workItemReportRecipients`). I couldn't read that session's traces from here, so this is the gap the code shows, not a confirmed cause for that thread. Now both tools follow the run's card with reason `started`, as `factory_start_session` did for a card's role before #30628 removed that mode. Dismissing a proposal doesn't follow. Both results also carry the card's `url`, like `factory_transition_work_item` in #30628. The approval or retry has committed before the card is read and followed, so a failed read or follow returns the result with a warning rather than an error. ```ts factory_resolve_proposal({ decisionId, action: 'approve' }) // before: { decisionId, status: 'pending', workItemId }, and the session hears nothing more // after: { decisionId, status: 'pending', workItemId, url }, and the run's report reaches this session ``` Not in this PR: whether the woken session then reliably posts the outcome in its thread. That's the agent's call today, guided by the channel instructions ("post the outcome when the people in the thread asked for this work"). A system-posted line, like the existing pull request opened and merged announcements, would make it deterministic but adds Slack noise, so it needs a decision first. ## Related issue(s) Reported in Slack (Factory review requests answered in the chat instead of on the card). Related to FACT-517. ## 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 - [x] I have addressed all Coderabbit comments on this PR Tests in `src/tools/work-item-tools.test.ts`, on the real transition service and LibSQL storage: a pull request card in Review with its review held as a proposal. Approving it from the chat, or retrying it after it failed, makes the chat session a recipient of the card's run-end report (`workItemReportRecipients`). Both fail without the fix (no recipients). Dismissing doesn't follow. A card read that fails after the approval returns the approved run with a warning (it rejected before the fix). Ran `tsc`, oxlint, and the `src/tools` and `src/mcp` suites (16 files, 342 tests). 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01VhgyDWFgVkhDt1X1NPmPas <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> **ELI5:** When a chat session approves a held Factory run or retries a failed one, the chat now follows that run's card. The tool result also includes the card's link. Dismissing a held run does not make the chat follow the card. ## Summary This change makes the chat session follow a Factory run's card when the session approves or retries that run. Both tool results include the card URL. Dismissing a held proposal does not follow the card. ### Changes by file - **`mastracode/factory/src/tools/work-item-tools.ts`** (+42/-11) - Adds `started` as a subscription reason for `follow`. - Adds `followStartedRun`. It looks up the decision's work item. - If the work item ID is missing or the lookup finds no item, the helper returns the original result. - If the lookup or subscription throws, the helper returns the result with a warning. The result includes the URL if it was already obtained. - Retry results and approved proposal results use this helper. Dismissed proposal results do not. - Tool descriptions document the follow behavior and the URL. - **`mastracode/factory/src/tools/work-item-tools.test.ts`** (+94/-0) - Imports `workItemReportRecipients`. - Adds `url: null` to the expected retry result. - Adds tests. Approving a held run and retrying a failed run each add the chat session to `workItemReportRecipients`. Dismissing a held run does not. - Adds a test. When the card read fails after approval, the approval still reports success. The result has a null URL and a warning. - **`mastracode/factory/README.md`** (+1/-1) - Documents that `factory_resolve_proposal` approves the run as the acting person. - Documents that `factory_retry_decision` keeps the run's original approver and needs no person in the turn. - Documents that both actions make the session follow the card and include the card URL in the result. - **`.changeset/silly-moose-read.md`** (+5/-0) - Adds a patch changeset for `@mastra/factory`. ### Scope and limits - The change adds the session to the card's report recipients. It does not show that the woken session posts its outcome in its thread. The PR description places that behavior outside this change. - The author reports that `tsc`, oxlint, and the `src/tools`, `src/mcp`, and `src/integrations/slack` suites passed (29 files, 669 tests). This summary does not verify those results. CI results for the current head: not available. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Claude <noreply@anthropic.com> |
||
|
|
c547a8303c |
fix(factory): let chat sessions run a card's work the way the board's buttons do (#30628)
## Description
When someone asks a Factory chat session (Slack or the web) to review a
pull request that already has a card, the session usually reviews it
itself or in a side session and posts the review in the chat. The card's
own review stays held for approval, nothing is recorded on the card, and
the review never lands on GitHub through the review stage. Romain hit it
on Oct 30 ("review this PR pls"), then Yujohn, Arthur and Charlie on Nov
16.
The cause is that session tools didn't do what the board's buttons do:
- The board's **Start**/**Review** button on a card already in its stage
sends a transition to that same stage with `reenter: true`.
`factory_transition_work_item` calls the same transition service, but
couldn't send `reenter`, so "move #30578 to pr-review" on a card already
there did nothing, and a re-review from Slack wasn't possible at all.
- So agents fell back to `factory_start_session(workItem, role)`, which
started a card's role straight from the start coordinator. That path
skipped the board's rules: it didn't check which stage the card was in
or whether it was busy, and it refused a role that had ever had a
session.
- The tools only took a card id or `#number`, so a pasted pull request
link didn't resolve. With several repositories linked, `#5001` picked an
issue in one repository over a pull request in another.
This PR makes session tools use the same operations as the board, and
adds a test that keeps it that way:
- `factory_transition_work_item` takes `rerun: true` to run the stage a
card is already in again, sending `reenter` like the button. On a
person's turn the run counts as approved by them, so a held run no
longer waits, and a busy card is refused as on the board. A turn nobody
signed in started can't rerun a stage. Without `rerun`, a request for
the card's own stage changes nothing and says whether its run is waiting
for approval, so "move it to review" on a card that was already reviewed
doesn't start another pass.
- `factory_start_session` only starts side sessions. Its `workItem` and
`role` inputs are removed, along with the code behind them.
- The tool descriptions steer a plain "review this pull request" to the
pull request's card, and keep side sessions for what people ask to run
in one and for work no stage does (investigations, pushing fixes to a
pull request, taking one over).
- Tools that take a work item also accept the issue or pull request it
tracks: its link (including `/files` or comment links), `owner/repo#12`,
`group/project!7`, or a key like `ENG-42`. They're matched against the
source keys the provider adapters already store. The pull request's own
card wins, then the card it's attached to, and a reference that matches
more than one card is refused with the candidates.
`factory_list_work_items` takes the same references as its query.
- `factory_inspect_work_item` returns `moves`: the card's stage, whether
it can run again, and the stages its board lets it move to next, so the
agent doesn't have to guess `review` vs `pr-review`.
- `board-parity.test.ts` scans `src/tools` and fails if a tool starts a
card's run, commits a transition, or settles a run without going through
the transition service and the shared decision actions that the board's
routes use. It flags 5 lines in the previous `session-tools.ts`.
Before, from Slack, on a card in Review whose review is held for
approval:
```ts
factory_transition_work_item({ workItem: '#30578', stage: 'pr-review' })
// accepted, nothing queued: the agent then starts a side session instead
```
After:
```ts
factory_transition_work_item({ workItem: 'https://github.com/mastra-ai/mastra/pull/30578', stage: 'pr-review' })
// { unchanged: true, message: '#30578 is already in pr-review, and its run there is waiting for approval. Pass rerun: true …' }
factory_transition_work_item({ workItem: 'https://github.com/mastra-ai/mastra/pull/30578', stage: 'pr-review', rerun: true })
// { stage: 'pr-review', reran: true }: a review run approved by the person is queued, as the board's button does
```
**Checked against how people use Shipyard from Slack.** I went through
#shipyard-graveyard and #eng-proj-factories for side session and card
requests:
- Explicit side sessions are the most common request: Abhi ("fix this
issue in a side session", 15+ times), Ryan ("take on PLTFRM-3694 in a
side session"), Romain, Nik, Justin, Charlie ("start separate sessions
to address the requested changes"). They still start side sessions; the
descriptions say so.
- "Review and take over this PR" (Abhi, several PRs a day): a side
session that reviews, pushes fixes and approves. A card's review stage
can't push commits, so this stays side-session work.
- Side sessions running the review skills without being bound to a card
(Abhi, mastra-ai/mastra#27918): unchanged, the workspace exception is
untouched.
- `factory_start_session(workItem, role)`: Shipyard offered it a few
times but didn't use it; it approved the held run or moved the card
instead. When a review got stuck after "changes requested", the
documented way out was moving the card to Building. It also couldn't
re-review ("I can't trigger the re-review from here"), which `rerun` now
can.
- "Move it to review" on a card that was already reviewed (Dustin, Nov
16, mastra-ai/mastra#30345): this is why `rerun` is explicit instead of
implied by the stage.
Not in this PR, as follow-ups:
- The UI's draft start (`/runs/start` from
`useStartCardSessionFromDraft`) also calls the start coordinator without
a destination stage; it needs the same check.
- A note from the person ("focus on security", or "point it at the nits
I found") can't ride along with a rerun yet; the agent can send it to
the card's session with `factory_signal_session` once it starts.
- A request for a review from GitHub by a maintainer is still held for
approval on human-authored pull requests (`transition-service.ts`, event
routes disarm). Whether that should count as approval is a separate
decision.
- "Review these in side sessions" on pull requests that have cards stays
a side session, as asked. Whether that wording should go to the cards
instead is a product call.
- A state signal that tells a session which cards the PR or issue links
in a message belong to, so it doesn't depend on the model looking first.
## Related issue(s)
Reported in Slack (Factory review requests answered in the chat instead
of on the card). Related to FACT-517.
## Type of change
- [x] Bug fix (non-breaking change that fixes an issue)
- [ ] New feature (non-breaking change that adds functionality)
- [x] 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
Tests: `src/tools/work-item-tools.test.ts` drives the real transition
service and LibSQL storage: a pull request card in Review with its
review held as a proposal, asked for by link. It fails without the
`reenter` change (`expected [] to deeply equal [ObjectContaining{…}]`).
Also covered: the same request without `rerun` leaves the held run alone
and says it's waiting, the busy refusal, the turn without a person,
`moves`, and resolving a link when an issue in another repository has
the same number, or when a pull request is attached to its issue's card.
`card-reference.test.ts` covers GitLab, Linear and Jira references. Ran
`tsc`, oxlint, and the `src/tools`, `src/mcp`, `src/integrations/slack`,
`factory.test.ts`, start coordinator and transition service suites
locally.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01VhgyDWFgVkhDt1X1NPmPas
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->
**ELI5:** This change lets the Factory chat tools act on the board's
cards the same way the board does. Users can rerun a card's current
stage, find cards by link or key, and start side sessions for work that
has no card.
## Overview
- Base: `main`, merge base `
|
||
|
|
d5991a1a6e |
fix(factory): explain gateway refusals with appropriate recovery actions
Distinguish gateway billing, routing, context and rate limit failures in the web UI and Slack so users get relevant recovery actions. Offer credits only when adding them can help. Recognize v1 billing replies by their structure and configured gateways by request origin, including saved errors that record it. |
||
|
|
39730d0340 |
fix(core): correct gateway diagnostics and studio model selection
Persist request origins so saved errors distinguish gateway failures from provider failures without retaining URL credentials or paths. Restore missing-memory warnings when the gateway does not manage memory, without delaying runs. Keep the gateway visible when its catalog fails to load. Use gateway credentials when selecting models for instruction enhancement. |
||
|
|
75ed0cbce9 |
fix(core): correct gateway catalogs, version routing and stream usage
Authenticate and cache v2 model catalogs with bounded fallback and retry delays to reduce waits during outages. Keep organization catalogs out of the shared provider cache so they stay isolated across projects. Honor v1 project keys and registered gateway settings so Studio and model calls agree on the gateway version. Request streaming token usage so final usage chunks are reported. |
||
|
|
33fba78931 |
fix: make URL slash trimming and PR number parsing linear-time (#30577)
## Summary Resolves four open CodeQL code-scanning findings. | Ticket | Alert | Rule | Location | Change | | --- | --- | --- | --- | --- | | SEC-326 | [#988](https://github.com/mastra-ai/mastra/security/code-scanning/988) | js/polynomial-redos | `packages/core/src/llm/model/gateways/mastra.ts` | `/\/+$/` trailing-slash trim replaced with an end-of-string scan | | SEC-325 | [#987](https://github.com/mastra-ai/mastra/security/code-scanning/987) | js/polynomial-redos | `mastracode/factory/src/boards/semantics.ts` | `/(\d+)$/` replaced with a `trailingDigits` scan from the end | | SEC-316 | [#985](https://github.com/mastra-ai/mastra/security/code-scanning/985) | js/polynomial-redos | `auth/supabase/src/index.ts` | `/\/+$/` trailing-slash trim replaced with an end-of-string scan | | SEC-316 | [#986](https://github.com/mastra-ai/mastra/security/code-scanning/986) | js/type-confusion-through-parameter-tampering | `server-adapters/nestjs/src/__tests__/builtin-mcp-oauth.test.ts` | Test auth provider now checks `typeof token === 'string'` before using it | | SEC-259 | [#752](https://github.com/mastra-ai/mastra/security/code-scanning/752) | js/insufficient-password-hash | `packages/core/src/utils.ts` | No code change. This is a false positive (see below) | ### ReDoS fixes These regexes are unanchored at the start. On a string with a long run of `/` (or digits) followed by another character, the engine retries the match from every position, which takes quadratic time. On 100k characters the old code took about 7s for the slash trim and about 10s for the digit match. The replacements walk back from the end of the string once and return the same results. That covers the edge cases too: an empty run, an all-slash or all-digit string, and leading zeros like `007`. ### #752 is a false positive `createDeterministicId` already uses SHA-256 (`createHash('sha256').update(input).digest('hex').slice(0, 8)`). It builds a short, non-secret `tool-<hash>` ID from `tool.description` in `setVercelToolProperties`, and nothing in it stores a password. CodeQL raises this rule for any fast hash it thinks might receive a credential. Here its taint path runs from the API keys passed to the Gateway model providers in `mastracode/sdk`, through provider/model objects, and not through a tool description. No hash change would satisfy the rule: it wants a slow KDF (bcrypt/scrypt/PBKDF2), which would change every existing tool ID that callers rely on. Recommend dismissing #752 as a false positive. ## Test plan - [x] Regression tests with 100k-character pathological inputs in `mastra.test.ts`, `auth/supabase/src/index.test.ts`, and `boards/semantics.test.ts`. I checked that each one fails (times out at 7–20s) against the old regex and passes with the fix. - [x] Behavior tests for gateway base-URL normalization (`///`, `/v1///`, `/api/`) and for falling back to the PR number from the GitHub key (`34`, `007`, empty, `12x`) - [x] `vitest` passes for the gateway tests in `@mastra/core`, all of `@mastra/auth-supabase`, the semantics and GitLab rules tests in `@mastra/factory`, and the MCP OAuth test in `@mastra/nestjs` - [x] `tsc --noEmit` is clean for `packages/core`, `auth/supabase`, `mastracode/factory`, and `server-adapters/nestjs` - [x] Changeset added for `@mastra/core`, `@mastra/auth-supabase`, and `@mastra/factory`. The NestJS change only touches a test, so it has no changeset Ref SEC-326 Ref SEC-325 Ref SEC-316 Ref SEC-259 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> **ELI5:** Some code used regular expressions that ran very slowly on very long strings of `/` or digit characters. This change replaces them with loops that scan each string once. The results stay the same. ## Overview The change replaces three end-anchored regular expressions with backward scans. It also adds a type guard in a NestJS test helper. The diff touches 9 files, with 93 lines added and 4 removed. The change addresses three polynomial ReDoS findings and one type-confusion finding from CodeQL. It does not change code for the insufficient-password-hash finding (`#752`) on `createDeterministicId`. The author classifies that finding as a false positive. The hash creates non-secret tool IDs from tool descriptions. A slow KDF would change existing IDs. ## Changes by area - **Gateway base URL** (`packages/core/src/llm/model/gateways/mastra.ts`): `getBaseUrl` removes trailing `/` characters with a character-by-character loop. It then removes a final `/v1` suffix. - **Supabase URL** (`auth/supabase/src/index.ts`): The provider stores a normalized `this.url`. A backward loop removes trailing `/` characters. The Supabase client still receives the original `supabaseUrl`. - **Pull request number** (`mastracode/factory/src/boards/semantics.ts`): The new helper `trailingDigits` scans backward over ASCII digits `0`–`9`. `boundChangeRequestNumber` calls it only for `github-pr` sources. It returns `undefined` when no trailing digit exists. - **NestJS test helper** (`server-adapters/nestjs/src/__tests__/builtin-mcp-oauth.test.ts`): `AudienceAuth.authenticateToken` accepts `unknown`. It returns `null` for non-string values before it parses `aud=`. - **Changesets**: - `.changeset/linear-slash-trim.md` sets patch releases for `@mastra/core` and `@mastra/auth-supabase`. It describes linear-time trailing-slash trimming. It states that the resulting URLs are unchanged. - `.changeset/linear-pr-number.md` sets a patch release for `@mastra/factory`. It describes linear-time PR-number extraction. It states that the returned number is unchanged. ## Tests The test file diffs were not inspected. The following test additions come from the raw summary and are not verified against the diff: - A Supabase test that uses a URL with two 100,000-slash runs. It asserts construction takes under 500 ms. - Factory tests for trailing-digit extraction, leading zeroes, `undefined` results, and 100,000-character keys. - Gateway `fetchProviders` tests for base URL normalization and a pathological slash-run case. The PR reports passing Vitest runs and clean `tsc --noEmit` runs for `packages/core`, `auth/supabase`, `mastracode/factory`, and `server-adapters/nestjs`. These results were not verified from completed checks on the current head: not available. ## Notes - The NestJS change is test-only. It has no changeset. <!-- 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> |
||
|
|
b07dd23713 |
feat(core): add knowledge.reembed() to embed existing Knowledge content (#30603) | ||
|
|
6fbd425c83 |
ci(renovate): keep store-test MongoDB on 7.x (#30601)
## Summary `Combined Store Tests / test (mongodb)` fails on every PR that touches stores (e.g. #30577, #30580, #30593) because the test container never starts: > MongoDB cannot start: Linux kernel versions 6.19.0 through 7.0.13 have a known incompatibility with this version of MongoDB `stores/mongodb/docker-compose.yaml` was deliberately pinned to `mongo:7.0.45` because MongoDB 8.x+ refuses to start on the self-hosted runners' kernel (TCMalloc rseq issue, SERVER-121912). The Renovate major Docker update in #19788 bumped it to `mongo:9.0.8`, undoing that pin. This PR: - Restores `mongo:7.0.45` for the `mongodb-storage` and `mongodb-fidelity` services (the `mongodb-vector` Atlas Local image is unchanged). - Adds a Renovate rule capping `mongo` below 8 for that compose file so it is not bumped again. - Updates the compose comment to cover 9.x. **This is a CI-only workaround.** It only changes the test container image; no published package or runtime behavior changes, so there is no changeset. Revisit the pin once MongoDB ships a release compatible with kernel 6.19+, or once the runners move off an affected kernel. ## Test plan - `Combined Store Tests / test (mongodb)` passes on this PR (the `stores/mongodb` `pretest` runs `docker compose up -d --wait` against this file). - 7.0.45 is the version the suite ran green on before #19788. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## ELI5 The test setup uses a database program that will not start on some test machines. This change sets the database to an older version that does start. It also stops automatic updates from moving that database to version 8 or later. ## Summary This change pins MongoDB to a version that works on the self-hosted CI runners. ### Changes - `stores/mongodb/docker-compose.yaml`: The `mongodb-storage` and `mongodb-fidelity` services use `mongo:7.0.45`. They previously used `mongo:9.0.8`. The `mongodb-vector` Atlas Local image is not changed. - `stores/mongodb/docker-compose.yaml`: The comments now state that the compatibility restriction applies to MongoDB 8.x and 9.x on Linux kernel 6.19+. They also state that the service must not move beyond 7.x until MongoDB ships patched TCMalloc. - `renovate.json`: A new package rule applies to Docker updates for `mongo` in `stores/mongodb/docker-compose.yaml`. It limits allowed versions to `<8`. ### Context The regression came from a Renovate major Docker update. That update changed the image from `mongo:7.0.45` to `mongo:9.0.8`. The MongoDB container then failed to start on self-hosted runners because of a kernel incompatibility. ### Impact - The change affects CI test infrastructure only. - No published package or runtime behavior changes. - The PR description reports that `Combined Store Tests / test (mongodb)` passes with the restored image. This summary does not verify that result. ### Review notes - The pin should be revisited when MongoDB supports kernel 6.19+ or when the runners move off an affected kernel. - The diff totals 2 files, 11 lines added, and 4 lines removed. The `renovate.json` change adds 7 lines. The Compose file change modifies 4 lines. <!-- 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> |
||
|
|
b35a72cc7c |
ci(test-tiers): fill the GitHub to Slack user map and add a skill to update it (#30629) | ||
|
|
3c7c00383d |
fix(factory): let the server decide which repository a card's session starts in (#30609)
**─────── TLDR ───────** > A card's draft now asks the server which repository its session starts in, so a card from an unlinked repository is refused instead of started somewhere else. The draft carried its own copy of the repository rule, and a looser one: when the card's repository wasn't linked, it fell back to the environment's first repository and wrote that slug onto the card before calling `runs/start`, which then accepted it. The fallback came from main's `useStartFactoryRun`, not from #30481. Now the draft reads `resolveRunRepository`, the same function `runs/start` checks with, through a new route, and shows its hint as is. ### Behavior changed GitHub card from `acme/docs`, only `acme/app` linked ├─ **was** — starts in `acme/app`, card rewritten to `repository: acme/app` └─ **now** — the draft says "Repository acme/docs is not linked to this Factory.", nothing starts, "Open repository settings" leads to the fix card whose repository resolves (linked, Linear mapping, or a single repository) ├─ **was** — starts there, after the draft writes `repository` onto the card └─ **now** — starts there, the card is left as it was the draft when the server can't answer └─ **new** — "Could not find this card's repository: …", sending stays off, also when an earlier lookup had answered; Retry asks again the draft after the repository gets linked, or after the card changes └─ **new** — asks the server again on reopen, on tab focus, and when the card changes GitHub card in a Factory whose repositories are all on GitLab, or the reverse ├─ **was** — the draft refused it; dispatch and `runs/start` ran it in the Factory's repository └─ **now** — refused everywhere, even when a repository there has the same name: "This card comes from GitHub, and no GitHub repository is linked to this Factory." card naming no repository among several └─ **unchanged** — starts in the environment's first one, the agent picks ### Shape changed new route the draft reads before the first prompt `GET /web/factory/projects/:id/work-items/:workItemId/session-repository` · `{ status: 'resolved', projectRepositoryId, slug }` · `{ status: 'unlinked', hint }` CLI: `mastra api factory work-item session-repository <project-id> <work-item-id>` one place every run reads its repository from: the draft route, rule dispatch, `runs/start` and `factory_start_session` `resolveRunRepositoryFromIntake(intake, args)` · reads the Linear mapping, then Ward's `resolveRunRepository` removed: `cardSessionRepository` · `firstEnvironmentRepository` · `cardRepositorySlug` · `cardLinearProjectId` · `useCardRepositorySlug` ### Decisions - **a GET the draft reads, not one call that resolves and starts** — the refusal has to show before the first prompt; `runs/start` still checks on its own. ### Not verified - [ ] a real Factory with an unlinked GitHub repository: covered by the route tests and the draft's MSW tests only --- > ██████████████████ **tests** `+257 −320` — net −63 > ███████████ **source** `+217 −150` — net +67 > ███ **generated** `+83` > █ **changeset** `+17` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ELI5: A Factory card used to choose its own code repository in the app, and that choice could be wrong. Now the server chooses the repository, and a card starts a session only when the server finds one. ## Summary This pull request moves repository selection for Factory card sessions from the client to the server. It changes 26 files, with 534 lines added and 468 removed. ### Server changes (`mastracode/factory`) - Adds the `GET /web/factory/projects/:id/work-items/:workItemId/session-repository` route. The contract is in `routes/contracts.ts`. The handler is in `routes/work-items.ts`. - The response is a discriminated union: - A resolved result returns `projectRepositoryId` and `slug`. - An unlinked result returns a `hint`. - The route returns 404 when the card is outside the caller's organization or project. It returns 503 when no `sessionRepository` resolver is configured. - Adds `resolveRunRepositoryFromIntake` in `session/work-item-repository.ts`. It reads Linear intake configuration for the organization and passes the `repositoryByLinearProject` map to `resolveRunRepository`. If intake or the map is absent, it passes no map. - Adds a provider check. When the active integration has no matching provider ID, and card metadata contains an ID for another supported provider (GitHub or GitLab), the result is unlinked, with a hint naming that provider. This check runs before the repository slug and Linear mapping are considered. - `rules/start-coordinator.ts`, `tools/session-tools.ts`, and `routes/surface.ts` call `resolveRunRepositoryFromIntake`. They no longer load intake configuration directly. - `routes/surface.ts` supplies the `sessionRepository` resolver when source-control integrations are registered. It returns an unlinked result when no source-control connection resolves. ### Factory UI changes (`mastracode/factory-ui`) - Adds the `WorkItemSessionRepository` type, the `workItemSessionRepository` query key, and `getWorkItemSessionRepository` in `services/workItems.ts`. - `useCardSessionRepository` takes `factoryId` and a card with `id` and `updatedAt`. It fetches the repository from the server. The query uses `staleTime: 0` and refetches on window focus. - `useStartCardSessionFromDraft` starts a session only when a resolved repository is available. It no longer writes the selected repository to the card. - `CardDraftPage` shows an error message when the lookup fails. It offers Retry, which is disabled while the lookup runs. It shows the server hint and a link to repository settings when the result is unlinked. Sending stays disabled in both cases. - Removes client-side repository logic from `boardRepository.ts`: `cardRepositorySlug`, `cardSessionRepository`, `firstEnvironmentRepository`, and `cardLinearProjectId`. Removes the `useCardRepositorySlug` hook. - Adds the `workItemSessionRepository` CLI command in `packages/cli`. It shows the repository a card session starts in, or the reason none is available. ### Tests and changesets - `work-items.test.ts` adds tests for resolved responses, unlinked responses, and 404 responses. The 404 test confirms that the resolver is not called. - `work-item-repository.test.ts` adds parameterized tests. A GitHub card is unlinked when only a GitLab repository is linked. A GitHub or GitLab card whose repository isn't linked is named from its URL in the hint. - `boardRepository.test.ts` targets `cardProjectRepositoryId` and covers provider-ID lookup. The old slug, session-repository, and first-environment tests are removed. - The UI MSW and unit tests now use the endpoint. Environment-based repository tests are removed. - The CLI descriptor test expects the new `factoryWork-itemSession-repository` entry. - Two changesets declare patch releases for `@mastra/factory`. A third declares a patch release for `mastra` and documents the new CLI command. ### Behavior notes - A card with a resolvable repository starts in that repository. The card is not rewritten. - A card with no resolvable repository shows the server hint. Sending stays disabled. - If the lookup succeeds and a later lookup fails, sending stays disabled. The PR description reports this as a tested case. - The PR description says that cards without a repository among several keep the first-repository behavior. The diff does not confirm this on the server. The client-side first-environment selector was removed. The server-side fallback was not checked. ### Verification - The PR description reports that the unlinked-GitHub scenario was covered only by route tests and draft MSW tests. It was not verified in a real Factory. - CI and build results are not available. <!-- end of auto-generated comment: release notes by coderabbit.ai --> |
||
|
|
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 --> |
||
|
|
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 ├─ **was** — filed as a card anyway └─ **now** — ignored; pull requests from that repository still come in a repository is added to the GitHub list ├─ **was** — nothing until the next new issue └─ **now** — its open issues are brought in a repository is linked from the UI, API or CLI ├─ **was** — the UI added it to the list; API and CLI links filed issues anyway └─ **now** — the server adds it unless the link sends `selectIntake: false` Vanta connected, nothing selected ├─ **was** — every active vulnerability synced into every project └─ **now** — nothing syncs until the Vulnerabilities source is selected intake order and Not routed ├─ **was** — Settings › Work Intake └─ **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 --> |
||
|
|
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 --> |
||
|
|
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 --> |
||
|
|
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**
├─ suggested run + running session: sidebar says waiting on
you, board says working
└─ one working session + one starting session: sidebar says
working, board says starting
**Now**
├─ suggested run + running session: waiting on you in both,
and the suggested run stays named but disabled until the session ends
└─ 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**
`GET …/session-activity` adds `cardStatuses` and
`sessionHeldCardIds`
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 ████████████████ +211 −219
> tests ██████████████████ +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 `
|
||
|
|
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 -->
|
||
|
|
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>
|
||
|
|
4feafd33e1 |
feat(mastracode): export runTui so other programs can start the TUI with extra session options (#30371) | ||
|
|
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> |
||
|
|
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 ` |
||
|
|
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`]( |
||
|
|
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> |
||
|
|
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:  **Tools from code**: a `tools` option narrowing PostHog to read tools, not using Linear, and adding one tool of its own:  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> |
||
|
|
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`:

**After**, same Factory:

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

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>
|
||
|
|
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
├─ **was** — your sidebar caught up after 15 to 60 s
└─ **now** — it updates on the next feed frame
a session follows or stops following a card
├─ **was** — same 60 s delay
└─ **now** — same feed frame
a session is still starting in an open sidebar
├─ **was** — the sidebar polled `session-rows` every 15 s
└─ **now** — no poll; each write sends its own frame
the session list, on a sidebar reload with no write since the last one
├─ **was** — one probe query, then a full reload whenever
the probe moved
└─ **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
`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 `
|
||
|
|
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 --> |
||
|
|
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 | |---|---| | <br> |  | **Add provider drawer** — a custom endpoint is one of the options | Before | After | |---|---| |  |  | Real app on Vite in Chromium, with Playwright answering the API. ### Behavior changed a personal custom endpoint └─ **new** — only its owner sees it, their personal sessions run on it an org-wide endpoint, in a personal session ├─ **was** — offered and used └─ **now** — not offered, personal work uses personal endpoints only a member adds, edits or removes an org-wide endpoint ├─ **was** — allowed └─ **now** — 403, and read-only in Settings like org keys an endpoint named like a built-in provider, with no key of its own ├─ **was** — called with the key saved for that provider └─ **now** — called with no key, and that name is refused for new ones editing an endpoint without retyping its key ├─ **was** — the saved key was wiped └─ **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 ├─ **was** — saved and called from the Factory server └─ **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 ├─ **was** — followed, carrying the request and its key └─ **now** — refused, the call fails the same endpoint on a local or self-hosted Factory └─ **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 `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> |
||
|
|
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> |
||
|
|
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 ├─ **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 └─ **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 └─ **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 ├─ **was** — Open session or Start session pills, and the source links only in the expanded card └─ **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 ├─ **was** — the board could show empty: its groups mounted before the scroll surface they measure against └─ **now** — the cards show at once list rows ├─ **was** — a details button swapped in on hover, and a wide gap sat between the avatar and the time └─ **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 --> |
||
|
|
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> |
||
|
|
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> |
||
|
|
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> |
||
|
|
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> <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> </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> |
||
|
|
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> |
||
|
|
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 |  |  | | Dark |  |  | 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 --> |
||
|
|
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 |  |  | | Dark |  |  | | Sidebar | Before | After | | --- | --- | --- | | Light |  |  | | Dark |  |  | | Toolbars | Before | After | | --- | --- | --- | | Light |  |  | | Dark |  |  | 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 --> |
||
|
|
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> |
||
|
|
02d080c280 |
Revert: Let Factory sessions push GitHub Actions workflow changes (#30586)
## Summary Reverts #30584, which added `workflows: 'write'` to the permission set on every Factory repository token. With that permission, any session (or prompt-injected repository content) can rewrite CI workflows that run with repository secrets, including the npm publish path. #30584 hasn't reached shipyard yet, so this reverts it before it deploys. Until an approval-gated path exists (see the closed #28967), a person pushes changes to `.github/workflows/*`. ## Test plan - [x] `vitest run src/integrations/platform/github/integration.test.ts`: 60 passed, with the expected token payloads back to no `workflows`. 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> |
||
|
|
b02659fcf1 |
fix(templates): upgrade mongodb-bedrock-agent to AI SDK v6 to resolve vulnerable dependencies (#30574)
## Summary Upgrades `templates/template-mongodb-bedrock-agent` to the AI SDK v6 stack used by the other templates, which clears the vulnerable dependencies we'd held back because the fixes needed major upgrades. - `ai` ^5.0.289 → ^6.0.332, `@ai-sdk/amazon-bedrock` 3.0.146 (exact pin) → ^4.0.216. ai v5's `@ai-sdk/provider-utils@3` pins `undici` 5.x, which has no patched release. v4 brings `undici` 6.29.1 and drops `@fastify/busboy`. - Removes `patch-package`, the `postinstall` script, the `patches/` directory and the Dockerfile `COPY patches` step. Bedrock v4 already ships the upstream fix (`BedrockToolUseSchema.input` is optional), and the patch only existed because that fix wasn't available on ai v5. Removed the matching notes from CONTRIBUTING.md and AGENTS.md. - Bumps Mastra packages to current versions (`@mastra/core` ^1.83.0, memory, mongodb, rag, observability, editor, `mastra` CLI). - Bumps `@opentelemetry/auto-instrumentations-node` ^0.79 → ^0.83.1 to fix GHSA-3v2p-hm54-8qcq (moderate). That package needs Node ≥22.15, so `engines.node` goes from `>=22.13.0` to `>=22.15.0`. The Dockerfile already uses `node:22-slim`. - Regenerated `package-lock.json` with npm. No source code changes were needed. `embed`/`embedMany`, `createAmazonBedrock`, and the Bedrock `dimensions` provider option work the same on v6/v4. ## Verification - `npm ls undici @fastify/busboy shell-quote image-size uuid follow-redirects proxy-addr`: `undici` 6.29.1 / 7.30.2 and `uuid` 11.1.1 only. No `@fastify/busboy`, and `shell-quote`, `image-size`, `follow-redirects` and `proxy-addr` are no longer in the tree. - `npm audit --omit=dev` and `npm audit`: **0 vulnerabilities** (before: 9, 2 high). - `npx tsc --noEmit` and `npm run build` pass. - `npx mastra build` succeeds. - `npm test`: 8 passed, 6 skipped. The skipped tests need `TEST_MONGODB_URI`, the same as before this change. - `npm ci --omit=dev` installs cleanly without the postinstall. Closes Dependabot alerts #3517–#3534 (undici / @fastify/busboy). Ref SEC-315 Ref SEC-263 Ref SEC-264 Ref SEC-252 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> **ELI5:** This change updates a MongoDB Bedrock agent template to newer libraries. It removes a patch that is no longer needed, because the newer Bedrock library includes the fix. It also raises the minimum Node.js version. ## Summary This change upgrades the `templates/template-mongodb-bedrock-agent` template to the AI SDK v6 stack. The `ai` package moves from `^5.0.289` to `^6.0.332`. `@ai-sdk/amazon-bedrock` moves from the exact version `3.0.146` to `^4.0.216`. The change also updates Mastra packages, `@opentelemetry/auto-instrumentations-node` (now `^0.83.1`), and the `mastra` CLI. The change removes the Bedrock tool-use workaround. That workaround used `patch-package`. The author states that Bedrock v4 includes the upstream fix, so the workaround is no longer needed. The change includes no source code changes. ### Changes by file - `package.json`: - Raises the Node.js requirement (`engines.node`) from `>=22.13.0` to `>=22.15.0`. - Removes the `postinstall` script and the `patch-package` dependency. - Updates the `ai`, `@ai-sdk/amazon-bedrock`, Mastra, OpenTelemetry instrumentation, and `mastra` CLI versions. - `patches/@ai-sdk+amazon-bedrock+3.0.146.patch`: Deleted. The patch made `input` optional in `BedrockToolUseSchema` in the CommonJS and ESM bundles. - `Dockerfile`: Removes the step that copies the `patches` directory into `/app` before `npm install`. - `CONTRIBUTING.md`: Removes the section on the pinned `@ai-sdk/amazon-bedrock` dependency, the `patch-package` workaround, the `ai` v5 constraint, and the rule that `patch-package` remain a runtime dependency for `npm ci --omit=dev`. - `AGENTS.md`: Removes the instruction to keep the pinned Bedrock provider version and its `patch-package` fix until a deliberate migration. - `README.md`: The Prerequisites section now states Node.js 22.15 or later. The diff reports 7 changed files, with 1,685 lines added and 2,071 removed. The per-file summaries cover 6 files. The summaries report about 12 added lines in total, so most of the added lines come from a file that is not described. That file is probably a lockfile, but this summary does not confirm it. ### Reported verification (author-reported, not independently confirmed) - `npm audit --omit=dev` and `npm audit`: 0 vulnerabilities. - `npx tsc --noEmit`, `npm run build`, and `npx mastra build`: succeeded. - `npm ci --omit=dev`: installed without the postinstall script. - `npm test`: 8 passed, 6 skipped. The skipped tests require `TEST_MONGODB_URI`. - `npm ls undici @fastify/busboy shell-quote image-size uuid follow-redirects proxy-addr`: results reported by the author, not summarized here. The PR states that it closes Dependabot alerts `#3517`–#3534. It references SEC-315, SEC-263, SEC-264, and SEC-252. <!-- 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> |
||
|
|
918d229b8b |
fix(cli): only open http(s) URLs, drop cmd.exe (#30573)
## Summary
CodeQL flags the CLI's `openBrowser` (used for `mastra auth login`,
`mastra connect`, and the add-credits flow) for command-line injection:
the login URL is built from `MASTRA_PLATFORM_API_URL`, which comes from
the environment, and is handed straight to the OS opener.
`openBrowser` already used `execFileSync` with an argument array on
macOS, Linux, and WSL, but two gaps remained:
1. **No URL validation.** Any string, such as `file:///…`,
`javascript:…`, a bare program name, or an option-like `--foo`, went to
`open` / `xdg-open` / `Start-Process`. Now the input is parsed with `new
URL()`, only `http:` and `https:` are accepted, and the normalized
`href` is what gets passed on. Normalizing also percent-encodes spaces,
quotes, and backticks.
2. **Windows went through `cmd.exe`.** `execFileSync('cmd', ['/c',
'start', '', url])` has no shell on the Node side, but cmd.exe parses
its own command line, so `&` in the URL acts as a command separator.
Every login URL contains `&` (`?product=cli&cli_port=…&state=…`), so on
Windows the URL was also cut off after the first query parameter.
Windows now uses `rundll32.exe url.dll,FileProtocolHandler <url>`, which
opens the default handler without a command interpreter.
All callers already catch errors from `openBrowser` and print the URL,
so a rejected URL falls back to "open this link manually" and does not
crash.
## Test plan
- New `openBrowser` tests in
`packages/cli/src/commands/auth/credentials.test.ts`:
- non-http(s) and invalid inputs throw, and no process is spawned
- on macOS the URL is passed as a single argv entry
- on Windows, `rundll32.exe` gets the full URL including `&`, and `cmd`
is never invoked
- shell metacharacters are percent-encoded before spawning
- `vitest run src/commands/auth src/commands/connect
src/commands/gateway`: all pass
- `tsc --noEmit` for `packages/cli`: clean
Ref SEC-249
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->
**ELI5:** The CLI opens a web page for login. Before this change, it
passed the page address to Windows in a way that could run extra
commands. Now it only opens normal web addresses, and it uses a safer
Windows method.
## Summary
This change hardens how the CLI opens a browser. The `openBrowser` flow
is used by `mastra auth login`, `mastra connect`, and add-credits.
### Changes
- **`packages/cli/src/commands/auth/credentials.ts`** (+22/-3)
- Adds `toBrowserUrl(url)`. It parses the input with `new URL()` and
throws on invalid input.
- `toBrowserUrl` also throws when the protocol is not `http:` or
`https:`.
- `toBrowserUrl` returns `parsed.href`, the normalized URL.
- `openBrowser` now takes `rawUrl: string`. It calls `toBrowserUrl` and
passes the result to the OS opener.
- On Windows, `openBrowser` calls `rundll32.exe` with
`url.dll,FileProtocolHandler` and the URL. It no longer calls `cmd /c
start`.
- The macOS, WSL, and other Linux paths are unchanged.
- **`packages/cli/src/commands/auth/credentials.test.ts`** (+63)
- Adds `openBrowser` tests. Per the PR objectives, they cover rejected
inputs, macOS argument handling, Windows invocation without `cmd`, and
encoding of shell metacharacters. The test contents were not inspected
in this review.
- **`.changeset/safe-browser-open-url.md`** (+5)
- Adds a `mastra` patch changeset. It describes the HTTP(S)-only
behavior and the Windows change.
### Behavior notes
- Callers receive an error for rejected URLs. The PR objectives state
that callers catch errors and show the URL for manual opening.
- The public signature changes only in its parameter name, from `url` to
`rawUrl`.
### Validation
The PR objectives report these results. They were not re-run in this
review.
- `vitest run src/commands/auth src/commands/connect
src/commands/gateway`: reported as passing.
- `tsc --noEmit` for `packages/cli`: reported as clean.
<!-- 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>
|
||
|
|
7f1f8a8ec6 |
Let Factory sessions push GitHub Actions workflow changes (#30584)
## Summary Factory sessions couldn't push any change to `.github/workflows/*` files. GitHub rejected those pushes with `refusing to allow a GitHub App to create or update workflow ... without workflows permission`, even though the Mastra GitHub App installation grants Workflows read & write. The cause is in `REPOSITORY_TOKEN_PERMISSIONS`. The Factory narrows every installation token it mints to that set, and the set didn't include `workflows`. This PR adds `workflows: 'write'` to it. The Platform token-mint route already treats `workflows` as a collaborator permission. Like `contents: write`, it needs push access on the repository, so the user role checks don't change. ## Tradeoffs / risk - **Wider blast radius.** Every Factory session token can now change CI workflows, which run with repository secrets. Before, a session could change code but not workflows. - **Unapproved installations.** GitHub refuses to mint a token that asks for a permission the installation hasn't granted. If an installation hasn't accepted the Workflows permission, minting fails for it until an owner approves the updated permissions on GitHub. ## Test plan - [x] `vitest run src/integrations/platform/github/integration.test.ts`: 60 passed, with the expected mint payloads updated. - [ ] After deploy, push the SEC-250 workflow-hardening branch from a Factory session. Ref SEC-250 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> |
||
|
|
09e48ffc4d |
test(core): give the goal step test's workflows store supportsRunJournal (#30571)
## Description Adds `supportsRunJournal` to the mock `workflows` store in `goal-step.test.ts`. Since #29370, `Workflow.createRun` calls `supportsRunJournal()` on the workflows store for every run. The test builds its own store with only `getWorkflowRunById`, `deleteWorkflowRunById` and `persistWorkflowSnapshot`, so the goal judge's agent threw `workflowsStore?.supportsRunJournal is not a function` and the goal was parked as `paused`. That fails 13 cases in the file on `main` and on every PR that includes that change (for example `expected 'paused' to be 'done'`). Real storage adapters extend `WorkflowsStorage`, which defines the method, so only the mock was affected. The mock returns `false` because it has no journal, so runs take the snapshot path the test already mocks. ### Tests `npx vitest run src/loop/workflows/agentic-execution/goal-step.test.ts` in `packages/core`: - Before: `Tests 13 failed | 17 passed (30)` - After: `Tests 30 passed (30)`, stable over three runs `npx vitest run src/loop/workflows/agentic-execution/` also passes: `Test Files 18 passed (18)`, `Tests 379 passed (379)`. ## Related issue(s) None. ## Type of change - [ ] 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 - [x] Test update ## Checklist - [ ] I have linked the related issue(s) in the description above - [ ] I have made corresponding changes to the documentation (if applicable) - [ ] 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:** A test helper was missing a method that the code now expects. This change adds the missing method so the test runs the expected path and stops failing. ## Summary This change updates the test mock for the workflows store in `packages/core/src/loop/workflows/agentic-execution/goal-step.test.ts`. It adds one line, a `supportsRunJournal()` method that returns `false`. The diff adds 1 line and removes 0. ## Why `Workflow.createRun` checks whether the store supports run journaling for every run. The mock did not implement this method. The goal judge's agent failed as a result, and 13 test cases failed. With `supportsRunJournal()` returning `false`, runs use the snapshot path, which the test already mocks. ## Test results The author reports these results. I did not verify them against a completed check on the current head. - `npx vitest run src/loop/workflows/agentic-execution/goal-step.test.ts`: 13 failed and 17 passed before the change. 30 passed after the change, stable across three runs. - `npx vitest run src/loop/workflows/agentic-execution/`: 18 test files and 379 tests passed. ## Scope - Production code: no change. - Exported or public declarations: no change. - Review effort: low. <!-- end of auto-generated comment: release notes by coderabbit.ai --> |
||
|
|
1d795bd423 |
fix(factory-ui): fix provider search field height (#30563)
> Opened by @DSchau ## Summary The search field in the Factory "Add provider" drawer rendered as a giant pill filling most of the drawer instead of a normal-height input. **Cause:** `SearchInput`'s root (`InputGroup`) has `flex-1` so it fills a row. The drawer body is `flex flex-col`, so `flex-1` grew the field vertically instead. **Fix:** give the drawer's `SearchInput` `className="flex-none"` so it keeps its normal control height (30px), matching other inputs. No design-system changes. ## Test plan - [x] `vitest run src/ui/domains/settings/components/models/providers` in factory-ui — 21 passed - [x] Rendered the same layout headlessly: field height 360px before → 30px after <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> **ELI5:** The search box in a settings panel got too tall and took up most of the panel. This change keeps the search box at its normal height. ## Summary This pull request changes one line in `mastracode/factory-ui/src/ui/domains/settings/components/models/providers/AddProviderDrawer.tsx`. The provider search input receives the `flex-none` class. The diff adds one line and removes none. ## Cause The drawer body uses a flex-column layout. The `SearchInput` root (`InputGroup`) has `flex-1`. In a column layout, `flex-1` lets the field grow vertically. The field then fills most of the drawer. ## Change - Adds `className="flex-none"` to the drawer's `SearchInput`. - Keeps the field at its normal control height. - Does not change the design-system `InputGroup` component. ## Reported verification The PR author reports these results. The reviewer did not confirm them from the current head: - `vitest run src/ui/domains/settings/components/models/providers` passed 21 tests. - A headless layout render measured the field at 360px before the change and 30px after. ## Alterations to public declarations None. ## Review effort Low. <!-- 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> |