Repository navigation
Establish the deploy gate's agent session on the deployed release - #490
Conversation
leaf-agent
left a comment
There was a problem hiding this comment.
reader_session proves the container it reached with leaf-release alone, but that header is not container-only: the Worker's passive api/state branch stamps Leaf-Release with manifest.release — the deployed release, unconditionally — so a session where activation didn't take reads back the release it asked for and passes the check. The gate then posts the turn into a container it never established, which is the failure this PR exists to close, arriving silently instead of as did not return its deployment-check comment.
verify_page guards the same handshake with two assertions the new copy drops: leaf-session == "active" on the activation response (did not activate a private container) and again on the state read (did not reach a private container). Either one distinguishes the container's answer from the edge's; leaf-release on its own does not. The inline suggestion adds the state-read one, which is the reading the release check is drawn from.
A passive api/state is answered by the Worker with the deployed release unconditionally, so leaf-release alone does not distinguish a container's answer from the edge's: a session whose activation did not take would read back the release it asked for and pass. Assert leaf-session == active on both the activation and the state read, as verify_page does.
leaf-agent
left a comment
There was a problem hiding this comment.
The delta closes the leaf-session gap: the release now reads as a container's answer rather than the edge's. The worker case added to pin that reading doesn't pin it — it asks after the release the edge already deploys, so an edge that echoed Leaf-Release would satisfy it just as well, and the reading reader_session rests on stays untested. Inline below, with the one-line change that makes the case discriminate.
The case asserted the edge answers a passive api/state with the deployed release, but asked under that same release, so an edge that echoed the request header would satisfy it. reader_session's release check rests on that reading being the edge's own stamp, so the case now asks under a release the edge does not serve.
…lease (#487) `publish-site` deployed release `c7531bac…` to leaf.page successfully, verified it, printed `✓ leaf.page serves release c7531bac… in /usr/bin/google-chrome` — and then failed six seconds later on the very reading it had just satisfied ([run 34313146474](https://github.com/max-sixty/leaf/actions/runs/34313146474)): `RuntimeError: https://leaf.page/api/state reached a different container release`. The deployment was fine; the gate contradicted itself. **This shape has now reddened `main` six times**, most recently at [run 34368424112](https://github.com/max-sixty/leaf/actions/runs/34368424112) (`52fab476`, release `7468df4d…`): the wait ended green at 15:15:19 with `✓ leaf.page serves release 7468df4d… in /usr/bin/google-chrome`, and the `LEAF_VERIFY_AGENT=1` pass raised `https://leaf.page/api/state reached a different container release` eight seconds later, at the container-release check `main()` re-runs through `verify_page`. Each occurrence has left a good deployment sitting behind a red default branch. The other red shapes on this step have been fixed as they were found — #483, #490, #500 and #508 have landed, #507 is open on the post-turn reload — and none of them touches this one, which raises before `verify_agent_turn` is reached. The comments below record the intervening runs. ## Why the gate disagreed with itself The deploy step is two invocations of the same script ([`publish-site.yaml`](https://github.com/max-sixty/leaf/blob/c9a0a27a4f3545488ec74018c11018514727c432/.github/workflows/publish-site.yaml#L103-L111)): a `until` loop that re-runs the release verification until it holds, then one `LEAF_VERIFY_AGENT=1` run for the deployed agent turn. The second run is a superset of the first — `main()` ran every page check before reaching `verify_agent_turn` — so it re-sampled the same readings, with none of the loop's protection. That re-sample is not idempotent, because a container rollout drains one allocation at a time. Each browser context the script opens is a new reader session, and the Worker keys a container on that session alone ([`worker/src/index.ts`](https://github.com/max-sixty/leaf/blob/c9a0a27a4f3545488ec74018c11018514727c432/worker/src/index.ts#L497)), so every invocation asks Cloudflare for a fresh allocation and gets whichever image that allocation happens to be running. The run's own timeline is the demonstration: six allocations landed on the previous image, one landed on the new one at 05:05:28 and ended the wait, and the allocation six seconds later landed on the previous image again and raised at [`verify-site.py:224`](https://github.com/max-sixty/leaf/blob/c9a0a27a4f3545488ec74018c11018514727c432/scripts/verify-site.py#L224-L226). Nothing regressed in between — the rollout was still draining, which is exactly the condition the loop exists to wait out. So the loop already states the policy: one coherent sample ends the wait. The second invocation quietly re-litigated it, and turned a rollout still in progress into a red default branch. ## The change The agent pass now runs the agent turn alone, and the release pass stays where the wait protects it. No claim is dropped: the loop's final iteration verifies the document, module graph, edge projection, session identity, cross-tab activation and container release seconds earlier, and the agent turn's own claim — one deployed Codex turn revising and answering a private page — is unrelated to which allocation the rollout is on. The turn is still run exactly once and is still fatal on failure; this deliberately does not put it inside the retry loop, since a hosted turn that edits a reader's page without answering for it is worth a red run rather than a retry. Removing the duplicate work also takes three page loads and the cross-tab check off every deployment, and the agent pass now prints a line on success instead of passing silently. ## Verification - `uv run pytest tests/test_website_server.py` — 20 passed. That module loads `scripts/verify-site.py` and covers its helpers. - `uv run pre-commit run --files scripts/verify-site.py .github/workflows/publish-site.yaml` — passed, actionlint and ruff included. - The changed step itself only runs on pushes to `main`, so this branch's CI cannot exercise it; merging re-runs `publish-site`, since both changed files are in its trigger paths. ## Relation to #483 #483 is open against the other red run of this step (`did not render the agent's published heading`) and rewrites `verify_agent_turn`'s waits. This branch touches `main()` and the workflow comment only — the two do not overlap, and [run 34312209085](https://github.com/max-sixty/leaf/actions/runs/34312209085) hit both shapes, so both are needed to keep this step green. Co-authored-by: leaf-agent <[email protected]>
publish-sitedeployed releaseb8550d06…to leaf.page, verified it in Chrome, and then failed its agent pass on a message about a missing event (run 34315250259):RuntimeError: https://leaf.page/examples/design-decision/ did not return its deployment-check comment. No event was missing. The container that answered the POST was still running the previous image, refused a layer it does not speak, and answered with its own generation instead of a state — which the gate read as an absent comment.Why the agent pass posts into a container it never checked
verify_agent_turnopened a context, readapi/state, and posted the deployment-check comment understate["layer"]["generation"]. Both readings are wrong for the container that has to admit the event:GET api/stateis answered by the Worker out of the built site (worker/src/index.ts), so the layer it names is the release's, whatever the containers are running. The POST is not — it always reaches a container (index.ts), which carries the layer of the image it runs (worker/server.py).A container whose layer the request does not match answers
{"layer": <its generation>}at status 200 without appending (http.py) — a deliberate shape, so a stale runtime gets the current generation rather than a verdict in a vocabulary it no longer speaks.posted.okis therefore true,accepted["state"]is absent, and the gate reported the one thing that had not happened.That the rollout was still draining during this pass is in the run's own timeline: nine allocations answered
reached a different container releasebetween 05:34:47 and 05:36:52 before one landed on the new image and ended the retry loop. A rollout drains one allocation at a time, so the agent pass's fresh session is an independent draw.The change
agent_sessionestablishes the session the turn will use, and only returns one whose container reports the deployed release: it activates throughapi/view— the same passive-state-then-projection probe #432 added for the page checks — then readsapi/stateback underLeaf-Release. It reads two things off that answer, asverify_pagedoes:leaf-sessionsays the read left the edge at all, and only then doesleaf-releasename a container rather than the manifest. The edge stamps a passiveapi/statewith the deployed release unconditionally, so the release check alone would pass a session whose activation never took. Because a container is bound to its session for that session's life, a stale draw is retried with a new session rather than re-read on the old one.verify_agent_turnthen posts under that container's own layer.Nothing in the retry writes: it is three GETs, and the turn is still posted exactly once, after a coherent session exists. The wait is bounded at 180s — the release verification ahead of this pass has already waited out most of the drain, and the step's budget still has to hold the turn's five minutes inside the job's thirty.
The POST answer is also checked for what it is, so the next occurrence of any container-side refusal names the answer rather than the missing event.
Verification
uv run pytest tests/test_website_server.py— 23 passed, including a new case that drives the mechanism at the file boundary: a comment posted under a layer the server does not hold is answered{"layer": <generation>}, and the log is unchanged. The gate's own path needs a live Worker and a rollout in progress, so this is the boundary that can hold it.npm run typecheck --prefix workerandnpm test --prefix worker— 57 passed. The passive-state case now asks under a release the edge is not serving and asserts it answers with the deployed one anyway, so it fails against an edge that echoed the request header. That is the readingleaf-sessionis load-bearing for above: an echoing edge would let the release check pass a session that never left the edge.uv run pre-commit run --files scripts/verify-site.py tests/test_website_server.py worker/test/index.test.ts— passed, ruff check and format at the pinned 0.16.1 included.main, so this branch's CI cannot exercise it; merging re-runspublish-site.Relation to the other two open gate fixes
All three failure shapes are live — run 34315493489, the next commit after this one, failed on the third. They are separate defects in the same function:
main(). It does not reach this: the pass would still post into an unchecked container, and with the page checks gone there is no release reading in the pass at all — this branch supplies the one that matters.did not render the agent's published heading). This branch changes what happens before it.Landing more than one will conflict textually at the top of
verify_agent_turn; the three changes are to disjoint concerns and compose.