Skip to content

fix(agent-status): stop foreground-idle Claude from rendering as active foreground work (STA-4119) - #14620

Closed
brennanb2025 wants to merge 4 commits into
mainfrom
brennanb2025/sta-4119-foreground-idle-status
Closed

brennanb2025 wants to merge 4 commits into
mainfrom
brennanb2025/sta-4119-foreground-idle-status

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

When Claude finishes a turn but leaves something running in the background — a dev server it started as a background shell, a subagent, a monitor, a session cron — Orca keeps the pane marked working. That is correct: the pane really is still live, and keep-awake, auto-hibernation and teardown all depend on it.

But the picture was wrong. The worktree card, the tab glyph and the agent row all drew the spinning "Claude is working right now" indicator, forever, while the TUI sat at its idle ❯ prompt. This PR keeps the pane live and stops it from looking like active foreground work.

What Changed

resolveClaudePaneState (src/shared/agent-hook-listener.ts) already knows the difference between "the lead turn is running" and "the lead turn ended but background work gated it back up to working". It threw that provenance away. Now it returns it, and the emitted row carries an optional backgroundOnly marker.

state is unchanged — still working. Only surfaces that render foreground activity consult the marker:

Surface main this PR
Worktree card dot working (yellow spinner) done (green)
Terminal tab glyph working done (check)
Sidebar / dashboard agent row working (spinning ring) new background dot — the same yellow ring, complete and still, labeled "Background work"
Subagent child rows working unchanged — live children keep spinning
Row tool line (Bash: npm run dev) shown dropped (it belongs to the turn that ended)
entry.state working working
Liveness / keep-awake / auto-hibernation / teardown live live, byte-identical

The marker is cleared the moment a new foreground turn starts, so the next prompt spins again even while the dev server keeps running.

New module src/shared/agent-background-only-activity.ts holds the one predicate all four presentation seams share.

Why

resolveClaudePaneState gating up to working is correct and must stay — it is the only thing keeping the pane out of the hibernation planner and the keep-awake reaper while a real dev server runs. So the fix cannot be "report done". It has to be "report working, and say why".

Keeping state fixed is what makes this narrow: every liveness consumer reads state and is untouched by construction. There is no new state in AGENT_STATUS_STATES, no capability negotiation, and no behavior change for panes with no background work (the marker is only ever set on the gated branch).

Relationship to #14580 — independent behavior, shared plumbing

#14580 fixes notification timing. This PR fixes the picture. Neither behavior depends on the other, but both carry additive metadata through the same agent-status pipeline, so they share plumbing and will need conflict resolution if both land.

  • fix(agent-status): announce Claude turn complete while background work runs #14580 stamps turnCompletedAt and changes when the completion banner fires; it explicitly preserves the spinner.
  • This PR stamps backgroundOnly and changes what the sidebar draws. It does not change notification identity or completion coordination.
  • The fields are orthogonal: turnCompletedAt is a timestamp keyed to announcement identity; backgroundOnly is a boolean keyed to presentation. Together they provide the complete behavior requested by the issue.
  • The branches overlap in eight files: src/main/agent-hooks/server.ts, src/main/runtime/orca-runtime.ts, src/renderer/src/hooks/useIpcEvents.ts, src/renderer/src/runtime/web-session-tabs-sync.ts, src/shared/agent-hook-listener.test.ts, src/shared/agent-hook-listener.ts, src/shared/agent-status-types.ts, and src/shared/runtime-types.ts.
  • A merge-tree check shows real textual conflicts in that shared plumbing. If fix(agent-status): announce Claude turn complete while background work runs #14580 lands first, this branch must be rebased and resolved by preserving both additive fields and their dedupe/projection paths; the product decisions remain independent.

Not a duplicate of #14375 (merged). That one narrows when a phantom working may be minted after a restart with no cached lead — buildClaudeCachedLeadStatusPayload's evidence path. This PR does not change any state value at all; it annotates a working that #14375 already agrees is legitimate. The evidence-minted working in that path is correctly left unmarked here: no lead boundary was observed, so there is nothing to claim finished.

Linked Issue

Related: #14253 (presentation half only; completion notifications remain tracked separately).

Linear: STA-4119. Same mechanism as #13245.

Visual Proof

Captured live over CDP against an isolated Orca dev instance launched from this worktree, driving the real store through setAgentStatus and reading the rendered accessibility tree.

Worktree card + agent rows — before (all spinning) → after (card green, rows static ring, child row still spinning):

4119-before-card.png

4119-after-card.png

Terminal tab glyph — before → after:

4119-before-tab1.png

4119-after-tab1.png

