Skip to content

Retry the deploy gate's agent ask for a turn_failed receipt, not only startup_failed - #791

Closed
leaf-agent wants to merge 1 commit into
mainfrom
fix/ci-35327552033
Closed

leaf-agent wants to merge 1 commit into
mainfrom
fix/ci-35327552033

Conversation

@leaf-agent

Copy link
Copy Markdown
Collaborator

publish-site failed on main at f249da60 — run 35327552033. The deploy itself is fine: Deploy public Leaf pages succeeded and the release pass printed ✓ https://leaf.page serves release 83204c73… in /usr/bin/google-chrome at 09:13:25, so leaf.page is published and current. What failed is the hosted-agent pass that follows it, on a receipt the host writes to tell the reader to send the message again — and the gate reported it instead of sending it again. This PR puts that receipt back in the retried set.

The receipt says retry; the gate did not

The pass posted one comment, and the container settled it 2.4 s later:

  request acknowledged 126 ms
  activity closed at 214 ms
  activity listening at 2.4 s
  replied at 2.4 s

RuntimeError: https://leaf.page/examples/triage-board/ agent did not publish 'Deployment 83204c73 verified'; it reached revision 1 from 1 with the page reading listening; it replied: The agent's turn ended without an answer to this message. Send it again to retry.

Those are the words of the turn_failed receipt — the one a container writes "from its own reading of a turn it followed to nothing" (worker/README.md). The page was back to listening with nothing holding it, and TURN_LIMIT had 9 and a half of its 10 minutes unspent, so a second ask was affordable. The gate ended the deploy instead.

The retried set fell behind the receipt table

Asking again on this exact condition is not new behaviour — it is what #508 was for. It read the receipt as meaning "the deployed container noticed a turn that never completed, closed it, and settled the reader's standing ask rather than leaving it open", and justified sending the message again with the property that still holds: "A release that cannot run a hosted turn at all settles the same way twice and still reddens main; a single model-side failure does not."

What happened since is that the condition moved codes while the gate's list did not:

So the one code that names the condition #508 retried became the one code the gate does not retry, and this run is that gap reached.

The change

ASK_AGAIN declares the two receipts whose own words end in "Send it again to retry" — startup_failed (a turn that never began) and turn_failed (a turn followed to nothing). rate_limited stays out: it names a load condition a second ask inside the same pass would meet again. A turn that ends with no receipt at all still fails on the first ask.

A retry does not paper over a bad release. Neither retried code says anything about the release that would settle a second ask differently, so a container that genuinely cannot run a hosted turn fails the deploy on the second receipt instead of the first — and the ↻ line now names which code was asked again, so the log says which one it was.

The predicate turn_failed(replies) — "any reply carries a failure" — is renamed settled_by_failure, because its name now collides with the receipt code of the same spelling and the collision sits exactly where this policy is read. worker/README.md, which owns the failure contract, and scripts/CLAUDE.md both state the widened policy.

Verification

uv run pytest tests/test_website_server.py — 81 passed. The two policy cases are parametrized over website_server.FAILURE_RECEIPTS itself rather than a literal pair, so a fourth code cannot be declared without them saying which side it falls on, and they assert against the literal rate_limited rather than against ASK_AGAIN, so they cannot agree with the constant by construction. Both are bug-back checked: narrowing ASK_AGAIN back to {"startup_failed"} fails test_the_deploy_gate_asks_again_for_every_receipt_that_invites_one[turn_failed] on assert 1 == 2 and test_the_deploy_gate_reads_a_durable_host_failure[turn_failed] on the predicate.

uv run pre-commit run over the four changed files passes.

The live path is not reachable from here — the hosted turn runs in a Cloudflare container against a Codex login this account has no credentials for — so the unit coverage is the evidence for the change and the run above is the evidence for the diagnosis. scripts/verify_site.py is exercised on the next push to main that deploys.

Why this is a durable gate gap rather than a transient

The container-side fault behind the receipt may well have been a one-off: the release pass ahead of the agent pass absorbed seven rounds of the rollout 503, at 09:11:19 through 09:12:56, before landing at 09:13:25, so the agent's turn was dispatched into a container the image rollout had only just reached. What is durable is that the gate has no ask-again for the receipt that condition produces: since #783 landed there is no wait covering turn_failed, so the next deploy whose turn faults once fails the same way. Reading the container's own logs to say which fault it was needs Cloudflare credentials this account does not have.

