Skip to content

Start each leaf.page container from its session object, under Durable Object scheduling - #6550

Merged
max-sixty merged 5 commits into
mainfrom
durable-object-scheduling
Nov 20, 2026
Merged

max-sixty merged 5 commits into
mainfrom
durable-object-scheduling

Conversation

@max-sixty

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

Copy link
Copy Markdown
Owner

Every leaf.page deploy was followed by 2–5 minutes in which container starts failed ("Failed to start container"): Cloudflare activated the Worker at once but rolled the image out over minutes, and the page store refused the previous image. This moves the session object to Cloudflare's Durable Object scheduling: LeafSession starts, proxies and idles out its own container on the Container API (the deprecated @cloudflare/containers SDK is removed), with the image from its own Worker version, so a start after a deploy always runs the deployed image. The image pre-build in publish-site, --containers-rollout and max_instances go.

Closes #4081

To weigh:

  • The new policy needs a new class (migration v3), so every visitor starts once from the published page. LeafWebsiteSession stays as an empty export: Cloudflare refuses to delete a class while its container application stands, and refuses a version that omits it. Deleting both is a follow-up.
  • A container from before a deploy is still stopped at the session's first request after it, and the store still refuses it meanwhile, so a turn in progress is cut off. Keeping it running was built and tried (first commit) and backed out (second): the Worker↔container interface has no version, so an older container could be left unable to save.
  • worker/wrangler-deploy.sh is now the one deploy retry, for publish-site and deploy-dev.sh: it folds in main's 100146 retry (Retry the site deploy when Cloudflare cannot find the uploaded Worker version #6546) and also reruns a deploy that uploaded the Worker but failed to apply the container application, which wrangler does when the same lookup outlasts its 2.5 s read-back (3 of 6 dev attempts). On production's first deploy, which creates the new application, that rerun is what gives the class a container, so the first retry comes after 30 s.

The maintainer asked for this on a Leaf page. Tests: worker vitest, tests/process/website_server, leaf-dev site verify website-worker, and three deploys to leaf-website-dev with a visitor's tab held open: no failed request to a visitor, one reload at the deploy, every sent question answered.

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

…ing ones through a deploy

Every production deploy was followed by 2-5 minutes of failed container starts
("Failed to start container"): all 14 Worker versions deployed on 19 November, 00:14 to
11:31 PT, show the deploy check's reads failing that way. Cloudflare activated the
Worker at once but rolled the container image out over minutes, so a start in between
booted the previous image, which the page store refused (409). The maintainer chose to
move to Durable Object scheduling, and then to let running containers keep their
image through a deploy, treating a deploy as a local Leaf treats a plugin update.

The session object now starts its container itself (`LeafSession`, on Cloudflare's
Durable Object Container API in place of the deprecated Containers SDK), with the
image from its own Worker version's image map, so every start after a deploy runs the
deployed image and the window is gone. The object proxies requests, waits for the
container's health route, sets its ten-minute idle timeout, and routes its outbound
requests through `SessionOutbound`, which reaches only its own page store and the
model API. A container already running keeps its image until it goes ten minutes
without a request: its agent turn finishes, and its tab keeps working against it.

Each answer now names the release of the code that gave it. Python stamps its image's
release on every answer and the edge passes it on instead of overwriting it with its
own, so a tab reloads only once a newer container answers. The page store keeps the
release the capturing container names beside each commit, rather than refusing any
container but the Worker's. An earlier release's release-addressed file, which such a
tab still imports on demand, goes to the visitor's session, whose container serves it.

What this deletes: the store's 409, the stop of every container at a deploy's first
request (`container-release`), the image pre-build and digest pin in `publish-site`,
`--containers-rollout=immediate`, `max_instances`, and the `@cloudflare/containers`
dependency. Cloudflare fixes a container application's scheduling policy and gives
each object class one application, so the move takes a new class: migration v3
creates `LeafSession` and deletes `LeafWebsiteSession`, and every visitor starts once
from the published page. The account's 1,500 concurrent vCPU now bounds the
containers, production's and dev's together.
… and retry unplaced starts

