Skip to content

fix(agent-status): announce Claude turn complete while background work runs - #14580

Merged
brennanb2025 merged 25 commits into
mainfrom
brennanb2025/issue-13245-turn-notification-supersede
Aug 17, 2026
Merged

brennanb2025 merged 25 commits into
mainfrom
brennanb2025/issue-13245-turn-notification-supersede

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 17 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2030 $\color{#cf222e}{\Huge{\mathbf{−}}}$​5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2025
Prod 18 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​690 $\color{#cf222e}{\Huge{\mathbf{−}}}$​81 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​609

ELI5

When Claude finishes a turn but still has a background subagent, shell, or session cron running, Orca kept the pane marked working. That is right for the sidebar spinner. It was wrong for the completion banner: the turn was already over, and the user was not told. This PR announces the finished turn immediately, while the pane can stay working for the leftover background work.

What Changed

Independently implemented from current main (not a merge of #13251 or #13295).

  • Stamp turnCompletedAt on a Claude lead Stop/StopFailure that resolveClaudePaneState gates up to working.
  • Hold that end time on the lead-turn record and repeat it on the later all-clear done.
  • The completion coordinator announces as soon as the stamped row arrives, without running done lifecycle while the pane is still genuinely working.
  • The later all-clear is recognized as that same turn's tail, not a second completion.
  • Notification identity and the OS notification id come from turnCompletedAt when present, because stateStartedAt is pinned for the whole working run.

#13251 and #13295 are left open. Useful insights from both are credited below; this branch replaces them wholesale against current main.

Why

resolveClaudePaneState is correct for pane lifecycle: leftover background work should keep the sidebar spinning. It must not gate the turn-complete announcement.

Replayed the issue sequences through the real normalizeHookPayload → observeAgentHookCompletionForNotification path, with stateStartedAt pinned the way the hook server pins it:

scenario main this PR
background subagent, one turn 1 banner when the child drains, carrying the earlier turn's text 1 banner at Stop, that turn's own text
background shell, turn N then N+1 turn N lost; only a later unblocked turn notifies 2 banners, distinct notification ids
persistent session cron, 3 turns 0 banners 3 banners, three distinct ids

A boolean "already notified" flag (the #13251 approach) stays sticky until a later done. Background shells and crons never emit that done for turn N, so the flag swallows turn N+1. Deriving identity from stateStartedAt + 1 also collapses every turn in one working-run onto one OS notification id. Keying both the announcement and the suppression on the turn's own end time removes both failures.

Related Windows report of the same suppression: #14253 / STA-4119.

Linked Issue

Fixes #13245

Visual Proof

N/A. No layout, styling, or sidebar-state change. The pane still reports working for the background lifetime; only the completion-notification timing and identity change. Proof is the hook-sequence replay in agent-hook-completion-background-turn-notifications.test.ts.

Testing

  • Automated tests added/updated
  • I manually tested these changes locally — not a visual UI change; OS banners depend on a live Claude session with background inventory. Reproduction and proof are the real listener + coordinator sequences below.

Replayed on current main first: gated Stop stays working, so the coordinator never sees a working → done edge (subagent: delayed until SubagentStop; shell/cron: no done at all).

pnpm exec vitest run --config config/vitest.config.ts \
  src/shared/agent-status-types.test.ts \
  src/shared/agent-hook-listener.test.ts \
  src/shared/claude-background-task-status.test.ts \
  src/renderer/src/components/terminal-pane/agent-completion-coordinator.test.ts \
  src/renderer/src/components/terminal-pane/use-notification-dispatch.test.ts \
  src/renderer/src/hooks/agent-hook-completion-background-turn-notifications.test.ts \
  src/renderer/src/hooks/agent-hook-completion-notifications.test.ts \
  src/renderer/src/hooks/useIpcEvents.test.ts \
  src/main/agent-hooks/server.claude-interactive-question.test.ts

Also tsc --noEmit for web + node, and oxlint on the touched production files.

Cross-platform: no shell, path, shortcut, or platform-branch changes. The only platform-adjacent surface is OS notification identity, which still goes through buildAgentNotificationId. New optional turnCompletedAt is wire-safe (unknown keys ignored); old hosts simply do not stamp it.

AI Disclosure

Internal.

Review

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 (full pnpm lint / pnpm test / pnpm build left to CI)

Author

  • X / Twitter: @BrennanKB5

…k runs

Lead Stop/StopFailure already ends the turn, but resolveClaudePaneState keeps
the pane working for subagents, background shells, and session crons. That
erases the working→done edge that mints the completion banner: subagent turns
notify late with a stale body, and shells/crons never notify at all.

Stamp turnCompletedAt on the gated lead Stop, announce immediately from that
row, and pair the later all-clear done to the same end time so it cannot
double-fire or collapse consecutive turns onto the pinned stateStartedAt.

Fixes #13245
@coderabbitai

coderabbitai Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e386b7f9-2541-42d1-8051-f4216e0c9dbe

📥 Commits

Reviewing files that changed from the base of the PR and between c72a864 and 20b9821.

📒 Files selected for processing (5)
  • src/main/agent-hooks/server.test.ts
  • src/main/agent-hooks/server.ts
  • src/renderer/src/components/terminal-pane/agent-completion-coordinator-dispose-leak.test.ts
  • src/renderer/src/components/terminal-pane/agent-completion-coordinator.test.ts
  • src/renderer/src/components/terminal-pane/agent-completion-coordinator.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/renderer/src/components/terminal-pane/agent-completion-coordinator.test.ts

📝 Walkthrough

Walkthrough

Added turnCompletedAt to agent status payloads with finite-number validation for working and done states. Claude lifecycle handling now records and restores the timestamp across gated stops and child-task transitions. Completion coordination announces completed turns while panes remain working and prevents duplicate notifications. Runtime projection and web session synchronization preserve completion metadata across paired sessions. Regression tests cover lifecycle, deduplication, remounts, vetoed stops, and background turns.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 45.45% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The implementation satisfies issue #13245 by announcing completed turns promptly, preserving message timing, deduplicating all-clear tails, and distinguishing consecutive turns.
Out of Scope Changes check ✅ Passed The production changes and extensive regression tests remain focused on turn-completion timestamps, notification timing, identity, and background-work handling.
Title check ✅ Passed The title clearly identifies the main fix: announcing Claude turn completion while background work continues.
Description check ✅ Passed The description follows the required template, explains the change and rationale, links issue #13245, documents testing, and addresses compatibility considerations.
✨ Finishing Touches 💡 1
📝 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.

… ordering

The stored row inherited the helper's default codex agentType while the event
named claude, so agentSnapshotMatchesExplicitTitle dropped it and
freshStoredAgentStatus was undefined — the assertion held under either side of
the `??`. Name the stored row's agent so the pinned working row survives and
the snapshot-first precedence is what the test actually pins.

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

🧹 Nitpick comments (1)
src/main/runtime/orca-runtime.ts (1)

31394-31418: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Consolidate the repeated hook-row lookup for paneKey.

getHookAgentRowForPane(getHookRowsForPane(paneKey)) can run up to three times for the same pane inside this method: once for hookAgentStatus (when tab.agentStatus is set), once inside buildPtyMobileAgentStatus, and again here as the turnCompletedAt fallback. getHookRowsForPane caches the raw rows, but getHookAgentRowForPane re-scans those rows each call.

This method runs on every tab during every graph sync. Compute the hook agent row once per pane and pass it into buildPtyMobileAgentStatus and the turnCompletedAt fallback, instead of gating hookAgentStatus on tab.agentStatus and re-deriving it later.

♻️ Proposed consolidation
-      const hookAgentStatus = tab.agentStatus
-        ? this.getHookAgentRowForPane(getHookRowsForPane(paneKey))
-        : null
+      const hookAgentStatus = this.getHookAgentRowForPane(getHookRowsForPane(paneKey))

Then reuse hookAgentStatus directly in the rawTurnCompletedAt fallback instead of calling getHookAgentRowForPane a second time, and pass the already-computed row into buildPtyMobileAgentStatus so it stops recomputing it internally.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4e83f9a1-fe14-47b4-8437-6a6c9626e0c3

📥 Commits

Reviewing files that changed from the base of the PR and between f3f1b9c and 94e7f30.

📒 Files selected for processing (7)
  • src/main/runtime/orca-runtime-hook-agent-status-projection.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/renderer/src/runtime/web-runtime-session.ts
  • src/renderer/src/runtime/web-session-tabs-agent-completion-notifications.test.ts
  • src/renderer/src/runtime/web-session-tabs-sync.test.ts
  • src/renderer/src/runtime/web-session-tabs-sync.ts
  • src/shared/runtime-types.ts

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Final-head QA — #13245 / d60c8e7bb462fc7e2b854bae3608189a3cdb5c3b

Result: PASS on exact pushed head d60c8e7bb462fc7e2b854bae3608189a3cdb5c3b (worktree HEAD, upstream, and GitHub PR head matched; worktree clean before and after).

Commands / fixture

Isolated Electron from this worktree (ORCA_DEV_USER_DATA_PATH + renderer 127.0.0.1:5176, CDP 9336). Interaction was agent-browser --session orca-13245-qa --cdp 9336 only. No Playwright e2e runner, computer-use, or OS-level input.

Truthful production fixture: HTTP POST to this instance’s hook server (user-data/agent-hooks/.../endpoint.env → POST /hook/claude), the same path live Claude hooks use. Sequence taken from the issue / existing hook-replay fixture:

  1. UserPromptSubmit → SubagentStart → gated Stop (background subagent still running, body Which cells need hand-verification?) → remount by switching worktrees → SubagentStop all-clear
  2. Two later turns with a persistent background shell: Dev server is up. then Route added.

Assertions

  • At the gated Stop, the pane stayed working with the live general-purpose child, while a completion notification was raised immediately (in-app fallback toast: “macOS is blocking Orca notifications”).
  • Banner/toast body context matched the current assistant text, not a later drain.
  • After remount + SubagentStop, the row went done and no second toast / delayed all-clear replay appeared.
  • unreadAgentCompletionPanes flipped at Stop, not at drain.
  • Background-shell turns 2 and 3 each updated the visible row to that turn’s own text while remaining working. last-status.json stamped turnCompletedAt on the gated Stop (1786757358618) while stateStartedAt stayed pinned (1786757355817).

Screenshots

Before (idle):

01-before-hooks-main-terminal.png

Switched off the Claude pane (so unread/OS path can fire):

02-switched-to-secondary-before-stop.png

Stop while background subagent is still alive — working spinner + current text + notification fallback:

03-after-stop-unread-while-background-alive.png

Remount visit (still working, same turn text):

04-remount-visit-main.png

After all-clear — done, no duplicate toast:

06-after-allclear-no-duplicate.png

Later shell-gated turns, current text each time, still working:

08-after-second-turn-stop-shell-still-alive.png
09-after-third-turn-stop-shell-still-alive.png

Cleanup

Stopped only the isolated Electron process group started for this QA (run-electron-vite-dev.mjs + user-data under /var/folders/.../orca-13245-qa.djLxuV). Closed only the orca-13245-qa agent-browser session. No source edits, commits, or pushes.

Limitations

  • This isolated profile has macOS notification permission blocked, so the native banner was not visible; the user-visible proof is the in-app blocked-notification toast (first dispatch only; that toast is session-once) plus sidebar working/done and unread state.
  • Fixture is the real hook HTTP server, not a live Claude CLI binary.
  • Local remount via worktree switch was exercised. A paired remote client remount was not: the existing QA fixture does not stand up a paired host without product/setup changes.

…245-turn-notification-supersede

# Conflicts:
#	src/main/agent-hooks/server.test.ts
#	src/renderer/src/components/terminal-pane/agent-completion-coordinator.test.ts
#	src/renderer/src/hooks/useIpcEvents.test.ts
#	src/renderer/src/runtime/web-session-tabs-sync.test.ts
#	src/renderer/src/runtime/web-session-tabs-sync.ts
#	src/shared/agent-hook-listener.test.ts
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Final-head QA — #13245 / eff10052db63a36b16db61d900f745e324bb3a61

Result: PASS on exact pushed head eff10052db63a36b16db61d900f745e324bb3a61 (worktree HEAD, upstream, remote branch tip, and GitHub PR head all matched; worktree clean before and after). The older evidence comment on d60c8e7bb462fc7e2b854bae3608189a3cdb5c3b was not reused.

Interaction / fixture

Isolated Electron from this worktree (ORCA_DEV_USER_DATA_PATH + renderer http://localhost:5173/, CDP 9333). Identity: devLabel=issue-13245-final-qa, branch brennanb2025/issue-13245-turn-notification-supersede. Interaction was agent-browser --session orca-13245-final-qa --cdp 9333 only. No Playwright e2e runner, computer-use, or OS-level input.

Truthful production fixture: HTTP POST to this instance’s hook server (user-data/agent-hooks/.../endpoint.env → POST /hook/claude), the same path live Claude hooks use. Two disposable folder workspaces (fixture-a / fixture-b) so the Claude pane could be unfocused and remounted. Sequence:

  1. UserPromptSubmit → SubagentStart → gated Stop (background general-purpose still running, body Which cells need hand-verification?) → remount by switching workspaces → SubagentStop all-clear
  2. Two later turns with a persistent background shell: Dev server is up. then Route added.

Assertions

  • At the gated Stop, the pane stayed working with the live general-purpose child, while unreadAgentCompletionPanes flipped immediately. Sidebar body was that turn’s assistant text (review the PR - Which cells need hand-verification?), not a later drain.
  • After remount, the row stayed working with the same turn text and the child still alive. No second completion appeared.
  • After SubagentStop, the row went done with the same text. unreadAgentCompletionPanes stayed empty even though the Claude pane was not focused, so the all-clear did not duplicate the announcement.
  • Background-shell turns 2 and 3 each updated the visible row to that turn’s own text while remaining working, and each flipped unread again after a visit/leave. last-status.json stamped distinct turnCompletedAt values (1786930619738 then 1786930637681) while stateStartedAt stayed pinned (1786930619127).

Commands / tests

pnpm exec vitest run --config config/vitest.config.ts \
  src/renderer/src/hooks/agent-hook-completion-notifications-import.test.ts \
  src/renderer/src/hooks/agent-hook-completion-fresh-working.test.ts

Both passed on this SHA (import does not call Zustand static getState; a stamped working completion after re-enable cannot satisfy the post-enable boundary).

Screenshots

Before (idle):

01-before-hooks-main-terminal.png

Switched off the Claude pane (so unread/OS path can fire):

02-switched-to-secondary-before-stop.png

Stop while background subagent is still alive — working spinner + current text + unread:

03-after-stop-unread-while-background-alive.png

Remount visit (still working, same turn text, child still alive):

04-remount-visit-main.png

After all-clear — done, no duplicate unread:

06-after-allclear-no-duplicate.png

Later shell-gated turns, current text each time, still working:

08-after-second-turn-stop-shell-still-alive.png
09-after-third-turn-stop-shell-still-alive.png

Cleanup

Stopped only the isolated Electron process group started for this QA (run-electron-vite-dev.mjs + user-data under /tmp/orca-13245-final-qa.z4UQMc). Closed only the orca-13245-final-qa agent-browser session. No source edits, commits, or pushes. Contributor PRs #13251 and #13295 were not touched.

Limitations

  • This isolated profile did not surface the in-app “macOS is blocking Orca notifications” fallback toast, and the native OS banner is not visible over CDP. User-visible proof is sidebar working/done, unread flip at Stop (not drain), and current-turn text.
  • Fixture is the real hook HTTP server, not a live Claude CLI binary.
  • Local remount via workspace switch was exercised. A paired remote client remount was not.

@brennanb2025
brennanb2025 merged commit 5e9e38f into main Aug 17, 2026
45 checks passed
@ethznn

ethznn commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

The description says insights from #13251 and #13295 are credited below, but I can't find that section — was it dropped before merge?

The two-failure analysis under "Why" — the sticky boolean swallowing turn N+1, and stateStartedAt + 1 collapsing every turn in one working run onto a single notification id — is what I posted on #13295 and in my review of #13251. A Co-authored-by trailer or a line in the body would settle it. Would appreciate you taking a look.

@ethznn

ethznn commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

@brennanb2025 — flagging the above in case it got buried. No urgency.

paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 21, 2026
…k runs (stablyai#14580)

* fix(agent-status): announce Claude turn complete while background work runs

Lead Stop/StopFailure already ends the turn, but resolveClaudePaneState keeps
the pane working for subagents, background shells, and session crons. That
erases the working→done edge that mints the completion banner: subagent turns
notify late with a stale body, and shells/crons never notify at all.

Stamp turnCompletedAt on the gated lead Stop, announce immediately from that
row, and pair the later all-clear done to the same end time so it cannot
double-fire or collapse consecutive turns onto the pinned stateStartedAt.

Fixes stablyai#13245

* fix(agent-status): suppress stamped turn replays

* fix(agent-status): notify paired clients at turn end

* Fix late-paired completion notification arming

* test(agent-status): make the notification-id test fail on the pre-fix ordering

The stored row inherited the helper's default codex agentType while the event
named claude, so agentSnapshotMatchesExplicitTitle dropped it and
freshStoredAgentStatus was undefined — the assertion held under either side of
the `??`. Name the stored row's agent so the pinned working row survives and
the snapshot-first precedence is what the test actually pins.

* Suppress stamped completion tail replays

* Prevent cross-coordinator title replays

* Preserve stamped tails across fallback signals

* Keep remount replay state while sibling lives

* Scope OSC turn stamp preservation

* Forward paired host completion stamps

* Deduplicate paired completion tails

* Bind paired completion tails to their turn

* Preserve paired completion tail ownership

* Keep paired tail replay state across remounts

* Seed paired recovery without replaying completions

* Seed startup replay and release stale fallback dedupe

* fix(notifications): preserve stamped OSC repaints

* fix(notifications): retain paired client turn boundary

* fix notifications module import safety

* chore: keep main integration focused

* fix: preserve completion re-enable boundary
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…k runs (stablyai#14580)

* fix(agent-status): announce Claude turn complete while background work runs

Lead Stop/StopFailure already ends the turn, but resolveClaudePaneState keeps
the pane working for subagents, background shells, and session crons. That
erases the working→done edge that mints the completion banner: subagent turns
notify late with a stale body, and shells/crons never notify at all.

Stamp turnCompletedAt on the gated lead Stop, announce immediately from that
row, and pair the later all-clear done to the same end time so it cannot
double-fire or collapse consecutive turns onto the pinned stateStartedAt.

Fixes stablyai#13245

* fix(agent-status): suppress stamped turn replays

* fix(agent-status): notify paired clients at turn end

* Fix late-paired completion notification arming

* test(agent-status): make the notification-id test fail on the pre-fix ordering

The stored row inherited the helper's default codex agentType while the event
named claude, so agentSnapshotMatchesExplicitTitle dropped it and
freshStoredAgentStatus was undefined — the assertion held under either side of
the `??`. Name the stored row's agent so the pinned working row survives and
the snapshot-first precedence is what the test actually pins.

* Suppress stamped completion tail replays

* Prevent cross-coordinator title replays

* Preserve stamped tails across fallback signals

* Keep remount replay state while sibling lives

* Scope OSC turn stamp preservation

* Forward paired host completion stamps

* Deduplicate paired completion tails

* Bind paired completion tails to their turn

* Preserve paired completion tail ownership

* Keep paired tail replay state across remounts

* Seed paired recovery without replaying completions

* Seed startup replay and release stale fallback dedupe

* fix(notifications): preserve stamped OSC repaints

* fix(notifications): retain paired client turn boundary

* fix notifications module import safety

* chore: keep main integration focused

* fix: preserve completion re-enable boundary
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants