Skip to content

fix(agent-status): a structured session with live child work reads as working - #22295

Merged
brennanb2025 merged 6 commits into
mainfrom
brennanb2025/investigate-subagent-working-indicator
Sep 22, 2026
Merged

brennanb2025 merged 6 commits into
mainfrom
brennanb2025/investigate-subagent-working-indicator

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​518 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​518
Prod 14 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​264 $\color{#cf222e}{\Huge{\mathbf{−}}}$​130 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​134

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.ts reduces child work to working, 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.
  • isAgentChildWorkKind in 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.ts combines 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.ts is the one table of which task types are agents, covering both the SDK stream names and the hook inventory names.
  • The renderer bridge reuses the shared child-work projection for subagent rows instead of carrying its own copy.

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 state now folds child work, working no longer implies "a turn is running". Two places depended on that older meaning and were corrected:

  • The stateStartedAt continuity key is now the whole published work identity — state and workingMode — 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.
  • evidenceObservedAt is 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:

  • Folding in the sidebar only. Rejected: the CLI, dashboard, and mobile would still disagree, and it breaks the store-owns-status rule.
  • Publishing a folded liveness field from the host. Deferred, not blocked. Clients and hosts update independently, so the reader-side fold has to exist as the mixed-version fallback regardless; a published field would therefore be a third representation of something already derivable from the task list the host sends today. Nothing but a badge would consume it. If a settlement policy or a session reaper ever needs it, an additive optional field is the right shape then.
  • Writing child-work records into the canonical status store and folding on the read path. Rejected for now. Those records are persisted, and their input requires an invocation fence and provenance that do not exist on the wire — a producer would have to mint identity at a reader, which cannot survive a restart or distinguish a re-run. The honest increment is to mint that identity at the host where the task is first observed, as its own change.

Known limits

  • Liveness is derived at the two status readers rather than published as its own field. Both call the same shared fold, and no downstream reader re-derives status, so they cannot disagree.
  • An unrecognised task kind counts as live and reads as monitoring rather than settling. This is deliberate fail-active: untyped work must never silently retire. There is no inert class.
  • The structured lane passes 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.
  • The rule that a blocked or out-of-contact child still holds its session working is reachable in the native-chat lane only. The hook lane's roster state is a two-valued type with no blocked or unverifiable member, so it cannot express the case.
  • The "Working for N" clock spans a lead turn and the child work that follows it. If a subagent is still
    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.
  • Other providers that track their own child work — notably Grok, whose stop path makes no agent/non-agent distinction — still answer this question their own way. Unifying them is follow-up work; this PR establishes the owner they would route through.

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 tc clean. pnpm exec oxlint clean 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

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and 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.md is updated: it described the mapping function this PR deletes and omitted the working mode the ingest now writes.

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)
  • 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)

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

coderabbitai Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

📝 Walkthrough

Walkthrough

The 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 workingMode. Child-work evidence uses host observation time, and state clocks reset when the working mode changes. Claude roster status resolution uses the same fold. Tests cover classification, liveness, status folding, server ingestion, and renderer behavior.

Priority: ➖ Normal

