Repository navigation
Conversation
When a Claude agent ends its turn with a background Monitor still running, the sidebar card dropped to the static "done" dot instead of showing the working spinner — even though the session is mid-flight and will resume when the monitor fires. Root cause: the Stop hook's `background_tasks` array carries monitors as a non-agent task kind, and `readClaudeBackgroundAgentTasks` keeps only subagent/teammate entries. With the monitor discarded, the "stay-working" gate saw an empty roster and resolved the pane to `done`. Fix: detect a running Monitor in `background_tasks` (`claudeBackgroundTasksHaveRunningMonitor`), track it per-pane, and OR it into the same three done->working gates that already hold a pane working while a subagent runs. Everything downstream (activity summary -> status resolver -> StatusIndicator) already promotes a `working` pane into the spinner, so there are no rendering changes. The flag is updated only from a present `background_tasks` list (so an event without the field can't clear a monitor tracked earlier) and self-heals to `done` on the next Stop that no longer lists the monitor as running.
📝 WalkthroughWalkthroughClaude hook handling now detects running or pending shell and monitor entries in 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 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 |
…nitor"
The prior commit gated the working spinner on background_tasks entries with
type starting "monitor", but the Monitor tool never surfaces that way. It
registers its watch as a backgrounded shell, so Claude's Stop-hook payload
reports it as { type: "shell", status: "running" } — the internal
kind: "monitor" is dropped. The predicate never matched, the done-gate never
fired, and the pane still resolved to done while a monitor was running.
Verified against a live 2.1.211 Stop payload:
background_tasks: [{ id, type: "shell", status: "running",
description: "sleep 300 background command",
command: "sleep 300" }]
Match type "shell" (the Monitor tool, indistinguishable from a plain
backgrounded shell once kind is dropped) plus "monitor" (ws/mcp monitors),
with status running|pending. Rename claudeBackgroundTasksHaveRunningMonitor ->
...ShellOrMonitor and the pane flag/helpers to match. Subagent/teammate types
stay excluded — the roster owns them and teammate entries read "running"
forever. Tests use the real shell shape.
Why the spinner still stopped — and the fixThe first commit gated the spinner on Evidence — a live
|
|
Closing as superseded by #11838 (preserve Claude background work). That merge cites this as a prior attempt and covers non-agent |
What & why
When a Claude agent ends its turn with a background Monitor still running, the left-sidebar agent card dropped to the static "done" dot instead of the working spinner — even though the session is mid-flight and will resume when the monitor fires. Reported from a real session: the footer read "1 monitor still running" while the agent's sidebar card showed the static done dot.
This makes the card show the working spinner while a Monitor is watching, reusing the exact mechanism that already keeps a card spinning while a subagent runs.
Root cause
The
Stophook payload carries abackground_tasksarray. A Monitor is a non-agent background-task kind (Claude's task kinds aresubagent, workflow, shell, monitor, MCP task, teammate, …).readClaudeBackgroundAgentTaskskeeps onlysubagent/teammateentries and discards the rest, so the monitor never entered the roster — the "stay-working" gate inagent-hook-listener.tsthen saw an empty roster and resolved the pane todone:The fix
claudeBackgroundTasksHaveRunningMonitor()detects a running monitor inbackground_tasks(matched on themonitortype prefix, somonitor_ws/monitor_mcpvariants gate too; shells/workflows/crons deliberately excluded).claudeRunningMonitorByPaneKey), updated only from a presentbackground_taskslist so an event without the field can't clear a monitor tracked by an earlier turn (mirrors how the roster is retained).done -> workinggates that already hold a pane working while a subagent runs.Everything
downstream (activity summary -> status resolver ->
StatusIndicator) already promotes aworkingpane into the spinner, so there are no rendering changes. It self-heals todoneon the nextStopthat no longer lists the monitor as running.Evidence
Before/after (proves the fix is load-bearing). With the monitor check temporarily neutered to a no-op, the 3 new integration tests — which drive the real
normalizeHookPayloadentry point — reproduce the bug exactly:With the fix in place, the same tests pass (state resolves to
working, which is what renders the spinner):Full affected suite + typecheck (fix on):
Test plan
claudeBackgroundTasksHaveRunningMonitor— running monitor (incl.monitor_ws/monitor_mcp), completed monitor, running shell/subagent (excluded), absent/malformed field.normalizeHookPayload): Stop with a running monitor ->working; monitor completes on next Stop ->done; running monitor retained across a Stop whose payload omits
background_tasks; monitor alongside a finished subagent ->working.tsc+oxlintclean.Notes / caveats
typestring is matched on themonitorprefix, inferred from the Claude Code build's task-kind list; if a live capture shows a different value it's a one-line tweak (flagged in a code comment).kind, a Monitor is byte-identical to a plainrun_in_backgroundshell in the payload — so a backgrounded dev server will also hold the spinner until it exits (or the existing 30-min status staleness decays it). There's no signal in the payload to separate the two.Made with Orca 🐋