refactor(x): one delivery path for turn events — chat, channels, deltas

Completes the turn-spine unification. Chat's SessionChatStore now
consumes turns:events like every other surface, joining live turns by
file offset (drop covered, append contiguous, refetch on gap) instead
of blind-appending session-bus events. Text/reasoning deltas cross IPC
only for turns a window subscribed to (turns:subscribe/unsubscribe, a
per-webContents registry that also survives window teardown), so
headless pipeline chatter never reaches windows that aren't watching.
The channels bridge settles turns off the turn event bus instead of
filtering the session broadcast. With no turn-event consumers left,
SessionsImpl stops forwarding entirely (it drains its execution streams
and keeps outcome/index handling) and sessions:events shrinks to
index-changed entries — one channel for turn events, one for session
metadata.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Ramnique Singh 2026-07-09 15:47:21 +05:30
parent f916cb1d70
commit 876bc35e9e
15 changed files with 284 additions and 115 deletions

View file

@ -357,18 +357,23 @@ which governs mutation of live logs, not their removal.
## 10. Event forwarding and live UI
1. For every `advanceTurn` it initiates, the session layer consumes
`TurnExecution.events` and forwards each `TurnStreamEvent` — tagged with
`sessionId` — through the application bus to renderer windows over one
IPC channel (`sessions:events`).
1. Live turn delivery is not the session layer's job: the turn runtime
publishes every turn's events to the process-wide turn event bus
(turn-runtime-design.md §17.1), which the app layer bridges to renderer
windows over one IPC channel (`turns:events` — durable events broadcast
with their file offsets; deltas only to windows subscribed to that turn).
The session layer drains each `TurnExecution.events` it initiates so an
unconsumed stream never buffers, and `sessions:events` carries only
`session-index-changed` entries.
2. When `outcome` settles, the session layer updates the index entry and
publishes `session-index-changed`.
3. The renderer follows the turn spec's historical/live pattern: fetch
turns via `getTurn`, run the shared `reduceTurn` per turn, compose the
session timeline turn-by-turn (each turn renders its input and its own
activity; the referenced prefix is never re-rendered from context),
append live durable events and re-reduce, and keep text/reasoning deltas
in an ephemeral overlay cleared by canonical responses.
join live durable events by file offset (drop covered, append
contiguous, refetch on gap) and re-reduce, and keep text/reasoning
deltas in an ephemeral overlay cleared by canonical responses.
4. Pending approvals and ask-human prompts render from the suspended turn's
reduced state, so they survive restarts without any session-layer
bookkeeping.

View file

@ -1435,9 +1435,10 @@ stream for the initiating caller.
events with `offset <= snapshot.length` — no gaps, no duplicates, no
sequence numbers in the durable schema.
- Text/reasoning deltas are published without an offset (they are not
durable). The app-layer IPC bridge (`turns:events`) forwards durable
events only in v1; deltas still reach session chat via the session-layer
forwarding. Scoping delta delivery to subscribed turns is future work.
durable). The app-layer IPC bridge (`turns:events`) broadcasts durable
events to every window; deltas are forwarded only to windows that
declared they are watching that turn (`turns:subscribe` /
`turns:unsubscribe`, a per-webContents registry in the app layer).
- The bus is ephemeral and observational, like the lifecycle bus: listener
errors are swallowed, nothing durable depends on delivery, and a crash
losing listeners accurately reflects that no execution is known active.