Skip to content

Verify the public Leaf pages with a new session per attempt - #419

Merged
max-sixty merged 2 commits into
mainfrom
fix/ci-34163256368
Sep 7, 2026
Merged

max-sixty merged 2 commits into
mainfrom
fix/ci-34163256368

Conversation

@leaf-agent

@leaf-agent leaf-agent commented Sep 7, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

publish-site has gone red on main twice since #414 introduced the layer-matching verification — run 34163256368 (the build of #414 itself) and run 34163695118 (the build of #411). Both times the deploy succeeded and Verify public Leaf pages spent its whole budget without the edge shell's layer and /api/state's layer ever agreeing. In the second run the state body carried "producer": {"commit": "cb02617a7704"} — the container was still serving the previous deploy's image while the edge served the new shell.

The step asks the same session cookie on all twenty attempts. That cookie picks one Durable Object, and sleepAfter = "10m" on LeafWebsiteSession keeps a container Cloudflare has already started alive for ten minutes. So the first attempt seats a container on whatever image the rollout has reached at that instant, and the remaining nineteen attempts re-read that one instance. What the step then measures is the image one session began on — not the image the fleet hands a reader arriving now, which is the property it exists to prove.

I measured both against the live site while run 34163695118's rollout was still in flight, polling a fresh session and one fixed session side by side against the edge shell's layer 6260affc:

edge shell layer: 6260affc432de909ef10a47d5552bb36
t+7s    fresh=017bc7bd  fixed=017bc7bd
t+45s   fresh=6260affc  fixed=017bc7bd
t+140s  fresh=017bc7bd  fixed=017bc7bd
t+217s  fresh=6260affc  fixed=017bc7bd
...
t+505s  fresh=6260affc  fixed=017bc7bd
fresh converged at: 45s ; fixed converged at: never

A new session reached the new image in 45 seconds. The fixed session never did, across 8.7 minutes of polling — consistent with the idle timer, and the reason the twenty attempts could not have converged however many of them ran.

Solution

Mint a session cookie per attempt, so each one asks as an arriving reader, and bound the loop by one fifteen-minute deadline shared across both pages rather than a fixed twenty attempts. The deadline is what covers the rest of what the measurement shows: a gradual rollout leaves the fleet mixed for a while, so fresh sessions still landed on the old image intermittently out to t+198s, well past the ~145s the old loop actually spent. Fifteen minutes is entered about 2 minutes into the job and leaves margin under timeout-minutes: 30. Sharing it between the two pages is right because they are waiting on the same rollout, but each page keeps five attempts past the deadline: the two pages mint separate cookies and so seat separate containers, and a rollout slow enough to run the first page to the deadline must not leave the second a single probe before it reports a healthy deploy red.

The failure line now names both layers, and each attempt clears the state layer and body it is about to overwrite so the line reports what this attempt observed rather than an earlier one's reading. Diagnosing these runs meant inferring the mismatch from producer.commit buried in the dumped state body, because the step printed the body and not the two values it had just compared.

What this does not address

During a rollout a real reader can be served a new edge shell against an old container, and sameLayer in layer-client.js reloads the tab on that mismatch — with the session cookie sticky, into a reload loop until the container's idle timer retires it. This PR makes CI observe that window honestly rather than closing it; narrowing it (a faster container rollout, or a reader-facing answer to the mismatch) is a deployment and reader-experience decision I have left to you.

Testing

publish-site runs only on pushes to main, so this branch's CI cannot exercise the changed step. I ran the step's script as CI runs it, extracted from the workflow with the same bash -e:

Extracted-step runs against the live site

Against the settled site, both pages pass on their first attempt:

$ time bash -e /tmp/verify.sh
true
true
real	0m7.165s
exit=0

The deadline path, with the deadline cut to 12s and the product predicate falsified so it can never pass — it breaks out, names both layers, dumps the body, and returns 1:

