Skip to content

Start page input's turn in an open Codex desktop chat, with no message in the user's name - #5424

Merged
max-sixty merged 5 commits into
mainfrom
grind/g-codex-wake
Nov 5, 2026
Merged

max-sixty merged 5 commits into
mainfrom
grind/g-codex-wake

Conversation

@max-sixty

@max-sixty max-sixty commented Nov 5, 2026 •

Copy link
Copy Markdown
Owner

A page comment to an idle Codex desktop chat arrived as a queued <leaf-delivery> user message, which the chat drew as if the user had typed it. A chat a window of the app has opened now takes the delivery as a turn the app starts, with the complete envelope as a leaf_delivery tool output. The chat shows the agent's answer and nothing for the input. A chat with no owner, such as one not opened since the app launched, stays on codex queue and the wake.

Closes #4015

The route

The app's chats run on an App Server child it speaks to over stdio, so nothing else can connect to that server. The local daemon and codex app-server proxy don't reach those chats. What does is the router the app's own clients share at $CODEX_HOME/ipc/ipc.sock: a client asks thread-owner-discovery which client owns a chat, then sends that owner thread-follower-start-turn, and the owner calls turn/start on its own App Server with the chat's settings. src/leaf/codex_desktop.py is that client, and it sends the request every Leaf delivery turn already takes (codex.app_server_turn_start_params).

The adapter tries this first in a desktop chat. The start keeps the App Server delivery contract (codex.start_app_server_delivery), so the same input never runs twice:

  • Before the start goes out, any failure falls back to the queue: no router, no owner, silence, or a frame that isn't a JSON object. The adapter's log gives the reason for each.
  • Leaf reserves the start (StartingOffer) once the app has named the owner. Only a refusal made before the owner ran the request releases it to the queue: no-client-found, no-handler-for-request and request-version-mismatch.
  • Any other answer may follow a started turn: a lost answer, a success of another shape, the owner's own 5 s thread-follower-start-turn-timeout, or an unreadable frame. The start then stays reserved. The chat's transcript settles it, since the app records the turn's leaf_delivery tool output there with the delivery id and turn_id (codex.transcript_delivery_turn). Leaf accepts it in that turn. If the page reads no turn of the chat as running and 60 s have passed without it, Leaf abandons it as unconfirmed (codex.abandon_uncertain_delivery), and the page says so. That reading is codex_state.delivery_turn's, whose dated activity ages out a turn a crash left open. It is never sent again. A crash between the app's answer and the acceptance leaves the same reservation, settled the same way. Any adapter of the chat settles it, one a terminal resume started outside the app included.
  • On a clean answer, the adapter adopts the returned turn id and accepts the delivery as Opened, so the page reads a pickup in that turn at once.

The envelope is the queue's, whose replies the agent writes with leaf thread reply, because Leaf sees nothing of the turn but its id.

Evidence

Everything below ran on app 26.1029.61003 (bundled Codex 0.166.0-alpha.6). Turns ran only on threads this work created, on a second instance of the app with its own CODEX_HOME and user data, or in that instance's own router.

  • Before, an unowned chat on the new code: a page comment took the queue, with the wake sent by hand to that instance because open reaches the default handler. Its stored turn opens on userMessage: <leaf-delivery id="2dbbf7ed" operation="delivery read" />.
  • After, an owned chat: the same comment through this tree's installed plugin and a real adapter had a new turn within 0.4 s. Its stored items open on functionCallOutput name=leaf_delivery with no userMessage, the page log holds pickup phase=opened with that turn's id, and the agent's reply reached the page at 28.5 s on a busy machine. The adapter log stayed empty.
  • The window: a screenshot over DevTools shows the agent's answers with no bubble for any delivery, and bubbles only for the two user messages.
  • Which chats have an owner: one whose window moved to another chat kept its owner and took a start, and so did one with thread_unload_delay_secs = 0. After an app restart the chat had none. On the running app, read-only discovery found one owned chat among those listed, the one in use, answered in about a millisecond. A scratch chat resumed only by the wake had none after more than two minutes.
  • A busy chat: a start during a running turn answered with that turn's id, and the tool output entered at its next boundary after the shell command. The turn then finished with its answer.
  • The daemon, by running: thread/list through it lists every chat as notLoaded, the chat in use included, and thread/loaded/list is empty. On a scratch chat the app held, thread/resume was refused with already has an active writer and turn/start with thread not found. With CODEX_APP_SERVER_USE_LOCAL_DAEMON=1 and a daemon answering, the app still started its stdio child.

