Skip to content

Establish the deploy gate's agent session on the deployed release - #490

Merged
max-sixty merged 3 commits into
mainfrom
fix/ci-34315250259
Sep 9, 2026
Merged

max-sixty merged 3 commits into
mainfrom
fix/ci-34315250259

Conversation

@leaf-agent

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

Copy link
Copy Markdown
Collaborator

publish-site deployed release b8550d06… 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_turn opened a context, read api/state, and posted the deployment-check comment under state["layer"]["generation"]. Both readings are wrong for the container that has to admit the event:

  • A passive GET api/state is 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).
  • The page checks that do assert the container release run in their own browser contexts. The Worker keys a container on the reader session alone, so they answer for their own allocations and say nothing about this one.

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.ok is 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 release between 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_session establishes the session the turn will use, and only returns one whose container reports the deployed release: it activates through api/view — the same passive-state-then-projection probe #432 added for the page checks — then reads api/state back under Leaf-Release. It reads two things off that answer, as verify_page does: leaf-session says the read left the edge at all, and only then does leaf-release name a container rather than the manifest. The edge stamps a passive api/state with 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_turn then 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 worker and npm 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 reading leaf-session is 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.
  • The changed step only runs on pushes to main, so this branch's CI cannot exercise it; merging re-runs publish-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:

Landing more than one will conflict textually at the top of verify_agent_turn; the three changes are to disjoint concerns and compose.

@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.

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.

Comment thread scripts/verify-site.py Resolved
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 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 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.

Comment thread worker/test/index.test.ts Resolved
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.
@max-sixty
max-sixty merged commit 7299eec into main Sep 9, 2026
7 checks passed
@max-sixty
max-sixty deleted the fix/ci-34315250259 branch September 9, 2026 06:46
max-sixty pushed a commit that referenced this pull request Sep 9, 2026
…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]>
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