Skip to content

fix(server): MCP tools in a Claude wake turn wait for the turn's run instead of failing with parent_not_active - #33330

Open
juliusmarminge wants to merge 9 commits into
mainfrom
fix/issue-33272
Open

juliusmarminge wants to merge 9 commits into
mainfrom
fix/issue-33272

Conversation

@juliusmarminge

Copy link
Copy Markdown
Member

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.dispatch commits, every run-scoped tool (delegate_task, create_threads, request_secret, thread and project writes) fails with parent_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, then delegate_task in the wake turn, with the continuation dispatch held 25 s by a scratch patch. The call returned parent_not_active in 23 ms.

Change

  • ProviderContinuationRequests counts, per thread, continuations that were offered but not yet settled. offer increments (uninterruptibly, together with the enqueue), and ProviderContinuationService settles each request once its dispatch ends, whether it succeeded or failed. The production layer exports the same instance so MCP handlers see it.
  • McpToolAccess wraps 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.
  • The wait runs before the caller, its modes and its run are read, and outside any thread lock. The existing run-ownership checks are unchanged. The check writesEnvironment reruns 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": drives delegate_task through the real MCP server while the wake turn's continuation dispatch is held. It fails on main with parent_not_active and 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 with capability_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".
  • Focused suites: McpToolAccess, OrchestratorMcpToolkit integration, ProviderContinuationService, RemoteDelegation, PeerLinkRequests, RemoteDelegatedTask, OpenCode2AdapterV2: 237 passed. vp run check:changed passes (format, lint, knip, typecheck of 27 packages, 11 test files).
  • Runtime transcript, real dev server (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:
    • Before (c73b38b): delegate_task returned parent_not_active in 23 ms, before the continuation committed.
    • After (e1d13ee): the MCP call waited 23.4 s, returned "status":"running", and the child was parented to wake run ordinal 2 and replied ok. 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.
    • runtime-transcript-before.md
    • runtime-transcript-after.md
    • continuation-delay.patch (scratch, not committed)
    • driver.mjs (scratch, not committed)
  • No render path changes, so there are no screenshots.
  • Not checked: the 60 s cap firing in a real session; a wake turn whose tool call reaches the server before the adapter has offered the continuation still fails as before.

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

juliusmarminge and others added 6 commits November 9, 2026 09:42
…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]>
@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Nov 9, 2026
macroscopeapp[bot]
macroscopeapp Bot previously approved these changes Nov 9, 2026
@macroscopeapp

macroscopeapp Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at 6af67b2

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:

  • All code in this push has already been reviewed. Approvability was decided on eligibility alone.

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

@github-actions

github-actions Bot commented Nov 9, 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: d756fed · PR result: 6af67b2 · 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.

@juliusmarminge juliusmarminge added bugfix Fix PR opened by an issue lead; enters the PR loop pr:needs-julius Needs Julius: route gate, unverifiable surface, or blocked labels Nov 9, 2026
@coderabbitai

coderabbitai Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The provider continuation service now tracks pending requests and settlement progress. Caller-facing MCP tools wait for a pending wake run before checking access or running handlers. Tests cover continuation timing, permission changes, and delegated task ownership.

Changes: Provider Wake Run Access

Layer / File(s) Summary
Continuation progress and settlement
packages/provider-core/src/server/ProviderContinuationRequests.ts, apps/server/src/orchestration-v2/ProviderContinuationService.ts, apps/server/src/orchestration-v2/runtimeLayer.ts, apps/server/src/orchestration-v2/ProviderContinuationService.test.ts, apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts, apps/server/src/orchestration-v2/RemoteDelegatedTask.test.ts, apps/server/src/peer/PeerLinkRequests.test.ts, apps/server/src/peer/RemoteDelegation.test.ts, apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts, packages/provider-pi/src/server/adapter.test.ts
The continuation request service tracks pending requests per thread and a cumulative settlement count. The worker settles requests after dispatch processing, and production wiring shares the service with the worker. Test service implementations now provide the added operations.
MCP caller checks and wake-run waiting
apps/server/src/mcp/McpToolAccess.ts, apps/server/src/mcp/McpToolAccess.test.ts, apps/server/src/mcp/OrchestratorMcpToolkit.integration.test.ts
Caller-facing MCP tools wait when a thread has pending continuations but no active run. Tests cover permission checks during settlement, calls during wake dispatch, and delegate_task associating a subagent with the wake run.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant MCPCall
  participant McpToolAccess
  participant ProviderContinuationRequests
  participant ThreadManagement
  participant ContinuationWorker
  MCPCall->>McpToolAccess: invoke caller-facing tool
  McpToolAccess->>ProviderContinuationRequests: read thread progress
  McpToolAccess->>ThreadManagement: read thread shell
  McpToolAccess->>ProviderContinuationRequests: await pending request settlement
  ContinuationWorker->>ProviderContinuationRequests: settle request after dispatch processing
  McpToolAccess->>McpToolAccess: evaluate handler after wait condition is met
Loading

Suggested reviewers: t3dotgg

Merge Risk: Minimal · up to 6af67

