Skip to content

Wait for the hosted agent's published heading before the deploy gate reads it - #483

Merged
max-sixty merged 2 commits into
mainfrom
fix/ci-34309999064
Sep 9, 2026
Merged

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

Conversation

@leaf-agent

Copy link
Copy Markdown
Collaborator

publish-site deployed release 41a8177c… successfully and then failed its own post-deploy agent gate (run 34309999064): RuntimeError: https://leaf.page/examples/design-decision/ did not render the agent's published heading; browser errors: []. Every check before it had passed, so the hosted turn had reached the model, published a revision, and replied with deployment verified; only the rendered heading disagreed, and the message named neither the heading it found nor the revision the browser was standing on.

What the gate was reading

verify_agent_turn polled for the first state where any newer revision and any reply existed, and broke out there. A Codex turn is a process rather than a step: it may publish a checkpoint revision, say something about the work, and only then publish what the comment asked for. So the state the loop stopped at was not necessarily the turn's outcome — and the reload that followed asserted page.locator("h1").inner_text() == heading, an equality over text that the agent may have quoted and that the runtime may add its own words to for anything a reader can point at.

I ran the same turn against the same deployed release twice, out of band, to find out whether the deployment itself was at fault. It was not: in both, the browser followed the agent's revision (meta[name="lf-revision"] moved 1 → 2) and rendered the requested heading at presentation, with the published document served through the container fallthrough #478 added. The gate was reading the page too early and too strictly, not reporting a broken deployment — which also explains why the next commit's run (34311442765) passed the same gate unchanged.

The change

The wait now names the turn's outcome — a published document that carries the requested heading, and a reply that answers for it — instead of the first revision and first reply to appear. The gate keeps every claim it made: one real agent edit, a published revision, the reply #478 asked for, and a rendered result. What changed is when it reads them and how tolerant each reading is:

  • the heading is checked in the published document before the reader's browser is asked about it, so a checkpoint revision no longer ends the wait;
  • the rendered heading is a containment, since the agent may quote the heading it was handed and the runtime may inject its own words into a text block;
  • the revision the browser stands on is checked separately, so the two failure shapes are distinguishable — a browser still on the built document never followed the agent's revision, while one that followed it and shows other words is the agent's edit rather than the reader's page;
  • every failure message now carries the values it judged, and a green run prints the revision and the agent's reply, so the next reader of a red run has something to compare against.

Verification

  • The patched verify_agent_turn run against the live deployment (release 66c2a28e…), which is the only place this code path exists: it passed, printing ✓ hosted agent published revision 2 and replied: deployment verified.
  • uv run pytest tests/test_website_server.py — 20 passed. That module loads scripts/verify-site.py and covers its helpers.
  • ruff check and ruff format --check at the pinned 0.16.1.
The three production turns behind this, and one thing they raise

Three hosted turns were run against leaf.page while diagnosing, each in its own session and container. All three published a revision whose <h1> was exactly Deployment <release[:8]> verified, which is what rules out both the model's wording of the heading and the render path.

The first two, which overlapped the rollout of release 66c2a28e…, completed without the agent replying at all: the container settled the delivery with worker/server.py's MISSING_REPLY — "I finished without posting a reply. Please send a new message to try again." Under this gate, as under the one it replaces, that is a failure, and deliberately so: #478's intent is a real reply, and a hosted session that edits a reader's page without answering for it is worth a red run. It is now reported as the reply text rather than as a bare mismatch. Whether that shape is rollout-specific or ordinary is not something three turns can say; if it recurs on a green deployment, the reply half of this gate is where it will show up.

The failure on 34311996078 is a different one — ERR_NETWORK_CHANGED in the pre-deploy local check — and is untouched by this branch.

…reads it

The deployed-site agent gate stopped at the first state carrying any newer
revision and any reply, both of which a Codex turn can pass through before it
publishes what the comment asked for, and then compared the rendered heading
for equality against text the runtime may add its own words to. Wait for the
outcome instead — a published document carrying the requested heading and a
reply that answers for it — read the heading as a containment, report the
revision the browser stands on, and print what the turn did.
@leaf-agent

Copy link
Copy Markdown
Collaborator Author