Rendered accessibility tree, same instance, same panes:

node before after
worktree card Working main primary Done main primary
tab 1 Working Terminal 1 Done Terminal 1
tab 2 Working Terminal 2 Done Terminal 2
agent row 1 Working wire up the release checklist - Bash: npm run dev Background work wire up the release checklist - Claude
agent row 2 Working start the dev server - Bash: npm run dev Background work start the dev server - Claude
subagent child Working scan the repo - explore Working scan the repo - explore

Then re-published a plain working (a new foreground turn while the background work persists) on the same panes: card, both tabs and both rows all returned to Working. The marker round-trips.

Design: no new tokens, no new color tier. background reuses the existing AgentWorkingSpinner ring in its documented reduced-motion form (complete ring, no rotation — #9515 already established that as "an intentional static marker"), so it stays in the working color family because work really is running, and loses the motion because nothing is happening in the turn the user is watching.

Testing

  • I manually tested these changes locally — live Electron/CDP session above (macOS).
  • Automated tests added/updated

Two new suites, 24 cases, both proven red on main by reverting each production seam in turn:

src/shared/claude-foreground-idle-background-work-status.test.ts (14) — replays real hook sequences through the real normalizeHookPayload:

  • live monitor at lead Stop; long-lived background shell; background subagent (and its row stays working); active session cron
  • the later all-clear drops the marker
  • a new foreground turn while background work persists clears it, and the next Stop re-sets it
  • an interrupted turn is never marked
  • an answered child question restoring a finished lead is marked
  • a roster hydrated from a restart snapshot is marked
  • wire contract: clamped to working; non-boolean values rejected; survives pickParsedAgentStatusPayload; an older peer that never stamps it reads as ordinary foreground work; an older receiver drops it on parse

src/renderer/src/components/sidebar/background-only-agent-presentation.test.ts (10) — card summary, tab glyph, row dot:

  • foreground working still spins on every surface
  • background-only reports hasLiveDone / done / background
  • a stale marker on a non-working row is ignored
  • live subagent child rows stay working under a background-only parent
  • interrupted still wins
  • the row is still a fresh non-done status, so keep-awake and hibernation see live work

Reverting agent-hook-listener.ts alone turns 7 listener cases red; reverting the three presentation seams turns 3 presentation cases red.

Also run: pnpm typecheck (node + cli + web) exit 0; oxlint + oxfmt --check clean on every touched file; pnpm exec vitest run over src/shared, src/main, src/renderer/src/components, src/renderer/src/store, src/renderer/src/hooks, src/renderer/src/lib, src/renderer/src/runtime — 800 files / 7998 tests green.

Review

  • Security — backgroundOnly arrives from an untrusted agent hook payload. It is accepted only as literal true and only on working; every other type or state normalizes to undefined, exactly like interrupted and sessionBoundary. It is never parsed, formatted into a path, or interpolated into a command. Worst case a hostile value makes that pane's own dot quieter; it cannot cross panes or suppress another agent's state.
  • Cross-platform — pure state resolution plus renderer presentation. No shell, path, keyboard, label, or Electron platform branch. The reporter is on Windows; nothing here is platform-conditional.
  • Remote SSH / mixed versions — the field rides ParsedAgentStatusPayload, which is what AgentHookRelayEnvelope.payload already carries and what ingestRemote re-validates at the trust boundary, so the relay path needs no change. New host → old client: normalizeAgentStatusObject rebuilds field-by-field and drops the unknown key, so the client renders today's spinner. Old host → new client: the field is simply absent and the row reads as ordinary foreground work. Additive-optional both ways, no new stream opcode, no capability gate needed — unlike sessionBoundary, an old peer cannot misact on it, since ignoring it reproduces current behavior exactly. Both directions are pinned by tests.
  • Folder workspaces — nothing here reads git state, worktree kind, or repo layout; attribution is by paneKey / tabId as before.
  • Mobile — RuntimeWorktreeAgentRow.backgroundOnly is forwarded so worktree ps and paired clients can see it. Mobile's own row rendering is deliberately unchanged in this PR (same scope call #14375 made for restoredUnconfirmed); paired clients that predate the field decode fine and render working. Mobile presentation parity is a clean follow-up on top of the now-available field.
  • Backwards compatibility — a pane with no background work never reaches the marked branch, so the overwhelmingly common case is byte-identical. AGENT_STATUS_STATES is unchanged; AgentStatusState gains no member.
  • Performance — one boolean per gated event, and one extra !== in the store's sort-relevance check. The new epoch term is required, not incidental: the whole transition is working → working, so without it the memoized card/tab summaries would never recompute. Same reason equivalentParsedAgentStatusPayload in agent-hooks/server.ts now compares it — deduping that edge would drop the fix before any receiver saw it.

Deliberately out of scope

  • Smart sort / smart attention is unchanged: a background-only pane stays in Class 3 (working). Background work is real work, so ordering by it is not a false claim, and the honest completion timestamp for the ranking is turnCompletedAt — which is fix(agent-status): announce Claude turn complete while background work runs #14580's field, not this one. Worth revisiting once both land.
  • Mobile row rendering, as above.

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • 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)
  • Focused typecheck / lint / tests pass locally (full pnpm build left to CI)

