fix(server): threads stay working while Claude starts a wake turn #15055
main fromrefs/pull/15055/head·merged by t3dotgg(GitHub profile, opens in a new tab) View on GitHubProblem#
A Claude thread that waits on a background command leaves "working", drops back into the inbox for a few seconds, then returns to "working" when Claude reacts to the finished command.
The adapter started the wake run only at the wake turn's first assistant/user frame. Claude thinks before that frame. In the local provider logs, init to first output took 3 to 49 s (often 5 to 30 s). During that time the roster was already empty and no run existed, so the thread looked done.
From the reported thread (8092e030):
05:38:29.230 task_notification background command done, roster clears
05:38:29.293 system/init Claude starts the wake turn
05:38:33.088 first assistant wake run created (05:38:33.131)
#15029 stops the timer reset on wakes, but not this status gap.
Change#
Claude opens every turn with a root system/init frame. With no T3 turn active, that turn is a wake. In 28 out of 28 idle notifications in the local logs, init came 21 to 108 ms after the notification.
bufferWakeMessagebuffers thatinitand offers the wake continuation on it.- The continuation drain counts a buffered
initas a native wake frame. The run stays open for the live output and does not settle at once.
The gate for a notification alone is unchanged: with no init, no run starts.
This also covers a background task that ends while a turn is still running. In that case the wake turn has no buffered notification, and before this change it got a run only at its own result.
Claude only. The other adapters detect wakes in their own way.
Scope and approval#
Small, focused fix of a bug Theo reported.
Verification#
- New test
starts the wake run when Claude opens the wake turn, before its output. It fails onmain(no continuation request afterinit). It also fails when only the drain change is reverted (the run settles before the output). ClaudeAdapterV2.test.ts,ClaudeReplayFixtures.integration.test.ts,ProviderContinuationService.test.ts,runtimeLayer.test.ts: 204 tests pass. TheOrchestratorreplay fixture suites pass (129).apps/servertypecheck is clean.
Not checked: a live run in the desktop app. The roster still clears about 60 to 150 ms before the new run appears, so a very short blink can remain.
Created with Claude Opus 5.5 in Claude Code (T3 Code).
🤖 Generated with Claude Code
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
juliusmarminge added labelsmacroscope-review
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts lines 5189 to 5189Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -5175,3 +5186,4 @@51755186 if (51765187 !isPendingSubagentNotification &&51775188 !isNativeOpaqueWakeFrame &&5189+ !isWakeTurnStart &&
🟠 High
Adapters/ClaudeAdapterV2.ts:5189A normal user turn's
system/initframe is buffered as wake evidence and starts a phantom continuation, leaving the provider turn permanently running after that continuation drains without aresult. BecauseopenQueryemits frames beforestartTurnassignsactiveTurn,isWakeTurnStartmust only acceptinitwhenhasBufferedNotificationproves an actual wake is pending.- !isWakeTurnStart && + !(isWakeTurnStart && hasBufferedNotification) &&🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file @apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts around line 5189: A normal user turn's `system/init` frame is buffered as wake evidence and starts a phantom continuation, leaving the provider turn permanently running after that continuation drains without a `result`. Because `openQuery` emits frames before `startTurn` assigns `activeTurn`, `isWakeTurnStart` must only accept `init` when `hasBufferedNotification` proves an actual wake is pending.Note
🤖 Claude Opus 5.5 responding on behalf of Theo
Not a real path. A user turn's
initcan't reach the idle buffer:startTurnsetsactiveTurnright afteropenQueryreturns, and offers the prompt only after that (Ref.set(activeTurn, context), thenquerySession.query.offer(userMessage)).- The CLI sends
system/initwhen it starts a turn, so after it gets the prompt. Every Claude recording intestkit/fixtureshas the orderquery.open,prompt.offer, theninit. Recordings with a fresh process (claude_idle_resume,claude_compact_after_resume_wake) have it too.
So an
initwith no active turn is always a turn Claude started by itself: a wake, or a steer that landed after the turn'sresult. Today each of those gets a continuation at itsresultanyway. Starting it atinitonly moves it earlier, and the turn's ownresultsettles it.Requiring a buffered notification would also drop the case where a task ends during a running turn. That wake turn has no idle notification, and today it shows no run until its last frame.
Navigate logical layers of code changes, visualize relationships, and explore their blast radius.
🧰 Additional context used
📚 Code guidelines (1)
docs/internals/effect-services.md — configuredNo actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
- Configuration used: Repository: pingdotgg/t3code/.coderabbit.yaml
- Review profile: CHILL
- Plan: Team
- Run ID:
979396a0-21c1-4429-863c-dd7d04310b17
📥 Commits
Reviewing files that changed from the base of the PR and between d1034d62b28e19c19240085566a39a92c5f9b466 and b46ff074d82bb1b6692d60646fb7512058d0dff9.
📒 Files selected for processing (2)
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.tsapps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.
📝 Walkthrough
Walkthrough#
ClaudeAdapterV2 now recognizes a root
initframe as wake-turn evidence and as native wake output during buffered drains. A lifecycle test checks when a continuation is offered and when it completes.Changes#
Claude wake-turn handling
Layer / File(s) Summary Recognize init frames during wake handling
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts,apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.tsWake detection and buffered-drain handling now include root initframes. The test verifies that the notification alone does not offer a continuation, that theinitframe does, and that the run waits for assistant and result frames before completing.Priority: ➖ Normal
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Suggested reviewers:
juliusmarmingeMerge Risk: ⚪ Minimal · up to
b46ffNo actionable issue is established for the Claude wake-turn change; it is ready to merge after normal checks.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
Check name Status Explanation Resolution Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold. ✅ Passed checks (4 passed)
Check name Status Explanation Title check ✅ Passed The title clearly summarizes the fix: keeping threads working while Claude starts a wake turn. Description check ✅ Passed The description covers the problem, change, scope and approval rationale, and verification. It also states the live desktop-app check was not performed and notes the remaining status gap. Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request. Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request. - Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
- Commit to this branch
- Create a new PR
- Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment `@coderabbitai help` to get the list of available commands.Approvability#
Verdict: Approved at
b46ff07Macroscope's review found this PR approvable — This is a focused Claude wake-status fix with a targeted regression test and no schema, default, infrastructure, or sensitive-path changes. An unresolved High finding identifies a normal-turn init race that can create a phantom continuation, so that correctness risk remains a blocker to merging.
Notes:
- This verdict was updated automatically after the outstanding correctness findings were resolved. Macroscope did not re-review the code.
Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Provider Metric Main baseline This PR Impact PR ceiling Codex Total thread wire 4.9 KiB 4.9 KiB 0 B (0.0%) 6.8 KiB ✅ Codex Thread snapshot wire 3.7 KiB 3.7 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 20.4 KiB 20.4 KiB 0 B (0.0%) 29.3 KiB ✅ Codex Live turn messages 2 2 0 (0.0%) 8 ✅ Claude Total thread wire 4.9 KiB 4.9 KiB 0 B (0.0%) 6.8 KiB ✅ Claude Thread snapshot wire 3.7 KiB 3.7 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 20.8 KiB 20.8 KiB 0 B (0.0%) 29.3 KiB ✅ Claude Live turn messages 2 2 0 (0.0%) 8 ✅ Baseline:
d1034d6· PR result:b46ff07· Source CI: successScenario 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: 106.1 KiB
- Claude decoded thread snapshot: 106.4 KiB
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed