Skip to content

fix(server): MCP mutation retries survive credential reissue - #23796

Open
juliusmarminge wants to merge 6 commits into
mainfrom
fix/issue-16184
Open

juliusmarminge wants to merge 6 commits into
mainfrom
fix/issue-16184

Conversation

@juliusmarminge

@juliusmarminge juliusmarminge commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Problem

Retrying a thread-owned MCP mutation with the same clientRequestId after a server restart created new work. In a real Codex/web reproduction, the same delegate_task call replayed before restart but created a second child after restart.

Change

Scope thread callers' mutation IDs to the calling thread instead of the random MCP credential ID. Reissued credentials now reach the existing command receipts, so keyed delegation, thread creation, messages, schedules, metadata updates and cancellation retain their identity. Credential IDs, authentication, revocation, liveness and capabilities retain their existing behavior; OAuth client callers retain their session namespace. Correct the existing scope documentation and comment.

Scope and approval

Fixes https://git.cafe/pingdotgg/t3code/issues/16184

Triaged bug via the automated issue flow: #16184. One reproduced idempotency defect; no new settings, storage or tool capabilities.

Verification

  • The regression uses real credential issuance, the MCP service, thread-management service, orchestrator and SQLite command receipts. Restoring the old credential namespace makes its task-identity assertion fail. With the fix, retry returns the original task and the persisted parent projection contains exactly one child; another thread and a new key create independent work. Provider execution is disabled because this test observes committed commands before side effects.
  • Initial head: vp test run src/mcp/OrchestratorMcpService.test.ts src/mcp/McpSessionRegistry.test.ts src/mcp/McpHttpServer.test.ts src/mcp/McpToolAccess.test.ts from apps/server: 113 passed. After replacing the mocked regression with real persisted receipts, vp test run src/mcp/OrchestratorMcpService.test.ts passes 34/34 at the current head; targeted lint, formatting and server typecheck pass. Server typecheck passed; targeted lint had only existing unused-variable warnings. Diff whitespace check passed.
  • Real isolated Linux dev server, Chromium web client and Codex: before the fix, explicit retry across restart created two completed children; with the fix, retry returned the same task and persisted exactly one child. Subsequent commits change only tests, documentation and comments.
  • Three independent review rounds with GPT-6.1-Sol and Claude Opus 5.5 found no code defects. Their NEEDS_JULIUS verdicts reflect the checklist's MCP-sensitive classification.

Evidence (server-only; visual fixture matrix is empty):

Proof Before After
Original credential-reissue proof (superseded by real-service regression below) Failing regression Focused test output, independent verification
Real server restart and explicit retry Two child tasks Same task, one child; before/after runtime transcript

Current real-service red/green proof. This replaces the original Map-backed receipt mock after review.

Evidence index · Empty visual matrix.

Limits: interrupted waiting calls and automatic restart continuation were not runtime-exercised. The guarantee applies to mutations first accepted with the fixed namespace; older per-credential receipt IDs cannot be reconstructed across the upgrade. No client render paths or platform-specific code changed.

Models and harnesses: GPT-6.1-Sol via Codex; Claude Opus 5.5 via Claude Agent SDK, orchestrated through T3 Code. Runtime probe: GPT-6-Astra via Codex.

Fixes #16184

juliusmarminge and others added 4 commits October 22, 2026 19:27
…ential reissue

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… reissued

Thread-issued MCP credentials namespaced mutation command ids by the
per-credential provider session id, so a restart that reissued the
credential turned a retried clientRequestId into a new child task. Key the
namespace by the owning thread instead; client callers keep their
client:<session> namespace.

Fixes #16184

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:S 10-29 changed lines (additions + deletions). labels Oct 22, 2026
@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

