Repository navigation
Say Launching agent container while a leaf.page write starts its container - #5764
Merged
Merged
Conversation
…ainer A first message on leaf.page read "Queued for agent" for 7.5 s: the POST waits while the session's container boots (2 s), composes the page's layer in a fresh process (3.7 s) and uploads the page record (1.5 s). The tab now reads, from the answers it already gets, whether its next write has to launch the agent's container: the edge's `Leaf-Session: passive` for a page with no private copy, or the Durable Object's `Leaf-State-Source: durable` for one whose container has stopped. A send records that reading, and its message says "Launching agent container" until the server answers; a send to a running container still says "Queued for <agent>". The glossary names the new word and lets visible copy name machinery where it alone explains a wait. `publish` now uploads the record's chunks eight at a time instead of one round trip each. On the website image at a quarter CPU, with a store adding 80 ms per call, the upload phase of a first write went from 1.21 s to 0.27 s.
leaf-agent
approved these changes
Nov 9, 2026
This was referenced Nov 10, 2026
Run leaf.page sessions on one vCPU, and start a visitor's container when they focus a text box
#5802
Merged
leaf-agent
pushed a commit
that referenced
this pull request
Nov 10, 2026
…hen they focus a text box (#5802) 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× `basic` per awake second, less than `standard-1` (1/2 vCPU with 4 GiB). Cloudflare checks the account's 1,500-vCPU limit at rollout, counting `max_instances` times vCPU. It refused 90 one-vCPU dev containers beside production's 5,900 `basic` ones, 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`) with `textBox`, 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 `basic` with the same code, and sent first comments from fresh browsers: | Arm | n | POST median (range) | Write after the container was ready | | --- | --- | --- | --- | | 1 vCPU, no prewarm | 8 | 12.2 s (7.5–19.3) | 7.7 s | | `basic`, no prewarm | 5 | 13.9 s (10.7–41.7) | 10.2 s | | `basic`, prewarm, 10 s of typing | 4 | 29.7 s (14.3–48.4) | 30.3 s (ready 0.7–6.8 s before the POST) | Every 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 check` passes. > _This was written by Claude Code on behalf of max-sixty_
max-sixty
added a commit
that referenced
this pull request
Nov 12, 2026
…5856) A page server answers each request on its own thread, and every route needs the page's layer vocabulary. `functools.cache` held the composition, but it lets concurrent callers of a missing key each compute it. On a cold leaf.page container, `/examples/pr-walkthrough/` sends 46 `api/deferred` loads as it opens, one for each file in its diff. The 46 threads composed the same layer at once and shared the CPU until they all finished together. A visitor's first comment, sent meanwhile, got a 47th share of the CPU. Last week's production logs show first writes of 33 s and 155 s on that page; the file-tree example has the same burst. `page_memory.once` keeps a reading in a dict. The first thread to ask for a missing key makes it, and the rest wait for that one. Two kinds of cache now use it: - the layer's vocabulary and composition (`layer._vocabulary`, `layer._composed`), which used `functools.cache`; - the readings derived from a vocabulary (`registry.storage.layer_vocabulary`, `_revision_composition`), which used check-then-set. This changes Leaf's main code. It's about 30 lines, and the fault isn't specific to the website: a local page server starting cold under a burst of requests duplicates the same work. **Measured** in the website's container image on 1 vCPU, with 46 concurrent deferred loads at startup and a comment 1 s later: | | Deferred loads all done | Comment | | --- | --- | --- | | Before | 4.6–5.2 s | 15.3–15.9 s | | This PR | 0.5 s | 11.7 s | | No deferred loads | – | 11.8 s | The comment's remaining time is that image's serial chunk uploads (#5764 has since made them parallel), so the comment now costs the same as with no burst. **Test**: eight threads asking together for a cold selection's vocabulary compose it once and share the result. With `functools.cache` restored, the test fails with 8 compositions. > _This was written by Claude Code on behalf of max-sixty_
max-sixty
added a commit
that referenced
this pull request
Nov 12, 2026
…5805) A leaf.page message sent while its session's container is starting now says *Starting the agent* instead of *Launching agent container*: the user chose these words on 10 November. The old label needed an exception to the glossary's rule against naming machinery in visible copy, which this removes, so the rule reads as it did before #5764. `tests/runtime/thread-workflow.test.mjs` covers the label. > _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 first message on leaf.page read Queued for agent for about 7.5 s. Production's records for one (event
7046fcd3, 9 Nov) show the POST held 7.2 s in the Durable Object: the stopped container booted and restored in 2.0 s, the fresh Python composed the page's layer during admission (3.7 s onbasic's quarter vCPU, racing the App Server's start), andpublishuploaded 12 chunks one round trip at a time (1.5 s).The wait now names itself. The tab already gets the fact it needs: the Worker answers a page with no private copy at the edge (
Leaf-Session: passive), and the Durable Object stamps what it serves while the container is stopped (Leaf-State-Source: durable).layer-client.jskeeps that reading, a send records it on its ledger entry, and the localsendingworkflow carrieslaunching, whichworkflowWordsays as Launching agent container until the server answers. A send to a running container still says Queued for . The glossary gains the word, and its rule against naming machinery now allows it where the machinery alone explains a wait.Uploads overlap.
publishkeeps eight chunk uploads in flight. On the website image at--cpus 0.25, with a stub store adding 80 ms per call, the upload phase of a cold first write went from 1.21 s to 0.27 s and the whole POST from 6.85 s to 5.76 s (medians of three).Two readings are approximate.
Leaf-Session: passiveis per page while the container is per session, so a first message on a second page says Launching though the container runs; that write still waits (2.6 s locally, against 0.4 s for the page's next) because the container composes and uploads each page on its first write. And a send keeps the reading it was sent with, so one wait reads as one state rather than flipping to Queued when the container starts answering partway through.Most of the remaining wait is composing the layer on
basic's quarter vCPU, which the saved responses need (holding the release's activation in the container didn't shorten the write). In the same harness a cold first write took 8.7 s at ¼ vCPU, 3.7 s at ½ and 1.9 s at 1 vCPU; which fix to take is left to a later change.