Skip to content

Wait 25 seconds per attempt when verifying the public Leaf pages, bounded at ten minutes per probe - #377

Closed
leaf-agent wants to merge 4 commits into
mainfrom
fix/ci-34088384337
Closed

leaf-agent wants to merge 4 commits into
mainfrom
fix/ci-34088384337

Conversation

@leaf-agent

@leaf-agent leaf-agent commented Sep 7, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

publish-site went red on main at run 34088384337: wrangler deploy succeeded and the verify step then spent its whole retry budget — 05:53:47 to 06:03:31 — across thirty-one attempts, twenty-seven of which aborted with curl: (28) Operation timed out after 10002 milliseconds with 0 bytes received and four of which returned curl: (22) The requested URL returned error: 500. The deploy itself was fine.

The seat is where it goes wrong. The Worker answers a session it cannot seat with Failed to start container: Maximum number of running container instances exceeded, and while every slot is held a seat request can also hang with no bytes at all — which is what the twenty-seven aborts are. The four attempts that did answer came back 1.4s, 5.7s, 1.4s and 5.4s into their attempt, well inside the ten-second cap, so in this run the cap did not cut off the busy reply; it cut off the hangs. The window cleared on its own: a fresh session was seated in 2.7 seconds at 06:11, roughly eight minutes after the step gave up.

Solution

Raise the per-attempt cap from 10 to 25 seconds on both probes in Verify public Leaf pages, and bound each probe's retry loop with --retry-max-time 600. The wider cap is a bet rather than a demonstrated fix: nothing in the failed run shows an answer arriving between 10 and 25 seconds, so it helps only if the hang resolves inside it. It does cover the busy reply measured by hand at ~11.5s while the window was still held, which ten seconds cut off.

--retry-max-time is what keeps the wider cap affordable. --retry counts attempts, not time, so 31 attempts at 25s plus their delays is ~17.9 min per probe, and the step runs two of them — ~35.8 min inside a job capped at timeout-minutes: 30. That overrun would end the step as a runner kill rather than as the curl error the step exists to report. Ten minutes per probe holds the step's worst case to ~20.9 min, entered 2.6 min into the job, which is roughly the wall-clock patience the step had at the ten-second cap while each attempt now waits two and a half times as long.

In practice the two probes share one container seat rather than taking one each: they send the same $COOKIE and the Worker keys the container on the session alone (getContainer(env.PAGES, sessionId) in worker/src/index.ts, with no route in the key), so the second reuses what the first got. The step comment records that, since an earlier draft of it claimed the opposite.

--retry-all-errors still fails the deploy if a route never answers, so a genuinely broken rollout is still caught. --fail discards the response body, so at any cap the log records curl: (22) The requested URL returned error: 500 and never Cloudflare's reason string; --fail-with-body would surface it but would pipe the error body into jq, so it is not a free swap and I have left it alone.

Remaining risk, for a maintainer to weigh

The widened budget does not remove the ceiling underneath it. worker/wrangler.toml sets max_instances = 10 against one container per browser session with sleepAfter = "10m", so an eleventh concurrent reader on https://leaf.page/ gets a raw 500 carrying Cloudflare's error string, and a deploy that lands during such a window is what reddened this run. Raising max_instances, shortening sleepAfter, or answering a seatless session with a styled "the demo is busy" page are all decisions about cost and reader experience, so I have not made one here. Cloudflare also had an unresolved Workflows incident open from 05:12 UTC, overlapping this window; I could not tell from outside whether it held the instances or ten real readers did.

Testing

Evidence

Attempt classes in the failed run, counted out of its log:

curl: (28) ... 0 bytes received   27
curl: (22) ... error: 500          4

