Skip to content

Say Launching agent container while a leaf.page write starts its container - #5764

Merged
max-sixty merged 2 commits into
mainfrom
agent-launch-state
Nov 10, 2026
Merged

max-sixty merged 2 commits into
mainfrom
agent-launch-state

Conversation

@max-sixty

@max-sixty max-sixty commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

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 on basic's quarter vCPU, racing the App Server's start), and publish uploaded 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.js keeps that reading, a send records it on its ledger entry, and the local sending workflow carries launching, which workflowWord says 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. publish keeps 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: passive is 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.

This was written by Claude Code on behalf of max-sixty

…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.
@max-sixty
max-sixty merged commit a793cf8 into main Nov 10, 2026
5 checks passed
@max-sixty
max-sixty deleted the agent-launch-state branch November 10, 2026 18:01
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_
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