Repository navigation
Ask the source before reloading, and answer for the edge while containers roll out - #775
Conversation
…ners roll out A reader's leaf.page tab restarts in a loop for the length of every deployment. Cloudflare activates a Worker and its assets in one operation and rolls the container application's image out in another, so for the first minutes after a deploy the edge serves one release while containers still answer for the previous one. Measured on leaf.page mid-deploy: the edge at 908c101b, the container at 7f2c04bd. The page refuses a foreign answer and reloads. That heals a document the server has moved past. It cannot heal a server the document has moved past, because the reload lands on the document the edge just served, the next state read disagrees again, and the page-local guard starts over with each load. Measured against a page whose state reads answer from another layer: 137 main-frame navigations in 20 seconds. The edge no longer relays an answer from a container on another release. It unseats the reader, serves GET api/state from the published projection, and holds every other request behind 503 Retry-After until the rollout lands. The deploy gate still waits for the containers, since verify_site.py requires Leaf-Session: active. The runtime now asks the source of documents before reloading, through the probe bootstrap.js already uses for startup recovery: a page's release-scoped assets are gone once the edge has moved on, and its registry still names this document's layer while it has not. A source that has not moved leaves the answers refused, which is the offline reading the page already holds, and says so once. A probe that cannot be read settles nothing, so the next foreign answer asks again. A replaced server incarnation still reloads on sight; that is not a question about generations. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
leaf-agent
left a comment
There was a problem hiding this comment.
reloadDelivery latches sourceAsked for the page's lifetime as soon as the probe answers "not moved", so the module's new rule — the page "rejoins the log by itself once the server is back on this delivery" — only holds while the source stays where it was. If the source moves on during the hold, nothing re-asks: every later foreign answer returns at the sourceAsked guard, the page refuses state indefinitely, and the notice that explained it is a four-second status line that faded long before. The old rule always converged; this is the one state the change adds that a reader cannot leave without reloading by hand.
It isn't only the second-deploy case, and it isn't website-only. On an ordinary leaf serve page, a revision artifact captured before a re-vendor answers with its own generation — _send_document and the /api/view branch in skills/leaf/scripts/leaf/http.py each set response_layer from artifact.registry["$layer"]["generation"] — while the /registry.json branch answers for the active revision. So opening a version comparison against a pre-re-vendor revision (authoredDocument and baseReading in runtime/version.js, both gated on sameDelivery) refuses, probes, is told the source has not moved, and latches. A genuine re-vendor after that never reloads the tab.
Reopening the question on a cool-down keeps the one-probe-per-disagreement property the new test pins while leaving the page able to converge. The two suggestions below do that; with them applied, test_a_page_asks_its_source_before_reloading_onto_the_same_document and test_a_revision_the_page_has_to_refuse_leaves_the_beat_beating both still pass. The visible cost is the notice repeating every 30 s through a long hold — given it is a transient status line rather than a standing banner, that may be the better reading anyway, so the interval is yours to pick.
The first pass asked the source once and kept the answer for the tab's whole life. The source can move while the page waits — this page can be re-vendored during the hold — and a page holding an earlier reading would refuse state for the rest of the tab's life with no way back. /api/view and an immutable document are stamped with the captured layer of the revision they name, and version.js puts both through sameDelivery, so a version comparison against a revision written before a re-vendor reaches this hold on an ordinary leaf serve page and not only on the website. One probe is in the air at a time, so a burst of refusals costs one. The words stay at once: a standing condition explained once is enough, and repeating a transient status line would hold the page's foot for as long as the disagreement lasts. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
leaf-agent
left a comment
There was a problem hiding this comment.
test_a_page_asks_its_source_before_reloading_onto_the_same_document reads probes without waiting for it, so its last assertion races the probe it counts. holding(page, reads, index + 1, …) returns as soon as the third /api/state handler has appended; the probe that refusal sets off is still on its way back into the driver. Instrumented, probe 3 lands ~9 ms after read 3 is dispatched into this process while the assertion runs ~2 ms after holding returns — and with six spinners on the box, one run in three reported probes=2 reads=3 at that point, which is the assertion failing on a correct runtime. The file is nightly, so this reddens main rather than the PR gate.
tests/CLAUDE.md names this case under State races are arrangements, not probabilities: "A handler that appends a route to held has established only that the browser made the request. Before reading that list — indexing it, asserting its length, or taking the handler away with page.unroute … — wait through holding."
Equality is also tighter than the runtime promises. reloadDelivery returns early while asking is set, so a refusal arriving during a probe deliberately costs no probe of its own — "a burst of refusals costs one", as the module says. What the test is defending is that the page re-asks rather than carrying one reading over, and holding states that directly: with the suggestion applied it passed four runs under the same load, and with asking = false dropped from the finally it fails at the route never took the asks the refusals made of the source: 1 of 3 dispatched into this process.
The count of probes was read behind the wait for the reads that caused them. An ask leaves the page a beat before the route records it here, so under load the assertion ran against a list the last probe had not reached, and the test would have flaked nightly at roughly one run in three. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
A revision keeps the layer it captured, and comparing to it is not a re-vendor. `/api/view` and the immutable document both answer for that captured generation rather than the live page's (`http.py`'s `_send_document` and its `/api/view` branch), and `version.js` ran both through `sameDelivery`, which reads a foreign generation as the page being re-vendored underneath the reader. After any re-vendor the base of a comparison is foreign by definition, so the page refused its own comparison, abandoned it without a word, and told the reader the server was updating. Measured on a real page: stamped at v1, re-vendored, stamped at v2, r1's captured registry still holds `e258ffa7…` while the live page answers for `37c87ab9…`. The new case in `test_render_projection.py` builds that page, drives its chooser to compare against v1, and requires the comparison to paint. It asserts its second `page init` succeeded, since a refused re-vendor would leave the base unforeign and the case green against the runtime it exists to pin. An artifact fetch is not a delivery answer, so neither goes through the gate, and `sameDelivery` leaves `version.js` entirely. A layer that really did move under the reader still reaches the page through the state feed, which is the live channel and refuses on its own. `authoredDocument` also feeds `revisionDocument`, so taking its null return away left `prepareActivation`'s refusal unreachable and the `stale` flag on its answer dead. That axis is deleted rather than re-gated — the branch, both `stale: false` returns, and the reading in `state-application.js` that consumed them — because a re-vendored layer changes the revision's executable identity, which takes the fresh-document install above that path, and a state belonging to another layer is refused by `receiveState` before it arrives. Found while verifying leaf-agent's reachability argument on #775, and left out of that PR as separate scope. Checked: everyday suite (1138), `test_render_projection.py` and `test_render_startup.py` under `--run-nightly` (238), and `pre-commit run --all-files`. > _This was written by Claude Code on behalf of max-sixty_ --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
… container rollout (#790) `publish-site` on `main` at [c9a5f20](c9a5f20) failed in **Verify the exact public release in Chrome** — [run 35320758891](https://github.com/max-sixty/leaf/actions/runs/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`](https://github.com/max-sixty/leaf/blob/c9a5f2078a6995533a90b09af75f6baf6fc63c10/worker/src/index.ts#L782-L810) 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](#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. <details><summary>Why this is filed as a durable cause rather than a transient one</summary> The rollout window is real on every deploy; whether the agent pass opens its session inside it is timing. The next deploy — [run 35320965464](https://github.com/max-sixty/leaf/actions/runs/35320965464) on [e5394c6](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. </details> Co-authored-by: leaf-agent <[email protected]>
A reader's leaf.page tab restarts in a loop for the length of every deployment. Cloudflare activates a Worker and its assets in one operation and rolls the container application's image out in another, so for the first minutes after a deploy the edge serves one release while containers still answer for the previous one. Measured on leaf.page mid-deploy: the edge at
908c101b, aPOST /api/eventat7f2c04bd.The page's rule for a foreign release was
location.reload(). That heals a document the server has moved past — a tab left open across a re-vendor. It cannot heal a server the document has moved past, because the reload lands on the document the edge just served, the next state read disagrees again, and the in-page "already reloading" guard resets with each load. Theactivecookie keeps the reader pinned to the container across reloads, so it does not drain on its own. Measured against a page whose state reads answer from another layer: 137 main-frame navigations in 20 seconds, now 0.The Worker no longer relays an answer from a container on another release. It unseats the reader, serves
GET api/statefrom the published projection, and holds every other request behind503 Retry-Afteruntil the rollout lands. A reader who has written nothing takes that projection as their own, since it shares the log basis their container started from, and their page stays live. A reader who has written is ahead of it and drops it as stale, so their page holds what it has until they next send, which re-seats them. The deploy gate still waits for the containers, sinceverify_site.pyrequiresLeaf-Session: active.The runtime now asks the source of documents before reloading, through the probe
bootstrap.jsalready uses for startup recovery: a page's release-scoped assets are gone once the edge has moved on, and its registry still names this document's layer while it has not. Every refused answer gets its own reading, because the source can move while the page waits — and/api/viewand an immutable document are stamped with the captured layer of the revision they name, whichversion.jsalso puts throughsameDelivery, so a comparison against a revision written before a re-vendor reaches this hold on an ordinaryleaf servepage too. One probe is in the air at a time, so a burst of refusals costs one, and the words stay at once, since repeating a transient status line would hold the page's foot for the length of the disagreement. A probe that cannot be read settles nothing, so the next foreign answer asks again. A replaced server incarnation still reloads on sight; that is not a question about generations.test_a_revision_the_page_has_to_refuse_leaves_the_beat_beatingfabricated a re-vendor by rewriting one response header while leaving the page directory alone, which is now exactly the non-converging case. Its fixture moves the registry too, as a real re-vendor does.Checked: everyday suite (1138),
test_render_startup.pyandtest_render_projection.pyunder--run-nightly(237), worker typecheck and vitest (62),pre-commit run --all-files, andscripts/verify-site-local.shgreen through Wrangler's Docker container in Chrome. The regression test fails both with the old reload behaviour planted and with a lifetime latch on the probe planted.