Skip to content

Ask the deployed agent again when its container reports a failed turn - #508

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

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

Conversation

@leaf-agent

Copy link
Copy Markdown
Collaborator

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): 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 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.

@max-sixty
max-sixty merged commit 6ba6e12 into main Sep 9, 2026
4 checks passed
@max-sixty
max-sixty deleted the fix/ci-34343130285 branch September 9, 2026 15:10
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]>
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