notes/codex-integration.md records these runs and how to repeat them.

uv run pytest tests/model/test_codex_adapter.py tests/model/test_codex_app_server.py tests/model/test_session_lifecycle.py -n2 passes (205). The desktop tests drive a fake router that speaks the observed framing, and assert each request's method, version, source and target client, and params. They cover each definitive fallback with its logged reason, each uncertain answer settled from a transcript and not by another delivery's tool output, settlement in an adapter started outside the app, abandonment held back while a turn runs but not by one a crash left open, a refused start that the queue then fails, and a crash after the app's answer. Each of 18 source mutations fails them, among them each version number, a dropped conversationId or target, the owner's timeout counted as a refusal, no reservation, a refused start left reserved, the delivery-id match removed, and non-object frames accepted. pre-commit passes on the changed files. The journeys weren't run. codex.py gains only the transcript reader the desktop route calls, and the desktop route it serves runs only in a desktop chat, which neither journey drives.

Not verified

  • No turn was sent into a chat on the user's running app. Only owner discovery touched that router.
  • The runs on the second app instance were on the first commit. The review's changes to how a start's answer is read and settled ran only in the model tests.
  • Interrupting a turn started this way, and answering an approval in one, weren't run. The turn runs on the app's own App Server through the same path as a typed message.
  • Ownership over hours of idleness wasn't run beyond the one chat in use for about two hours.
  • Settling from the transcript was tested against a fixture in the shape the app's bundled Codex (0.166.0-alpha.6) wrote for a tool-output turn in a scratch chat that a probe drove through that binary's App Server, not against a turn the router started in the app. notes/codex-integration.md holds that record and how to capture another. The 60 s window before abandoning was chosen, not measured.
  • thread-follower-start-turn is private and could change in any app release. A change that stops the start before it goes out falls back to the queue, and one after it leaves the start to the transcript. The adapter's log, sessions/<session>.codex.log, gives the reason for each. A version bump on discovery reads as no-client-found, the same as no owner.

Calls this makes

  • The private router rather than CODEX_APP_SERVER_WS_URL. That variable does put the app on a server Leaf can reach, which was run too: a second client saw the open chat and started a tool-output turn in it. It reaches every chat and would give the desktop the streamed App Server route, but only for an app launched with it, with a server kept running. The router needs no setup and leaves unowned chats on the queue.
  • The complete envelope as the tool output, so the turn needs no leaf delivery read or ack.
  • An uncertain start Leaf can't find in the transcript is abandoned as unconfirmed after 60 s, rather than queued, so the page asks the user to send it again rather than risk a second run.

This was written by Claude Code on behalf of max-sixty

…e in the user's name

A page comment to an idle desktop chat arrived as a queued `<leaf-delivery>` user
message. The app's chats run on an App Server child over stdio that nothing else can
reach, and the local daemon holds none of them, but the router the app's own clients
share can ask a chat's owner to start a turn. The adapter now does that first in a
desktop chat, with the delivery as a `leaf_delivery` tool output, and falls back to
`codex queue` and the wake on no owner or any failure.

Run on app 26.1029.61003, on a second instance with its own home: a page comment through
a real adapter opened a turn whose stored items start on the tool output with no user
message, and the window drew only the answer. An unowned chat on the same code still
took the queue, whose turn opens on the `<leaf-delivery>` user message.
`notes/codex-integration.md` records each route's runs and how to repeat them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The desktop start adopts its turn without the epoch check the App Server start applies (inline).

Comment thread src/leaf/codex_adapter.py Resolved
…unclear one from the chat's transcript

The desktop route queued its input whenever it couldn't read the router's answer, so a
start the app had taken ran a second time from the queue. That included a `success` of
another shape and the owner's own five-second `thread-follower-start-turn-timeout`,
after which its start runs on. A crash between the app's answer and the acceptance sent
the start again.

The start now keeps the App Server delivery contract (`codex.start_app_server_delivery`).
Leaf reserves it as a `StartingOffer` once the app names the chat's owner. Only the
refusals made before the owner runs the request release it to the queue:
`no-client-found`, `no-handler-for-request` and `request-version-mismatch`. Any other
answer leaves it reserved. The chat's transcript settles it, since the app records the
turn's `leaf_delivery` tool output there with the delivery id and turn id
(`codex.transcript_delivery_turn`). Leaf accepts the delivery in that turn, or, once no
turn is running and 60 s have passed without one, abandons it as unconfirmed without
sending it again.

