Repository navigation
fix(server): MCP tools in a Claude wake turn wait for the turn's run instead of failing with parent_not_active - #33330
juliusmarminge wants to merge 9 commits into
Conversation
…ails with parent_not_active A provider-started wake turn calls delegate_task while its continuation message.dispatch has not committed yet. The call fails at once with parent_not_active instead of waiting for the wake run and parenting the child to it. This test fails on main. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A provider-started wake turn (a Claude background command finished) calls MCP tools before its continuation's message.dispatch commits a run, so every run-scoped tool failed with parent_not_active while the orchestrator was slow. ProviderContinuationRequests now counts offered-but-unsettled requests per thread; the continuation worker settles each one when its dispatch finishes or fails. The run-ownership checks (delegate_task, create_threads, request_secret, both assertLiveCaller paths, remote delegation and peer link requests) go through one helper: on parent_not_active, if a continuation for the thread is pending, wait for it (at most 60 s) and recheck a fresh read. With nothing pending, or the default reference, they fail immediately as before. Fixes #33272 Co-Authored-By: Claude Opus 5.5 <[email protected]>
… reading the caller A provider-started wake turn calls T3 tools before its continuation dispatch commits the run, so run-scoped tools failed with parent_not_active. The previous attempt caught that failure and rechecked, which kept the modes it read before waiting, could wait under a thread lock the dispatch needs, missed a dispatch that settled before its pending check, and could leak a pending count from an interrupted offer. Tools that check a live caller now wait once at the McpToolAccess entry, before any caller read and outside any lock: when the calling thread has a pending continuation and no active run, they wait for it to settle (60 s cap). The run-ownership checks are back to their main form, writesEnvironment's under-lock recheck never waits, and offer counts and enqueues uninterruptibly. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… the thread's queue empties The wait released only when every continuation for the thread had settled, so a later continuation queued behind another thread's slow dispatch kept a call waiting after its wake run was already active. Recheck the thread after each settle and stop as soon as it has an active run. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…he wake run's settle The wait released on the thread's net pending count, so an offer arriving while the wake's dispatch settled kept the count unchanged and the call blocked until the 60 s cap. Count settles monotonically and recheck the thread after any settle since the wait began. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ApprovabilityVerdict: Approved at Macroscope's review found this PR approvable — MCP tools now wait briefly for a wake turn’s run to be committed instead of immediately rejecting the caller. The wait is bounded, and existing identity, access and mode checks still run afterward. Notes:
You can add or adjust custom eligibility rules. Learn more. |
Thread transfer impact✅ Thread transfer remains within every enforced ceiling.
Baseline: Scenario and decoded snapshot size10 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.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed. |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
AI-assisted; verified with the tests and tools listed above.
AI-assisted; verified with the tests and tools listed above.
Dismissing prior approval to re-evaluate 6af67b2
EvidenceSame steps on both commits: create fresh synthetic state; launch a full-access Claude thread; call Environment for both captures: Linux x86_64, real development server, fresh database with automatic seeding disabled. Recordings replay captured server output at its recorded timing, with private metadata omitted, using the same 1280×900 dark presentation. These are server-output recordings, not browser screen recordings. Provider tool events flush after continuation dispatch; HTTP response timing separately shows when the MCP request returned.
Reproduction artifacts: driver and synthetic seed, 25-second delay patch, sanitization and recording renderer. AI-assisted; verified with the tests and tools listed above. Not shown:
|
|
Note Written by Claude Opus 5.5 (Claude Code) on behalf of Navid We hit #33272 at scale and have ported this PR onto our build. Here is what we measured. How often. On a busy production server running many delegated threads:
Why the gap was long. It was not under a second. The wake's continuation is dispatched by the single continuation dispatcher.
That is #37413. A 60 s wait cannot cover it. With per-key dispatch (the fix described in #37413: each thread family in order, many at once, wakes ahead of re-deliveries),
What is still refused. A wake to a delegated child waits for its parent's lock before its run exists. When that lock is held Question. For those calls, would you consider either of these?
We are happy to send whichever you prefer, with the tests from our port. |
Upstream T3 Code 0.1.9 at main of 2026-11-15, with upstream migrations 93 to 95; Node 26.13.1. - Migrations: upstream's migrations 93 to 95 apply in order, and the fork's migrations leave the message-ordinal index to upstream's migration 94. - Queued messages: a message queued while a run is busy steers into it after 60 seconds, whether a person, an automation or another thread queued it. Due messages merge into one steer, oldest first and within the provider's text limit, with slash commands sent on their own; a turn takes at most one automatic steer a minute. Send now is offered on a waiting run only when the server can end its wait. - Completion and pull request wakes: a thread's queued completion wakes, and its pull request watch wakes, merge into one wake of at most 25 results. A wake whose start failed, or that a restart cut, sends its results again with backoff, at most eight times; merged pull request news survives a restart. - Restart recovery holds only the messages a person queued (unattended work only when continuation is off) and wakes a delegated seat whose waiter the restart cut. - Run ends are handled per thread, in commit order and with bounded workers, so one busy thread no longer holds up the others; provider wakes dispatch in a pool of their own. - A full thread snapshot is capped at 32 MiB of JSON by default and refused when too long for one socket frame. - MCP tools in a wake turn wait for the turn's run (port of upstream pingdotgg#33330); a run that ends its wait early still captures its checkpoint. - Traces: a per-minute span aggregate is written beside the trace file. - Includes 0.1.9-perf.8's checkpoint cohort and descendant process fixes. - Bench parameters in tools/server-bench set to chosen defaults. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Problem
When a background command finishes, Claude starts a wake turn on its own and calls T3 MCP tools before the orchestrator has committed the continuation run for that turn. Until that
message.dispatchcommits, every run-scoped tool (delegate_task,create_threads,request_secret, thread and project writes) fails withparent_not_active. The gap is usually under a second; when the orchestrator is slow it stretches to tens of seconds (53 s in the report), and every tool call in the wake turn fails.Reproduced on main (c73b38b) with a real dev server and Claude thread: a background
sleep, thendelegate_taskin the wake turn, with the continuation dispatch held 25 s by a scratch patch. The call returnedparent_not_activein 23 ms.Change
ProviderContinuationRequestscounts, per thread, continuations that were offered but not yet settled.offerincrements (uninterruptibly, together with the enqueue), andProviderContinuationServicesettles each request once its dispatch ends, whether it succeeded or failed. The production layer exports the same instance so MCP handlers see it.McpToolAccesswraps every tool that checks a live caller (actsAsCaller,writes*,startsThreads) with one wait at entry. It returns at once unless the calling thread has a pending continuation and no active run. Otherwise it waits for the next settle (a counter that only grows, so an offer arriving meanwhile cannot hide it) and checks the thread again. It stops as soon as the thread has an active run or nothing is pending, capped at 60 s. Callers without a thread never wait.writesEnvironmentreruns under the thread lock does not wait.Scope and approval
Fixes #33272
Verification
OrchestratorMcpToolkit.integration.test.ts› "delegate_task joins the run the wake turn's continuation starts": drivesdelegate_taskthrough the real MCP server while the wake turn's continuation dispatch is held. It fails on main withparent_not_activeand passes here; the child task is parented to the wake run.McpToolAccess.test.ts› "reads a waking caller's modes after its continuation starts the run": a mode downgrade during the wait makes the write refuse withcapability_denied.McpToolAccess.test.ts› "lets a waking caller act once its run starts, while later continuations queue": the call proceeds once its run is active even though another continuation for the thread is still queued (hangs with a wait-until-empty rule).McpToolAccess.test.ts› "lets a waking caller act once its run starts, when another continuation arrives meanwhile": an offer during the wait does not hide the wake's settle (hangs when the wait releases on the net pending count).ProviderContinuationService.test.ts› "releases run checks waiting on a continuation whose dispatch fails".vp run check:changedpasses (format, lint, knip, typecheck of 27 packages, 11 test files).T3CODE_DEV_SEED=0, fresh database), Claude provider, full-access thread, same driver and prompt on both sides, continuation dispatch held 25 s by an uncommitted scratch patch:delegate_taskreturnedparent_not_activein 23 ms, before the continuation committed."status":"running", and the child was parented to wake run ordinal 2 and repliedok. Later commits on this branch only change when a waiting call is released (once its thread's run is active, not when its whole queue empties, and not hidden by a concurrent offer); the unit tests above cover that.AI-assisted; verified with the tests and tools listed above.