The gate this PR rewrites failed again on main, so the failure is a recurrence rather than a one-off: run 34312209085 on c3c1c258 (#476), which started at 04:45Z and went red at 04:52Z — after this branch was pushed, and against the unpatched verify_agent_turn still on main.

It is the same shape and the same line: RuntimeError: https://leaf.page/examples/design-decision/ did not render the agent's published heading; browser errors: [], raised from the page.locator("h1").inner_text() == heading equality at the end of verify_agent_turn. The checks ahead of it passed, so the turn had again published a revision and replied deployment verified; only the reloaded heading disagreed. That is exactly the state this PR's diagnosis predicts — the loop stopping at the first revision-and-reply pair a turn passes through, and then asserting equality over text the agent may have quoted.

Two things it adds to the case for the change here:

  • Two failures on two separate deployments (41a8177c… and this one) make "the wait names the first state, not the outcome" the standing behaviour of the gate on main, not a single unlucky turn. Waiting for the published document to carry the heading before reloading is what would have kept this run in the loop instead of reading a checkpoint.
  • This run also spent about 100 seconds retrying https://leaf.page/api/state reached a different container release before the release check went green, so the container this turn ran against was still rolling over while the turn started. That is upstream of the heading assertion and is not something this PR changes; it is worth noting only because it is the kind of rollover under which a turn is most likely to publish a checkpoint first.

No separate fix PR — this one covers the failure. Its own lint, test, and review checks are green at c99aff04.

max-sixty added a commit that referenced this pull request Sep 9, 2026
## Summary

The hosted agent can publish the requested page edit yet omit an
explicit `leaf reply`, leaving the reader with an empty-result receipt
even though Codex produced a final response.

- Consume the merged App Server event reader's completed response as the
reply only when the agent left the accepted Leaf input unanswered.
- Preserve exact-turn settlement and explicit Leaf reply precedence.
- Keep every accepted input recoverable: failed turns use the failure
receipt, empty completed turns use the empty-result receipt, and invalid
model-authored media references fall back to that same receipt.

The deployment gate's separate asynchronous-revision fix remains owned
by #483.

## Validation

- `uv run pytest tests` — 959 passed
- `uv run pytest tests/test_interact_session.py
tests/test_website_server.py` — 174 passed
- `pre-commit run --all-files`

> _This was written by Codex on behalf of max-sixty_
@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Third occurrence of this shape on main: run 34315493489 on 4d606dda (#488), red at 05:44:32Z with the same message from the same line — RuntimeError: https://leaf.page/examples/design-decision/ did not render the agent's published heading; browser errors: [], raised by the page.locator("h1").inner_text() == heading equality at the end of verify_agent_turn on main.

The turn itself completed: the release verification printed ✓ leaf.page serves release ea6613a3… in /usr/bin/google-chrome at 05:42:28Z, and the agent pass ran for two minutes before raising, so it had passed the revision check, the reply-exists check, and the deployment verified containment. Only the reloaded heading disagreed — the state this PR's diagnosis names, where the wait stops at the first revision-and-reply pair the turn passes through rather than at its outcome.

Two things this adds. The heading shape is now three deployments across ninety minutes (7fc8c613, c3c1c258, 4d606dda), so it is the standing behaviour of the wait rather than an unlucky turn. And this run's agent pass reached the heading assertion cleanly — none of the container-release readings that redden the other two shapes fired in it — which is the separation #490 describes: the three are independent draws against the same rollout, and each needs its own fix to keep the step green.

For the wider picture: publish-site has been red on every push to main since 04:42Z — 28b5da99, c3c1c258, c9a0a27a, 3255716e, ba3d487d, 7453d8c4, 4d606dda — against one success at f22f920a. Each deployment still reached leaf.page; it is the gate behind them that is failing. This PR covers the heading shape; #487 and #490 cover the other two. No separate fix PR from this run.

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 missing-reply case this PR's body left open — "if it recurs on a green deployment, the reply half of this gate is where it will show up" — recurred twice and has a cause that has since landed, so it is no longer a shape this PR has to account for.

Run 34317965825 on 5272f8ca (#469) and run 34318460923 on 9f2cba57 (#493) both failed at check(reply is not None, ...) after waiting the whole 300 s with a published revision in hand: agent published but did not reply. Neither commit explains it — 5272f8ca changed only browser runtime, tests and fixtures, and touched no file under skills/leaf/scripts/ or worker/. The mechanism was on main instead: before 81b43106, _follow_turn caught a stream failure, called _clear_stream_activity, and returned without reaching _finish_turn, so the durable pickup survived and the reader's message was never settled — a turn that publishes its edit through the Leaf CLI and then loses its App Server stream leaves exactly the state the gate reported. #491 routes that failure through the terminal settlement path, so the input now gets a reply either way.

The first deployment carrying it is the evidence: run 34318780160 on 81b43106 (release 2a00aaaa…) passed all three reply checks — the revision advanced, the reply arrived, and it said deployment verified — and then failed on this PR's shape, did not render the agent's published heading; browser errors: []. That leaves this branch as the fix for the one shape still turning the deploy gate red on main; the container-release shape #487 and #490 address stayed inside the retry loop in both of the last two runs and was tolerated there.

For scale: 11 of the 13 publish-site runs on main since the agent gate landed in #478 have failed, in four distinct shapes. ci on main is green throughout — this step is the whole of it.

# Conflicts:
#	scripts/verify-site.py
@max-sixty
max-sixty merged commit ca67a55 into main Sep 9, 2026
4 checks passed
@max-sixty
max-sixty deleted the fix/ci-34309999064 branch September 9, 2026 07:18
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