Skip to content

view: steers enter where the runtime took them; text splits per message - #86

Merged
xxchan merged 1 commit into
mainfrom
view-steer-order
Oct 3, 2026
Merged

xxchan merged 1 commit into
mainfrom
view-steer-order

Conversation

@xxchan

@xxchan xxchan commented Oct 3, 2026

Copy link
Copy Markdown
Member

Closes #82.

Why

Two problems in the session view (viewOf / reduceSessionView), both visible in a real codex run (prompt sleep 100, then three steers while the agent waits):

  1. A steer appeared where it was sent, not where the runtime took it. upsertInput appended the input and sealed the turn on the steer request. Codex holds a steer until its current step ends, so the reply to test 1 rendered after test 2 and test 3, which the agent hadn't read yet.
  2. Two assistant messages merged. text_delta carried no message identity, so separate agentMessage items in one turn became one run-on text part.

Before (today's viewOf on the recording):

input  sleep 100
turn   好,我等 100 秒。
input  test 1
input  test 2
input  test 3
turn   收到“test 1”。…剩余时间。收到“test 2”和“test 3”。…

After:

input  sleep 100
turn   好,我等 100 秒。 · sleep
input  test 1
turn   收到“test 1”。… · sleep
input  test 2
input  test 3
turn   收到“test 2”和“test 3”。… · sleep · sleep · 已等待约 100 秒,…

(The sleep tool parts come from #84, already on main.)

Rules (as agreed with @cindy)

A steer enters the conversation where the agent read it.

  • A steer or queue input enters messages only at the first user_message whose inputId matches it, and seals the open segment there. Until then it is not in messages. It waits in the new SessionView.pendingInputs (ConversationInput[], request order), so a host can show it above the composer.
  • Echo detection reads the stream itself. There is no capability flag and no runtime-name check. Once the stream has carried a user_message with an inputId (codex and claude echo the first prompt), later steers and queues wait for their echo. A stream that never has (grok, kimi; pi's echo has no inputId, so it can't match) keeps today's placement at the request. This is derived from view.conversation: some input has an observation.
  • Prompts keep today's placement and open their turn.
  • A rejected input enters where it was refused, as today. If a deliver / steerOrQueue retry of the same input then has to wait for its echo (prompt refused busy → steer, steer refused → queue), the input leaves messages again. The segment it had sealed reopens, so the turn doesn't split at an input that is no longer there.
  • A steer still unread when the turn ends stays in pendingInputs. No position is invented for it. If its echo arrives later (a later turn, or a later stream after resume, since input identity crosses streamIds), it enters there.
  • A queued input's echo arrives when the runtime drains it, so it sits just before the adopted turn it starts.
  • reduceSessionViewInput (an app's own submission) still places the input immediately.

Text splits per message.

  • text_delta gains optional messageId: codex = the agentMessage itemId (item/agentMessage/delta), claude = the assistant message.id. pi and ACP name none, so they are left as is.
  • In the view, a text_delta whose messageId differs from the last text part's starts a new part. Without a messageId (pi, ACP, older records) text concatenates as before. Text ViewParts carry messageId.
  • coalesceText (Session.events({ coalesceText })) no longer merges across different messageIds.

Also fixed on the way: reduceSessionView now skips a record its stream has already folded, for the whole view. Before, only the conversation fold skipped it, so folding a log twice opened an extra empty turn from the duplicated prompt request.

Public API

  • SessionView.pendingInputs: readonly ConversationInput[] (new)
  • text_delta.messageId?: string on RuntimeEventBody / Event (new, optional)
  • ViewPart text: messageId?: string (new, optional)

Behaviour change for hosts on codex/claude: a steer or queue is no longer in messages until the runtime echoes it. A host that wants it visible meanwhile should render pendingInputs.

Tests

  • tests/replay/codex-steer-order.test.ts replays the real codex recording (tests/replay/fixtures/codex-steer-order.records.jsonl, oar RawEvent records, scrubbed). Every frame is re-read through today's codex projection, so messageId is exercised (frames whose native the scrub emptied keep their recorded events). It pins the order above, pendingInputs = [test 2, test 3] mid-run, re-read text = recorded text plus four distinct agentMessage ids, and double-folding idempotence. It also has a focused codex messageId adapter case.
  • tests/session-view-inputs.test.ts covers an echoing stream, the no-echo fallback (including pi's unlinked echo), an unread steer at turn end and its late echo in a later turn, the queue drain, a refused steer retried as a queue, a prompt refused busy retried as a steer, a pending steer echoed in a resumed stream, and records folded twice.
  • claude messageId adapter test, a view messageId split test, and a coalesceText messageId test.
  • pnpm run check (typecheck, lint, 530 tests, mock sea-trial) and pnpm run build pass. OAR_TEST=codex-aimock / claude-aimock pnpm sea-trial and their vendor tests pass.

Docs

docs/design/chat-ui.md (surface, mapping rows for prompt/steer/queue request and response, user_message, text_delta, assistant-ui mapping), docs/spec/conversation.md (new section: where an input enters the session view), docs/spec/record-stream.md, and the codex and claude runtime pages.

🤖 Generated with Claude Code

…er message

The session view put a steered input in `messages` when the steer
request was recorded. Codex holds a steer until its current step ends,
so the reply to an earlier steer rendered after inputs the agent had not
read yet (#82). Separately, `text_delta` carried no message identity, so
two assistant messages of one turn folded into one run-on text part.

Where an input enters the view:
- A prompt enters at its request and opens its turn, as before.
- A steer or queue enters at its first `user_message` carrying its
  `inputId` and seals the open segment there. Until then it waits in the
  new `SessionView.pendingInputs` (request order), so a host can show it
  above the composer.
- Whether a stream echoes is read off the stream: once it has carried a
  `user_message` with an `inputId` (codex and claude echo the first
  prompt), later steers wait for their echo. A stream that never has
  (grok, kimi; pi's echo has no inputId) keeps request placement. No
  capability flag or runtime name is involved.
- A rejected input enters where it was refused; a `deliver` or
  `steerOrQueue` retry of it that must wait for its echo takes it back
  out and reopens the segment it had sealed.
- An input never echoed stays pending after its turn ends; no position
  is invented for it.
- Records already folded in a stream are now a no-op for the whole view,
  not only for the conversation fold (a re-folded prompt request used to
  open an empty turn).

Text: `text_delta` gains an optional `messageId`, the runtime's id of
the assistant message (codex: the agentMessage `itemId`; claude: the API
`message.id`). The view starts a new text part when it changes, and
`coalesceText` no longer merges across it. Without one (pi, ACP, older
records) text concatenates as before. Text parts carry `messageId`.

Tests replay a real codex run (prompt `sleep 100`, three steers) with
every frame re-read through today's codex projection, plus unit cases
for the no-echo fallback, an unread steer at turn end, a late echo in a
later turn, the queue drain, refused-then-retried inputs, a resumed
stream and double folding; codex and claude messageId adapter tests and
a coalesceText case. Docs: chat-ui mapping, conversation spec,
record-stream, codex and claude runtime pages.

`pnpm run check` and `pnpm run build` pass; codex-aimock and
claude-aimock sea-trial and vendor tests pass.

Closes #82

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@xxchan
xxchan merged commit 6daf448 into main Oct 3, 2026
12 checks passed
@xxchan
xxchan deleted the view-steer-order branch October 3, 2026 09:07
@xxchan xxchan mentioned this pull request Oct 3, 2026
xxchan added a commit that referenced this pull request Oct 3, 2026
Minor release (behaviour change in the session view): #86 by Ferryman.
On a stream that echoes input ids (codex, claude), a steered or queued
input enters `messages` where the runtime took it (its first matching
`user_message`) and waits in the new `SessionView.pendingInputs` until
then; streams that never echo keep the request position.
`text_delta.messageId` (codex itemId, claude message id) splits two
assistant messages of one turn into separate text parts; `coalesceText`
no longer merges across them. `reduceSessionView` skips records its
stream already folded. Closes #82. Version bump only.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: exe.dev user <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

view: steered inputs render at send time, not when the runtime takes them; consecutive assistant messages merge

1 participant