Author

  • X / Twitter: @BrennanKB5

…ve work (STA-4119)

When a Claude lead turn ends while background work is still registered
(background shell, subagent, monitor, session cron), resolveClaudePaneState
gates the pane up to `working`. That is right for liveness — the work really
is running — but it made the worktree card, tab glyph and agent row draw a
finished turn as an active foreground spinner for the whole background
lifetime.

Carry the gate's provenance as an optional `backgroundOnly` marker instead of
discarding it. `state` stays `working`, so keep-awake, auto-hibernation,
teardown and every freshness gate are untouched; only surfaces that render
FOREGROUND activity consult the marker.

Fixes #14253
@coderabbitai

coderabbitai Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@brennanb2025, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 50 seconds

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1e3542e7-cb1b-4868-8ea7-2158898ed2c9

📥 Commits

Reviewing files that changed from the base of the PR and between 8450617 and a8d6c0f.

📒 Files selected for processing (24)
  • src/main/agent-hooks/hook-status-session-tabs-invalidation.test.ts
  • src/main/agent-hooks/hook-status-session-tabs-invalidation.ts
  • src/main/ipc/dashboard-payload-validation.test.ts
  • src/main/ipc/dashboard-payload-validation.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/renderer/src/components/activity/ActivityPrototypePage.test.ts
  • src/renderer/src/components/activity/ActivityPrototypePage.tsx
  • src/renderer/src/components/dashboard-popout/AgentKanbanCard.test.tsx
  • src/renderer/src/components/dashboard-popout/AgentKanbanCard.tsx
  • src/renderer/src/components/dashboard-popout/AgentMapWorktreeRingNode.tsx
  • src/renderer/src/components/dashboard-popout/AgentTerminalDialog.test.tsx
  • src/renderer/src/components/dashboard-popout/AgentTerminalDialog.tsx
  • src/renderer/src/components/dashboard-popout/agent-map-node-presentation.test.ts
  • src/renderer/src/components/dashboard-popout/agent-map-node-presentation.ts
  • src/renderer/src/components/dashboard-popout/dashboard-agent-status-patch.test.ts
  • src/renderer/src/components/dashboard-popout/dashboard-agent-status-patch.ts
  • src/renderer/src/components/dashboard/build-dashboard-snapshot.test.ts
  • src/renderer/src/components/dashboard/build-dashboard-snapshot.ts
  • src/renderer/src/components/editor/ReviewNotesSendMenuContent.test.tsx
  • src/renderer/src/components/editor/ReviewNotesSendMenuContent.tsx
  • src/renderer/src/runtime/web-session-tabs-sync.test.ts
  • src/renderer/src/runtime/web-session-tabs-sync.ts
  • src/shared/dashboard-snapshot.ts
📝 Walkthrough

Walkthrough

The change adds an optional backgroundOnly marker to agent status contracts and propagates it through Claude state resolution, runtime projections, IPC handling, synchronization, and storage. Renderer activity summaries, dashboard rows, sidebar rows, terminal tabs, and state indicators now distinguish background work from foreground work. Tests cover lifecycle transitions, presentation states, liveness, and wire-contract validation.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR fixes stale foreground presentation, but #14253 also requires completion notifications to fire, which this PR explicitly leaves to #14580. Address the completion notification requirement in this PR or link an explicit dependent change that implements it.
✅ Passed checks (4 passed)
Check name Status Explanation
Out of Scope Changes check ✅ Passed The changes remain focused on propagating and presenting background-only activity, with related tests and compatibility handling.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title clearly identifies the agent-status fix and accurately summarizes the foreground-idle rendering change.
Description check ✅ Passed The description covers the required sections, explains the change and rationale, provides visual proof, testing details, review considerations, and checklist results.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

@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: Pro Plus

Run ID: 6d8f8906-23a5-4d08-a101-8a813c3077ad

📥 Commits

Reviewing files that changed from the base of the PR and between 9bb8836 and 8450617.

