Repository navigation
fix(agent-status): a structured session with live child work reads as working - #22295
Conversation
… working An idle native-chat session whose subagent was still running showed a green check in the sidebar, the collapsed worktree pill, and worktree ps, while a terminal Claude session in the same situation showed working. The two lanes folded child work into the parent's status with different code: the hook listener did, the structured lane did not. Both lanes now share one child-work liveness vocabulary and one lead-status fold. Live agent work makes a settled lead working; shells and monitors alone make it monitoring. The structured lane derives liveness from the background task list already on the wire, in both its readers, so the sidebar, the CLI, the dashboard and mobile agree. The Claude task-kind table is one shared file covering both the hook inventory and SDK stream names, and the renderer bridge reuses the shared child-work projection instead of carrying its own copy.
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. 📝 WalkthroughWalkthroughThe change centralizes Claude background-task classification and child-work liveness evaluation. A shared lead-status fold combines lead state, interruption state, and child activity. Structured session server and renderer paths use the shared resolver and expose Priority: ➖ Normal Merge Risk: 🔵 Low · up to Background work can appear to have run longer than it has. Use the observation clock when child work starts the displayed state. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 54.17% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 24 functions across 20 files. (1 skipped: 1 unsupported.) Full details: Description checkExplanation The description is detailed and covers the user impact, implementation, rationale, testing, limits, and compatibility considerations. However, it does not provide the required linked issue and does not include the required before-and-after visual proof for this UI behavior change.
✨ 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 |
…ts session working Child-work liveness retired an agent-kind child on any state but working/monitoring, while the shell beside it stayed live on everything except done/idle. A subagent waiting on a permission prompt, or one whose host lost contact, therefore counted for less than a backgrounded sleep and let the session read done. Both kinds now share the settlement rule `resolveAgentChildWorkFreshness` already reads rows by: only an explicit done/idle retires child work. Also keep empty task labels out of the shared background-task projection candidate, so a host that publishes `name: ''` cannot beat the child-row fallbacks.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — the single commit dfbe3f1 (17 files, +503/−119), read end to end.
- Shared child-work liveness + fold — new
agent-status-child-work-liveness.tsreduces child work toworking | monitoring | null(agent/workflow kinds fail-active as agent work; shells/monitors/unknown fail-active unless explicitlydone/idle), andagent-lead-status-fold.tscombines it with the lead state and interrupt flag. - Structured status projection — new
structured-agent-session-agent-status.tsmaps the projectedworking/attention/idlestatus to a lead state and folds child work withinterrupted: false. - One Claude task-kind table —
claude-background-task-kind.tscentralizes the SDK-stream (local_*/monitor) and hook-inventory (subagent/teammate/shell/background_shell) names;claude-background-task-frames.tsre-exports it and the hook inventory classifies through it. - Structured lane folds at both producers —
server-ingest-structured.ts(canonical store row, now carryingworkingMode) andStructuredAgentSessionStatusBridge.tsx(renderer store). The bridge's subagent rows now reuse the shared child-work projection instead of a local copy. - Terminal lane routed through the same fold —
resolveClaudePaneStatusnow callsfoldAgentLeadStatus; the result is behavior-identical to the previous inline logic. - Tests — new unit suites for the fold, liveness, kind table, and structured status; ingest and bridge tests assert the folded parent
state/workingMode, and the existing hook-listener suites pin the terminal lane.
I traced the fold's reach: backgroundTasks on the structured summary is the live tasks list only, workingMode survives the renderer store, worktree ps, and mobile, and a sweep of parent-activity readers found none that still consume the raw summary.status or an un-folded state. The published turn status is left untouched, so send/rewind gating is unaffected. No wire change, and an old host's backgroundTasks (with optional state) folds correctly.
ℹ️ Stale reference in agent-status-store.md
docs/reference/agent-status-store.md:102 still describes the row's state as structuredAgentSessionStatusState(summary.status) "the mapping #19217 shared". That function was deleted by this PR, so the reference table no longer matches the ingest — the row's state now comes from structuredAgentSessionAgentStatus, which folds live child work and can also carry workingMode. Documentation only; worth a one-line refresh when convenient.
Technical details
# Stale doc row after function removal
## Affected sites
- `docs/reference/agent-status-store.md:102` — names `structuredAgentSessionStatusState(summary.status)`, removed in `src/shared/structured-agent-session-projection.ts`.
## Required outcome
- The reference table describes `state` as coming from the shared structured-session fold, and notes the optional `workingMode` field the ingest now writes.
## Suggested approach (optional)
- Point the row at `structuredAgentSessionAgentStatus(summary.status, summary.backgroundTasks)` and mention `workingMode` alongside the other row fields.DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
…orrect two stale claims The hook inventory now classifies through the shared kind table, which also maps the SDK stream's `local_agent` / `local_subagent`. Nothing pinned that widening, so add cases for all four agent names — including `teammate`, whose pane state stays `done` under the #8825 idle-squat rule. Two comments the fold made false: - the teardown marker rule's comment claimed it could not disagree with what the UI calls working; it is deliberately lead-only, so now it says that and why; - the agent-status store reference still described the structured row's `state` as the deleted `structuredAgentSessionStatusState`, and omitted the `workingMode` the ingest now writes.
… real turn `stateStartedAt` carried forward whenever the prior `state` matched, which was sound while `state` meant "a turn is running". Now that it folds in child work, an idle lead watching a `sleep 3600` publishes `working`/`monitoring`; the user's prompt 45 minutes later keeps `state: 'working'`, so the row inherited the watch loop's clock and read "Working for 45m" the instant the turn began. Monitoring is its own displayed label (`worktree-card-compact-agent-row.tsx:40`), so the continuity key is now the whole published work identity — state AND workingMode — in both writers. Also record two facts the code stated wrongly: the structured lane's `interrupted: false` is inert (a projected session status has no interrupted member) rather than a decision, and the child-work liveness rule's escape hatch is the roster's session lifetime, not a settled state.
Two defects the fold introduced. `isAgentChildWorkKind` counted `workflow` as agent work, so a structured session whose only live task was a backgrounded `local_workflow` published a full working spinner while the children projection — which admits `kind === 'agent'` only — rendered nothing to expand, and the same workflow in a terminal pane showed the monitoring badge instead. The repo already decides this: `isClaudeSubagentTask` excludes workflows by name, and MATERIALIZED_TASK_KINDS leaves "the backgrounded shell command and the workflow" to the non-agent owner. The predicate is now `kind === 'agent'`, and the three sites that restated the same test route through it, so a new kind is decided in one place instead of three that merely agree. `evidenceObservedAt` dated every row by `summary.updatedAt`, the journal's last activity. The journal cannot date child work: its clock stopped when the lead's turn did, so a genuinely live roster aged past the 30-minute staleness window and mobile's dot decayed a running session to idle. The fold now reports whether child work alone holds the row open, and only then does the host's observation clock stand in — keeping "a restart's republish is not new evidence" for lead turns.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — the two commits since the prior pullfrog review (e09c3ea, 0114ace), read against the full PR.
- Widened child-work liveness —
agent-status-child-work-liveness.tscollapsed its separate agent/non-agent paths into one settlement rule: a child is live unless its state is explicitlydone/idle. A subagent that iswaiting(e.g. on a permission prompt) orunverifiableno longer counts for less than a backgrounded shell, so the parent readsworking. This matches the terminal lane, whose roster is alreadyworkingfor a waiting child. - Empty labels dropped from the projection candidate —
agentChildWorkProjectionCandidateFromBackgroundTasknow checks name/description truthiness, so a host publishingname: ''can no longer beat thedescription ?? agentType ?? 'unknown'child-row fallbacks. - Stale doc row corrected — the
staterow indocs/reference/agent-status-store.mdnow points atstructuredAgentSessionAgentStatus(...).stateand documents the optionalworkingMode, which was the one item from the prior review. - Tests — liveness now pins
waiting/blocked/unverifiableagents as live anddone/idleas retiring; a bridge test drives an idle session through agent-running → shell-monitoring → all-settled and asserts the parentstate/workingMode/stateStartedAt; the ingest test does the same through the canonical store; the hook inventoryit.eachpinslocal_agent/local_subagent/subagent/teammateagainst the shared kind table. Each asserts an exact state, not a truthiness check.
The terminal lane is unchanged (claudeRosterHasWorkingSubagent still gates on roster working), the interrupted: false difference for the structured lane is now explained in code, and no wire field changed.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
… does `fromChildWork` reached the host ingest but not the renderer bridge, so after ~30 minutes of live child work with no journal activity the sidebar's row aged into staleness while `worktree ps` and mobile stayed fresh — two writers for one session answering differently, which is the defect this PR exists to remove. For a remote host the client's own receipt time is also the more honest clock, since the journal stamp is the host's and is never comparable against this machine's now.
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 2c2acb9f-e769-40fc-8bd6-154dd7a5150a
📒 Files selected for processing (15)
docs/reference/agent-status-store.mdsrc/main/agent-hooks/server-ingest-structured-status.test.tssrc/main/agent-hooks/server/server-ingest-structured.tssrc/main/claude/claude-subagent-task-frames.tssrc/main/native-chat/agent-session-wire/structured-agent-session-working-at-teardown.tssrc/renderer/src/components/native-chat/StructuredAgentSessionStatusBridge.test.tsxsrc/renderer/src/components/native-chat/StructuredAgentSessionStatusBridge.tsxsrc/shared/agent-status-child-work-liveness.test.tssrc/shared/agent-status-child-work-liveness.tssrc/shared/agent-status-child-work-projection.test.tssrc/shared/agent-status-child-work-projection.tssrc/shared/claude-background-task-inventory.tssrc/shared/claude-background-task-status.test.tssrc/shared/structured-agent-session-agent-status.test.tssrc/shared/structured-agent-session-agent-status.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review.
| stateStartedAt: | ||
| priorStatus?.state === state && priorStatus.workingMode === workingMode | ||
| ? priorStatus.stateStartedAt | ||
| : summary.updatedAt, |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
sed -n '25,95p' src/main/agent-hooks/server/server-ingest-structured.ts
sed -n '45,145p' src/renderer/src/components/native-chat/StructuredAgentSessionStatusBridge.tsx
sed -n '90,210p' src/main/agent-hooks/server-ingest-structured-status.test.ts
sed -n '300,465p' src/renderer/src/components/native-chat/StructuredAgentSessionStatusBridge.test.tsx
rg -n -C 5 'backgroundTasks|updatedAt|ingestStructuredStatus|publish.*summary|status summary' src/main/agent-hooks src/main/native-chat src/shared | head -n 420Repository: stablyai/orca
Length of output: 41486
🤖 get_repo_knowledge executed:
get_repo_knowledge stablyai/orca /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/learnings /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/conventions
Length of output: 47609
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '--- bound helper and summary types ---'
rg -n -C 8 'structuredAgentSessionAgentStatus|AgentSessionStatusSummary|backgroundTasks' src/main src/renderer/src src/shared -g '*.ts' -g '*.tsx' | head -n 500
printf '%s\n' '--- renderer timestamp sink ---'
rg -n -C 10 'function setAgentStatus|setAgentStatus\\s*[:=]|stateStartedAt|evidenceObservedAt' src/renderer/src src/main -g '*.ts' -g '*.tsx' | head -n 500
printf '%s\n' '--- summary update/publish paths ---'
rg -n -C 8 'updatedAt.*backgroundTasks|backgroundTasks.*updatedAt|subscribeStatus|emit\\(.*status|type: .status.|AgentSessionStatusSummary' src -g '*.ts' -g '*.tsx' | head -n 500Repository: stablyai/orca
Length of output: 41859
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '--- shared status fold ---'
sed -n '1,110p' src/shared/structured-agent-session-agent-status.ts
printf '%s\n' '--- wire summary and event types ---'
rg -n -C 12 'export (type|interface) AgentSessionStatusSummary|backgroundTasks|updatedAt|type: .status.|StatusSummary' src/shared/agent-session-wire.ts src/shared -g '*wire*.ts' -g '*status*.ts' | head -n 360
printf '%s\n' '--- summary projection ---'
sed -n '270,380p' src/shared/structured-agent-session-projection.ts
printf '%s\n' '--- reducer event handling ---'
sed -n '195,265p' src/shared/structured-agent-session-reducer.ts
printf '%s\n' '--- status bridge exact function ---'
rg -n -B 20 -A 95 'function projectStructuredAgentSessionStatus|setAgentStatus\\(' src/renderer/src/components/native-chat/StructuredAgentSessionStatusBridge.tsx
printf '%s\n' '--- setAgentStatus implementation and timestamp merge ---'
rg -n -C 15 'setAgentStatus\\s*\\(' src/renderer/src/store src/renderer/src -g '*.ts' -g '*.tsx' | head -n 420
printf '%s\n' '--- constructors and updateAt assignments ---'
rg -n -C 8 'backgroundTasks|updatedAt' src/main src/shared -g '*.ts' | rg 'structured|status|session|backgroundTasks|updatedAt' | head -n 500Repository: stablyai/orca
Length of output: 38831
🏁 Script executed:
#!/bin/bash
set -u
printf '%s\n' '--- renderer bridge ---'
grep -n -B 18 -A 90 'setAgentStatus(' src/renderer/src/components/native-chat/StructuredAgentSessionStatusBridge.tsx
printf '%s\n' '--- setAgentStatus definitions/callers ---'
rg -n -C 14 --fixed-strings 'setAgentStatus(' src/renderer/src/store src/renderer/src -g '*.ts' -g '*.tsx' | head -n 420
printf '%s\n' '--- status summary publishers ---'
rg -n -C 10 --fixed-strings 'projectStructuredAgentSessionStatusSummary' src/main src/shared src/relay -g '*.ts' | head -n 360
printf '%s\n' '--- updatedAt assignments near status feeds ---'
rg -n -C 8 'updatedAt:' src/main src/relay -g '*.ts' | rg -C 4 'status|session|journal|summary|background' | head -n 500
printf '%s\n' '--- background task publication paths ---'
rg -n -C 10 'backgroundTasks' src/main src/relay src/shared -g '*.ts' | rg -C 5 'status|publish|summary|updatedAt|snapshot|batch|subscribe' | head -n 600Repository: stablyai/orca
Length of output: 42810
🏁 Script executed:
#!/bin/bash
set -u
printf '%s\n' '--- resolved setAgentStatus implementation ---'
rg -n -l --fixed-strings 'setAgentStatus' src/renderer/src/store -g '*.ts' | head -n 20
rg -n -C 24 --fixed-strings 'setAgentStatus: ' src/renderer/src/store -g '*.ts' | head -n 260
rg -n -C 24 --fixed-strings 'setAgentStatus(' src/renderer/src/store/slices/agent-status.ts | head -n 320
printf '%s\n' '--- timestamp option type ---'
rg -n -C 12 'stateStartedAt\\??:|allowOlderTimestamp|evidenceObservedAt' src/renderer/src/store/slices/agent-status.ts src/shared/agent-status-types.tsRepository: stablyai/orca
Length of output: 13174
Use the observation clock for child-work state transitions.
When a settled lead first gains live background work, the roster can change without advancing summary.updatedAt. Both publishers can then initialize the new working or monitoring state's stateStartedAt from the lead's older journal timestamp. Keep the previous timestamp for the same state and working mode. Otherwise, use the host or client observation time when fromChildWork is true.
Suggested fix
--- a/src/main/agent-hooks/server/server-ingest-structured.ts
+++ b/src/main/agent-hooks/server/server-ingest-structured.ts
@@
stateStartedAt:
priorStatus?.state === state && priorStatus.workingMode === workingMode
? priorStatus.stateStartedAt
- : summary.updatedAt,
+ : fromChildWork
+ ? observedAt
+ : summary.updatedAt,--- a/src/renderer/src/components/native-chat/StructuredAgentSessionStatusBridge.tsx
+++ b/src/renderer/src/components/native-chat/StructuredAgentSessionStatusBridge.tsx
@@
- store.setAgentStatus(
+ const observedAt = Date.now()
+ store.setAgentStatus(
@@
? current.stateStartedAt
- : summary.updatedAt,
+ : agentStatus.fromChildWork
+ ? observedAt
+ : summary.updatedAt,
@@
- evidenceObservedAt: agentStatus.fromChildWork ? Date.now() : summary.updatedAt
+ evidenceObservedAt: agentStatus.fromChildWork ? observedAt : summary.updatedAt📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| stateStartedAt: | |
| priorStatus?.state === state && priorStatus.workingMode === workingMode | |
| ? priorStatus.stateStartedAt | |
| : summary.updatedAt, | |
| stateStartedAt: | |
| priorStatus?.state === state && priorStatus.workingMode === workingMode | |
| ? priorStatus.stateStartedAt | |
| : fromChildWork | |
| ? observedAt | |
| : summary.updatedAt, |
Visual proofCaptured in a hidden Electron dev host over CDP, in the structured native-chat lane. 1. Live subagent, lead turn already settled -> Lead turn had ended ( 2. Only a backgrounded shell live -> monitoring mode Row 3. Everything settled -> Row Lane proof (all three shots): composer textbox is "Send a message…" with Model/Effort pickers, Captured from a build at c230944, one commit behind the current head de06979. That commit changes only |
Review status: ready to mergeReviewed across correctness, architecture, precedent, lane coverage, and release readiness, with each finding verified against the code rather than taken on report. Five commits landed on top of the original. Defects found and fixed
Each behavioural fix is pinned by a test that was ablated — reverted against the fix to confirm it fails, restored to confirm it passes. The original regression slipped because nobody asserted the Consciously not changed
Verification
Visual proof for all three states is in the comment above, captured in the structured lane against a hidden dev host. Follow-ups filed, not fixed hereAll confirmed pre-existing on
|
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — the two commits pushed after the prior review (e86bcfc9, c2309443), read against the full PR.
- Workflows are watch work, not agent work —
isAgentChildWorkKindnow returnstrueonly foragent, so a workflow child reads asmonitoring. The spinner can no longer claim a running agent thatprojectAgentChildWorkLegacySubagentsrefuses to render as a child row.isClaudeSubagentTask, the hook-inventory classifier, and the subagent projection all route through that one predicate, and each was alreadyagent-only, so those three are behavior-preserving. - Child-work rows date themselves —
structuredAgentSessionAgentStatusnow returnsfromChildWork(a settled lead held open only by live child work), and the main-process ingest stampsevidenceObservedAtfrom the host's own observation clock for those rows instead ofsummary.updatedAt, whose journal clock stopped with the lead's turn. A test drives a held monitoring row and assertsisFreshNonDoneAgentStatusstill holds at the 30-minute window, which fails against the old stamp. - State-clock continuity includes
workingMode— both readers restartstateStartedAtwhen monitoring becomes a real turn (and vice versa), so the displayed timer belongs to the state it labels rather than the watch loop's age. Tests assert the restart in the main-process ingest and in the renderer bridge.
Everything else in the delta is comments and tests. No wire field changed, and both readers still fold from the same backgroundTasks.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — the one commit pushed after the prior review (de069792), read against the full PR.
- The renderer bridge now dates child-work rows like the host does —
StructuredAgentSessionStatusBridge.tsxstampsevidenceObservedAt: agentStatus.fromChildWork ? Date.now() : summary.updatedAt, matching the main-process ingest'sfromChildWork ? observedAt : summary.updatedAt. A held row kept open only by live child work no longer ages into staleness in the sidebar while the work is still running, which was the last remaining divergence between the two readers. - Test pins the stamp — the new bridge test emits an idle session with a live shell, asserts the folded
working/monitoringstate, and assertsevidenceObservedAt >= before; it fails against the oldsummary.updatedAtstamp.
I checked the one place this could still diverge: the bridge's field-dedup short-circuits a re-projection whose compared fields are unchanged, but the host feed already suppresses identical re-publishes (summariesEqual in structured-agent-session-status-feed.ts:192), so both readers refresh on the same summary changes. No action needed.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
…they mean Since #22295 a row's combined `state` reads `working` both while the lead's turn runs and while a subagent or background shell outlives a settled lead. The lead's own state now rides beside it (`lead`); each consumer in this slice reads the question it actually asks. - Smart sort and the Activity unread badge keep reading the combined state: their classes and rows are what the sidebar shows. Pinned with tests, including a restored `lead.state: 'working'` row that must never read live. - The stats recorder asks "was an agent executing" and now reads a shared derivation (`isAgentExecutionOwed`): the lead's turn, or live agent child work holding a settled lead's row open. A settled lead's background shell no longer accrues "Time agents worked". Old hosts without `lead` fall back to today's read; restored and replayed rows still never open a session. - The `agent.status.changed` plugin event gains `lead` as an optional field through one tested projection; `state` keeps its meaning and restored rows still project to nothing. - A Codex root Stop that follows an inferred interrupt keeps the `cancellation` verdict, as the Claude lane already does at its turn boundary, on both the hook and relay paths.
…they mean Since #22295 a row's combined `state` reads `working` both while the lead's turn runs and while a subagent or background shell outlives a settled lead. The lead's own state now rides beside it (`lead`); each consumer in this slice reads the question it actually asks. - Smart sort and the Activity unread badge keep reading the combined state: their classes and rows are what the sidebar shows. Pinned with tests, including a restored `lead.state: 'working'` row that must never read live. - The stats recorder asks "was an agent executing" and now reads a shared derivation (`isAgentExecutionOwed`): the lead's turn, or live agent child work holding a settled lead's row open. A settled lead's background shell no longer accrues "Time agents worked". Old hosts without `lead` fall back to today's read; restored and replayed rows still never open a session. - The `agent.status.changed` plugin event gains `lead` as an optional field through one tested projection; `state` keeps its meaning and restored rows still project to nothing. - A Codex root Stop that follows an inferred interrupt keeps the `cancellation` verdict, as the Claude lane already does at its turn boundary, on both the hook and relay paths.
…they mean Since #22295 a row's combined `state` reads `working` both while the lead's turn runs and while a subagent or background shell outlives a settled lead. The lead's own state now rides beside it (`lead`); each consumer in this slice reads the question it actually asks. - Smart sort and the Activity unread badge keep reading the combined state: their classes and rows are what the sidebar shows. Pinned with tests, including a restored `lead.state: 'working'` row that must never read live. - The stats recorder asks "was an agent executing" and now reads a shared derivation (`isAgentExecutionOwed`): the lead's turn, or live agent child work holding a settled lead's row open. A settled lead's background shell no longer accrues "Time agents worked". Old hosts without `lead` fall back to today's read; restored and replayed rows still never open a session. - The `agent.status.changed` plugin event gains `lead` as an optional field through one tested projection; `state` keeps its meaning and restored rows still project to nothing. - A Codex root Stop that follows an inferred interrupt keeps the `cancellation` verdict, as the Claude lane already does at its turn boundary, on both the hook and relay paths.
…ckground subagent as working (#22474) * fix(agent-status): renderer and recorder consumers read the question they mean Since #22295 a row's combined `state` reads `working` both while the lead's turn runs and while a subagent or background shell outlives a settled lead. The lead's own state now rides beside it (`lead`); each consumer in this slice reads the question it actually asks. - Smart sort and the Activity unread badge keep reading the combined state: their classes and rows are what the sidebar shows. Pinned with tests, including a restored `lead.state: 'working'` row that must never read live. - The stats recorder asks "was an agent executing" and now reads a shared derivation (`isAgentExecutionOwed`): the lead's turn, or live agent child work holding a settled lead's row open. A settled lead's background shell no longer accrues "Time agents worked". Old hosts without `lead` fall back to today's read; restored and replayed rows still never open a session. - The `agent.status.changed` plugin event gains `lead` as an optional field through one tested projection; `state` keeps its meaning and restored rows still project to nothing. - A Codex root Stop that follows an inferred interrupt keeps the `cancellation` verdict, as the Claude lane already does at its turn boundary, on both the hook and relay paths. * test(agent-status): pin that a child's approval wait no longer splits the recorded span The recorder's move to the lead fact quietly changed one more story: a Codex child's PermissionRequest turns the combined row waiting while the root's own turn keeps running. The old state read closed the span there and minted a second spawn on resume; the new read keeps one span, because the lead never stopped. Pin it at both boundaries (the shared derivation and the recorder) so the change is deliberate, not incidental. * fix(agent-status): date stats edges by this host's clocks and scope the accrual predicate to stats The recorder dated a start by the producer's mainAgent.stateStartedAt. An SSH host stamps that with its own clock while every stop is stamped locally, so each span gained or lost the clock skew. The same clock also survives a row that briefly lost the fact (an OSC repaint to another state), dating the reopen before the close already sent, and a subagent reopening a monitoring row took the row clock the hook lane pins to the main agent's turn start, re-billing the whole watch-loop window. Edges now use the row clock when the row settles or pauses and the evidence clock otherwise. Rename isAgentExecutionOwed to isAgentTimeAccruing and state that it is the stats question, not a liveness gate: it excludes watch loops, which lifecycle gates must keep treating as live. Note on the plugin schema that mainAgent.stateStartedAt is the execution host's clock. * fix(agent-status): pause agent time while the row waits on the user, whoever asked Time agents worked now accrues only while the combined row reads working. A child's approval or question wait pauses the clock exactly like the main agent's own prompt, and the pause edge is dated by the row's own clock. * refactor(agent-status): read agent time from the combined row and date edges by the row's own state Time agents worked now accrues while the combined row reads working and is not a watch loop. The shared fold emits monitoring only for a settled main agent, and hosts that predate the main agent fact did the same, so this is the same answer on every new-host row without reading mainAgent, and it applies the watch-loop rule to older hosts too instead of billing their monitoring windows. An edge that leaves working is dated by the row's state clock; an edge inside working is dated by the evidence clock. This also stops a live repeat of a hydrated working row (any row without the main agent fact, such as an OSC row) from dating its start at the persisted state clock from the earlier runtime. * fix(grok): read a background subagent as agent work, not a watch loop Grok's end-of-turn Stop lists each in-flight background task with its type (shell, monitor or subagent). Orca filed a running subagent with the shells, so a Grok subagent that outlived the main agent read "Monitoring background tasks" and, with the stats recorder now skipping watch loops, stopped the "Time agents worked" clock. Map shell and subagent entries to the shared child-work kinds and let the shared liveness classifier decide: any live subagent keeps the pane working, a shell alone or an active stop hook stays monitoring, monitors stay excluded. * test(agent-status): cover a waiting child in the fold's every-input accrual check Since the shared fold learned a child's human wait, a waiting child makes the row wait, so it must not accrue agent time whatever the main agent is doing. The exhaustive check now includes that input.




ELI5
When a native-chat session's own turn ends but a subagent it spawned is still running, the sidebar showed a green check as if nothing was happening. A terminal session in the same situation already showed "working". Now both show the same thing: working while a subagent runs, and "Monitoring background tasks" while only a background shell, workflow, or monitor runs.
What Changed
Before: a native-chat session with a live subagent showed done on its own row, done in the collapsed worktree pill, and done in
orca worktree ps. The only working signal was the child row hidden behind the row's chevron. Terminal sessions showed working.After: an idle native-chat session with a running subagent reads as working everywhere. One whose only live child work is a background shell or workflow reads as "Monitoring background tasks" — the row shows that label and an activity glyph in place of the working spinner, not the word "working". Once every task settles it reads as done. Terminal sessions are unchanged.
This fixes Claude and Codex native chat alike — the path is provider-agnostic, and a Codex native chat with a live subagent gets the corrected badge through the same fold.
Mechanism. The two lanes folded child work into the parent's status with different code. The hook listener (terminal lane) folded its subagent roster into the emitted state. The native-chat lane mapped the host's projected turn status straight through and published background tasks only as child rows, never as evidence for the parent.
This PR makes the policy one piece of shared code:
src/shared/agent-status-child-work-liveness.tsreduces child work toworking,monitoring, or null. Live agent work means working. Shells, workflows, monitors, and unknown kinds that are not explicitly settled mean monitoring, so untyped work can never silently retire.isAgentChildWorkKindin that file is the single owner of the "is this agent work?" test. The child-row projection, the hook inventory, and the subagent frame reader all route through it, so a new kind is classified in exactly one place. Three predicates that merely agreed was the state this started from.src/shared/agent-lead-status-fold.tscombines the lead's own state, the interrupt flag, and that liveness into the published state and working mode. Both lanes call it.src/shared/claude-background-task-kind.tsis the one table of which task types are agents, covering both the SDK stream names and the hook inventory names.A workflow counts as watch work, not agent work. The roster claims agents upstream and the agents a workflow runs announce themselves separately, so counting the workflow container as agent work produced a working spinner with an empty child list.
Because the published
statenow folds child work,workingno longer implies "a turn is running". Two places depended on that older meaning and were corrected:stateStartedAtcontinuity key is now the whole published work identity —stateandworkingMode— in both writers. Otherwise a session sitting at monitoring since 10:00 kept that clock when a real prompt arrived at 10:45 and read "Working for 45m" the instant the turn began.evidenceObservedAtis stamped from the host's observation clock only when the row is held open by child work. Lead-turn rows keep the journal clock, preserving the existing invariant that a restart's republish is not new evidence. Without this, a session with genuinely live background work decayed to stale on mobile while the work was still running.No wire change. The fold runs on fields already published, so an old host still folds correctly on a new client, and the published turn status keeps its meaning for every existing consumer.
Why
The sidebar deliberately never derives a parent's state from its children; the store owns status and readers keep presentation policy only. So the fix has to live where status is produced, and it has to be the same rule in both lanes or they drift again. Alternatives considered:
Known limits
interrupted: false, which is inert rather than a decision — a projected session status carries no interrupted member. Interrupting a native-chat session with a live backgrounded shell therefore reads working/monitoring where the hook lane reports done.live when the next prompt arrives, the timer continues rather than restarting. That is existing,
documented behavior — the per-turn identity is carried separately — and terminal sessions do the same
thing today; this PR deliberately does not diverge from it. The monitoring case is different and is
fixed here, because there the displayed label itself changes.
Linked Issue
None filed. Found in use.
Visual Proof
Before: an idle native-chat row with a green check while a child row underneath spins. Screenshots of the corrected states are attached in a comment below.
Testing
pnpm tcclean.pnpm exec oxlintclean on all changed files.The new and changed shared modules, the status bridge, and the main-process ingest: 105 tests passing locally, plus the hook-listener and background-task suites.
Each behavioural fix in this PR is pinned by a test that was ablated — reverted against the fix to confirm it fails, then restored to confirm it passes.
Not yet exercised in a running Electron app at the time of writing; screenshots follow.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Review
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
Shared code only; no platform-specific paths.
SSH and remote: native chat runs on the local execution host only, so there is no remote native-chat session to reconcile. The remote case that does exist is a terminal session on a remote host: it is folded on the execution host that owns the hook listener, and the already-resolved verdict crosses the wire to the local sidebar. A dropped connection keeps the row working while the observation becomes unverifiable, which is the intended vocabulary — loss of contact is not evidence that the work died.
Mobile reads the same folded row, so it picks up the state and working mode without a change.
docs/reference/agent-status-store.mdis updated: it described the mapping function this PR deletes and omitted the working mode the ingest now writes.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)