The four 500s landed 1.4s, 5.7s, 1.4s and 5.4s after their attempt started (each attempt starts one --retry-delay 10 after the previous line's timestamp), so none of them was cut off by --max-time 10.

Live probes against the deployed build, before and after the window cleared:

# during the window (fresh session each time)
try1 api:500 time:11.598585   Failed to start container: Maximum number of running container instances exceeded
try2 api:500 time:11.476960
try3 api:500 time:11.170504
try4 api:500 time:11.303604

# after it cleared — the step's own assertion, verbatim
fresh:200 time:3.552313
jq '.example.install_url == "/#install" and .claims == []'  ->  true

The static route was healthy throughout (https://leaf.page/ → 200 in 0.53s), which locates the fault at the container seat rather than the Worker or the asset build.

--retry-max-time bounds the loop and still reports curl's own error, checked with the same flag shape against a closed port:

$ curl --fail --silent --show-error --retry 30 --retry-all-errors \
    --retry-delay 2 --max-time 5 --retry-max-time 6 http://127.0.0.1:9/
curl: (7) Failed to connect to 127.0.0.1 port 9 after 0 ms: Couldn't connect to server   (x4)
exit=7 elapsed=6s

Four attempts in 6s rather than the 31 that --retry 30 alone would have run.

Budget arithmetic against the job's timeout-minutes: 30: each probe is capped at --retry-max-time 600 plus one in-flight attempt of up to 25s, so the step's worst case is 2 × 625 = 1250s ≈ 20.9 min, entered 2.6 min into the job.

pre-commit run --files .github/workflows/publish-site.yaml passes, actionlint included. publish-site only runs on pushes to main, so this branch's CI cannot exercise the changed step; merging it re-runs the workflow, since the file is in its own trigger paths.


Automated fix for failed run

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The arithmetic checks out and I could reproduce the timing claims: run 34088384337's step ran 05:53:47→06:03:31 (584s, 2.6 min into a 30-minute job), and the 20-second cadence between failures confirms --max-time is per attempt, so 31 × 25 + 30 × 10 ≈ 17.9 min is right and stays inside the job timeout.

The diagnosis recorded in the comment is the part I'd change. In that run the seatless 500 was not the slow answer — all four 500s came back inside the ten-second cap (1.4s, 5.7s, 1.4s, 5.4s after their attempt started); the other twenty-seven attempts aborted with zero bytes received, which is a hang rather than a slow reply. The ~11.5s figure comes from the probes taken minutes later, so nothing in the run itself shows an answer arriving between 10 and 25 seconds. The change is still cheap and plausibly right, but it's a bet that the hang resolves under 25s rather than a demonstrated fix for the twenty-seven aborts, and the comment as written will point the next diagnosis at the wrong shape. Suggestion inline.

One knock-on: --fail discards the response body, so at any cap the log gets curl: (22) The requested URL returned error: 500 and never the "Maximum number of running container instances exceeded" string — the reason still has to be recovered by hand-probing. --fail-with-body would surface it, but it pipes the error body into jq, so it isn't a free swap; worth leaving as is unless the next incident makes it worth the noise.

Comment thread .github/workflows/publish-site.yaml Resolved

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The comment rewrite lands: 9b2681e records the hang rather than the busy reply, and the merge carried that reading onto main's two-probe step intact. The earlier thread is resolved.

The base merge changed the arithmetic I confirmed last time, though, and nothing in the PR has caught up with it. When I checked 31 × 25 + 30 × 10 ≈ 17.9 min against timeout-minutes: 30, the step held one probe; it now holds two, each carrying the full budget. Details inline.

Two stale bits of prose that follow from the same merge, worth fixing while the arithmetic is being revisited:

  • The description still reads 31 × 25 + 30 × 10 = 1075s ≈ 17.9 min ... inside the job's 30-minute timeout. That is now one probe's budget, not the step's.
  • The title still names the deployed example server. The step it changes is Verify public Leaf pages, and half of what it now caps is the product route.

One correction to the new comment while it is the thing the next diagnosis reads. Both routes take a container seat is not quite what happens: both curls send the same $COOKIE, and the Worker keys the container on the session alone — getContainer(env.PAGES, sessionId) in worker/src/index.ts, with no route in the key — so the two probes take one seat between them and the second reuses what the first got. That is also the fact that keeps the doubled budget from biting in practice, so it is worth stating rather than losing.

Comment thread .github/workflows/publish-site.yaml Resolved
The base merge gave the step two probes, each carrying the whole widened
budget: 31 attempts at 25s plus 30 delays is ~17.9 min per curl, so the
step's worst case reached ~35.8 min inside a job capped at 30. That
overrun would land as a runner kill rather than as the curl error the
step exists to report.

--retry-max-time 600 bounds each probe's loop by time rather than by
attempt count, keeping the step inside the job while each attempt still
waits 25 seconds for a busy seat. The step comment also claimed both
routes take a container seat; the Worker keys the container on the
session alone, and both probes send one cookie, so they share one.
@leaf-agent leaf-agent changed the title Wait 25 seconds per attempt when verifying the deployed example server Wait 25 seconds per attempt when verifying the public Leaf pages, bounded at ten minutes per probe Sep 7, 2026

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The bound in 992b8ad checks out, and so does the comment it sits under. --retry-max-time on the runner's curl 8.5.0 is "Retry only within this period", so the loop stops retrying once the timer passes 600s and one in-flight attempt can still run its full --max-time 25 — the 2 × 625 = 1250s ≈ 20.9 min worst case is right, and it lands inside timeout-minutes: 30 with the step entered 2.6 min in. The seat claim in the comment is accurate too: SESSION_COOKIE = "__Host-leaf-page" and SESSION_ID = /^[0-9a-f]{32}$/ in worker/src/routing.ts accept exactly what openssl rand -hex 16 produces, sessionFromCookie therefore returns non-null on the second probe, and getContainer(env.PAGES, sessionId) keys on the session with no route in it — so the two probes do share a seat. The open thread is resolved.

What I'd raise now is not in the diff. #386, from the maintainer, rewrites this same step and is a superset of this PR:

  • It reaches the same budget by the other route — --retry 20 --retry-delay 5 --max-time 25 is 21 attempts, 21 × 25 + 20 × 5 = 625s per probe, the same ~20.9 min for two — so it buys the identical per-attempt patience without --retry-max-time.
  • It uses --fail-with-body with --output to a temp file, which recovers the "Maximum number of running container instances exceeded" string that this PR's --fail discards and that the description explicitly leaves unrecovered.
  • It raises max_instances from 10 to 100 in worker/wrangler.toml, which is the ceiling this PR's Remaining risk section hands to a maintainer rather than deciding.

The two edit the same lines and will conflict. Since #386 covers this PR's per-attempt fix, plus the error body and the underlying capacity limit, I'd land that one and close this — unless the --retry-max-time shape is wanted specifically, in that case it is a one-flag addition to #386 rather than a separate PR.

@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Superseded — I'd close this in favour of #386.

publish-site went red on main again at run 34099278145 (the build of #387), same shape as the run that prompted this PR: 27 attempts aborting with curl: (28) ... 0 bytes received and 2 returning curl: (22) ... error: 500. #386 already carries the live-reader consequence of the same ceiling, so I'm not repeating it here.

What this run settles is this PR's own bet. The description called the wider per-attempt cap "a bet rather than a demonstrated fix … it helps only if the hang resolves inside it". Probing the deployed build from this runner just now, it does not: a fresh session gets the 500 back inside the widened window, so the cap never becomes the thing that was cutting the answer off.

try1 -> 500 11.321576
try2 -> 500 21.671199
Failed to start container: Maximum number of running container instances exceeded. Try again later, or try configuring a higher value for max_instances

A 500 at 11.3s already fitted under --max-time 25, and every retry answers the same way while the slots are held — so raising the cap changes how the step spends its ten minutes, not whether it ends green. Only the max_instances = 10 → 100 in #386 does that, and #386 also reworks this exact step (25s cap, bounded retry loop, --fail-with-body so Cloudflare's reason reaches the log instead of a bare error: 500), which is the half this PR was carrying. Nothing here is left over for it to land separately.

@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Closing: #386 merged at 08:56 UTC and main now carries the whole of what this PR was for — --max-time 25 on both probes, a bounded retry loop, --fail-with-body so Cloudflare's reason reaches the log, and max_instances = 100, which is the ceiling the Remaining risk section here left to a maintainer.

The one shape not carried over is --retry-max-time 600. The merged step reaches the same bound by attempt count instead — --retry 20 --retry-delay 5 --max-time 25 is 21 attempts, 21 × 25 + 20 × 5 = 625s per probe — so it is a one-flag addition there if the time-based bound is wanted for its own sake, not a reason to keep this branch. The branch stays for that.

@leaf-agent leaf-agent closed this Sep 7, 2026
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.

1 participant