Skip to content

fix(claude): journal a task notification's wake-up turn after a failed turn - #51132

Merged
nwparker merged 1 commit into
mainfrom
bugbash/issue-51099
Nov 27, 2026
Merged

nwparker merged 1 commit into
mainfrom
bugbash/issue-51099

Conversation

@nwparker

@nwparker nwparker commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

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.

Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​69 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​69
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​3 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1

What Changed

  • Before: after a failed turn, a background task's completion woke Claude, and Claude's wake-up turn (which also failed on the limited account) was never journaled. newestTurnCompletedAt stayed older than the settled child work, so owesWakeUp stayed true, and retireOutgrownStructuredAgentSessionChild kept the old-account claude process alive. Every send went to the limited account until the user killed the process by hand.
  • After: the reopen-suppression latch in ClaudeOpenTurn is 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 resets reopenSuppressed, 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 owesWakeUp would 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 a task_notification, a new init and a failed wake-up turn (must be journaled as completed).

    • On main: fails. Only the first turn is journaled ([{completedAt: 1200}]).
    • On this branch: passes ([{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 init frame, inside the per-session translator. It adds no I/O, polling or renderer work, and nothing fans out across sessions. Measured init frame 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 init can 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

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Reported by bryant1410 in #51099.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

…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]>
@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

A provider-cycle start now clears Claude turn reopen suppression. Comments describe suppression as ending after a send or a new provider cycle. A regression test checks turn completion timestamps after failed results and after a later notification/init cycle.

Severity of issue fixed: Medium

Merge Risk: Minimal · up to 7e8d1

A failed Claude turn no longer blocks journaling of the next provider cycle's wake-up turn, so a finished background task can be recorded and the old-account process can be retired. The change is small and in-memory only, and the added test covers the reported scenario. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 3 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Linked Issues check Inconclusive Issue #51099 requires that, after a failed wake-up turn, the old-account child is retired and the chat relaunches on the selected account on the next send. The PR adds one reset, `reopenSuppressed = f… Provide evidence that the failed wake-up turn in the reported sequence begins with a system/init frame, or a test that runs the outgrown-child retirement check after the journal change and asserts the old-account child is retired on the n…
Passed Passed checks: 3 passed

Check name Status Explanation
Title check Passed The title names the main change: journaling the task-notification wake-up turn after a failed turn, with the fix scoped to Claude. It matches the changeset, which lifts the reopen-suppression latch at…
Out of Scope Changes check Passed The PR changes two files: src/main/claude/structured/turns/claude-open-turn.ts (the per-cycle reset and comment updates on the suppression latch) and a new regression test `claude-failed-turn-reopen…
Description check Passed The description covers every required template section: ELI5, What Changed, Why, Linked Issue (Fixes #51099), Visual Proof (N/A with reason), Testing, Performance (None, with reasoning), Risk (Low, wi…
Full details: Title check

Explanation

The title names the main change: journaling the task-notification wake-up turn after a failed turn, with the fix scoped to Claude. It matches the changeset, which lifts the reopen-suppression latch at a new provider cycle so the wake-up turn is recorded.

Full details: Out of Scope Changes check

Explanation

The PR changes two files: src/main/claude/structured/turns/claude-open-turn.ts (the per-cycle reset and comment updates on the suppression latch) and a new regression test claude-failed-turn-reopen.test.ts. Both relate directly to the journaling defect in #51099. The performance note and the static gate results are supporting claims. They do not add code outside the stated scope. No unrelated change was found in the reviewed evidence.

Full details: Description check

Explanation

The description covers every required template section: ELI5, What Changed, Why, Linked Issue (Fixes #51099), Visual Proof (N/A with reason), Testing, Performance (None, with reasoning), Risk (Low, with the riskiest part and a revert path), Agent skill upstream boundary, and Checklist. It explains the before and after behavior and the mechanism, and it states why this approach was chosen over special-casing owesWakeUp. The AI Disclosure section is left blank. That section applies only to outside contributors, so it does not block a pass. The final lint/typecheck/test/build checkbox is unchecked, but the template allows CI to cover it. The Testing section reports a failing-before and passing-after regression test, which the author attributes to CI-style runs and a local vitest run.

Full details: Linked Issues check

Explanation

Issue #51099 requires that, after a failed wake-up turn, the old-account child is retired and the chat relaunches on the selected account on the next send. The PR adds one reset, reopenSuppressed = false, in ClaudeOpenTurn.observeProviderCycleStart() (confirmed at head in claude-open-turn.ts). The stated effect is that a failed wake-up turn in a new provider cycle (system/init) gets journaled, so newestTurnCompletedAt advances and owesWakeUp clears. The regression test covers only the journal translation: it expects completions [1200, 5200] and does not exercise retireOutgrownStructuredAgentSessionChild or the relaunch. Two points are not established: (1) whether the reported wake-up turn starts with a new system/init in the real flow. If it does not, the reset never runs; (2) that the retirement path then retires the child on the next send. The issue's own 'at minimum' option, a user send overriding owesWakeUp on account mismatch, is not implemented. The PR states this is a deliberate alternative. No concrete unmet requirement is shown.

Resolution

Provide evidence that the failed wake-up turn in the reported sequence begins with a system/init frame, or a test that runs the outgrown-child retirement check after the journal change and asserts the old-account child is retired on the next send. Without either, the end-to-end outcome in #51099 cannot be confirmed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 106b35ed-d75b-4a84-8f4a-3b9d65cf9ea5
Commits

Reviewing files that changed from the base of the PR and between 3cc45b5 and 7e8d1cc.

Files selected for processing: 2

  • src/main/claude/structured/turns/claude-failed-turn-reopen.test.ts
  • src/main/claude/structured/turns/claude-open-turn.ts

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

@nwparker
nwparker merged commit 0cc0079 into main Nov 27, 2026
54 of 55 checks passed
@nwparker
nwparker deleted the bugbash/issue-51099 branch November 27, 2026 20:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Chat stays on a usage-limited Claude account after switching, even with no background task running (owesWakeUp blocks the move)

1 participant