Repository navigation
Run leaf.page sessions on one vCPU, and start a visitor's container when they focus a text box - #5802
Merged
Merged
Conversation
…hen they focus a text box A page's first write on leaf.page waits while its container boots and composes the page's layer. On basic's 1/4 vCPU that took 8.7 s in a local reproduction; on a custom 1 vCPU / 3 GiB instance it took 1.9 s. Cloudflare bills CPU only as it is used and memory as provisioned, so this instance costs 2.8x basic per awake second, less than standard-1's 1/2 vCPU with 4 GiB. The account's default limit of 1,500 concurrent vCPU caps production at 1,400 containers beside dev's 90. The tab's interaction log already reports each focus to the Worker within a quarter second. When a batch shows focus entering a text box (leaf-text or textarea), the Worker now starts the session's container, rate limited per source address, so the boot overlaps the visitor's typing. Reads still start nothing.
… first Cloudflare counts each application's max_instances times its vCPU against the account's 1,500 when it rolls out: ninety one-vCPU dev containers beside production's 5,900 basic ones (1,475 vCPU) were refused. Twenty fit beside either production size, and production takes the remaining 1,470.
leaf-agent
reviewed
Nov 10, 2026
leaf-agent
left a comment
Collaborator
There was a problem hiding this comment.
One finding, inline: the Worker's focus trigger keeps its own copy of the runtime's text-box selector, and no check ties the two together, so the prewarm can stop silently.
…warm reads it rather than matching tag names The prewarm matched the focused control's locator against its own copy of the runtime's TEXT_BOX, so renaming leaf-text would have stopped it with every check passing. describe() now sets textBox on a focus entry whose control matches TEXT_BOX, the Worker's projection keeps that field, and startsTyping reads it. The interaction recording browser test checks a textarea's focusin carries it.
max-sixty
marked this pull request as ready for review
November 10, 2026 21:14
leaf-agent
approved these changes
Nov 10, 2026
This was referenced Nov 10, 2026
max-sixty
added a commit
that referenced
this pull request
Nov 10, 2026
…ning a thread Opening a thread focuses its comment box, which since #5802 starts the session's container for the reply. verify-site opened the saved thread before checking that the revision resource and document came from the Durable Object, so the prewarm could wake the container first; publish-site for #5802's merge failed with 'private revision resource woke its container'. The thread check now runs after the checks that reading left the container asleep.
max-sixty
pushed a commit
that referenced
this pull request
Nov 10, 2026
… box's focus now starts the container (#5810) `publish-site` on `main` has failed since #5802 ([run 42904167365](https://github.com/max-sixty/leaf/actions/runs/42904167365), `RuntimeError: private revision resource woke its container`). #5802 made the Worker start a visitor's container (`prewarmContainer`) when an interaction batch reports a text box's focus. `verify_saved_state` in `leaf-dev verify-site` clicks the saved thread, which focuses its reply `leaf-text`, and only after that checks that the state, the revision stylesheet and the revision document came from durable storage. The run's log shows the sequence: a `focusin` on `leaf-text` with `textBox: true`, then `container_prewarm_completed`, then the stylesheet GET taking 4 s and being answered by the woken container. This PR moves the thread step to the end, after every durable read, the "reading saved content started a page container" comparison and the media write. Each of those checks again finds the container stopped: the reads still prove they are served from durable storage, and the write still proves it wakes the container and that the next writer restores the record. The thread's saved comment and the browser-error check still run, after the thread opens. Nothing changes in the Worker, the runtime or the prewarm. **Verification:** this PR's `ci` runs `uv run leaf-dev verify-site website-worker` ("Measure the bundled release in a browser"), the same command as the failing step. The failing run above is the before. **For the author of #5802 to weigh:** opening a thread puts focus in its reply box, so every thread open on leaf.page now starts the session's container, even when the visitor only reads. The rate limit bounds this. Whether that counts as "about to write" is a product call, and this PR doesn't make it. Refs #5809 — automated triage --------- Co-authored-by: leaf-agent <[email protected]>
This was referenced Nov 11, 2026
max-sixty
added a commit
that referenced
this pull request
Nov 12, 2026
…ntainer (#5812) When a leaf.page visitor focuses a text box, the Worker's prewarm (#5802) now asks the session's container to compose the page's layer, rather than only starting the container. The visitor's first write then finds the composition done instead of paying for it. **Why here.** A first write spends most of its admission composing the page's layer (theme, package modules, merged registry), which `leaf.layer` keeps only in process memory. Shipping it pre-built in the image would need a saved form of those caches in main code, so this computes it earlier instead: website code calls the public `registry.storage.selected` for the focused page. Everything is in `worker/`. **Measured** in the website image with a stub page store, on 1 vCPU, admission of the first write (median of 2–3 runs): | Write sent after boot | Today | Every page composed at boot | This PR (focused page, at focus) | | --- | --- | --- | --- | | 0 s, no focus (a first click) | 1.13 s | 1.47 s | 1.13 s | | 2 s after focus | 0.93 s | 0.45 s | 0.17 s | | 8 s after focus | 0.94 s | 0.18 s | 0.18 s | Composing one page takes about 0.9 s on 1 vCPU. Composing all 47 at boot took 2.0 s and slowed a write that arrived meanwhile, so the container composes only what the focus names. **Changes.** The container answers `POST <page>/_leaf/agent/prewarm` by composing that page's layer and logging `layer_prewarm_completed`. `prewarmContainer` posts there through the session's Durable Object, which starts the container as before. `tests/process/website_server/test_dispatch.py` and the Worker's prewarm test cover each side. > _This was written by Claude Code on behalf of max-sixty_
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A leaf.page visitor's first write waits while their session's container boots and composes the page's layer (about 7 s in production on 9 Nov, after #5764). This tries two ways to cut that wait.
One vCPU per session. Both environments run a custom instance with 1 vCPU and 3 GiB, the smallest custom size Cloudflare allows. In a local Docker reproduction, a cold first write took 1.9 s on it, against 8.7 s on
basic's 1/4 vCPU. Cloudflare bills CPU only as it is used and memory as provisioned, so this costs 2.8×basicper awake second, less thanstandard-1(1/2 vCPU with 4 GiB). Cloudflare checks the account's 1,500-vCPU limit at rollout, countingmax_instancestimes vCPU. It refused 90 one-vCPU dev containers beside production's 5,900basicones, so dev now reserves 20, which fit beside either production size, and production takes 1,470.Start the container when a text box gets focus. The tab's interaction log already reports each focus to the Worker within a quarter second. It now marks a focus entry whose control is one of the runtime's text boxes (
TEXT_BOX) withtextBox, and when a batch carries one, the Worker starts the session's container (prewarmContainer), with a per-source rate limit. Reads still start nothing.What dev showed. I deployed this to dev, then redeployed dev on
basicwith the same code, and sent first comments from fresh browsers:basic, no prewarmbasic, prewarm, 10 s of typingEvery test session landed on a container booting for the first time since its deploy re-placed it. Those first boots were slow on both sizes: the containers' startup steps took 2.3–2.8 s against production's 1.9 s, and the write after boot grew across the session. So dev shows that the prewarm hides the boot, but it can't show what 1 vCPU does on production's containers. Production had one visitor cold write last week, so the trial is better read a day after merging from steadier counts: the containers' startup steps (about 2,300 a week) and CI's cold page loads (about 770 successful a week).
The Worker tests cover the focus trigger and the config, and the interaction log's browser test checks that a textarea's focus carries
textBox.pnpm run checkpasses.