Send mid-turn chat prompts to the harness and queue the rest durably on the server
Claude Code (stream-json stdin) and Codex (turn/steer pinned to the active turn) receive a prompt sent while a turn runs immediately. Other harnesses (OpenCode) get a durable chat_prompt_queue row owned by the session: it survives the last client detaching and a server restart, is delivered in order when the turn ends with or without a client, and is deduplicated by operation id. chat_subscribe carries the queue, chat_queue frames report delivered/removed/failed changes, and chat_unqueue removes a waiting prompt.
This commit is contained in:
+24
-6
@@ -435,13 +435,31 @@ sessions pipeline runs create. The protocol types are:
|
||||
client that watches a session sees every frame any client's turn produces — the
|
||||
other devices' prompts and the turn's streaming output — and can answer a shared
|
||||
approval. Attaching is idempotent per connection; the subscription is released
|
||||
when the connection ends.
|
||||
when the connection ends. The reply carries `chat_queue` (`session_id`,
|
||||
`prompts`): the prompts the server still holds for the session, each with
|
||||
`operation_id`, `message_id`, `native_message_id`, `text`, `client`,
|
||||
`attachments` and `queued_at`, so a reloaded client draws them as queued.
|
||||
- `chat_prompt` may come from any client. A prompt whose session already has a turn
|
||||
in flight is accepted into that session's bounded queue (currently 8) and
|
||||
acknowledged with `chat_queued: true`; the agent never receives two interleaved
|
||||
turns. The prompt is echoed to the other watching clients as a `chat_event` of
|
||||
kind `user`, carried with the sender's `client` label (a device name), while the
|
||||
sender's own transcript keeps its local copy.
|
||||
in flight is handed to that turn at once when the harness accepts mid-turn input
|
||||
(Claude Code reads it from stdin at its next step; Codex takes it with
|
||||
`turn/steer` pinned to the active turn) and is acknowledged as sent. Otherwise
|
||||
(OpenCode, or a turn that ended meanwhile) it is written to the session's durable
|
||||
server-side queue (bounded, currently 8) and acknowledged with
|
||||
`chat_queued: true`; the agent never receives two interleaved turns. Queued
|
||||
prompts belong to the session, not the connection: they are delivered in order
|
||||
when the turn ends even with no client attached, and after a server restart once
|
||||
the harness is idle. A retry with the same `operation_id` is acknowledged again,
|
||||
never queued or delivered twice. The prompt is echoed to the other watching
|
||||
clients as a `chat_event` of kind `user`, carried with the sender's `client`
|
||||
label (a device name), while the sender's own transcript keeps its local copy;
|
||||
a queued prompt's user event is published again as it is delivered.
|
||||
- `chat_queue` is pushed to every watching client whenever a session's queue
|
||||
changes, with the current `prompts` and the change: `delivered`, `removed`, or
|
||||
`failed` with `error` (the harness refused it; it is not retried).
|
||||
- `chat_unqueue` (body `chat_unqueue`: `session_id`, `operation_id`) removes one
|
||||
prompt still waiting in the queue and replies with the updated `chat_queue`. A
|
||||
prompt already handed to the harness is refused as already sent. Closing a chat
|
||||
drops its queue.
|
||||
- `chat_reply` is exactly-once: the first answer to a pending request wins, is
|
||||
recorded with the answering client's label and is pushed back to every watching
|
||||
client as the same `chat_permission` frame with `resolved: true`, `decision` and
|
||||
|
||||
Reference in New Issue
Block a user