A review of the previous commit found that keeping a container on its image through a
deploy leaves the previous image's server talking to the deployed Worker and session
object over an interface nothing versions: the page store's request shapes changed
twice on 18 November (#6441, #6457), and after such a deploy every commit from an older
container would fail while its tab, answered on its own release, never reloaded. A
page the deploy adds is one the older image doesn't have, so it answered 404 and its
active cookie pinned the page to that container. And an open tab polls, so the
container never went idle and the visitor never got the deployed release.

So the session object records the release whose image it starts, and its first request
after a deploy stops a container still on another, as the Containers SDK version did;
under Durable Object scheduling the next start runs the deployed image at once, so
the tab reloads once onto the new release with no window of failed starts. An agent
turn running at the deploy is cut off, as before. Earlier releases' files no longer
route to the session.

A start the platform could not place, which carries no exit code, is tried again
within the readiness deadline, as the SDK did for eight seconds; a container that
misses the deadline is destroyed rather than left running; and a start failure
answers 503, which the tab waits out, rather than 500. A read that lost its
connection is retried once the container answers its health route again. On
leaf-website-dev the second deploy of the previous commit kept a held tab's container
on its image with no reload and no failed request, which this commit trades for one
reload at the deploy.

The deploy runs through `worker/wrangler-deploy.sh`, which reruns `wrangler deploy`
once when it fails to apply the container application after uploading the Worker, as
the first dev deploy of the new class did.

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

releaseAssetRoute (worker/src/routing.ts) still accepts any release segment, but the second commit removed the branch in the Worker's fetch that sent an earlier release's address to the session (if (releasedAsset.release !== manifest.release) return earlierReleaseFile(...)). Now the Worker answers /_leaf-release/<earlier>/<key>/<inside> with the current release's static file, stamped Cache-Control: public, max-age=31536000, immutable.

A tab loaded before a deploy imports its runtime on demand from its own release's address. After the deploy, a module it hasn't fetched yet comes back as the deployed build's module under the old URL. The tab then runs a mix of two builds, which is the failure releases-refusal in docs/website.html exists to prevent, and nothing reports it: the module loads, and the browser caches the wrong bytes under that URL for a year. On the base, that path matched no page and got a 404. Any segment matches, too: the test passes "b".repeat(40), which no release id is.

Nothing in index.ts reads the new release field, so the fix is to restore the base function (suggestion inline). The test in routing.test.ts then needs the earlier-release case moved from the matching loop into the toBeNull() list, and release dropped from toMatchObject. I can push both if you'd like. released_path in worker/leaf_website/__init__.py already matches only the current release, so restoring the function also brings the Worker back in line with it.

This change finishes backlog #4081 ("Start each release's containers on its own image"), so the description could say Closes #4081.

Comment thread worker/src/routing.ts Resolved
…d back off unplaced starts

A second review found that destroying an older container only at the session's first
request after a deploy leaves its store calls open meanwhile: with the tab hidden, the
container's turn could still commit across the unversioned boundary the previous commit
avoided. So the store again refuses a request naming a release other than the Worker's
(409), as on main, and commits are tagged with the Worker's release.

A disconnected read now waits on one shared recovery, the container's health route
answering again, in place of a readiness loop per request, and a container that never
answers is destroyed. A start the platform couldn't place is retried at intervals
doubling from 250 ms for 15 s rather than every 100 ms for two minutes; a crash, which
carries an exit code, answers 500 and an unplaced start 503, as the SDK did; and a
container whose process exits 0 counts as exited rather than unplaced.

The leaf-agent review found that `releaseAssetRoute` still matched any release: the
previous commit restored it from the first commit instead of main, so the Worker
would serve the current build's file under an earlier release's immutable address.
It is main's again.
leaf-agent
leaf-agent previously approved these changes Nov 20, 2026
On leaf-website-dev, 3 of 6 `wrangler deploy` attempts on 19 November uploaded the
Worker and then failed to apply the container application: wrangler reads the new
version back five times over 2.5 s, and Cloudflare answered 404 throughout. The last
dev deploy failed that way twice in a row, so one rerun isn't enough; each rerun
uploads a new version and races again. After a half-applied deploy on dev, the site
check and a hosted agent turn passed, since the application already existed with
the same settings; production's first deploy of the new class creates its
application, so there the rerun is what gives the session class a container.
leaf-agent
leaf-agent previously approved these changes Nov 20, 2026
…oy.sh

Main's #6546 retries `publish-site`'s deploy when Cloudflare answers 100146 for the
version just uploaded, every 5 minutes until 30 minutes after the first, since its
outages have lasted over 15 minutes. This branch's script retried the same lookup
failure where it surfaces after the upload, as "not fully applied". The two are one
mechanism, so the script now retries either, 30 s after the first failure and then
every 5 minutes until 30 minutes after it, and `publish-site` and `deploy-dev.sh`
both run it. Checked against a stub wrangler: success, 100146 then success, two
half-applied deploys then success, and another error exiting at once.
@max-sixty
max-sixty merged commit 1e6e50c into main Nov 20, 2026
6 checks passed
@max-sixty
max-sixty deleted the durable-object-scheduling branch November 20, 2026 00:50
max-sixty added a commit that referenced this pull request Nov 20, 2026
Deletes `LeafWebsiteSession`, the session class that #6550 replaced with
`LeafSession`, through Durable Object migration v4, and removes its
empty export from the Worker. #6550 had to keep the export because
Cloudflare won't delete a class while its container application stands,
nor accept a version that leaves out a class it keeps. Both old
container applications, on production and dev, are now deleted, and
neither had a container active or assigned.

The migration deletes every object of the old class and the records they
held. Nothing reads them: since #6550 every visitor's records live in
`LeafSession`.

The `LeafSession` header now records that the maintainer chose to stop a
container still on the previous image at the first request after a
deploy, rather than letting it run until it idles, and why that
alternative fails.

Asked for by the maintainer on the deploy page. Checked with `pnpm run
check:worker` and a dev deploy that applied v4.

> _This was written by Claude Code on behalf of max-sixty_
max-sixty added a commit that referenced this pull request Nov 20, 2026
…d handler (#6568)

For some seconds after a deploy, Cloudflare can run a session object on
the previous Worker version while it runs the object's outbound handler,
`SessionOutbound`, on the deployed one. The object then starts the
previous image, as its code names it. The handler refused that
container's first read of its records because it compared the
container's `Leaf-Release` with its own manifest, so the container
exited 1 and the visitor's request answered 500.

The release check now happens in the session object, which owns the
records. `SessionOutbound` passes each page store request to the
object's `pageStore`, which refuses a container on another release than
the object's own code before reading or writing anything. The object's
five separate store methods are folded into it. A container the object
started on its own release can read and write its records whichever
version runs the handler. Once the object restarts on the deployed code,
the same check refuses the previous image, including a request already
on its way when the restart happened, and the object's first request
stops that container, as before.

What to weigh: in those seconds, a previous-release container can still
write its session's records while the deployed code is live elsewhere.
`storage.ts` now says the store guarantees deployed-image writes from
the moment the object moves to the deployed code. Records already
outlive deploys at the same page protocol and store format, and the
maintainer ranked such incompatibility unlikely. The code that runs
during the next deploy's switch is this code, so the fix holds from that
deploy on; during this PR's own deploy an older object lacks
`pageStore`, which fails the same starts the old rule failed.

Evidence: on #6565's deploy at 19:11 PT, 14 s after the new version went
live, the deploy check's fresh session ran `LeafSession` on version
4cfec23e and `SessionOutbound` on fa6d68b8, and the store answered 409
"the page store serves release 9f3b4cc8…". It is the one failed
container start on production in the five deploys since #6550 went live.
A new test runs the object and the handler on different releases, and
fails under the old rule. An independent Codex review of a first
version, which passed the object's release to the handler in props,
found the restart case above, which moved the check into the object; its
review of this version, run in local workerd, found the 1 MiB bound and
error reasons intact across the RPC. On the dev site, the site check and
a real agent turn, which restores and saves its records through
`pageStore`, passed. `pnpm run check:worker` passes.

Found while measuring deploys for the deploy page the maintainer is
following.

> _This was written by Claude Code on behalf of max-sixty_
leaf-agent added a commit that referenced this pull request Nov 20, 2026
…nd picker export nothing calls (#6585)

These comments named code that is gone, and two pieces of code had no
caller. Nothing here changes behavior.

**Comments that named removed code**
- `src/leaf/render-checks/` (`framing.js`, `open-roots.js`, `words.js`,
`widgets.js`) named `OPEN_ROOTS`, but the export is `openRoots`. Two of
them also compared it with `UNMARKABLE_ITEMS`, which 90f9374 removed.
- `browser/runtime/version.js` said repeated comparisons of a revision
share its document fetch. In fact only `prepareActivation` reads that
cache, and `loadBase` calls `authoredDocument` directly.
- `browser/runtime/annotation-overlay/thread-preview.js` said a run's
earlier progress steps fold. #6508 removed that fold; only a closed
checkpoint's turns fold now.
- `dev/leaf_dev/website.py` and `leaf-dev site verify --wait` explained
their waits by a container image rollout, which #6550 removed. Now each
session object starts the deployed image, so the waits cover the edge
still serving another release and a lost activation connection. This
matches `verify.py`'s header, which #6550 already rewrote.

**Code with no caller**
- The Playwright timeline's `zoomBy` took a `fit` range that no caller
passes: lf-trace's two zoom commands pass a factor, and the wheel passes
a factor and an anchor. Its `zoom` getter had no reader.
- `createTargetPicker` returned `openTargetPicker`, which nothing
outside the module reads. Its own `s` command still runs it.

`pnpm run check:framework` and `pnpm run test:runtime` pass (1073), and
`ruff check` is clean on the two dev files. No test is added, since
nothing here changes behavior.

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.

Start each release's containers on its own image

2 participants