$ bash -e /tmp/verify-fail.sh
https://leaf.page/ served layer 6260affc432de909ef10a47d5552bb36; https://leaf.page/api/state served layer 017bc7bd82e042ede192a56a1e1b41de
{"layer": {"generation": "017bc7bd82e042ede192a56a1e1b41de", ...
exit=1
real	0m16.200s

That run also caught the live failure in the act: the edge was serving #411's shell while the container still served #414's image, the same disagreement both red runs reported.

Re-running the extracted step against the settled site after the review fixes still passes both pages on their first attempt (7.2s). With the deadline set to 0 so it is already spent, the first page passes and the second still probes five times instead of once. Stubbing curl so the shell fetch succeeds once and then fails: before the per-attempt reset the failure line reported served layer BBB and dumped attempt 1's body for a probe that never ran; after it, both read none.

The convergence measurement above polled https://leaf.page/api/state every 15s, reading Leaf-Layer from the response headers, with a new openssl rand -hex 16 cookie for the fresh column and one cookie held for the whole run for the fixed column.

pre-commit run --files .github/workflows/publish-site.yaml worker/README.md passes, actionlint — which shellchecks the run: block — included.


Automated fix for failed run 34163256368.

The deploy's verify step asked the same session cookie twenty times. That cookie
picks one Durable Object, and a container Cloudflare has already started keeps
its image for its ten-minute idle timer, so every retry re-read the image that
one session began on rather than the image the fleet now hands an arriving
reader — which is the property the step exists to prove.

Each attempt now mints its own session, and one fifteen-minute deadline covers
the whole rollout instead of a fixed twenty attempts. The failure line names
both layers, so the next mismatch reads off the log instead of the state body's
producer commit.

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The shared deadline can leave the second page a single attempt. verify_page checks (( SECONDS < deadline )) after an attempt, so once the first call has spent the budget the second enters the loop, probes once, breaks, and fails the step — where the old fixed count gave each page twenty attempts of its own.

The description rests this on "the second page passes immediately once the first does", but the routing does not guarantee that: getContainer(env.PAGES, sessionId) in worker/src/index.ts keys the Durable Object on the session id alone, so the second page's freshly minted cookie seats a different container from the one the first page converged on. The PR's own measurement is the case in point — while the fleet was mixed, fresh sessions kept landing on the old image out to t+198s. A rollout slow enough to push the first page near 900s therefore fails on the second page's one probe and marks a healthy deploy red, which is the failure mode this change exists to remove.

A per-page floor closes it while keeping one shared wall-clock bound: declare local attempt=0 again and break only on (( SECONDS >= deadline && ++attempt >= 5 )), so the deadline still caps the job but neither page can be cut to a single probe.

Comment thread .github/workflows/publish-site.yaml Resolved
@leaf-agent

Copy link
Copy Markdown
Collaborator Author

publish-site failed a third time with this shape on run 34164641277 (the build of #416), so this PR now covers three consecutive red deploys — every one since #414 added the layer match.

The dumped state body names the stale side directly: "producer": {"commit": "df94a89bfc8c"}, which is #411 — one deploy behind the 11f9619f the job was verifying. The layer generation is secrets.token_hex(16) per vendoring (vendoring.py:267), so the edge shell built at 11f9619f could not have matched that container whatever else agreed, and the predicate itself was satisfied by the body it dumped.

The run also shows the second half of your fix earning its keep: the step ran 21:53:39 → 21:55:37, about 118 seconds, short of even the 45s-to-198s intermittent window your fresh-session polling measured. So the twenty attempts would have been too small a budget here even with a per-attempt cookie; the fifteen-minute deadline is what covers it.

No new diagnosis to add — leaving this to you as the fix.

@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Right on both counts — 16debac2 adds the per-page floor you named and clears the state layer and body each attempt (replied inline on the second).

The floor is written as (( SECONDS < deadline || ++attempt < 5 )) || break, which keeps the existing || break shape that set -e is safe with, and short-circuits so attempt stays at 0 until the deadline actually passes — a page that converges inside the budget never touches it. Running the extracted step with the deadline set to 0 so it is already spent: the first page passes on its one attempt and the second then probes five times before failing, where on 5f7f2364 it probed once.

The description's "the second page passes immediately once the first does" was the claim that did not hold, since getContainer(env.PAGES, sessionId) seats each freshly minted cookie on its own Durable Object; I have rewritten that paragraph around the floor rather than the assumption.

Worst case the floor extends the step past the fifteen-minute deadline by five attempts per page — at --max-time 25 on both curls plus the 10s sleep, about 5 minutes per page. Entered ~2 minutes into the job that is ~27 of the 30 minutes timeout-minutes allows, so the step still gets to print its own failure line rather than being cut off by the job timeout.

@leaf-agent

Copy link
Copy Markdown
Collaborator Author

A fourth consecutive occurrence: run 34165866226, the build of d819059d (#402). Every publish-site run since #414 landed has now gone red on this step, and none on any other — cb02617a, df94a89b, 11f9619f, d819059d, against six green runs before it.

Two details from this one that bear on the deadline rather than just the recurrence count. The container was serving "producer": {"commit": "11f9619f"} — #416's image, two deploys behind the d819059d shell the edge was serving, with #418's deploy skipped over entirely. The earlier runs each showed a one-deploy lag; a session seated during a rollout can evidently sit out more than one. And the dumped state body satisfies the predicate on its face (.publication.kind == "product", .claims == []), so the mismatch is again the whole failure, which is what the two-layer failure line on this branch would have said directly instead of leaving it to be read out of producer.commit.

The step spent 22:14:36–22:16:38, about 122 seconds — consistent with the twenty attempts running out well inside the window a fresh session needs, and inside the fifteen-minute deadline this PR gives it.

@max-sixty
max-sixty merged commit b544b95 into main Sep 7, 2026
7 checks passed
@max-sixty
max-sixty deleted the fix/ci-34163256368 branch September 7, 2026 22:21
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