Skip to content

Retry the deploy gate's agent pass when the edge answers 503 during a container rollout - #790

Merged
max-sixty merged 1 commit into
mainfrom
fix/ci-35320758891
Sep 18, 2026
Merged

max-sixty merged 1 commit into
mainfrom
fix/ci-35320758891

Conversation

@leaf-agent

Copy link
Copy Markdown
Collaborator

publish-site on main at c9a5f207 failed in Verify the exact public release in Chrome — run 35320758891. The deploy itself succeeded: the release pass printed ✓ https://leaf.page serves release a471af1a… in /usr/bin/google-chrome at 07:48:31. Six seconds later the agent pass gave up on its first request:

RuntimeError: https://leaf.page/examples/triage-board/api/view?revision=1&through_seq=1 returned 503

The 503 is the edge's rollout answer, not a fault

GET api/view is the request that activates a private session, so it is the one that allocates a container. Until the container image rollout reaches that allocation, the container answers for the previous release, and rollingOut refuses to hand it on: the reader is unseated and every request but GET api/state gets 503 with Retry-After: 5. worker/README.md states that contract and worker/test/index.test.ts holds the Worker to it.

agent_session was already built to wait this out. Its docstring says so — "a rollout may still be propagating between edge locations, so the gate retries with a fresh context until both readings agree" — and its 180-second loop retries whenever reader_session reports an allocation on the wrong release. But it only ever saw that condition as a release header to compare, which is how the Worker used to surface it. #775 changed the edge to answer for itself, and on this path the same condition now arrives as a status. check(activated.ok, …) sits ahead of the comparison, so the retryable case became a hard failure before the loop could ever see it.

That is also why the release pass ahead of it was green on the same rollout: the workflow's until loop reruns the whole script, so it absorbed four rounds of exactly this 503 (07:46:57 through 07:48:06) before the fifth landed. The agent pass has no such loop — deliberately, since it posts a comment — and its own wait was the thing that had stopped covering the case.

The change

reader_session now recognises the Worker's rollingOut answer and returns it as one more reason this allocation cannot admit a turn, so agent_session's existing retry picks it up. Both reasons — a container that answered for another release, and the edge answering in its place — end in the same 180-second wait and the same message, which now names which reading ran the bound out.

Nothing about the bound, the write, or the rest of the gate moves: an allocation that never comes good still fails the deploy, just with reached no container able to admit its agent's turn; the last allocation was a container the image rollout had not reached instead of a bare status.

rolling_out matches on Retry-After rather than on the status alone — the Worker is the only thing in the system that sends it — so a container's own 503 — which comes back through the pass-through path with Leaf-Session: active and no Retry-After — is still a failure rather than something the gate waits out.

Verification

Two cases in tests/test_website_server.py drive agent_session against a fake allocation answering api/view exactly as rollingOut does. Both were verified paired — they reproduce the run's own … returned 503 without the change and pass with it:

  • test_the_agent_pass_waits_out_an_allocation_the_rollout_has_not_reached — the unseated context is closed, a fresh one is opened, and the turn runs on the second allocation.
  • test_a_rollout_that_never_lands_ends_the_agent_pass_naming_it — past the deadline the pass still fails, and the message names the rollout.

uv run pytest tests/test_website_server.py is green (78 passed), as is pre-commit over both files.

Why this is filed as a durable cause rather than a transient one

The rollout window is real on every deploy; whether the agent pass opens its session inside it is timing. The next deploy — run 35320965464 on e5394c64 — went green, so leaf.page is published and current, and this commit needs nothing further. What is durable is the gate: since #775 landed on 2026-09-17 there is no wait covering this answer, so a deploy that allocates a moment earlier fails again. The two prior open trackers are different shapes — #658 is the Cloudflare control plane in the push and deploy steps, #772 is a hosted turn follower that never binds its delivery.

@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Two more deploys have failed this way since this PR opened, on the same line and the same request. With run 35320758891 that makes three consecutive publish-site runs on main, and the last two are back to back:

