Skip to content

Tell a repeated Codex queue turn its delivery was already picked up - #3455

Merged
max-sixty merged 2 commits into
mainfrom
agent-a5d927f6f0a7aa487
Oct 21, 2026
Merged

max-sixty merged 2 commits into
mainfrom
agent-a5d927f6f0a7aa487

Conversation

@max-sixty

@max-sixty max-sixty commented Oct 21, 2026 •

Copy link
Copy Markdown
Owner

Builds Max's decision #41 on the overnight report, option A: tell the agent that a queued delivery is a repeat.

On the codex queue route (the desktop app and IDE), codex queue takes no message id and lists nothing queued. If the adapter dies, a state write fails, or the queue call times out after codex queue has 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

  • The first queued turn's ack accepts the offer (codex_state.confirm_codex_pointer). When that turn acknowledged the pointer before the adapter's retry, leaf delivery ack refused 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.
  • A second turn's ack says it repeats (delivery.earlier_pickup). Where the retry queues before the first turn acknowledges, Codex still runs a turn for each pointer. The second turn's leaf delivery ack now prints a delivery-repeated note: 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") and leaf delivery ack --help say what the note means.

Evidence

A codex-queue journey (codex-cli 0.160.0) ran this branch with a one-shot OSError injected right after queue_delivery returned. The adapter retried a second later and queued the release comment's pointer again, so Codex ran two turns opening on the same leaf-delivery message. The first did the work and replied. The second ran leaf delivery read and leaf delivery ack, got an 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, the codex-app-server and codex-queue journeys both pass on this branch.

Tests

  • test_a_codex_delivery_queued_twice_tells_its_second_turn_it_repeats injects the same failure into accept_codex_delivery after 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 the confirm_codex_pointer change, with the refusal above.
  • Focused suites pass: test_codex_adapter.py, test_codex_app_server.py, test_receipts.py, test_delivery.py, test_hooks.py.

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

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
leaf-agent previously approved these changes Oct 21, 2026
@max-sixty
max-sixty merged commit 1da13be into main Oct 21, 2026
3 of 4 checks passed
@max-sixty
max-sixty deleted the agent-a5d927f6f0a7aa487 branch October 21, 2026 08:02
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]>
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.

2 participants