Skip to content

Guard public Leaf deployment capacity - #386

Merged
max-sixty merged 8 commits into
mainfrom
codex/live-product-pages
Sep 7, 2026
Merged

max-sixty merged 8 commits into
mainfrom
codex/live-product-pages

Conversation

@max-sixty

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

Copy link
Copy Markdown
Owner

Summary

  • raise the public Leaf container ceiling from 10 to 100 concurrent private sessions
  • add deployment-config tests that pin the explicit Cloudflare application identity, align the container and Durable Object binding classes, and retain the public-session capacity floor
  • run those guards in the Worker-specific pull-request gate using the same TOML parser Wrangler uses
  • make post-deploy verification tolerate a realistic cold start, stay within the job budget, and print Cloudflare response bodies on failure

Why

#392 restored deployment by explicitly naming the standing container application, safely decoupling that external identity from the renamed TypeScript class. Its rollout then exposed the next production boundary: https://leaf.page/api/state returned Maximum number of running container instances exceeded because the example-only ceiling of 10 now applies to every product-page reader. The verification job retried for ten minutes but discarded that response body, leaving only timeouts and opaque HTTP 500 lines in the log.

The higher ceiling keeps a hard cost bound while allowing 100 concurrent private Leaf sessions. The new tests catch a lost application name, a container/binding mismatch, or a return to the example-only capacity in pull-request CI. Verification now allows 25 seconds per cold-start attempt, keeps the two-probe worst case below the 30-minute job timeout, and emits the final error body.

Testing

  • npm run typecheck --prefix worker
  • npm test --prefix worker — 21 passed
  • uv run pre-commit run --all-files
  • uv run scripts/site.py
  • npx wrangler deploy --dry-run --containers-rollout=none --outdir <temporary-directory>
  • local execution of the verification curl/jq path against the live preview

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.

The code revert and the PAGES binding read right, and the worker gate is green here (npm run typecheck clean, npm test 19 passed, uv run pytest tests/test_website_deployment.py 1 passed). Two things about the migration list, and one about the new test's floor.

The v2 migration looks already applied on the account, so deleting it is not the revert. wrangler deploy sends migrations with the script upload, and both post-#380 publish-site runs got past that step — 34094193513 and 34096665873 each printed Uploaded leaf-website with env.PAGES (LeafWebsiteSession) in the bindings table. A binding to a class no migration ever created is rejected at upload, so the namespace is currently named LeafWebsiteSession and the script's migration_tag is v2. The container step then failed against the existing application, name leaf-website-leafexamplesession id a033161d-…, which is the same namespace carried through the rename.

With v2 gone from the config, wrangler's getMigrationsToUpload finds the deployed tag absent from the list and takes the foundIndex === -1 branch — it warns "You may have already deleted it. Applying all available migrations to the script…" and sends old_tag: "v2", new_tag: "v1", steps: [{ new_sqlite_classes: ["LeafExampleSession"] }]. That re-runs the create-class step against an account where that name is now free, so either Cloudflare rejects it and publish-site stays red, or it creates a second, empty namespace: PAGES binds to that one while the standing container application stays attached to the old one, along with every seated reader session.

Keeping v2 and appending a v3 that renames back is correct under both readings — if the rename did apply, v3 undoes it; if it somehow did not, v2 then v3 apply back to back as a no-op. Either way the derived application name lands on leaf-website-leafexamplesession and the deploy takes the modify path. Inline suggestion on the migration block.

The new test would pass on the near-miss version of this fix. It compares the container class against the union of new_sqlite_classes without replaying renamed_classes, so a config with v2 retained and class_name = "LeafExampleSession" — the shape above, binding to a class the chain renamed away — passes. It also reads only new_sqlite_classes, so a future non-SQLite new_classes entry false-fails. Replaying the chain and asserting on the class it leaves standing is the invariant the docstring names; suggestion inline.

import tomllib breaks the project's declared floor. pyproject.toml says requires-python = ">=3.10", and tomllib is 3.11+, so on 3.10 this module fails to import and reddens the whole everyday suite at collection. The repo has already hit this — tests/test_interact_layer.py reads pyproject.toml off the lines rather than parsing it, and says why: "the project's own floor is 3.10, with no tomllib to parse with". Either raise the floor deliberately or read this config the same way; I haven't suggested one inline because which of those is right is a project call rather than a mechanical fix.

