Skip to content

Scale website containers with page visibility - #403

Merged
max-sixty merged 4 commits into
mainfrom
codex/fix-gallery-startup
Sep 7, 2026
Merged

max-sixty merged 4 commits into
mainfrom
codex/fix-gallery-startup

Conversation

@max-sixty

@max-sixty max-sixty commented Sep 7, 2026 •

Copy link
Copy Markdown
Owner

Leaf currently holds one EventSource connection open for every tab, including hidden ones. Cloudflare counts each streaming response as an in-flight container request, so those sessions never begin the existing idle timeout and consume the public instance ceiling indefinitely.

This change raises the public lite container limit from 100 to Cloudflare's current account capacity of 15,000. It also makes document visibility the browser lease: hidden tabs close their news stream and stop timed reads, while visible tabs reconnect and catch up from the canonical state projection. The ten-minute idle grace remains, and one visible tab is enough to keep a multi-tab reader session alive.

The browser test proves a hidden page neither hears nor polls for changed state, stops advancing reader presence, then reconnects once and catches up when visible. The storage contract now defines viewed.json as visible reader attention rather than background-tab lifetime. The parsed deployment-config test pins both the exact capacity and lite instance type while retaining the existing production application-identity guard.

This was written by Codex on behalf of max-sixty

@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.

Closing the stream on hidden also stops the only writer of viewed.json, which I think is a semantics decision worth making deliberately rather than a side effect.

_news is the sole bumper (http.py:413) and viewed is spread straight through full_state into the agent-facing state, so leaf state prints it. The recorded meaning is "when a browser last held the page open" (page-storage.md:90, and the comment at presence.py:216), and the distinction it exists for is stated in both places and again in test_an_open_stream_records_that_the_page_is_open: "a page nobody ever opened and one the user studied and left used to be indistinguishable from the agent's side."

After this change a tab the reader still has open behind another one stops bumping it, so from the moment it hides it reads to the agent exactly like a page the reader closed. The fact narrows to "when a browser last had it visible". That may well be the better fact for an agent asking whether anyone is looking — but it is a different one from what those three places describe, and the diff does not say so.

The rest reads clean to me. The stream lifecycle holds up on the paths I traced — a stale opened cannot rearm the silence timer or schedule a reopen, feedStarted keeps the visibility handler from racing the first read, and gating the shared clock is what stops an offline hidden tab from holding its container through ask every two seconds. max_instances = 15000 matches the README's own derivation from a 2 GB lite disk.

I can push the doc-only version of either reading if you say which one you want.

@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.

The visibility reading is now stated in the three places the earlier round named, so the narrowing of viewed.json reads as a decision rather than a side effect.

One sentence still states the old lifecycle. The ear comment in skills/leaf/assets/runtime/state-feed.js opens with "one stream, open for the page's life", a dozen lines above the new paragraph saying hidden tabs close their streams — a page now opens and releases a stream per visible interval, so that opening claim is the one place left in the file reading against the change. It sits outside this diff; I can push the one-line correction if you want it.

@max-sixty
max-sixty merged commit 3e92434 into main Sep 7, 2026
4 checks passed
@max-sixty
max-sixty deleted the codex/fix-gallery-startup branch September 7, 2026 16:29
max-sixty added a commit that referenced this pull request Sep 7, 2026
Leaf currently holds one EventSource connection open for every tab,
including hidden ones. Cloudflare counts each streaming response as an
in-flight container request, so those sessions never begin the existing
idle timeout and consume the public instance ceiling indefinitely.

This change raises the public `lite` container limit from 100 to
Cloudflare's current account capacity of 15,000. It also makes document
visibility the browser lease: hidden tabs close their news stream and
stop timed reads, while visible tabs reconnect and catch up from the
canonical state projection. The ten-minute idle grace remains, and one
visible tab is enough to keep a multi-tab reader session alive.

The browser test proves a hidden page neither hears nor polls for
changed state, stops advancing reader presence, then reconnects once and
catches up when visible. The storage contract now defines `viewed.json`
as visible reader attention rather than background-tab lifetime. The
parsed deployment-config test pins both the exact capacity and `lite`
instance type while retaining the existing production
application-identity guard.

> _This was written by Codex 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