Repository navigation
Tell a repeated Codex queue turn its delivery was already picked up - #3455
Merged
Merged
Conversation
On the `codex queue` route a failure after `codex queue` returns, before Leaf records the acceptance, leaves the offer to be queued again. Two cases follow: - A turn that opens on the first pointer and acknowledges it before the adapter's retry got a refusal from `leaf delivery ack`, and the adapter then queued the pointer again after that turn. The ack now accepts the offer (`codex_state.confirm_codex_pointer`), so nothing is queued twice. - Where the retry queues before the first turn acknowledges, Codex runs a turn for each. The second turn's `leaf delivery ack` now notes that an earlier turn already picked the delivery up and names the answers its updates still owe, read from the page (`delivery.earlier_pickup`), so the second turn does no repeated work and still answers what the first left owed. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
previously approved these changes
Oct 21, 2026
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
approved these changes
Oct 21, 2026
max-sixty
added a commit
that referenced
this pull request
Oct 21, 2026
A page server now installs its `exit_serving` signal handlers as its service commits, before its URL leaves the process. Before this change it installed them only after the URL was printed. This is a follow-up to #3452 (Max's decision #34 on the overnight report). **The bug.** #3452 installed the handlers just before the server started its threads, which comes after `server run` prints the URL. Ctrl-C sent as soon as the URL appeared could land in between. It then took the old unwinding path and exited 1 with `{"error": "interrupted"}` instead of 130. `test_server_run_persistent_declines_the_claim_a_harness_session_offers` sends SIGINT as soon as it reads the URL line, and it failed this way on CI in #3455, #3459 and #3460 ([run](https://github.com/max-sixty/leaf/actions/runs/39568649930/job/119117041536)). A user pressing Ctrl-C right after the URL appears hits the same window. **The fix.** `cmd_serve`'s `commit()` installs the handlers once the service is committed and before it returns. Both paths that hand the URL out run after `commit()`: `server run` prints it, and `_serve` sends the handshake confirmation that `server start` prints. A signal during the commit still unwinds, so a failed commit still rolls the service back. **Checked.** A temporary test (not committed) started `leaf server run --persistent`, read the URL line and signaled at once. With a 0.05 s sleep injected right after the URL is printed: | Version | SIGINT trials | Exited 130 | SIGTERM trials | Exited 143 | |---|---|---|---|---| | main | 100 | 0 (all exited 1, "interrupted") | 100 | 100 | | this change | 100 | 100 | 100 | 100 | SIGTERM's status doesn't show which path it took, since the unwinding path also exits 143. Without the injected sleep, 100 trials of each signal passed on both versions on a lightly loaded Mac; the failure needs CI's scheduling delay. The focused server lifetime, server process, title and preview handoff tests pass (193). > _This was written by Claude Code on behalf of max-sixty_ Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
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.
Builds Max's decision #41 on the overnight report, option A: tell the agent that a queued delivery is a repeat.
On the
codex queueroute (the desktop app and IDE),codex queuetakes no message id and lists nothing queued. If the adapter dies, a state write fails, or the queue call times out aftercodex queuehas taken the pointer but before Leaf records the acceptance, Leaf queues the same pointer again rather than risk losing the comment. Two cases follow, and this covers both.What changes
codex_state.confirm_codex_pointer). When that turn acknowledged the pointer before the adapter's retry,leaf delivery ackrefused it (delivery no longer owns its page or receiving turn), since the record was still a bare queue offer, and the adapter queued the pointer again once that turn ended. The pointer in the turn proves the queue took it, so the ack now records the queue's acceptance and the opened pickup, and nothing is queued twice.delivery.earlier_pickup). Where the retry queues before the first turn acknowledges, Codex still runs a turn for each pointer. The second turn'sleaf delivery acknow prints adelivery-repeatednote: an earlier turn already picked up the delivery, so don't redo that turn's work, followed by the answers its updates still owe, read from the page's obligations rather than the agent's memory. Leaf keeps those updates owed until they are answered, as before.harness-codex.md("Delivery") andleaf delivery ack --helpsay what the note means.Evidence
A
codex-queuejourney (codex-cli 0.160.0) ran this branch with a one-shotOSErrorinjected right afterqueue_deliveryreturned. The adapter retried a second later and queued the release comment's pointer again, so Codex ran two turns opening on the sameleaf-deliverymessage. The first did the work and replied. The second ranleaf delivery readandleaf delivery ack, gotan earlier turn already picked up delivery 9a338dc0, so don't redo the work that turn did. None of its updates still owes an answer., and ended on one sentence saying the comment was already handled, with no edit or reply. Every later step of that journey passed. Without the injection, thecodex-app-serverandcodex-queuejourneys both pass on this branch.Tests
test_a_codex_delivery_queued_twice_tells_its_second_turn_it_repeatsinjects the same failure intoaccept_codex_deliveryafter the queue call: the adapter queues the same pointer twice, the first turn's ack prints nothing, and the second turn's ack names the first turn and the reply still owed, or no answer once it is written. It fails without the note.test_a_queued_turn_that_acks_before_the_retry_takes_the_delivery_once: with the same failure, a turn that acknowledges before the retry gets its ack accepted, the adapter queues nothing more, and the page records one queued and one opened pickup. It fails without theconfirm_codex_pointerchange, with the refusal above.test_codex_adapter.py,test_codex_app_server.py,test_receipts.py,test_delivery.py,test_hooks.py.