Skip to content

Let a finished chat subagent go back to done when Claude doesn't resume it - #51765

Merged
brennanb2025 merged 6 commits into
mainfrom
brennanb2025/subagent-wake-lease
Nov 28, 2026
Merged

brennanb2025 merged 6 commits into
mainfrom
brennanb2025/subagent-wake-lease

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

In a Claude chat, when a background helper agent has finished but a job it started finishes later, Orca guesses that Claude will wake the helper back up, and shows it as working. Sometimes Claude never does, and the chat then said "working" forever with nothing running. Now that guess expires after a minute: if Claude doesn't actually run the helper again, the helper goes back to "done" on its own.

Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​177 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​177
Prod 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​355 $\color{#cf222e}{\Huge{\mathbf{−}}}$​61 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​294

What Changed

Before: in a Claude chat, a background subagent that Claude Code had already reported as finished was put back to working when a task it had launched ended (the "wake"). If Claude Code never resumed it, for example because the subagent had already been told it was finished, or because its worktree was gone, no frame for it ever arrived again. The row, the tab, the sidebar and the worker pill stayed working until the chat was closed. The ticket saw 50 and 75 minutes.

After: the wake holds the owner for a 60 second lease.

  • If any frame from Claude Code shows the owner's current run running inside the lease (task_progress, a running task_updated patch, or a running roster entry), the lease is cancelled and the owner keeps showing working for as long as it really runs. Frames and roster entries from an older run of the owner pass the same currency check as other task frames, so they can't cancel it.
  • If the owner really ends inside the lease, the lease is dropped and its real ending stands.
  • If nothing comes, the owner is restored to the ending it had (outcome, run id and its last summary and token count), emitted as an ordinary ended edge. A timer restates the row at the deadline, because in the stuck case no further frame arrives.
  • If Claude Code really does run the owner again later, a running report revives it with its saved kind and name.

Mechanism: ClaudeChildWorkDecoder now keeps the wake in ClaudeChildWake (claude-child-wake-lease.ts). drain() settles expired wakes before it hands out evidence. The lease is stamped at the first drain after the wake, so it runs on the same clock that settles it. ClaudeChildWorkPublisher reuses the scheduler the owed-notification lease already uses to restate a session's row at its next expiry. It only reschedules when a chat's deadline changes, and close/closeAll clear it. The decoder was at its line limit, so the owner index moved to claude-child-owner-index.ts. The task_notification report and the rest of the decoder's behaviour are unchanged.

This carries #47724 by @2SinceJuly (credited as co-author), with small follow-ups: unused helpers removed, the lease clock aligned with drain, the restored ending keeping the owner's summary, and the decoder tests trimmed to the lease invariants.

Why

The wake exists so a resumed subagent shows working from the frame that resumes it, not a moment later. Claude Code doesn't always resume, so an unbounded guess can pin a chat as working. Showing the owner working only once Claude Code reports it running would bring back that lag for every real resume. A bounded lease keeps the immediate feedback, and any real frame from Claude Code overrides it, so a genuine resume is never cut short.

Linked Issue

Tracked in #47715

Visual Proof

Same repro in both builds: an owner subagent starts two background readers (40 s each), is woken by a one-second command and ends its turn. Claude Code then reports it finished while its readers still run. When the readers end, Orca wakes the owner and Claude Code never resumes it.

Before (main): about 6 minutes after the readers ended, still working (spinner on the tab and sidebar, "owner" pill) After: back to done 60 s after the wake (Done on the tab and sidebar, no pill)
before after
before detail after detail

Testing

  • 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

Real-app QA on Linux (Electron dev copy, isolated profile, real Claude Code 2.1.332 in a Claude chat), with the UI and orca worktree ps --json sampled every 1-5 s:

  • Stuck case, before (main): the owner stayed working for more than 340 s after its readers ended, and never settled.
  • Stuck case, after (twice): the owner flipped to working when the readers ended, then returned to done/succeeded 60 s later (+0.7 s in the UI). The chat, tab and sidebar read Done, and the owner kept its replies and summary.
  • Real resume longer than the lease: an owner woken by its own background command ran a 90 s foreground command. It showed working for the whole run (about 92 s, past the 60 s lease) and went done when it really finished.
  • A settled owner messaged again ran for 33 s, showed working, then done.

All five decoder tests fail without this change except the real-ending one, which guards behaviour main already has (a real ending inside the window must stand) against the new restore.

claude-child-work-decoder.test.ts drives the decoder's public observe/drain with the ticket's frame sequence. It covers the restore after the lease (including the summary), a real resume cancelling the lease, stale running frames and roster entries not cancelling it, a real ending inside the lease standing (with no later revival from its late frames), and revival only from a running report.

Performance

None, because the lease adds one map entry per subagent wake and one shared timer entry per chat only while a wake is held. A frame in a chat with a held wake checks that chat's own wakes and does one map lookup for its deadline. It reschedules the shared timer only when the deadline changes, so there's no per-frame work across chats. Chats without a wake do nothing new.

Risk

The riskiest part is restoring an owner that Claude Code really did resume but reported no frame for within 60 s. It would show done until its next running frame revives it. In QA a resumed owner's frames arrived within about a second. Only Claude chat child-work rows are affected; terminal panes and other providers are not. A plain revert backs it out, and the lease is in memory only.

Level: Low

AI Disclosure

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

Security: no input, path or shell handling touched. Cross-platform: no platform-specific code; QA on Linux, and the decoder is shared. Remote SSH: the same decoder serves remote chats. Mobile: same child-work evidence on the wire. Backwards compatibility: nothing persisted changes.

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)

