You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Full spec for the purified core chat (plan Task 4), written and user-grilled BEFORE execution: module map for packages/core chat (run loop with runId stamping, attach snapshot+live stream, gate on typed parts with library ApprovalRequestedEvent, in-process MCP ask/reply await, app wiring without vetoes/notifyChange), the exact extension-facing surface that remains (session/token/launch observation — no send authority), the exact wire event shapes, and per-module ladder levels. Deliverable: spec doc + user approval.
chat.subscribe stream contract (the one meaty question, from the platform-fidelity citations)
On subscribe (and every re-subscribe/reconnect): the stream LEADS with one MESSAGES_SNAPSHOT chunk — {type: 'MESSAGES_SNAPSHOT', messages: UIMessage[]}. Core emits
full UIMessages (the library's aguiSnapshotMessageToUIMessage passes messages with parts
through unchanged — the documented server-echo path). Processor-side this is a full replace
(handleMessagesSnapshotEvent → reset + reconcile), which is exactly the refresh semantic.
A snapshot chunk is NEVER emitted in the same flush as RUN_FINISHED/RUN_ERROR
(unconditional resolveProcessing would kill an unrelated in-flight send).
After the snapshot: live StreamChunks of core-executed runs only, passed through as the
library produced them, each lifecycle chunk carrying its run's library-minted id (subscribe
mode stamps nothing client-side; the stamp is required for activeRunIds correctness).
Mid-run subscribe: snapshot first (transcript as-is), then the live chunks of the in-flight
run from its next chunk onward. No replay of already-emitted chunks (transcript catches the
final state via the next snapshot; createReplayStream rejected — core has no recording for
terminal-written history and two delivery paths is one too many).
Stream is strictly per-session (one subscribe call = one session, closure-bound adapter);
guarantees a foreign run's terminal event can never resolve this client's in-flight send.
Snapshot production
Source: harness history reader for the session's (harnessKind, cwd, nativeId); rows with no
nativeId yet (pre-first-turn) snapshot to their stored messages (empty for brand-new).
Cache keyed by ROW id; monotonic (never fewer messages than previously served) per core
lifetime; cleared on tombstone, rebuilt on restore/open. Truncated final JSONL line skipped.
Module map (packages/core/src/chat — one intention per file)
Module
Intention
Ladder
session-rows.ts
create/resolve/open/restore, tombstone, (harnessKind,cwd,nativeId) merge; records nativeId after turn 1
L3: identity precedes native file
run.ts
library chat() loop; claimRun held across approval auto-continuations (turn = N library runs); stamps lifecycle chunks with runId; passes UIMessages STRAIGHT THROUGH (no pre-conversion — approvals extract from parts before conversion inside the library)
L1 loop; L3 stamp+claim
subscribe.ts
per-session stream: snapshot lead + live-run mux per the contract above
L3: wire transport
stop.ts
release the session's active turn; abort library run; resolve pending asks as cancelled; idempotent ack
L3: library stop is local-only
ask.ts
in-process promise registry for the CLI-blocked family (permissionDecision, uiReply); resolve/reject by ask id; AbortSignal wiring
L3: no library pause maps to a blocked process
transcript.ts
snapshot production + cache per above, over harness history sidecars
L2 source, L3 cache
Deleted from core (already ruled, listed for the grep gate): converters, zod shadow-schemas,
sessionAsk/StreamProcessor forgery, ensureToolCallPart timeout, sendVetoes, epochs/snapshotKey/
externalRev, BUSY machinery, terminal-opener + launch RPCs (→ extension), adopt/attach/observer.
Approvals (restating the library truth this spec builds on)
Tool approval = CUSTOM/approval-requested chunk ends the turn (terminal hook skipped while toolPhase === 'wait'); client answers addToolApprovalResponse → automatic internal
continuation (second library runId, same held turn server-side). chat.permissionDecision and chat.uiReply are NOT approvals — they resolve ask.ts promises while a harness process blocks.
Acceptance
Kept frozen core tests green (chat.it, wire.it minus surgically-removed verdict/BUSY lines,
compact.it, resolve, markers, expand-attachments, mcp-approval reworked lines per bucket list);
core-purity grep gate; typecheck.
Ruling (user, 2026-08-03): subscribe stream KEPT — with its real justification on record. User challenged whether the persistent stream is needed at all (library request/response mode: send() returns the turn's own SSE stream, simpler, no snapshot contract, no runId stamping). Resolution: subscribe exists for ONE reason — reattaching to a turn already in progress (agent turns run minutes; page reload/navigation mid-turn must resume the live view). NOT for terminal mirroring (dead). User note: 'seems off but ok' — if mid-run reattach ever stops mattering, the sanctioned simplification is downgrading to request/response mode and deleting the snapshot-lead contract + stamping wholesale.
Post-approval correction from execution (T8.5, #209): the spec's 'no replay of already-emitted chunks' line is superseded — the frozen suite pins mid-run reattach replay (snapshot lead → active run's chunks from RUN_STARTED → live). Implemented in 24b1b86e; snapshot-lead and run-end-after-persistence clauses unchanged.
Activity
omridevk commentedon Aug 3, 2026
Spec #190 — purified core chat (fills design v2.6's named deferrals)
chat.subscribe stream contract (the one meaty question, from the platform-fidelity citations)
MESSAGES_SNAPSHOTchunk —{type: 'MESSAGES_SNAPSHOT', messages: UIMessage[]}. Core emitsfull
UIMessages (the library'saguiSnapshotMessageToUIMessagepasses messages withpartsthrough unchanged — the documented server-echo path). Processor-side this is a full replace
(
handleMessagesSnapshotEvent→ reset + reconcile), which is exactly the refresh semantic.RUN_FINISHED/RUN_ERROR(unconditional
resolveProcessingwould kill an unrelated in-flight send).StreamChunks of core-executed runs only, passed through as thelibrary produced them, each lifecycle chunk carrying its run's library-minted id (subscribe
mode stamps nothing client-side; the stamp is required for
activeRunIdscorrectness).run from its next chunk onward. No replay of already-emitted chunks (transcript catches the
final state via the next snapshot;
createReplayStreamrejected — core has no recording forterminal-written history and two delivery paths is one too many).
guarantees a foreign run's terminal event can never resolve this client's in-flight send.
Snapshot production
(harnessKind, cwd, nativeId); rows with nonativeId yet (pre-first-turn) snapshot to their stored messages (empty for brand-new).
lifetime; cleared on tombstone, rebuilt on restore/open. Truncated final JSONL line skipped.
Module map (packages/core/src/chat — one intention per file)
session-rows.ts(harnessKind,cwd,nativeId)merge; records nativeId after turn 1run.tschat()loop;claimRunheld across approval auto-continuations (turn = N library runs); stamps lifecycle chunks with runId; passes UIMessages STRAIGHT THROUGH (no pre-conversion — approvals extract from parts before conversion inside the library)subscribe.tsstop.tsask.tstranscript.tsDeleted from core (already ruled, listed for the grep gate): converters, zod shadow-schemas,
sessionAsk/StreamProcessor forgery, ensureToolCallPart timeout, sendVetoes, epochs/snapshotKey/
externalRev, BUSY machinery, terminal-opener + launch RPCs (→ extension), adopt/attach/observer.
Approvals (restating the library truth this spec builds on)
Tool approval =
CUSTOM/approval-requestedchunk ends the turn (terminal hook skipped whiletoolPhase === 'wait'); client answersaddToolApprovalResponse→ automatic internalcontinuation (second library runId, same held turn server-side).
chat.permissionDecisionandchat.uiReplyare NOT approvals — they resolveask.tspromises while a harness process blocks.Acceptance
Kept frozen core tests green (chat.it, wire.it minus surgically-removed verdict/BUSY lines,
compact.it, resolve, markers, expand-attachments, mcp-approval reworked lines per bucket list);
core-purity grep gate; typecheck.
omridevk commentedon Aug 3, 2026
Ruling (user, 2026-08-03): subscribe stream KEPT — with its real justification on record. User challenged whether the persistent stream is needed at all (library request/response mode: send() returns the turn's own SSE stream, simpler, no snapshot contract, no runId stamping). Resolution: subscribe exists for ONE reason — reattaching to a turn already in progress (agent turns run minutes; page reload/navigation mid-turn must resume the live view). NOT for terminal mirroring (dead). User note: 'seems off but ok' — if mid-run reattach ever stops mattering, the sanctioned simplification is downgrading to request/response mode and deleting the snapshot-lead contract + stamping wholesale.
omridevk commentedon Aug 3, 2026
Spec approved (user, 2026-08-03). Closing; the execution plan copies its contracts verbatim.
omridevk commentedon Aug 3, 2026
Post-approval correction from execution (T8.5, #209): the spec's 'no replay of already-emitted chunks' line is superseded — the frozen suite pins mid-run reattach replay (snapshot lead → active run's chunks from RUN_STARTED → live). Implemented in
24b1b86e; snapshot-lead and run-end-after-persistence clauses unchanged.