This is a different shape from open tracker #772, which is the unbound follower that reaches no receipt at all and leaves the page reading working for the gate's whole TURN_LIMIT. That one still needs the bound it asks for; this PR is about what the gate does once a receipt has arrived, so it neither fixes nor depends on it.

@max-sixty

Copy link
Copy Markdown
Owner

rather than adding retires / conditional retries, can we fix the underlying issue that's causing the need for retries?

@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Agreed, and the receipt turns out to name where the underlying fault is. Closing this.

turn_failed has exactly one writer: _report_failure, reached only when commit finds leaf_turn is None. leaf_turn is set in one place, bind, and its writer open_app_server_delivery returns a turn id or raises — never None. The Worker's door refuses the code, so nothing else can write it. So a turn_failed receipt on a page is proof that the follower never bound its delivery to an App Server turn — which is #772, not a new fault.

That reframes the run. #779 gave the unbound follower an outcome when a fault escapes the loop; this is that outcome reaching a reader for the first time, 2.3 s after dispatch. #772's open half is the other exit from the same unbound state — the silence loop that never raises, so the page reads working forever. Same condition, two endings.

I can't produce the fix from here. Which fault it was is recorded in the container's own turn_stream_completed line — status plus fault fields — on its stderr, and this account has no Cloudflare credentials to read Workers logs; there is no codex on the runner to drive a hosted turn against either, which is the same wall #772 records. So anything I wrote would be a guess at the lifecycle, which is the part that should not be guessed.

The one candidate I can name from reading the code

Inferred from the source, not observed — the logs above are what would settle it.

_start_turn deliberately discards the turn id from an acknowledged turn/start: "the follower learns which App Server turn took this delivery from the notification stream, which is the one reading that survives a lost acknowledgement." That leaves awaiting true, so should_resubscribe is armed on the first loop iteration. Its only test for "App Server has not started this delivery" is delivery_queue_state(...) == "offering" — and the claim that clears offering is $LEAF delivery claim running inside the container, seconds after the turn starts. So between an acknowledged turn/start and the model's first command, a follower whose turn/started did not arrive buffered drops a live subscription for a turn it has already been told exists. The resume that follows looks for a turn whose items name the delivery, and a turn that has not emitted its leaf_delivery output yet has none.

If that is the path, the fix is small and does not touch the binding rule: _start_turn knows App Server acknowledged a start, and should_resubscribe could be told so without binding to an id that may be stale. A slow container — this turn was dispatched into one the image rollout had only just reached, with seven rounds of the rollout 503 immediately before it — widens exactly that window.

I'll add this to #772 so it is on the durable record rather than only here.

