Repository navigation
fix: retry a leaf.page read once when the container connection drops - #5815
Merged
Merged
Conversation
The Containers SDK turns a lost container connection into a plain 500
("Container suddenly disconnected, try again" or "Error proxying request to
container: ..."). The session's forward logged that 500 and returned it, so a
page's /api/news poll that landed while a write woke its container showed the
visitor a console error, and failed publish-site's saved-state browser-error
gate after #5810 moved that gate behind the media write.
forward now classifies both SDK bodies as `disconnected` and sends a GET or
HEAD once more, returning the second answer. A write is never resent, since it
may already have reached Python. The http_error record gains `retried`.
The existing logging test no longer expects a disconnected GET to surface as a
500; a new test covers both SDK bodies, a second loss reaching the caller, and
a POST that is not resent.
Closes #5814
This was referenced Nov 11, 2026
max-sixty
pushed a commit
that referenced
this pull request
Nov 12, 2026
…n drops (#5862) `publish-site` [run 43160732700](https://github.com/max-sixty/leaf/actions/runs/43160732700) failed because the hosted journey's browser-error gate caught one 500 from `POST /examples/triage-board/api/user-view`. Cloudflare logged that 500 at 05:32:55 UTC as `{component: "leaf-container", event: "http_error", method: "POST", source: "disconnected", retried: false}`, which is the Containers SDK's connection-loss response. The container stayed up through it: the same hosted turn kept logging steps and finished normally about 7 s later. #5815 made `forward` resend a `GET` or `HEAD` once after a dropped connection, but no write, since a write may already have reached Python. A view report is a write Python answers the same way when it arrives twice. `observe_user_view` ignores a report whose sequence is not newer than the session's stored one, and still answers 204. So it's safe to resend. `forward` now resends a view report once too, from a copy of the request it takes before the first attempt. Every other write still passes its loss to the caller, and the README's description of `retried` now says so. The new case in the Worker test checks that a disconnected `POST api/user-view` is sent again with the same body, answered with the second response, and logged with `retried: true`. It fails on `main` (500 instead of 204) and passes here. `pnpm run check:worker` (type check and the Worker suite) passes. This change doesn't explain why the container connection drops while the container is still running. #4656 tracks that cause. It applies to the writes this change leaves alone, such as `api/event`. Refs #5861 — automated triage Co-authored-by: leaf-agent <[email protected]>
leaf-agent
pushed a commit
that referenced
this pull request
Nov 18, 2026
…ol, and record why a container stops answering (#6370) leaf.page's "Container suddenly disconnected" 500s (#4656) are a keep-alive race. The Workers runtime keeps an idle connection to a container for 5 s (kj's default `HttpClientSettings::idleTimeout`, which workerd's `api/container.c++` leaves unset), and uvicorn closes an idle keep-alive connection after 5 s too, so a request the pool sends at the 5 s mark is lost. Both drops in the last seven days of records came from a connection idle 4.86–5.03 s. A local `wrangler dev` repro lost 10 of 42 requests at a 5000 ms idle gap and none at any other gap, and 0 of 54 with a 75 s server keep-alive. `LeafHTTPServer` now keeps idle connections for 60 s. The Nov 15 13 s "taking too long to accept the connection" reads as the container's VM stopping (CPU below idle, no log line, Codex's timers late), which no change here repairs. For the next one, `http_error` records carry the SDK's failure sentence as `detail`, and a watcher thread in the container (`worker/leaf_website/stalls.py`) records `container_stalled` or `container_unresponsive`, which tell a stopped VM from a blocked server. To weigh: the keep-alive applies to every Leaf server, local ones too, and a stop still closes idle connections at once. uvicorn's shutdown still answers an in-flight request without `Connection: close`, so a container that stops mid-request can still drop a pooled request; #5815's resend covers reads. Max asked for the diagnosis and logging; a Codex review found four watcher and privacy issues, fixed or answered here. `pnpm run check:worker`, the server keep-alive and stop tests, and the adapter start/stop test pass. Refs #4656 > _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 read that hits a dropped container connection now gets one more attempt in the Worker instead of reaching the visitor as a 500. This is the failure behind
publish-site's red run on37de78c5458c(run 42909821856): the open page's/api/newspoll landed while the verifier's media upload was waking the container, the SDK answered500 Error proxying request to container: Error: Container port connection closed unexpectedly., and the saved-state browser-error gate counted the console error. #5810 had just moved that gate behind the media write.Cause. Containers SDK 0.3.7 catches a proxy failure and returns a plain 500 with one of two bodies:
Container suddenly disconnected, try againorError proxying request to container: …(dist/lib/container.js, thecatchincontainerFetch).LeafWebsiteSession.forwardlogged that 500 and returned it unchanged. The same shape (one/api/newsor/api/state500 at the Worker-to-container boundary, then a successful read) was written off as transient in #2331, #3115 and #3165.Change.
forwardclassifies both SDK bodies asdisconnected. It sends adisconnectedGETorHEADonce more and returns the second answer. A write is never resent, because it may already have reached Python. A 500 that Python stamped withLeaf-Release, or any other unclassified 500, passes through as before. Thehttp_errorrecord gainsretried, andworker/README.mddocuments it.Verification. The new Worker test (
reads again once when the container connection drops, but never resends a write) fails onmainwithexpected 500 to be 200and passes here.pnpm run check:workerpasses (92 tests plustsc). The start-up race needs Docker, which this sandbox doesn't have (#4293), so the real check is the nextpublish-siterun, which goes through a container start in the saved-state step.Closes #5814 — automated triage