Router frames that aren't JSON objects, and answers whose fields moved, now fall back
before the start, or stay uncertain after it, instead of escaping as `AttributeError`
and stranding the input. The adapter's log gives the reason for every fallback to the
queue, a discovery version the app doesn't know included, which reads as
`no-client-found`.

The desktop tests assert each request's method, version, clients and params, and cover
each fallback, each uncertain answer, abandonment held back while a turn runs, and a
crash after the app's answer. Each of 16 source mutations fails them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Settling an unconfirmed start depends on a transcript record shape nothing here shows the app writing (inline).

Comment thread src/leaf/codex.py Resolved
… outside the app

An unclear desktop start stood forever, holding back every later comment, when the
session record still showed a turn a crash left open: settling read the record's raw
`turn_open`. It now reads `codex_state.delivery_turn`, the dated reading the queue's gate
uses, which ages such a turn out, so the start is abandoned as unconfirmed once the
settle window passes.

Settling also ran only in an adapter that saw the app's originator, so one a terminal
resume started raised `AppServerDeliveryUncertain` on every pass. Any adapter of the chat
now settles it.

New tests fail before: settling from the transcript after the adapter loses the app's
environment, and abandonment with a turn left open an hour ago. Two mutations that
survived now fail the tests: settling on another delivery's tool output, and leaving a
refused start reserved after the queue command fails.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@max-sixty
max-sixty marked this pull request as ready for review November 5, 2026 18:15
… write the tests' records in its shape

`codex.transcript_delivery_turn` settles a desktop start whose answer Leaf couldn't read by finding an `event_msg` `item_completed` record whose item is a `FunctionCallOutput` named `leaf_delivery`. `notes/codex-integration.md` now holds that record as the app's bundled Codex 0.166.0-alpha.6 (app 26.1029.61003) wrote it on 5 November 2026, with how to capture it again. Every field the reader uses matched the record, so the reader is unchanged; its docstring now says which fields a tool output's item holds and that the early stop relies on Codex writing records in timestamp order.

The desktop tests' transcript now stamps records as Codex does, in UTC with a `Z` and an ordinal. One helper writes the tool output record with the captured fields, in place of three hand-built copies that left out its `id`, `thread_id` and times. No assertion changed.

Through the same binary in a scratch home, Leaf envelopes of 55 bytes, 60 KB and 400 KB were stored verbatim, and the reader returned the turn `turn/start` had answered each time.
@max-sixty
max-sixty merged commit 9ff6115 into main Nov 5, 2026
6 checks passed
@max-sixty
max-sixty deleted the grind/g-codex-wake branch November 5, 2026 18:50
max-sixty added a commit that referenced this pull request Nov 5, 2026
`test_a_wait_takes_the_suites_deadline` has failed on `main` since
#5424, which bounded the Codex desktop router's server thread in
`tests/model/test_codex_adapter.py` with `server.join(timeout=10)`. It
now takes `STATED_TIMEOUT`, as every Python-side wait does
(`tests/AGENTS.md`, "Waits").

The deadline check and `tests/model/test_codex_adapter.py` pass (80
tests).

> _This was written by Claude Code on behalf of max-sixty_

Co-authored-by: Claude Opus 5.5 <[email protected]>
leaf-agent added a commit that referenced this pull request Nov 7, 2026
…t_dir fixture (#5684)

#5424 added two `tempfile.TemporaryDirectory(dir="/tmp")` calls to
`tests/model/test_codex_adapter.py`, one in `desktop_router` and one in
`test_a_desktop_chat_the_app_cannot_start_falls_back_to_the_queue`. The
nightly `test_the_resources_a_fixture_owns_are_taken_from_that_fixture`
journey refuses these calls, because the `socket_dir` fixture owns short
directories that hold sockets. `desktop_router` now takes its home
directory from the caller, and each test that uses it asks for
`socket_dir`. Nothing outside the tests changes.

The journey fails on main `02a1e05cb` and passes on this branch (`uv run
pytest --run-nightly
tests/journeys/test_interact_layer.py::test_the_resources_a_fixture_owns_are_taken_from_that_fixture`).
The desktop tests in `test_codex_adapter.py` can't bind an `AF_UNIX`
socket in this sandbox (`Errno 97`), on main and on the branch alike, so
this PR's CI is the first run of them on the new code.

Refs #5658 — automated triage. It fixes one of that issue's twelve
cases.

Co-authored-by: leaf-agent <[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.

Wake idle Codex desktop chats without user messages

2 participants