📒 Files selected for processing (19)
  • src/main/agent-hooks/server.ts
  • src/main/runtime/orca-runtime.ts
  • src/renderer/src/components/AgentStateDot.tsx
  • src/renderer/src/components/AgentWorkingSpinner.tsx
  • src/renderer/src/components/dashboard/DashboardAgentRow.tsx
  • src/renderer/src/components/sidebar/background-only-agent-presentation.test.ts
  • src/renderer/src/components/sidebar/worktree-agent-activity-summary.ts
  • src/renderer/src/components/sidebar/worktree-card-agent-summary.ts
  • src/renderer/src/components/sidebar/worktree-card-compact-agent-row.tsx
  • src/renderer/src/components/tab-bar/terminal-tab-activity-status.ts
  • src/renderer/src/hooks/useIpcEvents.ts
  • src/renderer/src/runtime/web-session-tabs-sync.ts
  • src/renderer/src/store/slices/agent-status.ts
  • src/shared/agent-background-only-activity.ts
  • src/shared/agent-hook-listener.test.ts
  • src/shared/agent-hook-listener.ts
  • src/shared/agent-status-types.ts
  • src/shared/claude-foreground-idle-background-work-status.test.ts
  • src/shared/runtime-types.ts

Comment on lines +45 to +46
case 'background':
return 'Background work'

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

Localize the new background label.

agentStateLabel('background') supplies accessible labels and tooltip text. The raw Background work string remains English for localized renderer sessions. Add the generated renderer locale key and use translate.

Based on learnings, generate locale keys from the first 10 characters of the SHA-1 hash of <filePath>:<text>.

Source: Learnings

Carry the background-only marker through dashboard snapshots and live popout patches so the board, map, and notes target menu do not retain a foreground spinner. Keep the agent state and dashboard grouping working for liveness.
@brennanb2025

Copy link
Copy Markdown
Contributor Author

QA visual proof (isolated Electron, HEAD a8d6c0fd451f2f94200681aed1f2040e2996aed8)

Identity — window.api.app.getIdentity(): name=Orca: brennanb2025/sta-4119-foreground-idle-status, devBranch=brennanb2025/sta-4119-foreground-idle-status, devWorktreeName=sta-4119-foreground-idle-status, devRepoRoot=/Users/brennanbenson/orca/workspaces/orca/sta-4119-foreground-idle-status. Isolated launch: ORCA_DEV_USER_DATA_PATH=/var/folders/1y/_t14pyzd3qqdml33sfq8b34w0000gn/T/orca-electron-profile.TdkJRF, CDP 127.0.0.1:9334, renderer 127.0.0.1:5175.

Actions — added a temp git repo, opened two real terminal tabs, published setAgentStatus({state:'working'}) then setAgentStatus({state:'working', backgroundOnly:true, subagents:[{state:'working', agentType:'explore'}]}), then republished ordinary working. Exercised the rendered worktree card, tab glyphs, sidebar agent rows, Agent Dashboard board + AgentTerminalDialog, and Activity (status grouping). No code changes.

Rendered a11y (same instance)

surface foreground working working + backgroundOnly
worktree card Working main primary Done main primary
tab 1 / tab 2 Working Terminal 1/2 Done Terminal 1/2
parent rows Working … - Bash: npm run dev Background work … - Claude
child row n/a Working scan the repo - explore
dashboard grouping Working: 2 Working: 2 (still live)
dashboard cards main Working … main Background work …
AgentTerminalDialog Claude · Working Claude · Background work
Activity — region Working activity / rows Background work

Console: 0 errors (pre-existing tooltip / React Grab / xterm deadline warnings only).

Gap — drawer Agent Map hands off to dashboard.openPopout('map'); that pop-out did not appear as a CDP target, so map pixels were not captured. Board / Activity / dialog all used the same Background work label while grouping stayed Working.

Evidence

Foreground working (card + tabs + rows spinning):

01-foreground-working-card-tabs-rows.png

Background-only: card/tabs settle; parent rows still ring + Background work; child stays Working:

02-background-only-card-tabs-rows.png

Dashboard board stays in WORKING with Background work cards:

03-dashboard-board-background-work.png

Board child remains Working:

04-dashboard-board-subagent-working.png

AgentTerminalDialog reads Claude · Background work:

05-agent-terminal-dialog-background-work.png

Activity group WORKING, rows Background work:

08-activity-background-work-working-group.png

Ordinary working restores the spinner:

09-restored-foreground-working.png

Dialog restores Claude · Working:

10-restored-dialog-working.png

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Closing after reviewing the original Codex/Claude transcripts and screenshot: the foreground was idle while a real Claude monitor was still running and visibly reported in the TUI, so the existing working state is correct and this presentation change is unnecessary.

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