Provider Metric Main baseline This PR Impact PR ceiling
Codex Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅
Codex Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅
Codex Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅
Codex Live turn WebSocket decoded 21.5 KiB 21.5 KiB 0 B (0.0%) 24.4 KiB ✅
Codex Live turn messages 1 1 0 (0.0%) 8 ✅
Claude Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅
Claude Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅
Claude Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅
Claude Live turn WebSocket decoded 21.9 KiB 21.9 KiB 0 B (0.0%) 24.4 KiB ✅
Claude Live turn messages 1 1 0 (0.0%) 8 ✅

Baseline: 3a8c250 · PR result: 9250b25 · Source CI: success

Scenario and decoded snapshot size

10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

  • Codex decoded thread snapshot: 108.5 KiB
  • Claude decoded thread snapshot: 108.8 KiB

Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Thread-based MCP credentials now derive request namespaces from the thread ID. A live test checks that retries retain idempotency across credential reissuance while different threads and request IDs create separate work.

Changes: MCP mutation replay

Layer / File(s) Summary
Thread-scoped idempotency namespace
apps/server/src/mcp/McpSessionRegistry.ts, apps/server/src/mcp/OrchestratorMcpService.test.ts, apps/server/src/mcp/OrchestratorMcpService.ts, docs/orchestration-v2/orchestrator-mcp-server.md
The session registry uses the thread ID as the request namespace. The live test checks replay across credentials for one thread, separate work for another thread, and separate work for a new request ID. The service comment and documentation describe caller-scoped idempotency and replay after credential reissuance.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Possibly related PRs

  • pingdotgg/t3code#21611: Keeps request namespaces stable across credential rotation for keyed thread launches.

Suggested reviewers: t3dotgg

Merge Risk: Minimal · up to 9250b

The change supports retries across reissued credentials without a substantiated issue that needs resolution before merge. Normal checks remain appropriate.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary fix: MCP mutation retries remain stable after credential reissue.
Description check Passed The description includes all required sections: Problem, Change, Scope and approval, and Verification. It explains the defect, implementation, linked issue, test results, runtime evidence, and known l…
Linked Issues check Passed Issue #16184 requires stable mutation replay after MCP credential reissue. McpSessionRegistry.issue now assigns thread callers requestNamespace: thread:${request.threadId} instead of the credentia…
Out of Scope Changes check Passed The production change is limited to mutation namespace selection for thread callers. The added test verifies replay and isolation controls for issue #16184. The documentation and comment changes expla…
Full details: Description check

Explanation

The description includes all required sections: Problem, Change, Scope and approval, and Verification. It explains the defect, implementation, linked issue, test results, runtime evidence, and known limits.

Full details: Linked Issues check

Explanation

Issue #16184 requires stable mutation replay after MCP credential reissue. McpSessionRegistry.issue now assigns thread callers requestNamespace: thread:${request.threadId} instead of the credential ID. The live regression test uses shared SQLite command receipts and verifies that a reissued credential on the same thread returns the original task, that the same key on another thread creates independent work, and that a new key creates new work. The shared namespace applies to the affected derived mutation IDs. OAuth callers retain their session namespace. The documentation and scheduled-task comment match the new scope.

Full details: Out of Scope Changes check

Explanation

The production change is limited to mutation namespace selection for thread callers. The added test verifies replay and isolation controls for issue #16184. The documentation and comment changes explain the resulting namespace. No unrelated settings, storage, capability, authentication, or client-rendering changes are shown.

Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Usage-based review receipt

Note

This review was completed with usage-based billing: files reviewed beyond your plan's included limits are billed at $0.25/file. View usage-based billing.

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 6a60cb9 and 9250b25.

Files selected for processing: 4

  • apps/server/src/mcp/McpSessionRegistry.ts
  • apps/server/src/mcp/OrchestratorMcpService.test.ts
  • apps/server/src/mcp/OrchestratorMcpService.ts
  • docs/orchestration-v2/orchestrator-mcp-server.md
Files skipped from review as they are similar to previous changes: 1

  • apps/server/src/mcp/OrchestratorMcpService.ts

