Skip to content

fix(dev): fail MCP tool calls closed when the pinned epoch vanishes - #134

Merged
ScriptedAlchemy merged 1 commit into
mainfrom
fix/124-mcp-stale-epoch
Sep 1, 2026
Merged

fix(dev): fail MCP tool calls closed when the pinned epoch vanishes#134
ScriptedAlchemy merged 1 commit into
mainfrom
fix/124-mcp-stale-epoch

Conversation

@ScriptedAlchemy

Copy link
Copy Markdown
Owner

Summary

  • Root cause for the silent tools/call wedge in the MCP playground: epoch leases are process-local (epochReferenceCounts lives in module state), so an external agent-bundle build run's retention cleanup — which executes on every epoch publish — deletes the epoch a live dev-server MCP session has pinned. The session then keeps operating against a vanished artifact: new tool calls silently "succeed" from the child's memory, in-flight ones pend to an untyped SDK timeout, and nothing anywhere surfaces that the project changed underneath the session.
  • Fix: McpSession.callTool now probes the epoch store before dispatch and re-probes when a call fails mid-flight. A vanished epoch raises a typed McpSessionStaleEpochError (names the epoch, states the project changed), cancels every in-flight tool call with the same typed failure, and fail-closes the session — mirroring the existing stderr-overflow contract.
  • The MCP session routes map the typed error to a fail-closed AB8018 (409) diagnostic, mirroring the artifact routes' EPOCH_NOT_FOUND mapping, so the workbench playground surfaces it through its existing invocation-failure UI state. No wire DTO fields change, so the workbench strict decoders are untouched.

Regression coverage

  • mcp-session-service.test.ts: live stdio session pinned to epoch-1; epoch-2 published (pinned session keeps working, preserving the epoch-pinning contract); epoch-1 directory+metadata then removed the way an external process's retention would. Asserts the next tools/call and the already-in-flight hang call both reject with the typed stale-epoch error within a bounded time (session timeout is set beyond the test timeout to prove fail-fast), and the session is invalidated. Verified to fail on main (call silently resolves) and pass with the fix.
  • mcp-session-routes.test.ts: tools/call failing with McpSessionStaleEpochError maps to 409 { code: 'AB8018' }.

Fixes #124

A live playground session pins an artifact epoch, but epoch leases are
process-local: another process's build retention can remove the pinned
epoch underneath the session. tools/call then kept executing against a
vanished artifact (or pended untyped) with no indication the project
changed. Probe the epoch store on the tool-call path and fail closed
with a typed McpSessionStaleEpochError that cancels in-flight calls and
closes the session, surfaced by the session routes as AB8018 (409) like
the artifact routes' epoch mapping.

Fixes #124
@changeset-bot

changeset-bot Bot commented Sep 1, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1ae4610

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
agent-bundle Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-01T05:33:29.235483Z 1ae4610 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@ScriptedAlchemy
ScriptedAlchemy merged commit fa28261 into main Sep 1, 2026
6 of 9 checks passed
@ScriptedAlchemy
ScriptedAlchemy deleted the fix/124-mcp-stale-epoch branch September 1, 2026 05:31

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1ae461011a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/agent-bundle/src/dev/mcp-session/mcp-session.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Workbench MCP playground: tools/call hangs silently when the dev server's project changed underneath it

1 participant