Repository navigation
feat(attention): light the unread indicators when a structured chat finishes - #21408
brennanb2025 wants to merge 1 commit into
Conversation
|
Important Review skippedWe couldn't safely recover the incremental review. No full review was started, and the last reviewed checkpoint was preserved. Retry later, or explicitly request a full review by commenting You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThe change adds live structured turn-completion events from session journals through runtime streams and renderer feeds. Structured completions now update attention markers, notifications, and auto-acknowledgement state. Structured tabs and attention surfaces support session addressing and visibility checks. Notification delivery now supports shared handling and mobile event-identity deduplication. Tests cover completion derivation, streaming, attention behavior, auto-acknowledgement, and deduplication. Priority: ➖ Normal Merge Risk: 🟡 Moderate · up to Unread indicators can remain stuck or be cleared for the wrong chat, and the changed test fails a required lint rule. These issues should be fixed before merging. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 2📝 Generate docstrings 💡
🛠️ Fix failing CI checks 💡
Comment |
There was a problem hiding this comment.
Important
Two required checks are red on this head and need fixing before merge: cross-version wire compatibility (the new agentSession.subscribeTurnCompletion method is missing from the cross-version manifest) and static analysis (an anti-slop/no-shape-in-symbol-names error, commented inline). A new shared wire module is also committed as a binary file.
Reviewed changes
First review of the full diff at 24be8a7c2d (38 files). Note the diff against main also carries #21274's commit 4e64e434b4, which is still open — the PR documents the stacking. The substantive changes:
- Host completion feed (
structured-turn-completion-feed.ts, new) — derives a settled root turn from the journal commit edge only (publishJournal), announces(scope, sessionId, turnId, outcome, completedAt), and baselines (never advances) on every other status edge. Live-only recovery: nothing persisted, subscriber opens on nothing,MAX_ACCOUNTED_TURNS = 128. - New stream (
agentSession.subscribeTurnCompletion,agent-session.turn-completion.v1) — per connection, opens on nothing, gated behind the structured capability. Method count 26 -> 27. - Wire codec (
src/shared/structured-turn-completion.ts, new) — loose-object zod decoding, closedoutcomeenum, normalized execution host, andstructuredTurnCompletionKey. - Renderer feed (
runtime/structured-turn-completion-feed.ts, new) — one owner per runtime target with backoff reconnect; drops frames this build cannot place. - Attention dispatch (
structured-turn-completion-attention.ts, new) — success only, routed through the existingresolveAgentAttentionpolicy via the structured surface adapter, writing the same four markers the terminal path writes and carryingmobileDedupeKey. - Auto-ack across surface kinds —
agent-auto-ack-surfaces.ts(new) merges terminal + structured remainders;markTerminalTabUnreadnow accepts a unified chat tab id; the scan also watchesgroupsByWorktree. - Mobile per-event dedupe —
reserveNotificationEventOnce+ additivemobileDedupeKeyon the dispatch request, applied on top of the existing burst gate.
⚠️ The cross-version manifest does not register the new stream
cross-version wire compatibility is red: the suite pins the registered agentSession.* method count to STRUCTURED_CALLS.length, and the surface now registers 27 methods against a 26-entry manifest. This is the exact act the manifest comment says the gate exists to force, so the new opcode currently has no cross-version coverage in either skew direction.
Technical details
# Register `agentSession.subscribeTurnCompletion` in the cross-version manifest
## Affected sites
- `tests/e2e/cross-version-wire/structured-agent-session-surface-manifest.ts` — `STRUCTURED_CALLS` has 26 entries; the surface now registers 27 `agentSession.*` methods.
- `tests/e2e/cross-version-wire/cross-version-agent-session-wire.unit.test.ts:255` and `:321` — both assert `methodNames.filter((name) => name.startsWith('agentSession.')).toHaveLength(STRUCTURED_CALLS.length)`.
- CI log on this head: `AssertionError: expected [ 'agentSession.cancel', …(26) ] to have a length of 26 but got 27` at both sites.
## Required outcome
- A `STRUCTURED_CALLS` entry for `agentSession.subscribeTurnCompletion` with `hostMethod: 'subscribeTurnCompletion'` and no `result` (the stream opens on nothing, like `agentSession.subscribe`), so the old-host case asserts `method_not_found` and the current build exercises the gate.
- The job triggers on this PR because `src/main/runtime/rpc/methods/structured-agent-session*` is a `CROSS_VERSION_WIRE_PREFIXES` entry, so this is not a latent failure.
## Open questions for the human
- Should `AGENT_SESSION_TURN_COMPLETION_RUNTIME_CAPABILITY` also be asserted beside `AGENT_SESSION_STATUS_FEED_RUNTIME_CAPABILITY` at `cross-version-agent-session-wire.unit.test.ts:271` (capability advertised ⇔ method registered)?⚠️ The new shared wire module is committed as a binary file
src/shared/structured-turn-completion.ts is added as a binary blob (Bin 0 -> 4397 bytes). The NUL separator in structuredTurnCompletionKey is a literal 0x00 byte in the source rather than an escape, so git cannot diff or blame the file, the native file reader refuses it, and this PR's own diff renders it as (binary file or no changes) — for a brand-new shared contract other clients will need to read.
Technical details
# Replace the literal NUL byte in `structuredTurnCompletionKey`
## Affected sites
- `src/shared/structured-turn-completion.ts` — `[...].join('<0x00>')`; the separator is a raw NUL byte, so git reports `Bin 0 -> 4397 bytes`.
- Precedent in the same domain: `src/shared/agent-session-record.ts:168` uses `const SCOPE_KEY_SEPARATOR = '\u0000'` (escape sequence, text file).
## Required outcome
- The file is text again (diffable, blameable, reviewable) with identical runtime behaviour: use the escape `'\u0000'` (or `'\0'`) instead of the literal byte. The key string does not change.
- Confirm the committed file is no longer detected as binary (`git diff --stat` shows line counts).
## Suggested approach
- Edit the separator only; the surrounding schema and key logic are fine.DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| } | ||
|
|
||
| /** Which markers were written and how many times, with the addresses dropped. */ | ||
| function markerShape(record: Record<string, unknown[]>): Record<string, number> { |
There was a problem hiding this comment.
anti-slop/no-shape-in-symbol-names fires on markerShape here and on both uses at line 303, which is why the static analysis job is red. Rename it to a domain-role name, e.g. markerWriteCounts (all three sites).
There was a problem hiding this comment.
Actionable comments posted: 3
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 47e6cbaf-090e-4f07-9636-b54426dc5f96
⛔ Files ignored due to path filters (1)
src/shared/rpc-contract/rpc-params-catalog.generated.tsis excluded by!**/*.generated.*
📒 Files selected for processing (37)
src/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-turn-completion-feed.test.tssrc/main/native-chat/agent-session-wire/structured-turn-completion-feed.tssrc/main/notifications/notification-delivery-service.test.tssrc/main/notifications/notification-delivery-service.tssrc/main/runtime/rpc/methods/structured-agent-session-gate-classification.test-fixture.tssrc/main/runtime/rpc/methods/structured-agent-session-rpc.test-fixture.tssrc/main/runtime/rpc/methods/structured-agent-session-subscription-id.tssrc/main/runtime/rpc/methods/structured-agent-session-turn-completion-stream.tssrc/main/runtime/rpc/methods/structured-agent-session.test.tssrc/main/runtime/rpc/methods/structured-agent-session.tssrc/renderer/src/attention/agent-attention-acknowledgement.tssrc/renderer/src/attention/agent-attention-notification-delivery.tssrc/renderer/src/components/native-chat/StructuredAgentSessionStatusBridge.test.tsxsrc/renderer/src/components/native-chat/StructuredAgentSessionStatusBridge.tsxsrc/renderer/src/components/native-chat/StructuredTurnCompletionAttention.tsxsrc/renderer/src/components/native-chat/structured-agent-session-tabs.tssrc/renderer/src/components/native-chat/structured-attention-surface.test.tssrc/renderer/src/components/native-chat/structured-attention-surface.tssrc/renderer/src/components/native-chat/structured-turn-completion-attention.test.tssrc/renderer/src/components/native-chat/structured-turn-completion-attention.tssrc/renderer/src/components/terminal-pane/use-notification-dispatch.tssrc/renderer/src/hooks/agent-auto-ack-surfaces.tssrc/renderer/src/hooks/agent-auto-ack-targets.tssrc/renderer/src/hooks/useAutoAckViewedAgent.mixed-workspace.test.tssrc/renderer/src/hooks/useAutoAckViewedAgent.test.tssrc/renderer/src/hooks/useAutoAckViewedAgent.tssrc/renderer/src/runtime/structured-agent-session-client.tssrc/renderer/src/runtime/structured-turn-completion-feed.test.tssrc/renderer/src/runtime/structured-turn-completion-feed.tssrc/renderer/src/store/terminals/terminal-tab-attention.tssrc/shared/notification-event-dedupe.tssrc/shared/notification-settings-types.tssrc/shared/protocol-version.tssrc/shared/structured-turn-completion.test.tssrc/shared/structured-turn-completion.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review.
| const tab = Object.values(state.unifiedTabsByWorktree) | ||
| .flat() | ||
| .find((candidate) => candidate.id === groupId) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Scope structured subject resolution to the target workspace.
resolveViewedSubjectKey searches every workspace and selects the first matching tab.id. The target resolver permits duplicate tab IDs across worktrees.
If another workspace appears first, auto-acknowledgement clears that workspace's subject instead of the viewed subject. Pass the target workspace into this lookup or bind the surface to the target workspace.
| } | ||
|
|
||
| /** Which markers were written and how many times, with the addresses dropped. */ | ||
| function markerShape(record: Record<string, unknown[]>): Record<string, number> { |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Rename markerShape to pass static analysis.
The required anti-slop(no-shape-in-symbol-names) check rejects this helper and its use. Rename it for its domain role, such as markerCounts.
Proposed fix
-function markerShape(record: Record<string, unknown[]>): Record<string, number> {
+function markerCounts(record: Record<string, unknown[]>): Record<string, number> {
return Object.fromEntries(Object.entries(record).map(([key, value]) => [key, value.length]))
}
- expect(markerShape(chat)).toEqual(markerShape(terminal))
+ expect(markerCounts(chat)).toEqual(markerCounts(terminal))Also applies to: 303-303
🧰 Tools
🪛 GitHub Check: static analysis
[failure] 221-221: anti-slop(no-shape-in-symbol-names)
src/renderer/src/components/native-chat/structured-turn-completion-attention.test.ts:221:10: Rename symbol "markerShape" for its domain role; "shape" describes structure rather than ownership.
Source: Linters/SAST tools
| if (toAck.length === 0 && !viewedUnreadSubjectKey) { | ||
| return |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Clear a viewed group that has only container unread.
This return ignores state.unreadTerminalTabs[groupId]. Group-only unread is a supported remainder state.
If the user opens a structured tab in this state, the tab dot and workspace unread remain indefinitely. Include viewed group unread in the trigger. Permit the acknowledgement sink to clear the group and workspace when no subject key exists.
…inishes A finished structured native chat showed nothing outside its own Agent Activity badge. The workspace never went bold, the tab never took a dot, and the amber pane dot never appeared — three of the four indicators a finished PTY agent lights. The row already knew the chat had settled; nothing converted "this agent finished" into "you should look at this". Add that missing step. The execution host derives a completion at journal commit and publishes it on a new capability-negotiated stream; each connected window hands it to the attention policy already shared with the terminal path, asked through the structured surface adapter. Workspace bold, amber pane dot and tab dot now light on exactly the rules a PTY agent's completion lights them on. Only `success` lights anything. A failure or a cancellation is announced and earns no indicator, and a turn whose provider verdict was never recorded is not announced at all — a dot that says "done!" for an API error teaches the user to distrust every dot. Recovery is live-only by decision: nothing is persisted and nothing is queued, so nothing can strand. A session baselines on the first edge the feed sees, and a subscriber opens on nothing, so restore, rewind, restart and a reconnect after a gap all announce nothing. Both halves are pinned by tests, because a later refactor turning either into catch-up would otherwise be silent.
24be8a7 to
bd1b807
Compare
|
Closing as superseded by #21924, which merged the host-derived turn-completion transport and the structured attention bridge. Not discarded — salvage recorded. This branch (
The transport half here is superseded; only the notification/dedupe half is worth porting, and it will need rebasing onto #21924's structure rather than cherry-picking. Do not delete this branch until that port lands or is abandoned in writing. Notification and dedupe work is proceeding separately. |

ELI5
When a terminal agent finishes while you are looking somewhere else, Orca tells you: the
workspace name goes bold, its tab takes a dot, and an amber dot appears on the pane. A native
chat that finished did none of that. The chat itself knew it was done — the Agent Activity badge
lit — but nothing on the outside changed, so unless you happened to be staring at that chat you
never found out.
Now a finished chat lights the same indicators a finished terminal agent does.
What Changed
Before. A native chat completes a turn while its workspace is in the background. Measured on
the base of this branch:
Three of four never lit.
After. All four light, on the same rules as a terminal agent — including the rules that say
not to light: a chat you are actually looking at writes no unread, and a chat hidden behind
another tab in the workspace you are looking at does.
The mechanism. The chat's status row already knew the turn had settled. What was missing was
anything turning "this agent finished" into "you should look at this" — every writer of those
markers lived under the terminal pane code and was reachable only from a PTY.
Three pieces close that gap:
to the session journal, the host announces
(where it ran, session, turn, outcome, when)on anew stream. The host does this rather than a renderer because it is the only party that can
observe a chat whose window is not showing it — which is the entire case these indicators exist
for.
resolveAgentAttention, the provider-neutral policy the terminal path already uses, askedthrough the structured surface adapter added in fix(attention): count both terminal and chat siblings when clearing workspace unread #21274. No second suppression rule, no second
liveness rule, no change to how terminal evidence is arbitrated.
in that policy, so the banner comes along with the dot rather than needing its own path.
Only a success lights anything. A failure or a cancellation is announced and earns no
indicator; a turn whose outcome was never recorded is not announced at all. A dot that says
"done!" for an API error, or for a stop you asked for yourself, teaches you to distrust every dot.
Why
Why a separate stream instead of a field on the existing status feed. The status feed is a
summary: it carries no turn identity and no outcome, and it is re-broadcast on every status
change. A consumer would have to infer "a turn finished well" from a status transition, and a
transition is not evidence of that. Putting an outcome on the summary would also make every
status consumer a completion consumer.
Why recovery is live-only. Nothing is persisted and nothing is queued, so nothing can strand.
A session baselines the first time the feed sees it, and a subscriber opens on nothing — so
restore, rewind, restart, and reconnecting after a gap all announce nothing. The accepted cost is
that a turn finishing while no window is connected produces no banner; the row still shows its
state. Both halves of this are pinned by tests, because a later refactor quietly turning either
into catch-up would otherwise be invisible.
Why the tab dot is behind the same setting as the terminal's. The container marker is
presentation policy, gated on
experimentalTerminalAttentionfor a PTY today. A chat tab lightsits dot under exactly that setting, rather than getting its own rule.
The addressing decision, stated deliberately
unreadTerminalTabsis named for terminals, so a chat tab going into it deserves an explicitanswer rather than a silent one. A chat tab goes in that set, keyed by its unified tab id.
Reason: the set is read back by
SortableTab, which draws the dot for both kinds of tab from thatone index, and #21274 had already taught
markTerminalTabUnreadto accept both tab indexes forexactly that reason. A second set would need a second reader and a second acknowledgement path,
and the two could then disagree about one workspace. The name is now narrower than the contents;
renaming it is a separate, mechanical change and not mixed in here.
Mobile vs desktop delivery
The host's mobile fan-out already happens before the desktop focus gates, so these are already two
decisions. One completion now yields at most one mobile push no matter how many windows dispatched
it, keyed on the completion's own identity with no expiry — the pre-existing coarse
per-workspace burst gate is a five-second window, which is not the same guarantee. That coarse gate
still applies on top, so naming an event never loosens existing policy. Each window still decides
its own desktop banner independently, matching current PTY behaviour.
Linked Issue
Fixes #
Visual Proof
Not captured. This change has no new pixels of its own — it makes three existing indicators light
for a case that previously lit none, and their rendering is untouched. The observable effect is a
store fact (
folderWorkspaces[].isUnread,unreadTerminalTabs,unreadAgentCompletionPanes),which the acceptance test asserts directly against a PTY control in the same workspace and the same
run. Reproducing it live needs a real provider turn on a backgrounded workspace; the test covers
the same four writes the UI reads.
Testing
Automated, at this PR's final head:
structured-turn-completion-attention.test.ts) — a successful turn on abackgrounded workspace writes the same four markers a PTY agent writes, with a PTY control in the
same mixed workspace and the same run; failure and cancellation light nothing; a chat that is
itself the focused surface writes no unread but still requests delivery; a hidden sibling chat
inside the focused workspace does mark; a folder workspace behaves the same as a git worktree; a
closed tab and a tab rebound to another session are both rejected.
structured-turn-completion-feed.test.ts) — announces a settled root turnwith its scope; announces failure and cancellation for a consumer to decline; stays silent when
no outcome was recorded; baselines a session whose turn finished before the feed saw it; opens a
late subscriber on nothing; never re-announces an accounted turn; forgets a closed session.
structured-turn-completion.test.ts) — keeps reading a newer host that addedfields, and refuses an outcome arm from a later vocabulary rather than inventing a verdict.
structured-turn-completion-feed.test.ts, renderer) — never subscribes andnever retries against a host without the capability; baselines across a reconnect.
notification-delivery-service.test.ts) — one push per completion even whenthe coarse burst key differs, and long past the burst window.
Ablation at this head: disabling the renderer consumer and the host announcement turns 12 of those
24 tests red; restoring both is byte-identical and green. The negative cases are vacuous under
ablation by construction, which is why the positive control sits in the same file.
PTY lane unchanged: 8,928 tests across 925 files pass, covering the whole terminal-pane, attention,
native-chat, notifications, agent-session-wire and structured RPC suites — the existing suites, not
only the new ones.
pnpm tc,oxlintandpnpm run check:code-quality:changedall clean. Tested on macOS only.pnpm-lock.yamlis absent from every commit in the range.Review
Stacked on #21274. The first commit in this range is #21274's, which adds the structured
attention surface this PR consumes. Merge #21274 first and this reduces to the second commit.
Agent skill upstream boundary
Notes
distro, workspace id and kind — so one turn id from two hosts can never collide. The stream is a
new RPC method and therefore capability-negotiated: a client probes
agent-session.turn-completion.v1before subscribing, and against a host that lacks it theclient subscribes once, learns no, and stops rather than relay-probing forever. Loss of contact
is never treated as a turn ending — nothing here settles a turn, it only reports one the journal
already settled.
and the notification labels resolve through the folder catalog rather than a repo.
existing capability gate), every decoded object is loose so a newer host's extra fields are
ignored, and the one optional field added to the notification dispatch request leaves the
existing path behaving exactly as before when absent.
already projects on that same edge, so no new scan class. Per-session bookkeeping is one bounded
set of turn ids, cleared when the session closes. One stream per runtime target, shared by every
chat tab.
timestamp, all behind the existing structured-session capability gate.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)