Run Commit Agent pass failed on
35320758891 c9a5f207 (#784) …/examples/triage-board/api/view?revision=1&through_seq=1 returned 503
35324499878 de1f4a4e (#785) same
35325145249 5311ed03 same

Both new runs end at check(activated.ok, …) in reader_session — the check this PR moves the rollingOut answer past — so the recurrences are this PR's case rather than a second shape wearing the same status.

The asymmetry the description names is what the logs show, twice over. On de1f4a4e the release pass absorbed four rounds of the identical 503 between 08:31:58 and 08:32:48 and went green at 08:33:15; the agent pass failed five seconds later. On 5311ed03 it absorbed six rounds between 08:38:58 and 08:40:21, went green at 08:40:49, and the agent pass failed seven seconds later. The until loop covers one pass and not the other, and the rollout window is wide enough that the unprotected pass lands inside it more often than not.

Deploy public Leaf pages succeeded in every one of the three, so https://leaf.page/ is published and current — it serves release fabf456c… from 5311ed03, main's tip. What is red is the gate, and it will stay red on roughly every deploy until this lands.

Nothing here asks for a change to the diff; it is the occurrence evidence behind classifying the cause as durable.

@max-sixty
max-sixty merged commit 2684c18 into main Sep 18, 2026
4 checks passed
@max-sixty
max-sixty deleted the fix/ci-35320758891 branch September 18, 2026 09:01
max-sixty added a commit that referenced this pull request Sep 19, 2026
…835)

Two changes from re-tracing #658, which is closed: its live failure mode
was fixed by #790 before its last comment was written, and that
comment's account of the cause is wrong. The correction and its evidence
are on the issue.

## The deploy gate reads its activating request in one place

`publish-site`'s release pass and its agent pass both `GET api/view`,
the request that allocates a reader's container. While the container
image is still propagating, the Worker's `rollingOut` answers it with
`503` and a `Retry-After`. Since #790 the agent pass recognises that and
waits; the release pass read the same answer as a bare status and raised
`… returned 503`, which is the line [run
35320758891](https://github.com/max-sixty/leaf/actions/runs/35320758891)
printed seven times — six inside the workflow's `until` loop, which
reran the script and went green, then the seventh in the agent pass,
which ended the deploy.

Workers Observability settles what those seven were. One request logs
twice under a single `traceId`, once for the Durable Object and once for
the stateless Worker; for the fatal `api/view` at 07:48:37 (`traceId
c3a65be546478da87775ae3682c42305`) the Durable Object answered **200**
and the Worker answered **503**. `rollingOut` is the only Worker path
that makes that conversion, and it sends the header.

`activation_read` now makes the request for both passes and returns
`None` while the rollout is still landing, so the release pass reports
it in the sentence the agent pass already uses. Neither wait moves: the
agent pass keeps its 180 seconds, and the release pass keeps relying on
the workflow rerunning it. A `503` without `Retry-After` — what
`@cloudflare/containers` returns when no instance can be allocated — is
still this release failing on the first read, which one of the two new
cases pins.

## A reader is told what a 503 means

The open question on the issue was whether a reader arriving at a cold
page gets this too. They do, and their gesture has always landed:
`deliver` retries every two seconds. But the notice it showed came from
the JSON decode that `rollingOut`'s plain-text body fails — "Couldn't
read the answer — retrying your change…" — which reports the page
failing to read an answer the server never sent.

`deliver` now reads the status before decoding. A `503` on the page's
one door is the server saying it cannot take this yet, whatever the
reason, so the browser needs no equivalent of the gate's header test:
the gate has to separate the two 503s because it decides pass or fail,
while both mean the same retry here. The reader is told "The server
isn't ready yet — retrying your change…".

## Verification

Both runtime claims were established by running the shape rather than
reading it: a preview with `rollingOut`'s exact answer replayed at
`/api/event` refuses the attempt and the outbox retries it, landing the
gesture when the refusal stops, under the old wording and the new. Each
new case was verified paired — removing the branch it covers reds it,
restoring greens it.

`uv run pytest tests` and `uv run pytest tests/test_render_outbox.py`
are green, as is pre-commit over every changed file.

Ref #658

> _This was written by Claude Code on behalf of max-sixty_

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 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