Skip to content

Run the deploy gate's agent pass without re-verifying the deployed release - #487

Merged
max-sixty merged 1 commit into
mainfrom
fix/ci-34313146474
Sep 9, 2026
Merged

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

Conversation

@leaf-agent

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

Copy link
Copy Markdown
Collaborator

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): 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 (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): 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), 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. 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 hit both shapes, so both are needed to keep this step green.

@leaf-agent

Copy link
Copy Markdown
Collaborator Author

This shape recurred on main at run 34314328359 (3255716e, release 5bfdfc01…), so the default branch is red on it again and this branch is the fix that clears it.

The timeline is the same one this PR describes, on a different page. Six loop iterations raised on /api/state (05:21:04 through 05:22:15), the seventh got a coherent sample and printed ✓ leaf.page serves release 5bfdfc01… in /usr/bin/google-chrome at 05:22:38 — and the LEAF_VERIFY_AGENT=1 pass raised eight seconds later at verify-site.py:224:

RuntimeError: https://leaf.page/examples/design-decision/api/state reached a different container release

That the raise moved from /api/state to /examples/design-decision/api/state is the point: the two invocations open separate reader sessions, so which page catches the still-draining allocation is incidental. It confirms the cause is the re-sample rather than anything specific to the root page. With main() returning after verify_agent_turn on this branch, the agent pass never reaches that check, so neither reading can raise there.

Occurrence count for this step since #478 landed: five publish-site failures in the last hour and a half (7fc8c613, 28b5da99, c3c1c258, c9a0a27a, 3255716e), against one success. ba3d487d is mid-deploy as I write this.

@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Third consecutive main commit on this shape: run 34314505674 (ba3d487d, release 0f773061…). The wait ended green — ✓ leaf.page serves release 0f773061… in /usr/bin/google-chrome at 05:27:04 — and the LEAF_VERIFY_AGENT=1 pass raised https://leaf.page/api/state reached a different container release four seconds later, at verify-site.py:224, the same re-sample this branch removes.

Every push to main since c9a0a27a has been red here — c9a0a27a (34313146474), 3255716e (34314328359), ba3d487d — so the deploy gate's red is the standing state rather than an intermittent one, and each deployment still reached leaf.page before the gate contradicted itself.

