Repository navigation
Start a turn for a Codex wake that waits after an interrupt - #103
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #101, which also changes
adapters/codex/wake.mjs. Merge #101 first; this PR's base iscodex-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/addand starts a turn with it throughthread/queue/start, instead of runningcodex queue. Ifthread/queue/startfails and the line is still waiting in the queue of an idle thread,wakethrows. 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 throughcodex queue, which exited 0. The hub recordedok: 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 isInterrupted.enqueuecalls it right afterthread/queue/add.on_thread_idle(lines 549-553) returns early when the idle cause isInterrupted.Interruptedthread.The status stays
Interrupteduntil 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, thenQueuedItemService::start) callsstart_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/startfails 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 callsthread/queue/listandthread/read, and throws only when the line is still queued and the thread is idle.The
thread/queue/*methods are experimental, soinitializenow declarescapabilities.experimentalApi. Ifthread/queue/addfails, as on a daemon without it, the adapter falls back tocodex queueas before.viastaysqueue, so the hub and the frame need no change.Evidence
Real run with a bare
codex0.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:ok: true, via: "queue", statesent. For the next 56 s,thread/readgaveidlewith last turninterrupted, andthread/queue/listheld the pair line. No turn started.01a11335-6f93…within 1 s of the wake. The agent ranpair readandpair reply, and the thread went torepliedwith 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 andnpm 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.mjsfails on the code before this change. The fake daemon now refusesthread/queue/*methods unlessinitializedeclaresexperimentalApi, as Codex does.Not verified
thread/queue/startfails while the line still waits, was tested only against the fake daemon.turn/steerfails) and that the user then interrupts with Esc still waits in the queue. This PR does not change that path.-c) still goes throughcodex queue, and the adapter cannot reach its queue.🤖 Generated with Claude Code