fix(server): Claude child continues after a worktree handoff #22825
main fromrefs/pull/22825/head·opened View on GitHubFixes #15136.
On e27a03e94d, moving a Claude child with t3_worktree_handoff fails its first run and leaves continuation run 2 queued with queueHeld=true and no start time. The Codex control continues and writes its file.
Evidence pending. Before runtime transcript.
Implementation, scope assessment for the related stale handoff banner, and after evidence pending.
Model and harness: GPT-6.1-Sol through Codex in T3 Code.
Evidence#
Head captured: after = ab1166d777 (this branch with main merged in), before = 8d3b061121 (main, the merge base). The PR head, 2251684173, only adds the driver, apps/server/scripts/verify-worktree-handoff-live.ts; the server code is identical to ab1166d777.
Fixture matrix (proof audit pass 1): audit1-matrix.md. A Claude child never shares its parent's provider session, so the bug only shows when the thread that calls t3_worktree_handoff is on Claude. R1 is the child handing itself off (the issue repro); R1b is the brief's literal "parent hands off while its child runs".
| Row | Before (8d3b061121) | After (ab1166d777) |
|---|---|---|
R1: Claude child calls t3_worktree_handoff | Child run 1 failed. Server logs ProviderAdapterEventStreamError … Workspace changed.. Continuation run 2 stays queued, queueHeld:true, never starts. Parent receives failed. | Child run 1 interrupted. Run 2 completed ("DONE") on a new session whose cwd is the worktree. Parent receives completed. No ingestion warnings. |
| R2: user interrupts the child's continuation | Run 2 never starts, so it can't be interrupted. The driver cancels the held queued run instead; the parent already had failed. | run.interrupt → run 2 interrupted 0.67 s after it started. Task interrupted, delivered once, no hang. |
| R3: top-level Claude thread hands off, no child | Run 1 failed, continuation held. | Run 1 interrupted 67 ms after detach, continuation completed in the worktree. (Claude changes here too; only Codex is unchanged.) |
| R1b: Claude parent hands off while its Claude child runs | Parent run 1 failed, continuation held. The child's result still arrives as parent run 3. | Parent run 1 interrupted, continuation completed, then the child's result arrives and is acknowledged. |
After timings: 51–376 ms from detach to the turn being interrupted; 0.98–2.06 s from detach to the new worktree session. The new 30 s terminal wait was never close to being used.
Captures (ghdrop upload -m output):
captures.md
captures-pr-22825.tar.gz
r1-before-child-timeline.txt
r1-after-child-timeline.txt
Environment: fs-33 (Linux 6.1, x86_64), Node v26.12.1. A real dev server per side with isolated --home-dir under /tmp and a throwaway git repo per side. Real Claude turns (claude-sonnet-5-5, effort low) through the CLIProxy hub; prompts forbade every tool except the named T3 MCP tools.
What else changed between sides:
- 129 commits of main came in through the merge. The before side is that same main, so both sides share them.
- Model output is nondeterministic. Only the run states and lifecycle events are compared, not the text, beyond "DONE" or an ACK.
- On after, the
t3_worktree_handofftool item endsfailed/user-rejectedin R2, R3 and R1b andinterruptedin R1, even though the handoff succeeds. On before it staysrunningforever. The label comes from the Claude adapter marking a tool call as not executed when its turn is interrupted mid-call. It's cosmetic, and the audit found it isn't a blocker; it's worth a follow-up.
Verification log
Proof audit pass 1: matrix derived from the diff (audit1-matrix.md). It corrected the brief: a parent's handoff can't touch a Claude child, R3 changes for Claude, and R2 can't be reached on before.
Proof audit pass 2: SUFFICIENT (audit2.md).
- Every row was checked against the raw projections, milestones and server logs.
git diff ab1166d777 2251684173 -- apps/server/src apps/web/src packagesis empty.- The before SHA was pinned by matching the stack-trace line numbers to 8d3b061121; the after SHA by the worktree reflog against the capture timestamps.
- After-R3 was rebuilt from the committed driver on a fresh isolated server: run 1
interrupted71 ms after detach, run 2completedin the worktree, no warnings. - The draft and committed versions of the driver couldn't be diffed (the draft is gone); the rebuild covers that gap.
Tests:
vp test run src/orchestration-v2/SelectionRestart.integration.test.ts src/orchestration-v2/ProviderSessionManager.test.tson the merged head: 2 files, 50 tests passed.vp lintandvp fmt --checkpass on the three changed files.CI (
cafe pr statusat 2251684173): 25 passing, 0 pending, 2 failing (Lint,Check).cafe cireturns no runs for this repo, so I couldn't read the failing logs or confirm which commit they ran on. The changed files lint clean locally.Not verified:
- R1-codex and R3-codex controls: Codex was rate-limited, so the multi-thread branch of
detachis unchecked at runtime. - R4 (archive or runtime-mode change on a running Claude turn, which goes through the same path): out of scope.
- R1-codex and R3-codex controls: Codex was rate-limited, so the multi-thread branch of
Model and harness: evidence lead, auditors and capturer were Claude Opus 5.5 (
claude-opus-5-5) through Claude Code in T3 Code; the agents inside the fixture wereclaude-sonnet-5-5.Takeover CI fix and review round (2026-10-22):
- CI cause:
LintandCheckfailed on 2251684173 because knip reportedapps/server/scripts/verify-worktree-handoff-live.tsas an unused file. Localknip --include files,dependenciesshowed that same file as the only finding. - Fix: 9767a4c7f3 registers the script as an
apps/serverentry inknip.jsonc, next toverify-background-live.ts. With that entry, both the files/dependencies knip pass and theapps/serverexports pass are clean. CI on the new head is pending. - Review A, Claude Sonnet 5.5 (
claude-sonnet-5-5): VERDICT: MERGE. No failing sequence, and no auth, permission, mode, sandbox, trust or MCP surface is touched. It notes that other exclusive adapters could wait the full 30s if theirinterruptTurnno-ops on a turn that has already ended (bounded). Thefailed/user-rejectedlabel on the tool call isn't blocking and deserves a follow-up. - Review B, Claude Opus 5.5 (
claude-opus-5-5): VERDICT: MERGE. No failing sequence and no security surface touched. Nit:DETACH_TURN_TERMINAL_TIMEOUT_MS(30s) equals the effect worker's 30s lease, so a wedged adapter could outlast the lease; it suggests 15s and calls this theoretical. Same view on the tool-call label. - Both reviewers question keeping the 435-line evidence driver in the repo. Neither treats it as blocking.
- Model and harness: Claude Opus 5.5 (
claude-opus-5-5) through Claude Code in T3 Code; reviewers as listed.
- CI cause:
Fixes #15993 GitCafe: https://git.cafe/pingdotgg/t3code/issues/15993
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
juliusmarminge added labelsvia-triage:gates-failing
juliusmarminge removed labelsvia-triage:gates-failing
juliusmarminge added labelsbugfix
juliusmarminge added labelspr:gate-failed
juliusmarminge added labelspr:in-progress
juliusmarminge removed labelspr:gate-failed
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:M
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
juliusmarminge added labelspr:gate-failed
juliusmarminge removed labelspr:gate-failed
juliusmarminge added labelspr:ready
juliusmarminge removed labelspr:in-progress
juliusmarminge removed labelspr:ready
juliusmarminge added labelspr:needs-julius
tanstack-source added labelsbug
juliusmarminge linked this to fix #15993
Note
🤖 Claude Opus 5.5 responding on behalf of leonhoulier
This draft fixes the agent-initiated hand-off for Claude, Muse and Grok as well, once merged with current
main. Grok also hangs without it (#35274).What I ran: the PR head
a9dc2e30c2, merged locally ontomainate9e934bb3d. The head predates #24545, so on its own a hand-off would endinterruptedrather thancompleted.- Merge conflict: one trivial conflict in
ProviderSessionManager.ts, where both sides add constants next toUNLOAD_THREAD_TIMEOUT_MS. - Typecheck after the merge fails only in this PR's own files:
SelectionRestart.integration.test.ts:1034is missingSecureRandomin the effect context.scripts/verify-worktree-handoff-live.ts:303and:410tripglobalJsonInEffect.
The test: I ran an isolated dev server on macOS with real CLIs. Each thread learned a code word, then called
t3_worktree_handoffwith nocontinuationPrompt. A follow-up message then checkedpwd, the branch and the code word.Provider Hand-off turn on mainHand-off turn with this PR Next message with this PR Codex (gpt-6-luna) completed completed runs in the worktree, code word kept Claude 2.1.322 (sonnet-5-5) failed: "provider event stream closed" completed same Muse 1.4.15 (spark-1.3) failed: same message completed same Grok 1.0.77 (4.7-build-fast) never settles; later messages stay queued (3 of 3) completed (2 of 2) same With this PR,
dev.logshows noWorkspace changed.ingestion failures and nodetach-interrupt-failedwarnings, so no turn hit the 30 s fallback. Onmain, each of Claude, Muse and Grok logs one ingestion failure per hand-off.One residual risk, which I haven't tested: if
DETACH_TURN_TERMINAL_TIMEOUT_MSdoes fire, the run falls back to the ingestion-failure handler inRunExecutionService. That handler callsinterruptTurnon the released session again, the call that hangs Grok onmain. Skipping that interrupt whenhasWorkspaceMoved()is true would close that path too.- Merge conflict: one trivial conflict in
Closing this draft: it has sat unfinished and #15993, which it was for, is closed.
juliusmarminge closed this
Data point: this also affects GLM via the ACP registry (
acpRegistry_glm_agent,glm-5.3-flash), which isn't in the test matrix. On released 0.1.5, 7 of 10 GLM runs that calledt3_worktree_handoffsettled asfailed— the tool call succeeds, the run fails ~9 ms later withProviderAdapterEventStreamError: Workspace changed.("provider event stream closed unexpectedly"), matching your Claude/Muse rows onmain. Timeline and run ids in #36209 (closed as a dup of #35274).One addition worth making to the test matrix: a handoff with
continuationPrompt. In the GLM case the queuedworktree-continuationrun never started on its own — it only ran after a manual re-prompt ~2 minutes later — and the current matrix tests all use nocontinuationPromptwith a manually sent follow-up.
Sign in to join this conversation.
Thread transfer impact#
⚠️ The latest CI run did not produce a thread transfer result for
a9dc2e3.This comment will update automatically after the next completed run.