Skip to content

fix(server): keep remote delegation idempotency namespace durable across restarts - #222

Open
nullStack65 wants to merge 1 commit into
release/native-0.1.10from
fix/clo-1091-remote-delegation-idempotency
Open

nullStack65 wants to merge 1 commit into
release/native-0.1.10from
fix/clo-1091-remote-delegation-idempotency

Conversation

@nullStack65

Copy link
Copy Markdown
Owner

Problem

McpSessionRegistry set each thread credential's requestNamespace to its ephemeral in-memory providerSessionId UUID. When the origin T3 server restarted (or rotated credentials), retrying delegate_task with the same clientRequestId produced a new idempotency key:

  • retries could launch duplicate remote tasks, and
  • a crash between the remote launch and local delegated_task.remote.request recording could not be recovered by retrying with the same clientRequestId, stranding the remote thread and lane.

Fix

  • Derive thread MCP requestNamespace deterministically from durable thread identity (thread:${threadId}) in McpSessionRegistry while keeping providerSessionId and bearer tokens ephemeral per credential.
  • Match both environmentId and threadId when looking up a replayed remote task record in RemoteDelegation.
  • Add focused unit and integration tests using real McpSessionRegistry instances across origin restarts covering:
    • restart retry idempotency (no duplicate remote launch, same taskId and remote thread),
    • crash-window recovery between remote launch and local record creation (reconciles remote thread, records local task, attaches follower, completes when remote finishes), and
    • distinct clientRequestId values still launching new remote tasks.

Verification

  • vp run typecheck: 41/41 packages passed
  • vp test run (apps/server/src/mcp/McpSessionRegistry.test.ts, apps/server/src/peer/RemoteDelegation.test.ts): 2 files, 69/69 tests passed
  • vp fmt --check & vp lint on touched files: 0 warnings, 0 errors

Deploy: fleet
Model: gemini-4-neon
Task: fix

@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@nullStack65

Copy link
Copy Markdown
Owner Author

Independent fresh-context review of the change that keeps the remote-delegation retry namespace durable across origin restarts, at exact head 6e7117730fe7a6333167c46b0e0eee22e842be55 against base release/native-0.1.10 at caf9ebeb0cae23bee584f7b0acf3856fb6f6cada.

What I checked

  1. McpSessionRegistry.ts: requestNamespace is now thread:${threadId}; token and providerSessionId stay ephemeral. ProviderSessionManager revokes the thread before it issues a new credential, so each thread holds one credential. Subagents are their own threads, so a parent and its child never share a namespace.
  2. PeerForwarding.scopedRequestId hashes the namespace with the clientRequestId. The forwarded key is therefore stable across restarts while still unique per origin thread. The remote side's dedupe is unchanged.
  3. RemoteDelegation.ts replay lookup now matches environmentId as well as threadId. This lines up with followUp's isThere and stops a lookup from matching a same-id thread in another environment.
  4. Every other requestNamespace consumer (OrchestratorMcpService stable command, thread and message IDs; PeerLinkRequests; ThreadMetadataMcpService; project launch; SecretRequests.savePasted; RemoteDelegation placement and cancel) now dedupes per thread instead of per provider session. docs/orchestration-v2/orchestrator-mcp-server.md:451 already describes replay as "for the same action and thread", so the docs stay accurate.
  5. Tests: the new registry test covers rotation, a restart (a new registry instance) and thread separation. The RemoteDelegation tests cover a retry after restart, recovery from a crash between the remote launch and the local record, and distinct clientRequestIds.
  6. CI on this head: all checks pass (deploy line, ARC core, web, mobile and founder inbox, CodeRabbit). I did not run the tests locally because this worktree has no installed dependencies. I relied on CI and the verification listed in the PR body.

Result: no important or critical findings. One nit (below) about the wider dedupe scope. It is intended and documented, so it does not block.

{
  "reviewed_base": "caf9ebeb0cae23bee584f7b0acf3856fb6f6cada",
  "reviewed_head": "6e7117730fe7a6333167c46b0e0eee22e842be55",
  "reviewer": "claude-opus-5-5, Claude Code via T3 Code (drain-supervisor reviewer)",
  "author_session": "unknown: native author session not supplied; PR body names Model gemini-4-neon, Task fix",
  "reviewer_session": "claude-code:47fbd824-a68e-4b56-a5c6-7670a76330b5",
  "fresh_context": true,
  "review_kind": "full",
  "round_id": "claude-code:47fbd824-a68e-4b56-a5c6-7670a76330b5",
  "intent": [
    "R1: retrying delegate_task with the same clientRequestId after an origin restart or credential rotation does not launch a duplicate remote task",
    "R2: a crash between the remote launch and the local delegated-task record is recoverable by retrying with the same clientRequestId",
    "R3: distinct clientRequestId values still launch new remote tasks"
  ],
  "prior_findings": [],
  "findings": [
    {
      "id": "F1",
      "severity": "nit",
      "outcome": "open",
      "file": "apps/server/src/mcp/McpSessionRegistry.ts",
      "line": 139,
      "summary": "The thread-scoped namespace widens dedupe for every MCP tool, not only delegate_task. Reusing a clientRequestId on the same thread in a later provider session now replays the earlier result instead of acting again. For example, request_secret with a pasted value returns the first file unchanged (SecretRequests.savePasted). This matches the documented 'same action and thread' contract, so it is not a defect. A one-line note on clientRequestId that a key must be unique for the thread's lifetime would make it explicit for models."
    }
  ]
}

@nullStack65
nullStack65 force-pushed the fix/clo-1091-remote-delegation-idempotency branch from 6e71177 to 79eda00 Compare November 27, 2026 03:58
…oss restarts

Squash-rebase of PR #222 onto current release/native-0.1.10; no behavior change from the original
commits. Original authoring trailers: Model gemini-4-neon / Task fix / Agent antigravity

Model: claude-opus-5-5
Task: fix
Agent: Builder drain parked-PR lane (Claude Code worker F3)
Lane: magpie
Harness: t3/claude-code
Model-family: Claude
Model-generation: Opus 5.5
Skills-SHA: unknown (source unavailable)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nullStack65
nullStack65 force-pushed the fix/clo-1091-remote-delegation-idempotency branch from 79eda00 to 816e682 Compare November 28, 2026 05:47

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant