Repository navigation
fix(claude): journal a task notification's wake-up turn after a failed turn - #51132
Conversation
…d turn A failed turn latched reopen suppression until the next accepted send. When a background task finished after a usage-limit failure, Claude's own wake-up turn answering the task notification was therefore never journaled, so the newest completed turn stayed older than the settled child work. The outgrown-child check kept treating the child as owing a wake-up and never retired it, leaving the chat on the limited account after an account switch. Lift the latch at the start of a new provider cycle as well as on send, so the wake-up turn is journaled and its completion is recorded. Fixes #51099 Co-authored-by: Claude <[email protected]>
|
No actionable comments were generated in the recent review. Walkthrough
Severity of issue fixed: Medium Merge Risk:
|
ELI5
When a Claude turn fails (for example on a usage limit), Orca stops listening for that turn's leftover output so a stale message can't reopen it. That "stop listening" switch stayed on until you sent a new message. If a background task finished in the meantime, Claude answered it on its own, but Orca ignored that answer. Orca then thought the chat still owed the task a reply, so it never swapped the chat over to the account you switched to.
What Changed
newestTurnCompletedAtstayed older than the settled child work, soowesWakeUpstayed true, andretireOutgrownStructuredAgentSessionChildkept the old-accountclaudeprocess alive. Every send went to the limited account until the user killed the process by hand.ClaudeOpenTurnis lifted at the start of a new provider cycle (system/init) as well as on an accepted send. Output that arrives late in the failed cycle still can't reopen the failed turn. The wake-up turn in the next cycle is journaled and its completion recorded, so the outgrown-child check no longer sees owed work and retires the old-account child on the next send.Mechanism:
observeProviderCycleStart()now also resetsreopenSuppressed, next to the other per-cycle flags it already reset.Why
The latch is meant to stop output from the same cycle reopening a turn that already ended. A new provider cycle is new work by definition, so keeping the latch across it threw away a real turn. Lifting it at the cycle boundary fixes the root cause (the missing completion record). Special-casing account mismatch in
owesWakeUpwould only hide the symptom, and the journal would still be missing a turn.Linked Issue
Fixes #51099
Visual Proof
N/A. This is main-process turn journaling with no UI change. The behavior is covered by a regression test that fails on main and passes on this branch (see Testing).
Testing
Added
src/main/claude/structured/turns/claude-failed-turn-reopen.test.ts. It replays the reported sequence through the real Claude journal translator: a usage-limit failure, late output in the same cycle (must not open a new turn), then atask_notification, a newinitand a failed wake-up turn (must be journaled as completed).[{completedAt: 1200}]).[{completedAt: 1200}, {completedAt: 5200}]).vitest run src/main/claude/structured: 12 files, 34 tests pass.CI static gates on touched files: anti-slop oxlint, native code-quality oxlint, ast-grep, the changed-code quality gate and oxfmt are all clean.
Platforms: platform-independent main-process logic, unit-tested on macOS.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
Performance
None. The change adds one boolean assignment per provider-cycle
initframe, inside the per-session translator. It adds no I/O, polling or renderer work, and nothing fans out across sessions. Measuredinitframe handling: main 1.60 to 1.87 us/frame, branch 1.50 to 2.39 us/frame (3 runs each). That is within noise.Risk
Level: Low
The riskiest part: output that comes after a failed turn but after a new
initcan now open a turn. That is the intended behavior, because it is a new cycle Claude started itself. Output in the same cycle as the failure is still suppressed, and the test asserts this. No saved data, settings or wire protocol changes. Back out with a plain revert.Review
Agent skill upstream boundary
Notes
Reported by bryant1410 in #51099.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)