Skip to content

Start a turn for a Codex wake that waits after an interrupt - #103

Merged
RyanSaxe merged 1 commit into
developfrom
codex-queued-wake
Oct 6, 2026
Merged

RyanSaxe merged 1 commit into
developfrom
codex-queued-wake

Conversation

@RyanSaxe

@RyanSaxe RyanSaxe commented Oct 6, 2026

Copy link
Copy Markdown
Owner

Stacked on #101, which also changes adapters/codex/wake.mjs. Merge #101 first; this PR's base is codex-subagent-wake.

What

When the Codex daemon runs the agent's thread and no turn is in progress, the Codex adapter now adds the wake line with thread/queue/add and starts a turn with it through thread/queue/start, instead of running codex queue. If thread/queue/start fails and the line is still waiting in the queue of an idle thread, wake throws. The hub then records the wake as not delivered, where before it showed it as sent.

Why

A manual test found this. In a bare codex (daemon mode), after the user pressed Esc to interrupt a turn, wakes went through codex queue, which exited 0. The hub recorded ok: true, via: "queue" and the browser showed Sent, but Codex started no turn. The line waited in the thread's queue until the user typed in the terminal.

The cause is in Codex's queue extension (rust-v0.160.0, codex-rs/ext/queue/src/service.rs):

  • wake_if_loaded (lines 472-483) skips dispatch while the thread's agent status is Interrupted. enqueue calls it right after thread/queue/add.
  • on_thread_idle (lines 549-553) returns early when the idle cause is Interrupted.
  • The 10 s watcher (lines 218-226) also returns for an Interrupted thread.

The status stays Interrupted until a new turn starts, so a queued line waits until the user sends a message.

The choice

The proposal allowed two fixes: start the turn, or report the wake as waiting. This PR starts the turn, because then the agent actually reads the line. thread/queue/start (codex-rs/app-server/src/request_processors/thread_queue_processor.rs:186-241, then QueuedItemService::start) calls start_turn_if_idle. That call checks only for an active turn, not the agent status, so it starts the queued line after an interrupt. If Codex already started the line itself (a normal idle thread), thread/queue/start fails with "queued submission not found". If a turn is running, it fails with "thread already has an active or pending turn" and Codex reads the line when that turn ends. After a failure the adapter calls thread/queue/list and thread/read, and throws only when the line is still queued and the thread is idle.

The thread/queue/* methods are experimental, so initialize now declares capabilities.experimentalApi. If thread/queue/add fails, as on a daemon without it, the adapter falls back to codex queue as before. via stays queue, so the hub and the frame need no change.

Evidence

Real run with a bare codex 0.160.0 (no -c, on the shared daemon) on a scratch hub on port 4892. Codex started the session there, and its sessions never appeared on 4747. Each run sent a thread, pressed Esc once the wake's turn was in progress, then sent a reply to the thread:

  • develop hub: the reply's wake was recorded ok: true, via: "queue", state sent. For the next 56 s, thread/read gave idle with last turn interrupted, and thread/queue/list held the pair line. No turn started.
  • this branch's hub, same session and Codex: the reply's wake started turn 01a11335-6f93… within 1 s of the wake. The agent ran pair read and pair reply, and the thread went to replied with the agent's "received" and "again". A later feedback wake on a normally idle thread also started its turn at once, with the queue empty.

Checks: node --test (263 pass), prettier, ESLint and npm run test:browser (76 pass, 12 WebKit tests skipped because Playwright's WebKit does not run on macOS 14).

The new test in tests/adapters/codex.test.mjs fails on the code before this change. The fake daemon now refuses thread/queue/* methods unless initialize declares experimentalApi, as Codex does.

Not verified

  • The throw path, where thread/queue/start fails while the line still waits, was tested only against the fake daemon.
  • A wake that Codex queues behind a running turn (when turn/steer fails) and that the user then interrupts with Esc still waits in the queue. This PR does not change that path.
  • A Codex run in-process (any -c) still goes through codex queue, and the adapter cannot reach its queue.

🤖 Generated with Claude Code

After the user presses Esc in a Codex that runs on the app-server
daemon, the thread's agent status stays Interrupted until the user sends
a message, and Codex's queue extension does not dispatch queued input
for an Interrupted thread (ext/queue/src/service.rs, wake_if_loaded and
on_thread_idle). A wake through codex queue then waited in the queue
while the hub recorded it as sent, and the agent read it only when the
user typed in the terminal minutes later.

For a thread the daemon runs with no turn in progress, the adapter now
adds the line with thread/queue/add and starts it with
thread/queue/start, which starts a queued line on any idle thread. When
that fails and the line still waits in the queue of an idle thread, the
wake throws, so the hub records it as not delivered instead of sent.
The thread/queue methods need the experimentalApi capability, so the
adapter declares it in initialize, and the fake daemon refuses them
without it, as Codex does.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@RyanSaxe
RyanSaxe marked this pull request as ready for review October 6, 2026 22:30
@RyanSaxe RyanSaxe mentioned this pull request Oct 6, 2026
Base automatically changed from codex-subagent-wake to develop October 6, 2026 23:01
@RyanSaxe
RyanSaxe merged commit 0a2ccc1 into develop Oct 6, 2026
25 of 27 checks passed
@RyanSaxe
RyanSaxe deleted the codex-queued-wake branch October 6, 2026 23:01
@RyanSaxe RyanSaxe mentioned this pull request Oct 7, 2026
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.

1 participant