Overlap: #392 is mine and fixes the same red deploy from the other side — it pins name = "leaf-website-leafexamplesession" on [[containers]] and leaves the class renamed. This PR's direction is the better one once the migration chain is right, since it puts the code and the deployed identity back in agreement instead of pinning a name that lags the class; #392 should close if this lands. Separately, the instance ceiling #392 describes (max_instances = 10 with every product page now taking a seat) is underneath both and is not addressed by either.

Holding a verdict on the migration point rather than on style — a deploy that half-applies here costs the standing namespace, and I'd want that confirmed against the account before it runs.

Comment thread worker/wrangler.toml Resolved
Comment thread tests/test_website_deployment.py Resolved
@max-sixty max-sixty changed the title Keep deployed container identity stable Guard public Leaf deployment capacity Sep 7, 2026

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

Approving. The worker gate is green here — npm run typecheck clean, npm test 21 passed — and actionlint (shellcheck included) accepts the rewritten step. I checked the description's timing arithmetic and the test's derived application name against curl and wrangler themselves rather than taking them on trust; both hold.

One inline suggestion, on the half of the step that stays undiagnostic.

Overlap: #377 is mine and raises --max-time from 10 to 25 in this same step, and its "remaining risk" section is the max_instances = 10 ceiling this PR raises — it is fully superseded and should close once this lands.

What I verified

--max-time is per attempt, not per whole operation, so the budget arithmetic in the description holds: curl --retry 3 --retry-all-errors --retry-delay 1 --max-time 2 against a black-holed address takes 11s, not 2s. The two-probe worst case is 2 × (21 × 25 + 20 × 5) = 1250s ≈ 20.8 min, essentially where the old --retry 30 --retry-delay 10 --max-time 10 sat (20.3 min), so the 30-minute job timeout is no tighter than before.

--fail-with-body with --output does not accumulate across retries — curl truncates the file before each attempt, so cat "$response" prints the final body alone. Confirmed against a local server returning a distinct 500 body per attempt: the file held the third body, 10 bytes.

Wrangler derives the container application name as ${topLevelName}-${containerAppOptional.class_name} then .toLowerCase().replace(/ /g, "-"), so ${config.name}-${createdClass.toLowerCase()} reproduces it exactly for the no-environment case. Deleting the explicit name from [[containers]] now reddens the test rather than the deploy.

set -e propagation through the function is intact: simulating the step under bash -e, both a retry-exhausted 500 and a false predicate exit 1 without reaching the line after the call.

Comment thread .github/workflows/publish-site.yaml Resolved
@leaf-agent

Copy link
Copy Markdown
Collaborator

publish-site went red again on main at run 34098097774 (the main build of #392): the verify step spent its whole budget — 08:00:22 → 08:10:19 — on 29 attempts that aborted with curl: (28) ... 0 bytes received and 2 that returned curl: (22) ... error: 500. Same shape as the run that prompted this PR, so it is this ceiling rather than a new fault.

What is new is that the ceiling now takes the landing page with it, not just /api/state. Probing from this runner just now, a fresh session gets a plain-text 500 on https://leaf.page/ itself:

$ curl -s -w '\n-- %{http_code} %{content_type}\n' https://leaf.page/
Failed to start container: Maximum number of running container instances exceeded. Try again later, or try configuring a higher value for max_instances
-- 500 text/plain;charset=UTF-8

Repeated four times over ~90s across https://leaf.page/ and https://leaf.page/api/state, all 500 with that body, 11–22s each. In #377's evidence three hours ago the static root was still healthy (200 in 0.53s) while only the API probe failed; since #380 serves the product site as live Leaf pages, every reader of / now takes a seat, so ten held slots at sleepAfter = "10m" is the whole site down for the eleventh. That is the boundary this PR's max_instances = 10 → 100 moves, and it is live for readers right now, which is the only thing I would add to the case for landing it.

No fix PR from me — this PR already carries the remedy at the right level, and #377 stays superseded.

@max-sixty
max-sixty merged commit 8de0b9a into main Sep 7, 2026
13 checks passed
@max-sixty
max-sixty deleted the codex/live-product-pages branch September 7, 2026 08:56
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