Limit details: You’ve used all 10 included reviews currently available.

requestNamespace: providerSessionId,
// Keyed by thread, not credential: a reissued credential (for example
// after a server restart) must replay the thread's earlier mutations.
requestNamespace: `thread:${request.threadId}`,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The credential-reissue regression uses a mocked ThreadManagementService to implement receipt lookup and replay in an in-memory map. That mocks core business logic rather than only external services, so it cannot verify that a real persisted command receipt is replayed after reissue. Could you add a focused test with the real thread-management service and test layers only for external dependencies, asserting that the retry creates no second child?

Posted via Macroscope — Effect Service Conventions

@macroscopeapp

macroscopeapp Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Needs Human Approval

Macroscope's review found this PR requires human approval — MCP mutation identities now remain stable across credential reissue for the same thread. An unresolved review concern asks for real persisted-receipt coverage demonstrating that a retry does not create a second child or launch duplicate work.

You can add or adjust custom eligibility rules. Learn more.

…rvices

Replace the mocked ThreadManagementService replay with the real thread
management service, command receipt store, and in-memory orchestrator, so the
retry after a reissued MCP credential is proven against persisted receipts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copy link
Copy Markdown
Member Author

Addressed the receipt-replay test finding in 6a60cb9. The regression now uses real thread management, orchestration and SQLite command receipts. Reissue returns the original task and leaves exactly one persisted child. Restoring the old namespace fails the identity assertion; the fixed full test file passes 34/34. Red/green proof. Production code is unchanged.

macroscopeapp[bot]
macroscopeapp Bot previously approved these changes Oct 22, 2026
@juliusmarminge juliusmarminge added the bugfix Fix PR opened by an issue lead; enters the PR loop label Oct 22, 2026 — with GitCafe Production
@juliusmarminge juliusmarminge added the pr:needs-julius Needs Julius: route gate, unverifiable surface, or blocked label Oct 22, 2026
# Conflicts:
#	apps/server/src/mcp/OrchestratorMcpService.test.ts
@macroscopeapp
macroscopeapp Bot dismissed their stale review November 11, 2026 05:53

Dismissing prior approval to re-evaluate 9250b25

@juliusmarminge

Copy link
Copy Markdown
Member Author

Evidence

On both commits: create a fresh synthetic project and active replay parent; call async delegate_task with clientRequestId review-round-1; retry immediately; restart the server; continue the same parent with a newly issued credential; repeat the identical call and inspect its children.

Both captures use isolated Linux development servers, Chromium, a 1280×800 CSS viewport, light theme, and fresh synthetic databases. The driver calls the real MCP endpoint using actual provider-issued credentials.

Before After
Before: duplicate review tasks and two previous agents
3a8c250cb0
After: original review task and one previous agent
9250b259cd
Restart retry returned a new task and child; persisted child count 2. Restart retry returned the original task and child; persisted child count 1.
Before recording After recording

Immediate retries returned the original task on both commits. Credentials changed across both restarts. Fresh-key and other-thread controls created independent work on both commits. Each final still matched a second screenshot taken at least 500 ms later. Stills and sampled recording frames were visually inspected.

Runtime transcript and task IDs · Driver and seed script · Launcher · Launcher helper · Redacted setup logs

Manual runtime proof followed two scenario setup failures. No unit-test results are used as evidence.

AI-assisted; verified with the tests and tools listed above.

Not shown:

  • Live Codex execution was not exercised; replay execution held each parent active while the driver called the real MCP endpoint.
  • Other keyed MCP mutations and OAuth client namespace behavior were not runtime-exercised; this proof covers delegate_task across server restart and credential reissue.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Fix PR opened by an issue lead; enters the PR loop pr:needs-julius Needs Julius: route gate, unverifiable surface, or blocked size:S 10-29 changed lines (additions + deletions). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Retrying an MCP mutation with the same clientRequestId creates duplicate work after a server restart

1 participant