@leaf-agent leaf-agent closed this Sep 18, 2026
max-sixty pushed a commit that referenced this pull request Sep 19, 2026
… event id off --section (#837)

`publish-site` on `main` failed at the deploy gate's hosted-agent pass.
The turn spent three commands failing to reach Leaf's reply interface,
and the revision that did reach the page never carried the heading the
ask named. This PR fixes the two dead ends those three commands hit: a
refusal that offers no recourse when `--section` is handed an id from
another namespace, and five printed command forms that omit their
required `PAGE` argument. It does not make the failed run green — what
the turn chose to publish is the model's, and the section below says why
I did not reach for the gate's retry instead.

## What the run did

The gate reported:

```
RuntimeError: https://leaf.page/examples/triage-board/ agent did not publish ‘Deployment de34a7d1 verified’; it reached revision 2 from 1 with the page reading listening; it replied: deployment verified
```

Workers Observability for that turn (event
`56f596b2765bf1b5f1a6f40bc4232ab6`, turn
`01a0b800-c8fd-7f72-a404-2316ffc1f704`) records the sequence: one
`commandExecution` at exit 0, one `fileChange`, then three
`commandExecution` items with status `failed` at exits 1, 2 and 1, then
the final model message the host published as the reply. No publish
command ran at all. The gate's own activity profile names the three that
failed:

```
$LEAF reply --section 56f596b2… --quote 'deployment verified' "deployment verified"
$LEAF reply . --section 56f596b2… "deployment verified"
$LEAF reply . --section 56f596b2… --text "deployment verified"
```

One wrong belief runs through all three: that `--section` takes the
delivered event id. It takes an element id. The first also drops the
`PAGE` argument entirely, so `"deployment verified"` landed as the page
directory.

Revision 2 was not one of those three. `_capture_anchor` exits before
`activate_checked_source` runs, so a reply refused on its section
activates nothing; the turn's only other write was the host-bound final
message, whose reply carries `validate_source=True` and so activated the
edited `index.html`. What that revision actually held is the one thing
the records do not say — no content is logged, by design — so whether
the model wrote a different heading or the gate's fetch of the private
revision never landed is not settled here. Either way the turn reached
its reply through a route that never confirmed the edit.

The 503s earlier in the same log are separate and already answered: the
image rollout draining, absorbed by the workflow's own `until` loop,
with #835 since landing the reading that names them. The commit under
test (#832) changed only browser runtime modules and their tests, so it
did not cause this.

## What changes

**The refusal names the namespace.** Reproduced at the CLI, `leaf reply
<page> --to <id> --section <that same id>` exits with `can't anchor in
revision r1: no element id '…' in this version` and nothing else,
sending an agent that holds a log id to look through the page's markup
for something that was never there. `_foreign_id_recourse` in
`conversation.py` reads the log, and when `--section`'s value is an
event there the refusal continues:

```
; <id> is a comment in this page's log — `leaf reply <page> --to <id>` answers a message and `--for <event-id>` addresses a delivered move, while `--section` takes an element id the page's markup declares
```

It sits at `_capture_anchor`, the one door both `leaf comment` and `leaf
reply` reach `--section` through, and it stays silent unless the log
actually holds the value, so the existing typo refusals are untouched.

`--for` is named for every kind the log holds, not only for a message. A
reader's press on a widget frozen into a reply is addressed through that
action event's own id and nothing else — `current_responses` returns a
reply obligation keyed on it, and `--to` names messages — so gating the
pointer on a message kind would have left the one case where a single
option is the only route without one. The article is derived rather than
fixed, so `action`, `undo`, `edit`, and `unresolve` do not read as "a
action".

**Every printed command form carries its page.** `leaf comment --section
<ask-id>` cannot run: `PAGE` is a required argument, so the next token
is eaten as the page directory. It was printed that way in five places —
`ANSWER_ASK_INSTRUCTION`, both `requires a page version` refusals in
`cmd_reply`, and the `comment` and `reply` handling sentences in the
layer registry, which is the vocabulary an agent reads for the exact
event it is answering. The public reference in
`references/conversation-threads.md` already writes every form with its
page; these now agree with it.

## Why not the gate's retry

The turn replied without doing the work, and `ask_until_answered`
re-asks only on a `startup_failed` receipt, so that shape gets one ask.
Widening it is where #791 went, and you closed that with "rather than
adding retries / conditional retries, can we fix the underlying issue
that's causing the need for retries?" — so I have left the gate alone
and fixed what the turn actually ran into. What remains unaddressed is
the model's own choice, which no change here reaches.

## Verification

Two new cases in `tests/test_interact_anchors.py` — one for a message id
handed to `--section`, one for a delivered widget press — each fail
against the refusal they replace with exactly its production message,
and pass with the fix. `uv run pytest tests/test_interact_anchors.py` is
green (53 passed), as are `tests/test_interact_product.py` and
`tests/test_interact_contract.py` (329 passed).

<details><summary>Wider selection and its environment failures</summary>

`uv run pytest tests/test_interact_session.py
tests/test_interact_layer.py tests/test_interact_contract.py` ran 627
passed, 3 skipped, with 2 failures and 2 errors that belong to this
sandbox rather than the change: three are `OSError: [Errno 30] Read-only
file system` on `/tmp`, which the agent sandbox mounts read-only, and
`test_staged_writes_honor_umask_without_copying_a_replaced_symlink_mode`
reads the sandbox user's umask. None touch the anchor or conversation
paths.

</details>

`publish-site` has since gone green on `main` twice, at `ce11d502` and
`d21cd640`, so nothing is currently red and this is not urgent.

Failed run:
[35422088941](https://github.com/max-sixty/leaf/actions/runs/35422088941).

---------

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

2 participants