Merge Risk: 🔵 Low · up to de069

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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning 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:… Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning 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 no… Add the issue reference after Fixes #. Attach before-and-after screenshots or a video in the pull request, then update the Visual Proof and checklist sections to reflect the attachments.
✅ Passed checks (3 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly identifies the main fix: structured sessions with live child work now report as working.
Full details: Docstring Coverage

Explanation

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 check

Explanation

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.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

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

Comment @coderabbitai help to get the list of available commands.

…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.

@pullfrog pullfrog 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.

✅ 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.ts reduces child work to working | monitoring | null (agent/workflow kinds fail-active as agent work; shells/monitors/unknown fail-active unless explicitly done/idle), and agent-lead-status-fold.ts combines it with the lead state and interrupt flag.
  • Structured status projection — new structured-agent-session-agent-status.ts maps the projected working/attention/idle status to a lead state and folds child work with interrupted: false.
  • One Claude task-kind table — claude-background-task-kind.ts centralizes the SDK-stream (local_*/monitor) and hook-inventory (subagent/teammate/shell/background_shell) names; claude-background-task-frames.ts re-exports it and the hook inventory classifies through it.
  • Structured lane folds at both producers — server-ingest-structured.ts (canonical store row, now carrying workingMode) and StructuredAgentSessionStatusBridge.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 — resolveClaudePaneStatus now calls foldAgentLeadStatus; 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.

Pullfrog  | View workflow run | Using 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.

@pullfrog pullfrog 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.

✅ 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.ts collapsed its separate agent/non-agent paths into one settlement rule: a child is live unless its state is explicitly done/idle. A subagent that is waiting (e.g. on a permission prompt) or unverifiable no longer counts for less than a backgrounded shell, so the parent reads working. This matches the terminal lane, whose roster is already working for a waiting child.
  • Empty labels dropped from the projection candidate — agentChildWorkProjectionCandidateFromBackgroundTask now checks name/description truthiness, so a host publishing name: '' can no longer beat the description ?? agentType ?? 'unknown' child-row fallbacks.
  • Stale doc row corrected — the state row in docs/reference/agent-status-store.md now points at structuredAgentSessionAgentStatus(...).state and documents the optional workingMode, which was the one item from the prior review.
  • Tests — liveness now pins waiting/blocked/unverifiable agents as live and done/idle as retiring; a bridge test drives an idle session through agent-running → shell-monitoring → all-settled and asserts the parent state/workingMode/stateStartedAt; the ingest test does the same through the canonical store; the hook inventory it.each pins local_agent/local_subagent/subagent/teammate against 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.

Pullfrog  | View workflow run | Using 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.

@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

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 2c2acb9f-e769-40fc-8bd6-154dd7a5150a

📥 Commits

Reviewing files that changed from the base of the PR and between dfbe3f1 and de06979.

📒 Files selected for processing (15)
  • docs/reference/agent-status-store.md
  • src/main/agent-hooks/server-ingest-structured-status.test.ts
  • src/main/agent-hooks/server/server-ingest-structured.ts
  • src/main/claude/claude-subagent-task-frames.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-working-at-teardown.ts
  • src/renderer/src/components/native-chat/StructuredAgentSessionStatusBridge.test.tsx
  • src/renderer/src/components/native-chat/StructuredAgentSessionStatusBridge.tsx
  • src/shared/agent-status-child-work-liveness.test.ts
  • src/shared/agent-status-child-work-liveness.ts
  • src/shared/agent-status-child-work-projection.test.ts
  • src/shared/agent-status-child-work-projection.ts
  • src/shared/claude-background-task-inventory.ts
  • src/shared/claude-background-task-status.test.ts
  • src/shared/structured-agent-session-agent-status.test.ts
  • src/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.

Comment on lines +74 to +77
stateStartedAt:
priorStatus?.state === state && priorStatus.workingMode === workingMode
? priorStatus.stateStartedAt
: summary.updatedAt,

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.

🎯 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 420

Repository: 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 500

Repository: 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 500

Repository: 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 600

Repository: 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.ts

Repository: 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.

Suggested change
stateStartedAt:
priorStatus?.state === state && priorStatus.workingMode === workingMode
? priorStatus.stateStartedAt
: summary.updatedAt,
stateStartedAt:
priorStatus?.state === state && priorStatus.workingMode === workingMode
? priorStatus.stateStartedAt
: fromChildWork
? observedAt
: summary.updatedAt,

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Visual proof

Captured in a hidden Electron dev host over CDP, in the structured native-chat lane.

1. Live subagent, lead turn already settled -> working (the case this PR fixes; previously a green check)

state1-subagent-working.png

Lead turn had ended (data-native-chat-working=false, chat shows "Worked for 7s"); the Explore subagent was still running. Row aria-label="Working", 3 working spinners, 0 green checks.

2. Only a backgrounded shell live -> monitoring mode

state2-monitoring.png

Row aria-label="Monitoring background tasks", yellow activity glyph, 0 spinners, 0 green checks. Worth noting for anyone expecting a chip: the sidebar renders monitoring mode as the line "Monitoring background tasks"; it does not print the word "working" beside a separate MONITORING badge.

3. Everything settled -> done

state3-done.png

Row aria-label="Done", green check, 0 spinners, 0 activity icons.

Lane proof (all three shots): composer textbox is "Send a message…" with Model/Effort pickers, [data-native-chat-root=true] present, tab contentType=agent-session / agentSessionAgent=claude, and no "Terminal input" textbox or bypass-permissions footer. That rules out a PTY chat merely rendered as chat.

Captured from a build at c230944, one commit behind the current head de06979. That commit changes only evidenceObservedAt (how a row held open by child work is dated), not the state word or working mode, so these three states are unaffected by it.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status: ready to merge

Reviewed 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

Fix What was wrong
e09c3eae09 An agent-kind child retired on any state but working/monitoring, while a shell beside it stayed live on everything except done/idle. A subagent blocked on a permission prompt therefore counted for less than a sleeping shell, and an out-of-contact child read as done — treating loss of contact as evidence of death.
0114ace264 A comment claimed the resume-marker rule "cannot disagree with what the UI calls working"; the fold made that false. Also corrected the agent-status reference doc, which still described a function this PR deletes.
e86bcfc9c1 User-visible regression. state: 'working' stopped meaning "a turn is running", but the timer-continuity key still assumed it did. A session sitting at monitoring since 10:00 kept that clock when a real prompt arrived at 10:45 and displayed "Working for 45m" the instant the turn began.
c2309443f8 A live workflow produced a working spinner with an empty child list — a session claiming an agent was running with nothing to expand. A workflow is watch work; the roster claims agents upstream. Also made the kind test single-owner, and dated child-work rows by observation rather than a journal clock that stopped with the lead's turn.
de0697921e The freshness fix had landed in only one of the two writers, so the sidebar and worktree ps/mobile would disagree about the same session after 30 minutes.

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 monitoring → working edge; that edge is now asserted in both writers.

Consciously not changed

  • The "Working for N" clock spans a lead turn into the child work that follows it. Investigated as a suspected second regression and deliberately left alone: terminal sessions do exactly the same thing and the repo documents it as intentional, with the per-turn identity carried separately. Changing it in one lane would have created the divergence this PR exists to remove.
  • interrupted: false in the structured lane is inert rather than a decision — a projected session status has no interrupted member. Documented instead of papered over.

Verification

pnpm tc clean · pnpm exec oxlint clean on all changed files (confirmed against a positive control) · affected suites green · changed-files quality gate 0 findings.

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 here

All confirmed pre-existing on main and reachable by terminal sessions today, so they are not regressions from this change:

  • A session with a live watch loop holds the display awake and vetoes pack-refs maintenance, because the status-change entry carries no working mode. The right fix excludes monitoring from the lease and repairs the terminal lane too — roughly four lines.
  • Smart-attention sorting, the session-transition recorder, the plugin event shape, and the activity unread badge all read working as proof a turn is running.
  • Mobile re-derives freshness without the short-circuit the shared helper has, so it can disagree with the sidebar past 30 minutes.
  • The terminal lane's own clock has no working-mode term — the same monitoring edge fixed here, unfixed there.
  • Grok classifies child work on its own axis; routing it through the shared table would close a real hole where a pane reads done while a monitor runs.

@pullfrog pullfrog 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.

✅ 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 — isAgentChildWorkKind now returns true only for agent, so a workflow child reads as monitoring. The spinner can no longer claim a running agent that projectAgentChildWorkLegacySubagents refuses to render as a child row. isClaudeSubagentTask, the hook-inventory classifier, and the subagent projection all route through that one predicate, and each was already agent-only, so those three are behavior-preserving.
  • Child-work rows date themselves — structuredAgentSessionAgentStatus now returns fromChildWork (a settled lead held open only by live child work), and the main-process ingest stamps evidenceObservedAt from the host's own observation clock for those rows instead of summary.updatedAt, whose journal clock stopped with the lead's turn. A test drives a held monitoring row and asserts isFreshNonDoneAgentStatus still holds at the 30-minute window, which fails against the old stamp.
  • State-clock continuity includes workingMode — both readers restart stateStartedAt when 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.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog 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.

✅ 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.tsx stamps evidenceObservedAt: agentStatus.fromChildWork ? Date.now() : summary.updatedAt, matching the main-process ingest's fromChildWork ? 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/monitoring state, and asserts evidenceObservedAt >= before; it fails against the old summary.updatedAt stamp.

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.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@brennanb2025
brennanb2025 merged commit 4c696a1 into main Sep 22, 2026
37 checks passed
brennanb2025 added a commit that referenced this pull request Sep 23, 2026
…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.
brennanb2025 added a commit that referenced this pull request Sep 24, 2026
…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.
brennanb2025 added a commit that referenced this pull request Sep 24, 2026
…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.
brennanb2025 added a commit that referenced this pull request Sep 24, 2026
…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.
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.

1 participant