Repository navigation
fix(native-chat): alert when a structured chat asks for approval or input mid-turn - #25766
Conversation
…nput mid-turn A structured Claude or Codex chat that stopped mid-turn to ask for approval or a question raised no OS notification, no phone push and no unread dot: the host's attention feed only fired when a turn settled. The host now announces each newly pending prompt once, from the same feed, and owns the phone push for its own structured sessions; desktops keep presentation only. - host feed: a `prompt` edge per pending approval/question, opt-in on the existing stream; a clean settle that only restates an announced prompt is not re-announced to prompt-aware clients; failures always are - host push: an in-process subscriber pushes the host's paired phones with labels from in-memory metadata, and withdraws a prompt's alert once answered - one attention identity for desktop banner, phone push, dedupe and retirement; delivery dedupes on it instead of the per-workspace burst window - agentSession.acknowledgeAttention routes reading a chat to its owning host, which retires what it pushed for that session via its dismissal record
Review summary (final head
|
…2025/nc-prompt-attention
…2025/nc-prompt-attention
- Mark read and Mark all read on a chat that was never opened, or is hidden, now cover what lit its row: the read boundary is the later of the transcript cursor and the newest edge the tab was handed, captured at the click. The one boundary closes the banners, retires relayed phone alerts and drives the host acknowledgement; an edge after the click stays live. - An alert from a host older than journal cursors has no position, so a pane read retires it again, banner and relayed phone push, as before this change. - A desktop-relayed prompt alert for a remote chat is withdrawn once that host's live status stops reporting attention (answered elsewhere, cancelled, host restart); cached status after loss of contact never settles it. - The attention acknowledgement is agent-session.attention-ack.v1 with a required journal cursor and strict params; the cursorless no-op is gone. - The dismissal store keeps a record whose origin a newer build wrote, dropping only that origin. - Host reconciliation runs on restore and when a prompt leaves the pending set, not on every journal commit. - Remove unused session-wide retirement (retire, retireMatching, retireMobileNotificationsMatching) and test-only store lookups.
…view - A remote chat's status and its prompt edges arrive on separate sockets, so a status row queued before the prompt could land after it and withdraw a relayed alert that was still pending. Settlement now needs a live, non-attention row whose host updatedAt (the journal's latest row time, never decreasing) is later than the prompt's host raisedAt. The owed prompt is cleared only once the settle call succeeds, so a failed call retries on the next qualifying row. - An acknowledgement without captured reads now reads as a view. Mark read, Mark all read, the hover-card jump and both dashboard acks pass 'explicit'; Activity's automatic per-turn read stays a view.
…g is a view - Settlement is one check of the current mirror, run on each status row, after each settle call returns, and when a prompt edge arrives. A row that lands while a call is out is no longer dropped, and an edge that arrives after its own resolution settles at once. A rejected call is retried only once the mirror holds a different row, so a failing call cannot loop. - The Agent Dashboard's card click acknowledges as explicit; watching the open dialog acknowledges as a view, through both the in-window drawer and the pop-out relay, and no longer re-acks the state the click just read.
A chat pane memoizes its read owner. When every holder let go in one commit and the same owner was picked up again (React StrictMode's effect re-run in development, or a pane remounted in one commit, as on a tab move), the release dropped it from the registry and nothing put it back. The attention bridge then found no owner, so a view read carried no cursor: the unread dot cleared but the banner and phone alerts stayed. An owner now names its key again whenever it gains an activation or a subscriber and the key is free, never over a different live owner.
… ack retires by read
Main moved these types into agent-session-turn-completion-wire.ts while this branch moved them into agent-session-attention-wire.ts. They now live at main's path with this branch's additions (journal cursor, prompt attention, prompt arm); the unused completion key is dropped.
📝 WalkthroughWalkthroughThe change adds prompt events to structured agent-session attention streams and adds APIs for acknowledging reads. The renderer captures view and explicit reads, while host services use read cursors and prompt state to retire desktop and mobile notifications. Mobile delivery records structured origins and preserves the original delivery identity when retiring alerts. Notification wording uses the active desktop translation where available. Priority: ➖ Normal Merge Risk: 🔵 Low · up to Prompt alerts mostly work as intended. However, when an agent raises several approvals at the same moment, only one alert may appear. A rare delivery error could also stop phone alerts until the app restarts. Both fixes are small and local. 🚥 Pre-merge checks | ✅ 4 | ❓ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 13.64% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 44 functions across 50 files. (45 skipped: 45 over the file limit.) ✨ Finishing Touches 💡 2📝 Generate docstrings 💡
🛠️ Fix failing CI checks 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
c22eb892-d3b4-4407-8a73-88040f8420b8
⛔ Files ignored due to path filters (1)
src/shared/rpc-contract/rpc-params-catalog.generated.tsis excluded by!**/*.generated.*
📒 Files selected for processing (95)
mobile/src/notifications/desktop-notification-events.tsmobile/src/notifications/push-original-delivery-retirement.test.tsmobile/src/notifications/push-socket-dismissal.tssrc/main/host/electron-runtime-desktop-surface.tssrc/main/host/structured-attention-localization.test.tssrc/main/ipc/dashboard-popout.test.tssrc/main/ipc/dashboard-popout.tssrc/main/ipc/notification-options.tssrc/main/ipc/notifications-subject-retirement.test.tssrc/main/ipc/notifications-test-harness.tssrc/main/ipc/notifications.tssrc/main/native-chat/agent-session-wire/structured-agent-session-client-delivery.tssrc/main/native-chat/agent-session-wire/structured-agent-session-host.tssrc/main/native-chat/agent-session-wire/structured-agent-session-status-feed.tssrc/main/native-chat/agent-session-wire/structured-agent-session-turn-completion-feed.test.tssrc/main/native-chat/agent-session-wire/structured-agent-session-turn-completion-feed.tssrc/main/notifications/announced-notification-registry.test.tssrc/main/notifications/announced-notification-registry.tssrc/main/notifications/notification-delivery-service.test.tssrc/main/notifications/notification-delivery-service.tssrc/main/runtime/mobile-notification-dismissal-store.test.tssrc/main/runtime/mobile-notification-dismissal-store.tssrc/main/runtime/orca-runtime-get-worktree-ps.tssrc/main/runtime/push/push-delivery-policy.test.tssrc/main/runtime/push/push-dispatcher.tssrc/main/runtime/rpc/methods/structured-agent-session-attention-ack.test.tssrc/main/runtime/rpc/methods/structured-agent-session-rpc.test-fixture.tssrc/main/runtime/rpc/methods/structured-agent-session-schemas.tssrc/main/runtime/rpc/methods/structured-agent-session-turn-completion-stream.test.tssrc/main/runtime/rpc/methods/structured-agent-session-turn-completion-stream.tssrc/main/runtime/rpc/methods/structured-agent-session.test.tssrc/main/runtime/runtime-desktop-surface.tssrc/main/runtime/runtime-mobile-notification-controller.tssrc/main/runtime/runtime-service-command-surface.tssrc/main/runtime/structured-agent-session-mobile-attention.test.tssrc/main/runtime/structured-agent-session-mobile-attention.tssrc/main/runtime/structured-agent-session-mobile-restore.test.tssrc/main/runtime/structured-agent-session-mobile-retirement.test.tssrc/main/runtime/structured-agent-session-runtime.tssrc/main/runtime/structured-attention-original-delivery.test-fixture.tssrc/preload/api/dashboard-api.tssrc/preload/api/dashboard-bridge.tssrc/preload/api/notifications-bridge.tssrc/preload/api/os-permission-api.tssrc/renderer/src/attention/agent-subject-read-actions.tssrc/renderer/src/components/activity/activity-auto-mark-read-loop.react185.test.tsxsrc/renderer/src/components/activity/activity-thread-actions.test.tssrc/renderer/src/components/activity/activity-thread-actions.tssrc/renderer/src/components/activity/activity-thread-hover-card-summary.tsxsrc/renderer/src/components/activity/use-activity-thread-action-bindings.test.tsxsrc/renderer/src/components/activity/use-activity-thread-action-bindings.tssrc/renderer/src/components/dashboard-popout/AgentKanbanBoard.test.tsxsrc/renderer/src/components/dashboard-popout/AgentKanbanBoard.tsxsrc/renderer/src/components/dashboard/AgentDashboardDrawer.tsxsrc/renderer/src/components/dashboard/useDashboardPopoutBridge.tssrc/renderer/src/components/native-chat/StructuredAgentSessionAttentionBridge.test.tsxsrc/renderer/src/components/native-chat/StructuredAgentSessionAttentionBridge.tsxsrc/renderer/src/components/native-chat/structured-agent-session-read-owner-registry.tssrc/renderer/src/components/native-chat/structured-agent-session-read-owner.tssrc/renderer/src/components/native-chat/structured-attention-dispatch.test.tssrc/renderer/src/components/native-chat/structured-attention-dispatch.tssrc/renderer/src/components/native-chat/structured-attention-read-observation.tssrc/renderer/src/components/native-chat/use-structured-agent-session-read.tssrc/renderer/src/components/native-chat/use-structured-agent-session-transport.tssrc/renderer/src/hooks/agent-auto-ack-surfaces.tssrc/renderer/src/hooks/useAutoAckViewedAgent.tssrc/renderer/src/runtime/structured-agent-session-client.tssrc/renderer/src/runtime/structured-agent-session-turn-completion-feed.test.tssrc/renderer/src/runtime/structured-agent-session-turn-completion-feed.tssrc/renderer/src/store/slices/ui/ui-slice-activity-actions.tssrc/renderer/src/store/slices/ui/ui-slice-contract-core.tssrc/renderer/src/web/preload-api/web-notifications-api.tssrc/shared/agent-session-attention-capabilities.tssrc/shared/agent-session-attention.tssrc/shared/agent-session-turn-completion-wire.tssrc/shared/mobile-notification-identity.tssrc/shared/notification-settings-types.tssrc/shared/protocol-version.tssrc/shared/rpc-contract/structured-agent-session-identifiers.tssrc/shared/rpc-contract/structured-agent-session-params.tssrc/shared/structured-agent-session-projection.tssrc/shared/structured-agent-session-surface-capabilities.tstests/e2e/__mocks__/structured-attention-read-surfaces.tstests/e2e/cross-version-wire/cross-version-agent-session-wire.unit.test.tstests/e2e/cross-version-wire/cross-version-structured-attention-frames.unit.test.tstests/e2e/cross-version-wire/structured-agent-session-surface-execution.tstests/e2e/cross-version-wire/structured-agent-session-surface-manifest.tstests/e2e/structured-attention-explicit-read.unit.test.tstests/e2e/structured-attention-headless-delivery.unit.test.tstests/e2e/structured-attention-host-read-retirement.unit.test.tstests/e2e/structured-attention-prompt-relay.unit.test.tstests/e2e/structured-attention-read-owner-lifecycle.unit.test.tstests/e2e/structured-attention-read-retirement.test-fixture.tsxtests/e2e/structured-attention-read-retirement.unit.test.tstests/e2e/structured-attention-relay-settlement.unit.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
| // An answered prompt leaves the set, so only a prompt not pending last commit is news. | ||
| const raised = state.pendingPromptIds.find((id) => !baseline.prompts.has(id)) | ||
| baseline.prompts = prompts | ||
| const completion = this.settledCompletion(sessionId, session, state, baseline) | ||
| if (completion) { | ||
| completion.journalCursor = cursor | ||
| const restatesPrompt = completion.awaitingUser === true && completion.outcome === 'success' | ||
| this.broadcast({ type: 'completion', completion }, restatesPrompt ? 'legacy' : 'all') | ||
| if (!restatesPrompt) { | ||
| return | ||
| } | ||
| } | ||
| if (raised === undefined) { | ||
| return | ||
| } | ||
| this.broadcast( | ||
| { | ||
| type: 'prompt', | ||
| prompt: { | ||
| scope: session.params.location, | ||
| sessionId, | ||
| promptId: raised, | ||
| journalCursor: cursor, | ||
| raisedAt: this.deps.now() | ||
| } | ||
| }, | ||
| 'prompt-aware' | ||
| ) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Announce every prompt that a commit adds, not only the first one.
raised uses find, so it holds at most one new prompt id. Line 145 then adds every pending id to baseline.prompts. If one commit adds two prompts, for example two parallel subagent approvals in one batch, only the first gets a prompt edge. The second id never gets one, because later commits treat it as already seen.
There is a second consequence. The host's phone delivery and the desktop alert exist only for the first prompt. When the user answers that prompt, publishState reports the second prompt as still pending. reconcileStructuredPromptAttention then withdraws the first alert, so no alert is left while the agent still waits for input.
Send one prompt edge for each new id. Each id already has its own attention key, so delivery dedupe and retirement keep working.
🐛 Proposed fix
- const raised = state.pendingPromptIds.find((id) => !baseline.prompts.has(id))
+ const raised = state.pendingPromptIds.filter((id) => !baseline.prompts.has(id))
baseline.prompts = prompts
@@
- if (raised === undefined) {
- return
- }
- this.broadcast(
- {
- type: 'prompt',
- prompt: {
- scope: session.params.location,
- sessionId,
- promptId: raised,
- journalCursor: cursor,
- raisedAt: this.deps.now()
- }
- },
- 'prompt-aware'
- )
+ for (const promptId of raised) {
+ this.broadcast(
+ {
+ type: 'prompt',
+ prompt: {
+ scope: session.params.location,
+ sessionId,
+ promptId,
+ journalCursor: cursor,
+ raisedAt: this.deps.now()
+ }
+ },
+ 'prompt-aware'
+ )
+ }The doc comment on observe ("at most one event per subscriber") would need the same update.
📝 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.
| // An answered prompt leaves the set, so only a prompt not pending last commit is news. | |
| const raised = state.pendingPromptIds.find((id) => !baseline.prompts.has(id)) | |
| baseline.prompts = prompts | |
| const completion = this.settledCompletion(sessionId, session, state, baseline) | |
| if (completion) { | |
| completion.journalCursor = cursor | |
| const restatesPrompt = completion.awaitingUser === true && completion.outcome === 'success' | |
| this.broadcast({ type: 'completion', completion }, restatesPrompt ? 'legacy' : 'all') | |
| if (!restatesPrompt) { | |
| return | |
| } | |
| } | |
| if (raised === undefined) { | |
| return | |
| } | |
| this.broadcast( | |
| { | |
| type: 'prompt', | |
| prompt: { | |
| scope: session.params.location, | |
| sessionId, | |
| promptId: raised, | |
| journalCursor: cursor, | |
| raisedAt: this.deps.now() | |
| } | |
| }, | |
| 'prompt-aware' | |
| ) | |
| // An answered prompt leaves the set, so only a prompt not pending last commit is news. | |
| const raised = state.pendingPromptIds.filter((id) => !baseline.prompts.has(id)) | |
| baseline.prompts = prompts | |
| const completion = this.settledCompletion(sessionId, session, state, baseline) | |
| if (completion) { | |
| completion.journalCursor = cursor | |
| const restatesPrompt = completion.awaitingUser === true && completion.outcome === 'success' | |
| this.broadcast({ type: 'completion', completion }, restatesPrompt ? 'legacy' : 'all') | |
| if (!restatesPrompt) { | |
| return | |
| } | |
| } | |
| for (const promptId of raised) { | |
| this.broadcast( | |
| { | |
| type: 'prompt', | |
| prompt: { | |
| scope: session.params.location, | |
| sessionId, | |
| promptId, | |
| journalCursor: cursor, | |
| raisedAt: this.deps.now() | |
| } | |
| }, | |
| 'prompt-aware' | |
| ) | |
| } |
| emit: (event) => { | ||
| if (event.type === 'end') { | ||
| return | ||
| } | ||
| const sessionId = | ||
| event.type === 'prompt' ? event.prompt.sessionId : event.completion.sessionId | ||
| delivery.deliver(event, installed.readStatusSummary(sessionId)) | ||
| }, |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Keep one failed delivery from removing the host phone subscriber permanently.
When emit throws, the feed's broadcast catches the error and deletes the subscriber. Nothing subscribes host-attention-delivery again, so this host sends no phone alerts until the process restarts. Nothing is logged. emit runs readStatusSummary, buildNotificationOptions, getRuntimeDesktopSurface().isAwayForMobileNotifications and controller.dispatch. A throw from any of them costs every later alert on this host, not only the current one.
Catch the error inside the callback and log it, so one bad edge is dropped and the subscription survives.
🛡️ Proposed fix
emit: (event) => {
if (event.type === 'end') {
return
}
const sessionId =
event.type === 'prompt' ? event.prompt.sessionId : event.completion.sessionId
- delivery.deliver(event, installed.readStatusSummary(sessionId))
+ try {
+ delivery.deliver(event, installed.readStatusSummary(sessionId))
+ } catch (error) {
+ // One edge's failure must not unsubscribe host delivery for the rest of the run.
+ deps.logger.warn('structured attention delivery failed', {
+ scope: 'attention-delivery',
+ sessionId,
+ error
+ })
+ }
},The PR summary already lists this as a deferred limitation. The fix is local and small.
📝 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.
| emit: (event) => { | |
| if (event.type === 'end') { | |
| return | |
| } | |
| const sessionId = | |
| event.type === 'prompt' ? event.prompt.sessionId : event.completion.sessionId | |
| delivery.deliver(event, installed.readStatusSummary(sessionId)) | |
| }, | |
| emit: (event) => { | |
| if (event.type === 'end') { | |
| return | |
| } | |
| const sessionId = | |
| event.type === 'prompt' ? event.prompt.sessionId : event.completion.sessionId | |
| try { | |
| delivery.deliver(event, installed.readStatusSummary(sessionId)) | |
| } catch (error) { | |
| // One edge's failure must not unsubscribe host delivery for the rest of the run. | |
| deps.logger.warn('structured attention delivery failed', { | |
| scope: 'attention-delivery', | |
| sessionId, | |
| error | |
| }) | |
| } | |
| }, |
ELI5
When a built-in Claude or Codex chat stopped mid-task to ask for approval or a question, Orca stayed silent: no desktop notification, no unread dot, no phone alert. Only a finished turn alerted you, so an agent could sit waiting for hours while you were in another workspace. Terminal agents already alert in this situation; native chat did not.
After this change you get the same alerts for a mid-turn question that you already get for a finished turn: the unread dot, the desktop notification (with your existing notification settings), and a push to phones paired with the machine running the agent. Reading the chat, using Mark read / Mark all read, or answering the question withdraws that alert. A read never withdraws a newer question you have not seen yet.
What Changed
Why
The missing event belongs in the host's existing feed, because that host owns the session, knows when a prompt starts and ends, and owns its paired-phone delivery. A renderer-derived alert would add a second producer without the prompt identity needed to withdraw the right alert. A session-wide "read" would let a delayed read remove a newer question; bounding each read by the transcript position the user actually reached prevents that without a stored read flag or a retry obligation. Withdrawal of relayed remote alerts is derived from the host status the desktop already mirrors, so no new wire field is needed.
Differences from the common pattern:
Known limits (each has a workaround: open the chat, or swipe the phone alert):
Linked Issue
N/A — maintainer change from a native chat audit.
Visual Proof
Remote Electron QA ran on a separate Mac (M4Air) against the PR branch, with an isolated test profile and a scripted Codex stand-in that raises a real approval request mid-turn through the actual chat host. Dev builds on that machine cannot show macOS banners, so notification and phone delivery were checked through main-process logs plus the rendered app.
Background chat asks for approval: the workspace is marked as needing input (round 2, final head)

After opening the chat and clicking in it, the alert is withdrawn while the approval is still pending (round 2, final head; log showed the read at journal position 14 and the phone alert withdrawn)

Activity Mark read on a chat that is not open withdraws its alerts (round 1)


Answering the approval withdraws the prompt alert (round 1)

After restart, nothing re-alerts for resolved prompts (round 1)

Testing
Final head:
29d0bcebebd6578ac5ab56ff34b7c27cdbfa2db3(includes current maincc6006779ff).tc-gate pnpm tc:node,tc:webandtc:clipass.153 explicit test files / 1410 tests pass, including new production-path tests for: Mark read and Mark all read on never-opened chats, older-host alerts, remote prompts answered elsewhere / cancelled / host restart, status frames arriving out of order, failed withdrawal retry, dashboard click vs. watch intent, and the chat read tracker surviving a tab move. Each new test failed before its fix. Mobile typecheck and test-type checks pass.
Cross-version wire suites pass (session 41, registered agents 8, attention frames 4). Saved delivery history survives upgrade, rollback and re-upgrade (10/10, real main and PR store code against one file).
Changed-code quality: zero new findings across 96 files; oxlint and React Doctor pass; no lockfile or dependency change.
CI on the final head: 16 passed, 16 skipped, 0 failed (one unrelated timing test,
terminal-history-gc.test.ts, failed once and passed on re-run).Remote Electron QA (M4Air, isolated profile, scripted Codex stand-in, CDP-driven hidden window): a background mid-turn approval produced one desktop alert request and one phone push under the prompt's identity; answering withdrew it; Activity Mark read on an unopened chat withdrew all of its alerts; a normal background turn still alerted once as finished; restart did not re-alert. Round 1 found that opening a chat did not withdraw its alert; the cause was a real bug (fixed, see Review) plus the existing "user is away" check, which treats an untouched test machine as idle. Round 2 on the final head confirmed that a real click in the opened chat withdraws the pending prompt's phone alert. Not run in round 2: withdrawing a finished-turn alert by reading (the test app was closed by an outside quit of every dev Electron app on that machine); covered by automated tests. Not verified: a real phone receiving or clearing a push, a real macOS banner, foreground focus suppression, Windows/WSL, SSH remote hosts.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
AI Disclosure
Review
Review rounds found and fixed 21 proven issues (1 P1, 13 P2, 7 P3). The P1 was the headless host failing to load because the new phone producer imported desktop-only code. The P2s cover alert identity, delayed and out-of-order reads, restart withdrawal, older-host compatibility, Mark read on unopened chats, and withdrawal of remote alerts relayed to phones, and a chat losing track of what was read after a tab move. A final readiness review of all eight release categories found no release-blocking issue. Details, deferred items and what was not verified are in the review comment.
Agent skill upstream boundary
Notes
Draft, unmerged, auto-merge disabled.
Checklist
N/Awith reason