Skip to content

Serve an active reader's live page document from their own container - #682

Merged
max-sixty merged 2 commits into
mainfrom
fix/ci-34777568838
Sep 13, 2026
Merged

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

Conversation

@leaf-agent

Copy link
Copy Markdown
Collaborator

publish-site deployed release 5903b07f and then failed its agent pass on run 34777568838, and the gate was reporting a live break rather than a flaky reading: on leaf.page today, a reader whose agent publishes a revision is thrown into an endless reload. The page never reaches the revision, never presents, and never shows the conversation again — reply never became visible in Threads: {'panel': True, 'messages': []} is that page, caught mid-reload with nothing rendered.

What causes it

#666 made every live revision activate by reloading the stable page address (prepareActivation in skills/leaf/assets/runtime/version.js), replacing the fetch of the revision document that preceded it. The Worker answers that address from the built site: worker/src/index.ts takes the edge branch for any page GET that is not an API request, and only falls through to the container when the edge answers 404, which the page root never does. So the reloaded document is the build's revision, the runtime reads it back as the revision it was leaving, asks to activate again, and the loop closes. The session's own index.html — the one its agent just wrote — is in the container the whole time.

Session files already avoid this: media, revisions and versions miss at the edge and fall through. The live document is the one case the edge answers with a stale 200, so this adds it to the same rule — an active session reads its live document from its container. Passive readers, every static asset, and the release-addressed module graph are untouched.

Verification

Measured against the deployed release on leaf.page, driving the page the way the gate does:

  • posting a comment that asks the agent to publish left the page reloading /examples/triage-board/ continuously for the whole six-minute observation, still on revision 1, still reading Release triage, never presented, no messages;
  • with the same session reading its live document from the container — the routing this change makes — the agent's revision 2 arrives at the same address, headed Deployment probe verified, presented, conversation rendered, no browser errors.

npm run typecheck --prefix worker and npm test --prefix worker pass (63 tests, including two new cases that fail without the change).

The cost, and what it does not cover

The container composes its document with page-relative asset paths, so an active reader's document loads the revision's modules from /<page>/revisions/rN-<hash>/…. The edge still serves those files, but under public, max-age=0, must-revalidate rather than the immutable year that /_leaf-release/<release>/… carries, so an active reader's reload revalidates its module graph instead of reading it from cache. That route is content-addressed by the revision's own digest, so marking build-present revision assets immutable would recover it; that is a separate change and this one does not make it.

The local pre-deploy gate could not have caught this: scripts/verify-site-local.sh runs verify_site.py without --agent, so the Worker is exercised before the deploy but the agent turn only afterwards, against the public origin.

An unrelated live defect found while reproducing this

A session pinned to its container by the __Host-leaf-container cookie — the state a drained rollout leaves — cannot start /examples/ship-review/ at all: the page throws leaf: page failed to start: leaf: $command.widgets declares no command role, then Leaf application has not been mounted, and never presents. It reproduces on every attempt, and only when the container serves the module graph as well as the document; /examples/triage-board/ is unaffected, and the registry the two routes return is byte-identical and does carry $command. This change neither causes nor addresses it — with the container serving only the document, ship-review presents cleanly.

The edge answers the stable page address out of the built site, which is a revision behind any the reader's own session has published. Since a live revision now activates by reloading that address, the reloaded document reports the older revision, the runtime asks for the newer one again, and the reader reloads forever. An active session takes its live document from the container that owns its index.html.

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

worker/README.md is the document that states this routing rule, and the change leaves two of its sentences false. It opens with "Cloudflare serves each product and example page's live shell and initial canonical projection from .tmp/site-assets, so the document paints and presents without waiting for a container" — after this change an active reader's live shell comes from their container, and that reader does wait for one. It then enumerates the fallthrough as "Published media, revisions, and version documents stay on the edge; when one of those paths is absent from the release, the Worker asks the reader's active container so a newly created private revision can become the live document" — that absent-from-the-release condition is no longer how a private revision becomes live, which is the whole mechanism this PR repairs. A reader deriving the delivery model from that paragraph would conclude an active reader's document is still edge-served and still release-addressed, which is exactly the wrong picture to make the next edit to index.ts against. I'm pushing the prose update to this branch.

Two things I checked that hold, since the routing now splits document and module graph across the two origins. The container composes the live document against /<page>/revisions/rN-<hash>/, and artifact_name digests the document together with every resource, so a release that moves the runtime yields a different rN-<hash>: the edge 404s that path, isPageSessionFileRequest falls it through, and the same container that served the document serves its modules. Document and module graph cannot land on different releases. The container's HTML also keeps frame-ancestors 'none' (Handler.frame_ancestors_policy, which WebsitePageHandler does not override), so dropping staticAssetResponse from this path costs no clickjacking header.

npm run typecheck --prefix worker and npm test --prefix worker pass at 63, and reverting only the new clause in the edge condition reds the two added cases — they pin the behaviour rather than the shape.