@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

The decoder now tracks child ownership and manages wake leases for successfully ended agent owners. Running confirmations can revive an expired owner, while lease expiry restores the saved ending and queues evidence. New roster helpers identify running tasks, and a publisher schedules republishing at wake expiry. The session adapter delegates child-work publication and clears publisher state when sessions close.

Merge Risk: Low · up to a987e

A finished chat subagent now returns to done after 60 seconds if Claude doesn't resume it. In the rare case where Claude resumes it without sending any update for over a minute, the row may briefly show done until the next update arrives. This is a known, deferred trade-off with a low merge risk.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title states the main behavior change: a finished chat subagent returns to done when Claude does not resume it. The changeset adds a 60-second lease to the child-wake state. On expiry, the owner r…
Description check Passed The description follows the repository template and fills in the main sections. It has an ELI5, a before/after account of the change, the mechanism, the reasoning for the approach, a linked issue refe…
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.
Full details: Title check

Explanation

The title states the main behavior change: a finished chat subagent returns to done when Claude does not resume it. The changeset adds a 60-second lease to the child-wake state. On expiry, the owner restores its recorded ending. The title matches this change.

Full details: Description check

Explanation

The description follows the repository template and fills in the main sections. It has an ELI5, a before/after account of the change, the mechanism, the reasoning for the approach, a linked issue reference, visual proof, testing notes, a performance line, a risk level with a revert path, and a checked checklist. The AI Disclosure section is blank, but the template marks it as optional for internal contributors. The Linked Issue line says 'Tracked in #47715' and not 'Fixes #', so it does not follow the template's exact form. The section is still substantively complete.

  • 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: b880dda5-39d5-4222-8d8e-252e27e22327
Commits

Reviewing files that changed from the base of the PR and between 4c18db6 and a987e62.

Files selected for processing: 2

  • src/main/claude/child-work/claude-child-work-decoder.test.ts
  • src/main/claude/child-work/claude-child-work-roster.ts

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

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: 8e2a7d04-368d-44d0-9ada-c45886524efa
Commits

Reviewing files that changed from the base of the PR and between 5d7416c and 01d3257.

Files selected for processing: 9

  • src/main/claude/child-work/claude-child-owner-index.ts
  • src/main/claude/child-work/claude-child-wake-lease.ts
  • src/main/claude/child-work/claude-child-work-decoder.test.ts
  • src/main/claude/child-work/claude-child-work-decoder.ts
  • src/main/claude/child-work/claude-child-work-evidence.ts
  • src/main/claude/child-work/claude-child-work-roster.ts
  • src/main/claude/structured/claude-structured-session-adapter.ts
  • src/main/claude/structured/lifecycle/claude-child-wake-expiry-timers.ts
  • src/main/claude/structured/lifecycle/claude-child-work-publisher.ts

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

@brennanb2025
brennanb2025 force-pushed the brennanb2025/subagent-wake-lease branch from 01d3257 to ff3064d Compare November 28, 2026 11:07

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

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: 0efb5bf6-0325-4446-acbd-4c9679cc75b9
Commits

