Skip to content

Check a container's release in its session object, not in the outbound handler - #6568

Merged
max-sixty merged 3 commits into
mainfrom
session-release-props
Nov 20, 2026
Merged

max-sixty merged 3 commits into
mainfrom
session-release-props

Conversation

@max-sixty

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

Copy link
Copy Markdown
Owner

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

…ndler's

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 started the previous image, as its code names it, and the
handler refused that container's first read of its records, since the handler compared
the container's `Leaf-Release` with its own manifest. The container exited 1 and the
visitor's request answered 500.

Seen 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 was
the one failed start in the three production deploys since #6550.

The object now passes the release of its own code in the handler's props, and the store
holds a container to that. A container the object started on its own release reads and
writes its records whichever version runs the handler; once the object restarts on the
deployed code it routes a running container under the new release, which the store
refuses, and its first request stops it, as before. The handler that runs during the
next deploy's switch is this code, so the fix holds from that deploy on.
leaf-agent
leaf-agent previously approved these changes Nov 20, 2026
…live

Review found that holding the handler to the object's release in props still admits an
old container's write when the object restarts on the deployed code while that request
is on its way: the handler had passed it, and the object, now on the new code, stored it
under the new release. Only the object knows, as it handles a request, which code it
runs. So `SessionOutbound` now passes each page store request to the object's
`pageStore`, which refuses a container on another release than its own code's before
reading or writing anything, and the props and the five separate store methods go.
@max-sixty max-sixty changed the title Hold a container to its session object's release, not the outbound handler's Check a container's release in its session object, not in the outbound handler Nov 20, 2026
@max-sixty
max-sixty merged commit 6c320e0 into main Nov 20, 2026
6 checks passed
@max-sixty
max-sixty deleted the session-release-props branch November 20, 2026 03:41
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