Repository navigation
fix(agent-status): stop start-less child stops from minting phantom working - #14375
Conversation
…orking buildClaudeCachedLeadStatusPayload fell back to 'working' whenever the pane had no cached lead-turn state. That default is right for a spawn or a child tool call, but the same helper serves SubagentStop and TeammateIdle, which end work and prove the opposite. claudeLeadStateByPaneKey is in-memory only, so every app restart empties it. A Claude session that outlives the restart reports its next child event into an empty map and the pane latches 'working' with an empty roster -- no Stop ever clears it, and the 30-minute window only decays the sidebar dot, never the stored state. Fall back by the event's evidence: terminating child events resolve to 'done', which still gates up through resolveClaudePaneState when the roster or background work proves the pane is busy.
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThe listener now handles missing Claude child rosters, creates rosters on child starts, updates restored-row markers, removes matching children, and deletes empty rosters. Confirmed child removal can resolve cached lead state to 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/shared/agent-hook-listener.ts (1)
2590-2594: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winShorten the added lifecycle comments.
Keep the rationale, but use one concise line at each location. The current comments restate control flow and make the state transition harder to scan.
Proposed change
-/** Child lifecycle events that end work. They say nothing about the lead being busy, so they must never be the reason a pane reads 'working'. */ +/** Stop and idle child events do not prove lead activity. */ ... -// Why: with no cached lead (Orca restarted mid-session) the fallback must follow the event's -// evidence. A spawn or child tool call proves activity; a stop/idle proves the opposite, so -// defaulting those to 'working' mints a phantom no Stop will ever clear. 'done' still gates up -// through resolveClaudePaneState when the roster or background work proves the pane is busy. +// When the lead cache is missing, terminating child events default to done.As per coding guidelines, comments must be concise, non-obvious, and brief—prefer one line.
Also applies to: 2731-2735
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 3943e57f-3690-4c7c-b126-90c101c8223d
📒 Files selected for processing (2)
src/shared/agent-hook-listener-startless-child-lifecycle.test.tssrc/shared/agent-hook-listener.ts
Visual QA @
|
…orking (stablyai#14375) * fix(agent-status): stop start-less child stops from minting phantom working buildClaudeCachedLeadStatusPayload fell back to 'working' whenever the pane had no cached lead-turn state. That default is right for a spawn or a child tool call, but the same helper serves SubagentStop and TeammateIdle, which end work and prove the opposite. claudeLeadStateByPaneKey is in-memory only, so every app restart empties it. A Claude session that outlives the restart reports its next child event into an empty map and the pane latches 'working' with an empty roster -- no Stop ever clears it, and the 30-minute window only decays the sidebar dot, never the stored state. Fall back by the event's evidence: terminating child events resolve to 'done', which still gates up through resolveClaudePaneState when the roster or background work proves the pane is busy. * fix(agent-status): require evidence for child completion * fix(agent-status): publish matched teammate idle * fix(agent-status): preserve confirmed child work * fix(agent-status): retain live restored teammates * fix(agent-status): reap unconfirmed siblings after child drain * fix(agent-status): preserve unmatched restored children * fix(agent-status): wait for lead completion after child stop * fix(agent-status): persist restored child transitions --------- Co-authored-by: Brennan Benson <[email protected]>


ELI5
When Orca restarts, it forgets what each Claude pane was doing. If a subagent then finished, Orca used to guess "the parent must be busy" and show a spinner forever. Now it only says "busy" when something actually proves it, and records when its guess is based on stale, restored data.
What Changed
buildClaudeCachedLeadStatusPayload(src/shared/agent-hook-listener.ts:2775-2812) previously did:It now takes an
evidenceobject and, only in the no-cached-lead case, decides:workingChildEvidence— a roster row isworkingand was seen this runtimeworkingendedRuntimeChildWork— the row that just stopped was working and seen this runtimeworkingendedChildWork— a restored (disk-hydrated) row endedworking+restoredUnconfirmednull— emit nothing at allBehavior with a cached lead is unchanged.
Two supporting pieces carry most of the weight:
hasCachedLeadEvidence(:2612-2620) — a cachedwaitingstate minted by this child's own permission/question event isn't treated as lead evidence; it's the child's footprint, not a turn boundary.restoredUnconfirmedprovenance — newclaudeUnconfirmedRestoredStatusPaneKeysset (:139), stamped onto the payload (:4482). Downstream,isFreshNonDoneAgentStatusreturns false for these, so the sidebar dot, tab spinner, smart-attention andworktree pstreat the pane as not-live, andserver.ts:1279drops it fromruntimeObservedStatusPaneKeysso it stays reap-eligible.Roster changes (
src/shared/claude-subagent-roster.ts): newclaudeRosterHasRuntimeWorkingSubagent;stopClaudeSubagent/idleClaudeTeammateByNamenow clearrestoredFromSnapshotandbackgroundTasksAuthoritativeon the row they park;reapRestoredClaudeSubagentsWithoutLiveAgentrenamed toreapUnconfirmedRestoredClaudeSubagents.Why
claudeLeadStateByPaneKeyis in-memory only, so every app restart empties it. A Claude session that outlives the restart (PTYs live on the daemon) reports its next child event into an empty map. On main that unconditionally mintedworkingwith an empty roster — noStopis coming, since the turn ended before the restart.AGENT_STATUS_STALE_AFTER_MSonly decays the sidebar dot after 30 minutes; the stored row staysworkingand re-hydrates on next launch.Reported as: "stuck in loading even when AI is done working — maybe coming back from sleep or from app restart (installing new update), happens fairly often."
The principle: absence of evidence must not become evidence of activity. A child stopping is the weakest possible ground for claiming the parent is busy.
Linked Issue
Linear STA-4144 (Urgent), with duplicate reports STA-3532 and STA-3522.
Visual Proof
Before — Claude idle at its prompt (
- · - tokens, empty input) while the sidebar card spins:After (commit 1 only) — same input, same conditions, completed glyph:
Testing
Automated — 897 passed / 4 skipped across 51 agent-hook, agent-status, roster and server files, run against the current head.
tsc --noEmit -p config/tsconfig.node.jsonexit 0;oxlintclean.New coverage (
agent-hook-listener-startless-child-lifecycle.test.ts, 14 cases;server.test.ts, +297 lines / 7 cases) spans: unknown stop/idle with no roster →null; runtime children draining →working; restored children →working+restoredUnconfirmed; full persist → restart → hydrate → live-event round trips asserting the flag clears only on a real leadStop; and a truncatedbackground_tasksinventory not confirming a restored row.Manual — the original defect was reproduced end to end against Claude Code 2.1.229 in an isolated dev instance: launch Claude, kill only the app process group so the daemon and session survive, relaunch (fresh process, empty lead cache), deliver the child event. That reproduction validated commit 1, not the current implementation.
Review
workingstate can be fabricated.src/shared. No paths, shells, shortcuts, or platform branches.restoredUnconfirmedis added toAgentHookEventPayload, a local main-process type; it is not onAgentHookRelayEnvelopeand is not forwarded byrelay/agent-hook-server.tsor accepted byingestRemote. So for SSH/relay-hosted panes the marker is computed relay-side and dropped in transit — remote panes get the state-value changes but none of the provenance mitigation, and they were already excluded from the liveness reap byconnectionId === null. Not a regression (main emitted a bareworkingtoo), but the fix does not cover the SSH case.RuntimeWorktreeAgentRow.restoredUnconfirmedin new circumstances. Older paired clients that predate the field render those rows as ordinary freshworking: additive-optional, decodes fine, mixed-version rendering divergence rather than a wire break.SubagentStopnow emits nothing where it previously emittedworking.Open questions for review
Three things a reviewer should decide on deliberately:
The original phantom is still reachable, unmarked. Verified by running the listener directly:
SubagentStart→ clear the lead cache →SubagentStopyieldsstate=working, restoredUnconfirmed=undefined, rosterSize=0. BecauseendedRuntimeChildWorkis true and no restored child exists, the marker condition at:2669-2675is false, soserver.ts:1281adds the pane toruntimeObservedStatusPaneKeys, which permanently disqualifies it from the liveness reap. This is asserted as intended behavior by the test "keeps the parent working when a current-runtime child drains with no cached lead". The real-world path is the same missed-lead-event class that emptied the cache in the first place. Is holdingworkinghere deliberate?endedChildWork → 'working'for a restored child has no guaranteed clearer. The marker correctly suppresses freshness everywhere, but the only things that can clear the state are another Claude hook (requires the user to prompt again) or the liveness reap — and the reap can't fire, for two independent reasons: candidate selection requiresclaudeRosterHasRestoredSnapshotSubagent, whichidleClaudeTeammateByNamejust cleared on that row, and the reap also requires the pane to be dead, whereas the pane just proved it's alive by delivering the hook. Concrete case: restart, surviving session, teammate emitsTeammateIdle, lead's turn ended pre-restart so noStopfollows, user leaves the pane at the prompt → storedworkingindefinitely. The visible symptom isn't a spinner but hibernation lockout, sinceagent-hibernation-planner.ts:147-152rejectsstate !== 'done'and doesn't consultrestoredUnconfirmed. ShouldrestoredUnconfirmedmake aworkingrow hibernation-eligible, given it already means "never fresh" everywhere else?Two inference paths are disabled for marked panes —
server.ts:794and:886skip Ctrl+C interrupt inference and AskUserQuestion answered-inference whilerestoredUnconfirmedis set, andrunning-agent-targets.ts:74-75labels the pane "Agent status is stale" and disables it as a dispatch target. Both were designed for genuinely hydrated rows; they now also apply to a pane that just proved it is live. Intended?Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred) — targeted lint/typecheck/tests run locally as listed; full build and remaining typecheck projects left to CIAuthor