Reviewing files that changed from the base of the PR and between 01d3257 and ff3064d.

Files selected for processing: 4

  • src/main/claude/child-work/claude-child-wake-lease.ts
  • src/main/claude/child-work/claude-child-work-decoder.test.ts
  • src/main/claude/child-work/claude-child-work-decoder.ts
  • src/main/claude/structured/lifecycle/claude-child-wake-expiry-timers.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.

2SinceJuly and others added 4 commits November 28, 2026 03:21
…he ending's summary

Leaves the task_notification report inline, drops unused helpers, and keeps the decoder tests to the lease invariants.

Co-authored-by: 2SinceJuly <[email protected]>
… ending, and skip unchanged re-arms

A stale running roster entry no longer cancels a held wake, a real ending inside the lease drops it and leaves nothing to revive, and frames that leave a chat's deadline unchanged no longer reschedule the shared timer.

Co-authored-by: 2SinceJuly <[email protected]>
…real endings stand

The lease deadline now uses the same monotonic clock as its timer, so a wall-clock correction cannot stretch it or make the timer spin. A real ending clears any revival of that run, and roster entries, which carry no run state, no longer cancel or revive a wake.

Co-authored-by: 2SinceJuly <[email protected]>
@brennanb2025
brennanb2025 force-pushed the brennanb2025/subagent-wake-lease branch from ff3064d to 4e93ebd Compare November 28, 2026 11:21

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

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: 4bd8ad64-1f5c-49db-a24d-e975498f847c
Commits

Reviewing files that changed from the base of the PR and between ff3064d and 4e93ebd.

Files selected for processing: 5

  • src/main/claude/child-work/claude-child-wake-lease.ts
  • src/main/claude/child-work/claude-child-work-decoder.test.ts
  • src/main/claude/child-work/claude-child-work-decoder.ts
  • src/main/claude/child-work/claude-child-work-roster.ts
  • src/main/claude/structured/lifecycle/claude-child-work-publisher.ts

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

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status

Problem. In a Claude chat, a background subagent that Claude Code had already reported as finished was shown as working again when a task it launched ended, on the guess that Claude would resume it. When Claude didn't, nothing ever settled the row, and the chat said working until it was closed (tracked in #47715).

User-facing change. That guess now expires after 60 seconds. If Claude really runs the subagent again, it keeps showing working for as long as it runs. If not, the row goes back to its recorded ending (done, with its summary), and the chat reads done, with nothing typed.

Fixed during review (two fresh reviewers, then blinded regression audits):

  • Stale running frames from an older run of the subagent can't cancel the 60 s window. Roster entries, which carry no run state, neither cancel nor revive it (as on main).
  • A real ending, inside the window or after it, stands. Late frames from that run can't reopen the row.
  • The window and its timer both use the monotonic clock, so a wall-clock correction can't stretch it or make the timer spin.
  • Per-frame cost is constant. Pending wakes stay in deadline order, so a frame checks only the next one. The shared timer is rescheduled only when a chat's deadline changes.
  • Unused helpers were removed. The restored ending keeps the subagent's summary and token count. Tests were cut to five lease invariants.

Deferred (not blockers):

  • If Claude resumes a subagent but sends no frame for more than 60 s, the row shows done until its next frame, then working again. This is stated in Risk; in QA, resume frames arrived within about a second.
  • Reviving from a start frame emits two identical live edges. That's redundant but harmless.

Verified.

  • CI is green on 4c18db6.
  • The final blinded regression audit on that head is SAFE.
  • Real-app QA ran on Linux (earlier head, before and after) and on Windows (final head), with a real Claude Code 2.1.332 chat. Every flow passed:
Flow Before (main) After
Subagent woken but never resumed stuck working for more than 340 s back to done 60.0 s after the wake, summary kept, chat done
Real resume running 90 s (past the window) – working the whole 91.6 s, then done
Settled subagent messaged again – working again, then done
Before After
before after

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Update for head a987e62: only a running report or a progress frame now counts as proof that Claude resumed a woken subagent, so a pending or paused update can't keep it working (covered by the stale-frame test). CI is green and a fresh blinded regression audit on this head is SAFE. Everything else in the status above is unchanged.

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.

2 participants