This change lets a tool call made during a Claude wake turn wait briefly for its continuation run instead of failing with parent_not_active. The wait is bounded at 60 seconds and existing run-ownership checks are unchanged. I found no concrete defect to block merging. A call that reaches the server before the adapter offers its continuation will still fail as before.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title clearly summarizes the main change: MCP tools wait for a Claude wake turn’s run instead of failing with parent_not_active.
Description check Passed The description includes all required sections and gives detailed reproduction steps, implementation details, and focused verification results. The scope section links issue #33272 but does not includ…
Linked Issues check Passed Issue #33272 requires delegate_task in a Claude provider wake turn to use the continuation run rather than fail with parent_not_active. The current PR description and change summary report a bound…
Out of Scope Changes check Passed The reported source changes implement continuation tracking, settlement, and MCP wait behavior for issue #33272. The integration and unit tests exercise that behavior. The test-mock updates add method…
Full details: Description check

Explanation

The description includes all required sections and gives detailed reproduction steps, implementation details, and focused verification results. The scope section links issue #33272 but does not include an explicit maintainer approval comment.

Full details: Linked Issues check

Explanation

Issue #33272 requires delegate_task in a Claude provider wake turn to use the continuation run rather than fail with parent_not_active. The current PR description and change summary report a bounded wait before caller and run checks, per-thread tracking of pending continuations, settlement after dispatch success or failure, and an integration test that delays dispatch and verifies the delegated child uses the wake run. The prior assessment found this implementation compliant, and the focused incremental diffs show no changes to the core wait, tracking, or settlement files since that review. The issue’s separate request to investigate the server-wide dispatch stall is not a coding acceptance criterion for this fix.

Full details: Out of Scope Changes check

Explanation

The reported source changes implement continuation tracking, settlement, and MCP wait behavior for issue #33272. The integration and unit tests exercise that behavior. The test-mock updates add methods required by the continuation-request service. The current summary identifies no unrelated functional changes.

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
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 3d94bc7 and 6af67b2.

Files selected for processing: 5

  • apps/server/src/mcp/McpToolAccess.test.ts
  • apps/server/src/mcp/OrchestratorMcpToolkit.integration.test.ts
  • apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts
  • apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts
  • packages/provider-pi/src/server/adapter.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

@macroscopeapp
macroscopeapp Bot dismissed their stale review November 10, 2026 20:35

Dismissing prior approval to re-evaluate 6af67b2

Copy link
Copy Markdown
Member Author

Evidence

Same steps on both commits: create fresh synthetic state; launch a full-access Claude thread; call orchestrator_capabilities; start sleep 8 && echo done in the background; end the initial turn; immediately call delegate_task on wake without retrying. Hold continuation message.dispatch for 25 seconds with the same scratch fixture.

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.

Before After
d756fed7aa 6af67b205a
Before recording After recording
MCP response returned in 8 ms during the hold. Tool result: parent_not_active. No child created. MCP response took 22.637 seconds and returned after dispatch committed. Tool result: status=running. Child belonged to wake run 2 and completed with ok.
Events and RPC result Events and RPC result

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:

  • The 60-second wait cap, failed dispatch, concurrent continuation offers, and permission or ownership changes during the wait were not exercised; this reproduction used one successful delayed wake dispatch.
  • Other run-scoped MCP tools and remote forwarding paths were not exercised; the runtime proof covers delegate_task.
  • Web, desktop, and mobile interaction was not captured; this server behavior was driven through the real server RPC and Claude MCP connection.

@navidnadali

Copy link
Copy Markdown
Contributor

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:

  • one coordinator had 50 parent_not_active refusals in a day, 38 of them delegate_task;
  • agents on the delegated threads reported 136 such refusals in 72 h, across 39 threads.

Why the gap was long. It was not under a second. The wake's continuation is dispatched by the single continuation dispatcher.
Each dispatch can wait for a lock, and a wake to a delegated child first takes its parent's lock. So one held lock, or a restart's
re-delivery wave, holds up every wake on the server. We measured:

  • 0 wakes dispatched for 159 min after a restart, while about 1,277 completion re-deliveries went first;
  • some single dispatches of 9–308 s.

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),
this PR covers most of it. In an in-process model of that load:

  • a wake whose family's lock is free is dispatched in about 0.1 s;
  • through a restart wave, wake dispatch p99 was 43–117 s instead of 2.4–2.9 h.

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
longer than this PR's 60 s, the call is still refused. In the model, those waits had a p99 of 4–5 min. We have no production
numbers for this part yet.

Question. For those calls, would you consider either of these?

  • Keep the wait going while the thread's continuation is still being dispatched, bounded by the client's request timeout rather
    than a fixed minute.
  • Do not take the parent's lock before the child's own continuation run is created.

We are happy to send whichever you prefer, with the tests from our port.

navidnadali added a commit to navidnadali/t3code that referenced this pull request Nov 17, 2026
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]>

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:L 100-499 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.

delegate_task fails with parent_not_active when a Claude wake turn runs before T3 opens its run

2 participants