Repository navigation
fix(native-chat): Codex async question cards on phone and desktop, one shared decision resolver - #25448
fix(native-chat): Codex async question cards on phone and desktop, one shared decision resolver#25448brennanb2025 wants to merge 39 commits into
Conversation
Add one shared decision-envelope parser and pending-decision resolver, the Codex async-question reader and fold, and the terminal-transport host derivation: the Codex rollout decoder keeps delivery/questions on both durable shapes, the transcript watcher reconstructs the pending set from the snapshot's consumed-byte boundary back to the newest delivered user message (publishing 'pending' until complete), folds appends in file order, and publishes an optional asyncQuestions side field on snapshot, replacement and appended frames over RPC and IPC. Async question calls fold away from the transcript, never become a blocking ask, and the structured translator and journal schema keep the questions.
…ames Derive the pending Codex async-question set from the whole journal once per commit (cached by cursor, shared by every subscriber) and attach it as an optional asyncQuestions field: whole on snapshot and reset frames, on batches only when it changed, and on the caught-up frame a resumed cursor is owed. A direct send retires what was asked before its submission once accepted; a queued send counts at its handover. The field's 256 KiB budget is reserved from the history page budget before items are packed.
The terminal-backed pane now takes its card from the shared resolver: an approval or unplaceable request shows only while the agent waits, and a request this build cannot place shows its own words with one line and no options. The structured pane maps prompts through the same resolver. Both panes show Codex's pending async questions in a non-blocking card above the composer, keyed per question: Send posts the answers as an ordinary message (prose-prefixed so it is never a command) and is only disabled while one is in flight; Dismiss is local. Terminal answers go through the PTY message seam with an honest accepted/rejected/unknown outcome; structured answers are outbox entries with a card origin whose wait ends on every disposition and which a Stop never restores into the composer draft.
…e phone The phone's terminal prompts come from the shared resolver: an envelope (approval or unsupported) outranks the prose guesses, which now run only when there is no envelope, no blocking ask and no pending async question, so plan steps never become digit buttons and an unplaceable request shows its own words with no options. Structured prompts follow journal order, as on desktop, and an unknown approval subject is never approvable. Codex async questions show in a controller-owned card fed only by the host-published set (so a question outside the loaded window still shows): answers go through answerQuestion (now returning its outcome) or the structured bridge's new answer(), neither of which touches the composer draft.
…hecked types An older release's structured reducer, coalescer and journal guard reduce snapshot and batch frames that carry the optional asyncQuestions field, and admit a text block with async question metadata, exactly as before. Frame readers read the field through a checked helper instead of widening existing casts.
…ecision-cards-9142 # Conflicts: # src/renderer/src/i18n/locales/es.json
…a; read-only journals publish no set A text block whose async-question annotation this build can't read was rejected by the journal schema, which truncates the journal from that row. The schema now admits any value and the host validates it when deriving. A read-only journal (an unreadable newer row) can't derive the set, so it publishes nothing, as an older host does, instead of an authoritative empty set that prunes client state.
…ly and recover from a failed scan A user reply over the 2 MiB record cap was skipped before it was checked, so it never retired the pending questions (and a fresh subscriber could bring answered ones back). Both the backward reconstruction and forward reads now inspect such a record's head, which says whether it is a delivered user message. A reconstruction that fails on an idle file used to stay pending until Codex wrote again; it now retries with backoff until it succeeds, the source is replaced, or the subscriber leaves.
…l and waits out a model switch The answer seam only noticed a cancel through its own handle, so a model or effort change that drained the PTY queue before Enter still reported the answer as sent and the card cleared it. The queue now says whether Enter fired. The seam also refuses to write while an option command owns the PTY, as the composer already does, so an answer can't land in the model picker.
…wn and requeued answers settle The card kept one state per hook, so switching session tabs on the phone dropped typed answers and dismissals (and could allow a second Send while one was in flight). The shared reducer now parks each conversation's state, bounded, and settles a send for the conversation it came from. A Stop-withdrawn answer is restored into the card; a structured answer that an owner change puts back in the queue ends as unknown, so Send is never left disabled. Desktop and phone share one submit path.
…sync field The structured and phone controllers always provide the async-question view, so the card hooks read it directly; the controller mocks that lacked it now carry it. Adds render tests for both async cards (choices, free text, Send, Dismiss, the omitted count) and for the unsupported-request card on both clients.
The answer hook runs over the real PTY queue: a refused write marks the echo not sent, a lost acknowledgement holds it, Stop before Enter settles rejected, a model switch or a phone-held terminal refuses without an echo, and no answer writes Escape or touches the composer draft. The resolved view puts the card between the transcript and a composer that stays, and yields to a blocking card.
…ured command gate The overlay adds the async card after the queued cards only when no blocking card holds the prompt slot. A terminal answer heals an orphaned image paste before it clears the line or writes, sends nothing when the heal fails, and carries no composer images. A /model-titled answer goes through the session's real command gate as an ordinary message, while a typed /model is caught.
A question older than the byte-cut hydration page still rides the snapshot. An over-budget set publishes its oldest questions with omittedCount, and the whole frame stays inside the page limit because the field's share is held back from history. The released reducer reads an over-budget frame exactly as it reads the same frame without the field.
…ecision-cards-9142
…he questions it answers Codex records an answer from its own async-question editor as a user message wrapped in its reply envelope naming the answered question ids, and keeps the other questions pending. The rollout adapter now reads that envelope (mirroring Codex's parser, including the IDE-context prefix) and the shared fold retires only the named questions. A plain prompt still clears the whole set; entries keyed by record position, which no reply can name, clear on any reply.
… and retry through the watcher A failed reconstruction now publishes absent, the old-host state, so a read failure never turns off the phone's fallback approval cards; the tracker no longer owns a retry timer. A retry is due only after a backoff and runs from a watcher drain or reconcile, so it inherits the WSL running check. Each settled fold is cached host-wide per rollout (path, file identity, the offset it reached and a boundary fingerprint; bounded to 32 files). A re-subscribe to an unchanged file publishes ready on its snapshot with no scan; otherwise it reads only the bytes written since the cached offset, after verifying the fingerprint. A miss or a rewrite only means a rescan.
…cript re-derives its questions A re-subscribe (phone resume, reconnect, desktop hide/show) publishes pending first. Clients now keep showing the last ready set over that pending, so the card no longer unmounts and the phone keyboard no longer drops; a new ready, absent, or a source change replaces it. The desktop resets the view only when the transcript source changes.
…running turn An answer sent while Codex is working used to go out as queue-if-active (follow-up queueing is on by default), so the host held it until the turn ended while the card showed blank inputs and a live Send. Codex's own app delivers an answer into the running turn, and Orca's structured Codex host already steers a plain send into the active turn (turn/steer). Desktop outbox entries with an async-answer origin and the phone's answer() now send plain; ordinary composer messages still queue.
…rd state survives the chat toggle The desktop structured card tracked an answer through a module-level outcome map, a waiting-promise map and record calls spliced into four outbox mutation sites. A remount resolved every wait as unknown and re-enabled Send while the persisted entry could still be queued or dispatching, inviting a duplicate answer, and the persisted origin.edits had no reader. Now each render reads the persisted outbox: an async-answer entry that waits or goes out holds its questions' Send and shows the sent answers; one held for Retry, refused or unconfirmed shows them with Send enabled. Once the host has it the entry leaves and the card waits for the host's set. A Stop or host withdrawal, or a refusal whose row loaded, hands origin.edits back to the card, as the composer draft gets its text back. Card state (edits, dismissals, in-flight) now lives in a bounded module store per conversation scope, like the composer draft cache, so the terminal card keeps it across a terminal/chat toggle and a send settles into it after an unmount.
…al suffix, Codex only Every journal commit (text deltas commit about every 60 ms) rebuilt the set from a full sorted snapshot once any message had ever asked, for every structured session. The host now keeps, per journal epoch, the newest delivered root user message as a boundary and folds only the messages after it, read without a sorted snapshot; submissions are read only when a pending send sits in that suffix. A vanished boundary item or a new epoch re-derives from the start. A session whose provider is not Codex publishes the empty set without reading the journal.
…arries, not a flat 256 KiB The shared history content budget lost 256 KiB for every reader: OpenCode terminal pages and appends, the conversation outline, structured history pages, and the per-item 'too large' cutoff, though only structured subscribe frames carry the field. The budget is restored; structured snapshot, reset and catch-up pages now hold back the serialized size of the field the frame will carry, so a full frame still stays under the page limit.
…ion set the host no longer publishes After a reconnect the desktop resumes with its cursor, so the host replies with catch-up batches, and a batch without the field kept the previous set. Against a host that never publishes it (a downgrade), a stale card stayed up and kept heuristic cards off indefinitely. A deriving host now attaches the set to a subscription's first frame even mid catch-up (later changes still wait for the final page), and the read transport treats a resumed subscription's first frame without it as an old host: the held set becomes absent. The phone always subscribes without a cursor, so its snapshot already states the set.
…t out settles unknown, not rejected The answer seam uses the observed write path, which marks a send submitted only once Enter's acknowledgement returns. A Stop, an option command's drain or a PTY swap in that window (up to 15 s on a remote runtime) reported a delivered answer as rejected: the echo showed failed and Send invited a duplicate. The observed path now records that Enter was handed to the runtime, and the answer seam reports unknown for a cancel after that point: the edits stay and the echo is held as unconfirmed.
…of Orca' A truncated or non-JSON prompt, raw tool input with no envelope arm, or a known arm that doesn't parse rendered 'This request needs a newer version of Orca.' on both clients and turned off the phone's fallback cards, telling an up-to-date user to upgrade. Those are now no envelope, as before this change: no card, fallback cards allowed. Unsupported is kept for what a newer host sends: a well-formed arm this build doesn't know, or an approval subject of an unknown kind.
…ted choices, narrower phone memo - The omitted-questions line uses the catalogs' plural forms on desktop (all six catalogs, plus the boot catalog) and the phone's count pattern. - Option buttons key by label and occurrence, so a choice the model repeats no longer collides as a React key on either client. - The phone resolves the prompt cards only when the status fields the resolver reads change, not on every status update. - The side-field cap comment now says frames hold back its actual size.
…old publishes its questions A subscriber whose question scan failed retries after a drain. When another subscriber of the same idle rollout had already folded it, the retry was answered from the shared cache but nothing published the result, so the client kept 'absent' until Codex next wrote to the file.
…p journal messages before the boundary without building them
…has it, on every client Codex holds an answer steered into a running turn until its next model step. The phone (both transports) and desktop terminal chats cleared the card as soon as the send was accepted, so the same question came back blank with Send live while Codex still held the answer; desktop structured chats already held it through the outbox. Each client now reads the hold from a record its transport already keeps, fed through the shared progress input: a terminal answer's optimistic echo carries its answers until the row lands or is marked not sent; a phone structured answer is tied to its journal submission, held while pending, given back when refused (a Stop before Codex drained it included) and let go once accepted.
…ver Dismiss A transport hold (an answer on its way to the agent) used to mark the whole card as sending: every input, every later question and Dismiss were disabled until the hold released. The hold is now per question: a held question shows its sent answer read-only, other open questions (including ones asked after the send) stay editable, Send builds its reply from unheld questions only, and Dismiss and the Sending label follow only the card's own write.
…ts answers back A terminal answer's echo held its questions until a transcript row with the echo's exact text landed. When Codex consumes the paste some other way (its question editor files it as a reply to one question, or a steer is dropped) that row never comes, so the hold never released. The echo now records the sends queued ahead of it; once the agent records a user row after the send that neither the echo nor those sends account for (harness machinery aside), the hold ends and the answers go back to the card, on desktop and phone alike.
…he card shows it The Codex request_user_input_async call and its acknowledgement were dropped from every transcript unconditionally. With no card to replace them (an older host that publishes no question set, a failed derivation, a child agent's question, or questions past the overflow line) the question's options were shown nowhere. The fold now takes the call ids the client's ready question set holds and drops only those calls; any other call keeps today's row. Desktop (terminal and structured) and phone pass their view to the shared fold.
…es or goes With no blocking card the prompt slot wrapped the queued cards in a fragment beside the async question card; with one it passed the queued cards alone. React saw a different element at that position and remounted the queued cards, dropping their in-flight busy state, same-frame double-tap guard and open action menu. The slot is now one tree either way, with the async card left out while a blocking card shows.
…oads on the phone The phone's Hermes runtime has no Array.prototype.toSorted, and the mobile compatibility test rejects it anywhere in the phone bundle, src/shared included. Copy then sort instead.
…e to read The incremental reader joined every part of an oversized pending record (up to about 2 MiB) to keep its first 4 KiB, and the kept slice pinned the whole join until the line ended. It now copies just the head.
…hared module The card-state module outgrew the line limit once the per-question hold and the terminal echo rule landed. Where a sent answer stands (transport records to progress, and when a terminal echo still holds) now lives in native-chat-async-answer-progress.ts; the card reducer reads it. No behaviour change.
The async-question fixture fields this branch added pushed the file one line over the limit; the structured session fixture drops its redundant error: undefined (absent reads the same).
…riving the card Opening a Codex chat with an open async question showed the raw request_user_input_async row on the first frame, then hid it when the card arrived: the host's first snapshot says "pending" and only the later ready set named the calls to fold. While the view is pending a card may follow, so every async question call and its acknowledgement fold away on every client. An absent view (an older host, or a derivation that failed) and ready calls the card doesn't show keep their rows as before.
…hone holds the terminal While a phone holds a terminal agent's input, the desktop chat hides the async question card, but the message list still folded the question's tool row away, so the desktop showed neither the card nor the row with its options. The chat view that decides whether its card can show now hands the message list which async calls to fold, instead of the list deriving that on its own. The terminal view folds nothing while the phone holds the terminal, so the raw row shows as before; a blocking card hiding the async card only briefly still folds. The structured view hands its own view's set the same way.
Review summaryThe problem. When Codex asks a question with What changes for you. Codex's open questions now appear as a card above the composer on both phone and desktop: the question, its choices, and a text field. Send (labelled Submit on desktop) posts your answers as an ordinary message that goes straight into the turn Codex is running. Until Codex records it, each answered question shows what you sent and is held; Dismiss and the other questions stay usable. Dismiss is per device and per question. The card stays across reconnects and the terminal/chat toggle, and a reply from Codex's own question editor clears only the questions it answers. The phone and desktop now pick approval and question cards with one shared resolver, so a Claude terminal plan approval shows the same card on both. Nothing new appears for prompts this version can't read except a request of a newer kind, which shows "This request needs a newer version of Orca." with no Approve. Review. Four review rounds plus a readiness check (verdict PASS: no data loss on rollback, no regression for Claude Code, Codex or OpenCode). Every finding was fixed in this PR, each with a test that fails without the fix:
Deferred (low impact, recorded for follow-up).
Verified.
Not verified.
|
Derive pending questions from delivered history so cards remain available outside the loaded message window. Extend the current-request transport from stablyai#29121 with opt-in async rows and adapt rollout reconstruction and regressions from stablyai#25448.
|
@brennanb2025 I've carried forward the Codex async-question part of this work in #30062, adapting the pending-question reconstruction and regression tests and using the current-request transport you merged in #29121. It covers desktop and mobile, structured and terminal-backed chat, Other answers, questions outside loaded history, and resolution across clients. Turn completion does not discard unanswered questions. The latest review also fixed a late rejected send incorrectly clearing newer questions after a context clear. The shared decision resolver and plan-approval changes from this PR remain outside #30062; #24415 is not fixed by it. Once reviewed and merged, #30062 could provide a new base for resuming that remaining work. I'd welcome your review of what was carried forward and the boundary between the two changes. 384 focused tests and the build pass. Full CI needs maintainer approval for the fork; physical phones and live SSH remain unverified. |
ELI5
When Codex asks you a question while it keeps working (its "async question"), the Orca phone app shows only the question as prose, with nothing to tap or answer. The desktop chat shows it as prose plus a raw tool row. This PR gives both a question card you can answer from either device. It also makes the phone and desktop decide which approval or question card to show with the same shared code, so the phone stops guessing at plan approvals from the terminal text.
What Changed
The problem.
request_user_input_asynctool asks the user one or more questions and returns at once ({"accepted":true}), so Codex keeps working. The question stays open until the user replies.questions. The phone shows the prose and nothing to answer (Mobile omits Codex request_user_input_async decision cards #20073). The desktop shows the prose and a raw tool row.What you see now.
request_user_input_asynctool row{"accepted":true}result fold away like other question rows. Without a card (an older host, a child agent's question) the row stays as todayNo new notice, banner or toast. The only new text is the "newer version" line, the Dismiss label, and "n more questions in the transcript" (shown only for a pathologically large set, see below).
How it works.
src/shared/native-chat-pending-decision.ts,native-chat-decision-envelope.ts). Desktop and phone both run it, for terminal and structured chats. It tells "no envelope" apart from "an envelope or subject this version can't read". An unreadable one is shown but never approvable, and it turns off every phone text guess. The phone's copy of the envelope parser is removed.native-chat-async-questions.ts,native-chat-async-question-facts.ts):transcript-async-question-boundary-scan.ts) finds questions asked since the last delivered user message. Its result is shared by every subscriber of the same file, so a reconnect costs only the bytes written since. If the scan fails, the host publishes no set (today's behaviour) and retries through the watcher's own read path, which never touches a stopped WSL distro.Why
Credit: this supersedes #22513 by @lorenzozanee (delivering the answer as a normal message, keeping async questions out of the blocking path) and #20074 by @jakeparkcolde (matching calls to their results, local dismissal). Both approaches are reused here.
Differences from the common pattern, labelled.
Linked Issue
Fixes #20073 (STA-7243).
Part of #24415 (STA-9142). This PR covers Claude plan approval on the phone (structured chats already worked; terminal chats get the desktop's card instead of guessed digit buttons). The OMP plan review the issue reports, Codex's terminal "Implement this plan?" menu, and the real choices of Claude's terminal plan menu need producers written against captured terminal transcripts. That is a follow-up, so #24415 stays open after this PR.
Visual Proof
Desktop, structured Codex chat, real Codex 0.159.0 (isolated test app; phone screenshots to follow).
The card appears while Codex keeps working (here, running
sleep 25); the raw tool row is folded away:Answer sent while
sleep 60is still running: it goes into the running turn, and the questions show the sent answers held until Codex records them (gone within 2 s):The same turn ends using the answers; no second turn:
Dismiss is per question; the remaining question stays answerable:
Testing
Unit tests for the shared resolver and envelope, the async-question fold and keys, the terminal tracker and backward scan (including oversized replies and recovery from a failed scan), structured journal rows and frames, desktop and phone cards and their send settlement (sent, rejected, withdrawn, cancelled, owner change), and the size cap.
Mixed versions:
tests/e2e/cross-version-wire/async-questions-field-downgrade.unit.test.ts. Old clients ignore the new optional field. An old host sends no field, so new clients show today's prose. A row this build can't read never truncates the journal.Local: renderer native-chat, main native-chat/codex/agent-session/runtime RPC, shared and cross-version tests (2181 files pass); mobile session tests (214 files pass);
tc:node,tc:web,tc:cli, mobiletsc; full oxlint and the changed-code gates.Live, desktop, structured Codex chat (real Codex 0.159.0, isolated test app, scratch repo): the card appears while Codex works; Submit posts
Question: …\nAnswer: …; sent during a running command it goes into that turn, the questions show the sent answers held, and the card retires within 2 s once Codex records them; Codex's reply in the same turn used the answers; per-question Dismiss leaves the composer usable and the questions in Codex's prose.Not yet run live: the phone, and terminal-backed Codex chats on desktop. The test machine's rig can't produce agent status with hooks turned off; that is pending a rig decision.
Not run live: an answer reaching Codex's terminal app. Running real terminal Codex for this check is not allowed on the test machines, so terminal delivery rests on Codex's source. Codex's question editor starts collapsed, so a pasted answer is an ordinary prompt that clears all its questions. Known limitation: if someone at the Codex terminal has opened its question editor, a pasted answer (from this card or any message) is filed under that editor's current question. A follow-up will disable terminal Send while the editor is open, based on a captured screen.
Known limitation (terminal chats): if Codex drops a steered answer (for example, Stop at the Codex terminal before Codex takes it) and no other input reaches Codex afterwards, that one question keeps the sent answer held. Dismiss, the other questions and the composer stay usable, and the next message gives the answer back or clears the question. On the phone, the hold otherwise lasts as long as the pending message bubble, which today has no expiry for any message.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
AI Disclosure
Review
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Author: @BrennanKB5
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)