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

open6
main
fix/issue-16184
openedOct 22, 2026byJJulius Marminge
View on GitHubTwo-way sync enabledPR last imported 5d ago

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

ProofBeforeAfter
Original credential-reissue proof (superseded by real-service regression below)Failing regressionFocused test output, independent verification
Real server restart and explicit retryTwo child tasksSame 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 pingdotgg/t3code#16184

Checks

21 successful · 12 skipped · 1 neutral
All checks passed
9250b25

Added 4 commits

  • fix(server): delegate_task retries replay after the MCP credential is reissued204dcdf
  • fix(server): correct schedule-task idempotency scope comment5923e2d
  • docs(server): clientRequestId replay is scoped to the calling threada781b07
  • test(server): reproduce issue 16184, delegate_task replay across credential reissueaff1375
Synced from GitHub

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

ProviderMetricMain baselineThis PRImpactPR ceiling
CodexTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
CodexThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
CodexLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
CodexLive turn WebSocket decoded21.5 KiB21.5 KiB0 B (0.0%)24.4 KiB✅
CodexLive turn messages110 (0.0%)8✅
ClaudeTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
ClaudeThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
ClaudeLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
ClaudeLive turn WebSocket decoded21.9 KiB21.9 KiB0 B (0.0%)24.4 KiB✅
ClaudeLive turn messages110 (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.

Synced from GitHub

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

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: 4

Check nameStatusExplanation
Title checkThe title clearly and concisely describes the primary fix: MCP mutation retries remain stable after credential reissue.
Description checkThe 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 checkIssue #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 checkThe 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 6a60cb9ab85611564c4ba65778d452472fd934c3 and 9250b259cd1817ea335fa5ab9655fdc053e6fa6a.

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.

Synced from GitHub

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.

Added 1 commit

  • test(server): cover credential-reissue delegation replay with real services6a60cb9

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.

Added 1 commit

  • Merge remote-tracking branch 'origin/main' into fix/issue-161849250b25

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.

BeforeAfter

3a8c250cb0

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 recordingAfter 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.