max-sixty pushed a commit that referenced this pull request Sep 9, 2026
`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](https://github.com/max-sixty/leaf/actions/runs/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`](https://github.com/max-sixty/leaf/blob/7453d8c4eeef8fe22c9959c5701be04ff75df376/worker/src/index.ts#L453-L460)),
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`](https://github.com/max-sixty/leaf/blob/7453d8c4eeef8fe22c9959c5701be04ff75df376/worker/src/index.ts#L497)),
which carries the layer of the image it runs
([`worker/server.py`](https://github.com/max-sixty/leaf/blob/7453d8c4eeef8fe22c9959c5701be04ff75df376/worker/server.py#L631)).
- 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`](https://github.com/max-sixty/leaf/blob/7453d8c4eeef8fe22c9959c5701be04ff75df376/skills/leaf/scripts/leaf/http.py#L816-L821))
— 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](#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](https://github.com/max-sixty/leaf/actions/runs/34315493489),
the next commit after this one, failed on the third. They are separate
defects in the same function:

- #487 stops the agent pass re-verifying the whole site, and touches
`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.
- #483 rewrites what the gate waits for *after* the comment is posted
(`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.

---------

Co-authored-by: leaf-agent <[email protected]>
@leaf-agent

Copy link
Copy Markdown
Collaborator Author

The three other fixes to this step have all landed, and the shape this branch names is still what reddens main: run 34329393725, attempt 2 at d5902aa3, release a34afab4…. The wait ended green at 08:45:52 — ✓ leaf.page serves release a34afab4… in /usr/bin/google-chrome — and the LEAF_VERIFY_AGENT=1 invocation four seconds later raised https://leaf.page/api/state reached a different container release at verify-site.py:252, on /, the first page it walks.

What is new since the earlier recurrences is what has merged in between. #483, #490 and #500 all rewrote verify_agent_turn's waits and each cleared its own shape; none of them touches main(), so the second invocation still re-samples the release readings the loop had just satisfied. This run never reached the agent turn at all — it failed on the duplicate page pass ahead of it, which is precisely the work this branch removes. The deployment itself was fine: leaf.page serves a34afab4… now, so the cost is a red gate rather than a stale site.

The run's other failure, on attempt 1

Attempt 1 failed earlier, in Verify the bundled release locally in Chrome, when the local wrangler dev process exited mid-walk — the browser reported one 500, then ERR_EMPTY_RESPONSE, ERR_CONNECTION_RESET and 34 consecutive ERR_CONNECTION_REFUSED. Attempt 2 passed that same step on the same commit, so it is unrelated to this branch; it is tracked separately.

@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Recurred again on main, and this is the second red deploy inside an hour: run 34334797041 at 6df40353, release f7c4c842….

The timeline is this PR's, once more. Six loop iterations raised on /api/state and /examples/design-decision/api/state between 09:30:14 and 09:31:42, the seventh sampled coherently and printed ✓ leaf.page serves release f7c4c842… in /usr/bin/google-chrome at 09:32:10, and the LEAF_VERIFY_AGENT=1 invocation raised https://leaf.page/examples/design-decision/api/state reached a different container release thirteen seconds later. The traceback names verify-site.py:252 inside verify_page, so the raise is the re-sampled release pass this branch removes — agent_session's own drain loop, which #490 landed, was never reached.

publish-site runs on every push to main, so each merge re-rolls the same allocation until this lands. Nothing new to fix here; recording the occurrence.

max-sixty pushed a commit that referenced this pull request Sep 9, 2026
…#508)

`publish-site` deployed release `1f9662ae…` to leaf.page, verified it in
Chrome, and then failed the agent pass on what the deployed container
itself said ([run
34343130285](https://github.com/max-sixty/leaf/actions/runs/34343130285)):
`RuntimeError: https://leaf.page/examples/design-decision/ agent
returned an unexpected reply; it replied: I couldn't generate a reply
just now. Please send a new message to try again.` The agent had already
published the requested heading — the `published` and `replies` checks
ahead of it passed — so what stopped the run was the reply, not the
deployment. Re-running the same job on the same commit confirmed that:
[attempt
2](https://github.com/max-sixty/leaf/actions/runs/34343130285/attempts/2)
started twelve minutes later, changed nothing, and went green.

## The gate failed on the deployment answering correctly

That reply is `worker/server.py`'s `GENERATION_FAILURE_REPLY`, and the
container posts it from exactly one place: `_finish_turn`, when the App
Server turn it was following ended with a status other than `completed`.
So reaching it means the deployed container noticed a turn that never
completed, closed it, and settled the reader's standing ask rather than
leaving it open — the behaviour #497 was built to produce. What it
reports is the model, not the release.

The gate read it as a release defect, which puts every push to `main`
behind one live hosted turn generating successfully. That tail is not
rare: the three earlier `agent published but did not reply` failures on
this step were the same event before #497 gave it a settlement to land
in.

## The change

The pass now sends the new message that reply asks for, once, and
requires that turn to answer. A release that cannot run a hosted turn at
all settles the same way twice and still reddens `main`; a single
model-side failure does not. Every other ending is still reported on the
first ask — a turn that completes without posting a reply settles as
`MISSING_REPLY` instead, and a reply that says something else is the
deployed agent breaking its own instructions. Both are the agent failing
its contract rather than the model failing to run.

Two smaller readings follow from that split:

- A settled generation failure ends its own wait where it lands. It is
posted from where the container closes the turn, so nothing further is
coming on that comment — unlike every other reading the wait takes, each
of which a live turn can still be passing through. The red run spent
five minutes past that reply waiting out `TURN_PATIENCE`.
- `TURN_LIMIT` now bounds the pass rather than one ask, and a second ask
is only posted while a healthy turn's `TURN_PATIENCE` still fits inside
it. The job's budget in `.github/workflows/publish-site.yaml` is
unchanged, and the comment stating it stays true.

`ask_until_answered` holds the pass so it can be driven without a
browser; `ask_for_the_heading` and `await_turn` are the two halves of
one ask lifted out of the old body unchanged apart from taking their
revision and deadline as arguments.

## Verification

- `uv run pytest tests/test_website_server.py` — 29 passed. The three
new cases drive both sides of this: the container settling a failed
turn, the wait ending on that settlement instead of the budget, and the
whole two-ask pass against a page whose first turn stops without
replying. Each was checked against a mutation of the code it covers —
dropping the retry, reusing the first ask's attempt id, and drifting the
settlement text all fail it.
- `uv run pre-commit run --files scripts/verify-site.py
tests/test_website_server.py scripts/CLAUDE.md` — passed, ruff included.

The live path is not reachable from here: Chrome will not launch in this
sandbox (`process_singleton_posix.cc:297] Check failed: . socket()
failed: Operation not permitted`), so the run above is the evidence for
the diagnosis and the unit coverage is the evidence for the change. The
step itself only runs on pushes to `main`, and `scripts/verify-site.py`
is not in `publish-site`'s trigger paths, so the next push that touches
the site payload is what exercises it.

## Relation to #487 and #507

Both are open against other red shapes on this step and neither covers
this one: #487 changes `main()` so the agent pass stops re-verifying the
release, and #507 changes `await_presentation`'s bound for the reload
after the turn. This branch changes what happens between those two — the
ask and the wait on it — so the three are independent.

Co-authored-by: leaf-agent <[email protected]>
@max-sixty
max-sixty merged commit babd27d into main Sep 9, 2026
4 checks passed
@max-sixty
max-sixty deleted the fix/ci-34313146474 branch September 9, 2026 16:04
max-sixty pushed a commit that referenced this pull request Sep 9, 2026
… meet (#507)

`publish-site` deployed release `4ef93dd9…` to leaf.page and verified
it, then failed the agent pass on the reload that follows the turn ([run
34337785873](https://github.com/max-sixty/leaf/actions/runs/34337785873)):
`RuntimeError: https://leaf.page/examples/design-decision/ never
presented, reaching no startup milestone`. The turn itself was fine —
every check ahead of the reload had passed, so the hosted agent had
published the requested revision and replied for it. What ran out was
`await_presentation`'s fixed 30 seconds.

## The bound was inside the distribution it was judging

`await_presentation` is calibrated for the three pages the release pass
walks. Those are served from the edge, and the same run's own profile
prints them presenting in 618, 918 and 2267 ms. The reload at the end of
`verify_agent_turn` is a different page: it is answered by the private
container that has just run a hosted model turn, and its first
`/api/state` read is measured in seconds rather than milliseconds.

I measured that against the live deployment of the very release that
failed, on one session and one page, before and after a turn:

| reading | `/api/state` | presented |
| --- | --- | --- |
| reload before the turn | 123 ms | 0.8 s |
| reload after the turn | 3275 ms | 4.7 s |
| second reload after the turn | 3918 ms | 5.4 s |
| third reload after the turn | 2252 ms | 3.6 s |

The cost is ~25× and it does not decay across reloads, so it is what
serving a page a turn has written to costs, not a warm-up. It also
varies widely with what the turn did: separate turns against the same
release presented in 12.4 s and, running this branch's
`verify_agent_turn` end to end, **28.4 s** — 1.5 seconds inside the
bound that had just failed. A gate whose limit sits inside the
distribution of the healthy readings it takes reddens `main` on the tail
of that distribution, which is what happened here.

So the reload now gets the same patience as every other read this pass
makes of that container — the 120 s already used for `page.goto` and
each `context.request` call — while the release pass keeps the 30 s that
suits an edge-served page. `await_presentation` takes the bound from its
caller instead of holding one for both.

## The gate could not say which of the two it was

The message was `reaching no startup milestone` whatever had stalled,
because `reader_session` never installed `PROFILE_SCRIPT` — the two
other page openers do. `unpresented`'s whole purpose is to separate an
upgrade that never settled from a first state read that never answered,
and on the one page it matters for it was reporting an empty
`window.__leafStartup`. That is why the red run's log cannot distinguish
the slow read above from a page whose modules never arrived. The agent
session records the stamps now, and the reload's response is checked the
way every other navigation in this script checks its own.

A green deployment now also prints what the reload cost — `✓ hosted
agent published revision 2 and replied: deployment verified; the
reloaded page presented in 28444 ms` — so this path's drift is visible
on every run instead of arriving as the next timeout.

## What this deliberately does not do

The seconds-long post-turn `/api/state` read is a real cost that a
reader reloading after their own agent turn pays too, and it is worth
its own look. It is not a deployment fault, and this gate is explicitly
not a startup budget — it prints its profile as "observed, not a
pass/fail budget". Widening the gate here and reporting the number is
the honest split; making the deploy gate the place that fails on it
would redden `main` for a performance question it was not built to
judge.

I also tried and dropped a runtime change — bounding the first state
read in `runtime/state-feed.js`, since a `fetch` that never settles
leaves the page with no tick, no stream and no presented stamp. The
measurements above rule it out as this failure's cause: the read
answers, it is just slow, and aborting a healthy 3-second read would
present an offline banner and then wait out an equally slow retry. A
page wedged on a genuinely hung first read remains a real gap, but not
one this run demonstrates.

## Verification

- `verify_agent_turn`, run against the live deployment of release
`4ef93dd9…` — the only place this code path exists. It passed: `✓ hosted
agent published revision 2 and replied: deployment verified; the
reloaded page presented in 28444 ms`. That run was made from this branch
before it was rebased onto #508; the rebase changed the ask ahead of the
reload, not the reload itself, and Chrome does not launch in the sandbox
the rebase was done in, so it has not been repeated.
- `uv run pytest tests/test_website_server.py` on the rebased branch —
30 passed, #508's three cases included. That module loads
`scripts/verify-site.py`, and this branch's case drives
`verify_agent_turn` itself against a container double, stubbing only
`ask_until_answered`, so both waits are read at the call sites that set
them. Each of the four product changes here fails it on its own: the
reload's bound, the startup stamps the agent session installs, the
reload-response check, and the presentation cost the green run prints.
- `uv run pre-commit run --files scripts/verify-site.py
tests/test_website_server.py .github/workflows/publish-site.yaml` on the
rebased branch — passed, ruff and actionlint included.

The changed step runs only on pushes to `main`, so this branch's own CI
cannot exercise it; merging re-runs `publish-site`, since all three
changed files are in its trigger paths.

## Relation to #508 and #487

#508 has merged, and this branch is rebased onto it. The two met in
`verify_agent_turn`, where #508 lifted the single ask into
`ask_until_answered`'s bounded two-ask flow and rewrote the reply checks
that precede the reload. That flow is preserved as it landed — the
resolution drops this branch's copy of the old single-ask `answer is not
None` check, which #508 had already replaced with the version that
reports how many asks it took — and this branch's `TURN_PRESENTATION`
bound, startup instrumentation, reload-response check and presentation
timing sit on top of it, all after the ask has been answered.

#487 is still open against the third red shape on this step — the agent
pass re-sampling release readings the retry loop had just satisfied,
which raises before `verify_agent_turn` is ever reached. It does not
overlap this branch either.

---------

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