@leaf-agent

Copy link
Copy Markdown
Collaborator Author

This break recurred on main: run 34780462213 on 3ebd5a869f7e87321a68f3a321d32d3c9dab4ee3 (#684) failed the same --agent pass with the identical reading — RuntimeError: https://leaf.page/examples/triage-board/ reply never became visible in Threads: {'panel': True, 'messages': []}, raised from the same verify_agent_turn line. #684 is a docs-and-refusal-text change, so it did not cause this; the deployed page is still the one this PR describes.

The publish-site history corroborates the causal account in this PR's body rather than just repeating the symptom. The workflow was green through #678 at 18:00, and the first red run is #666's own merge run (34777568838) — the commit that moved live-revision activation onto a reload of the stable page address. Every merge since has been red at the same step, so this is a standing break on leaf.page, not an intermittent reading.

Both failures isolate cleanly to the agent turn. The rollout pass ahead of it settled and passed in this run (✓ https://leaf.page serves release fd2ceef675342b330dbc68f4be74b4d614929c0c4078c757027da926b5b9d5e2), with the reached a different container release retries before it being ordinary rollout settling inside the step's until loop. Nothing else in the deploy is implicated.

Nothing to add to the diff from here — merging it is what clears main, so I have opened no separate fix.

@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 routing change and the README rewrite agree with the code, but the details block's
conclusion about /examples/ship-review/ does not survive this change.

That note says the startup failure reproduces "only when the container serves the module
graph as well as the document", and concludes "This change neither causes nor addresses
it — with the container serving only the document, ship-review presents cleanly." The
container serves only the document while the reader's active revision is still the build's
revision, because rN-<hash> is present in the release and the edge answers it. The moment
the agent publishes, the document changes, so artifact_name yields a hash the build does
not carry, the edge 404s that path, and isPageSessionFileRequest falls the whole revision
directory through to the container — which the README's own new sentence states. So after a
publish the container serves the document and its module graph, which is the configuration
the note names as broken, and it is reached on this fix's success path rather than only from
a drained rollout.

The verification in this PR drove /examples/triage-board/, which the note says is
unaffected, so the case that matters here is untested. Drive a publish through
/examples/ship-review/ under this routing before landing. If it presents, the note's
reproduction condition is narrower than stated and the sentence should say so; if it does
not, this change makes an existing live defect reachable for any reader of that page whose
agent publishes, and that belongs in the PR's cost section rather than in a collapsed
"unrelated" block.

@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Third consecutive red merge run, and this one caught the reload directly: run 34781705451 on f14fd6d7f73d66deabced384da741cda4019e391 (#683) died one line earlier than the previous two — at the page.evaluate("window.__leafVerifier.visibleReplyDebug") that composes the "reply never became visible" message — with playwright._impl._errors.Error: Page.evaluate: Execution context was destroyed, most likely because of a navigation.

That is the same failure, one reload later. visibleReplyAt was still None after the 30s wait, exactly as in 34777568838 and 34780462213; the difference is only that the debug read landed on a navigation instead of between two. The gate's own error path is now being torn down by the loop it was trying to describe, which is the mechanism this PR's body names observed rather than inferred. #683 is an error-reporting change in the page runtime and does not touch activation or Worker routing, so it did not cause this either.

The rollout pass ahead of the agent turn settled and passed again (✓ https://leaf.page serves release 4b316a631d98318db5e7fbbb5f975fdc025af55a8b6a9e1ce27983985af89010).

@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Every publish-site run since #666 landed has been red, and this is the record for the two that had not been reported here yet — plus a note that further per-run recurrences will not be.

run commit terminal failure
34777568838 859c6ccb (#666) reply never became visible
34780462213 3ebd5a86 (#684) reply never became visible
34781705451 f14fd6d7 (#683) Playwright error composing that same message
34782073842 f66e3caa (#675) reply never became visible
34784221223 76a2990c (#680) reply never became visible

The last green publish-site was 34773295315 on cff0eee7 (#678), the last merge before #666 — so the break tracks the merge this PR names, on every run since, with no run of either colour in between.

Run 34784221223 reads exactly as the first one did: the non-agent pass confirmed release 05006b7d at 21:40:01, then the --agent pass raised RuntimeError: https://leaf.page/examples/triage-board/ reply never became visible in Threads: {'panel': True, 'messages': []} 55 seconds later — page load, ask, and the 30-second visibleReplyRecorded wait, with the conversation never rendering.

This branch still merges cleanly into 721497dc, and its lint and test checks are green at 114314f5.

Nothing further is needed from CI to characterise this. Each red merge run opens a ci-fix session that lands here and finds the same shape, so unless a run fails differently, later sessions should read this comment and stop rather than add another row.

@max-sixty
max-sixty merged commit cebf705 into main Sep 13, 2026
7 checks passed
@max-sixty
max-sixty deleted the fix/ci-34777568838 branch September 13, 2026 23:33
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