Repository navigation
chore(build): make preview discovery survive a slow cloudflare deploy - #134
Merged
Merged
Conversation
The 6-minute deadline was not a margin over Cloudflare's build time, it WAS that build time: across 86 measured `Cloudflare Pages: sahajatlas` check runs on this repo the p95 is 373s, so 360s sat below it. #124 came in at 397s and #99's hard-fail turned a healthy commit red. Raise it to 10 minutes (overridable via PREVIEW_TIMEOUT_MS) and, more usefully, stop collapsing every unhappy path into one empty output. A second `preview_status` output names which it was, and ci.yml gives the two cases different instructions: `absent` (no Cloudflare signal at all) says investigate, `pending`/`unreachable` (a deploy demonstrably exists) says re-run. Both still fail a same-repo PR, so the #99 invariant is untouched — a green Smoke check still means the specs ran. The wait is flat rather than adaptive because there is nothing to wait on: across 230 check runs every one was already `completed` when first visible (`started_at == completed_at`), and GitHub pre-creates a `queued` check suite per installed app, so Cloudflare's is indistinguishable from the suites of apps that never post. That verification is recorded in the script header and in .claude/rules/tests.md rather than left to be re-derived. Sources and `pick()` are unchanged; a new spec pins the latter's hostname boundary, which was previously untested. Closes #132 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Three follow-ups from exercising the script against the live API: - `explain()` no longer restates the elapsed time that `emit()` already prefixes every line with (it read "after 18s … after 18s"). - the poll loop no longer sleeps past its own deadline, so the reported wait is the budget we set rather than the budget plus a trailing interval. - ci.yml gives `error` its own message: the discovery step itself failed, which is not "Cloudflare posted nothing". An unrecognised status still takes the loud branch. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Self-triage of the branch diff: - Source 3 accepts a check run whose NAME begins with "cloudflare pages" from ANY installed app, not only Cloudflare's, and that name is now quoted into the step summary. `report()` only defangs a LEADING `::`, so a newline in a crafted name could forge a summary line mid-string. `note()` flattens whitespace and caps at 120 chars before any API text is quoted. - `explain()`'s `detail` arm was unreachable — `fail()` passes the error message straight to `emit()` and never routes through it. Dropped, so the three timeout outcomes are the whole function. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Deploying sahajatlas with
|
| Latest commit: |
1fd0de8
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://cb474d03.sahajatlas.pages.dev |
| Branch Preview URL: | https://chore-preview-discovery-time.sahajatlas.pages.dev |
Review triage. The headline finding: a FAILED Cloudflare build still posts a check run, so counting any run as "a deploy exists" classified it `pending` and told the reader to RE-RUN a job that fails identically — training the exact habit #132 set out to break, and making the rate-limit advice on the `absent` branch unreachable in the one case it was written for. - add a `failed` status, taken from the run whose name matches CF_PROJECT's own slug (the `-design` sibling succeeding says nothing about the app's build, and its "(success)" was often the only evidence shown). It outranks every other signal, and ci.yml tells the reader to read the Cloudflare log. - bound every request with AbortSignal.timeout. undici defaults to 300s, so one hung socket could overrun the budget by 5 minutes and trip the job's `timeout-minutes` — which CANCELS the job, skipping the reporting step and leaving a red check with no message at all. Strictly worse than the timeout this ticket fixes. - validate + cap PREVIEW_TIMEOUT_MS. `600` read as seconds was a 0.6s deadline and a confident "the deploy did not happen"; document the unit. - write GITHUB_OUTPUT before the step summary, so an unwritable summary can't take the contract down with it. - narrow source 2's evidence to /cloudflare/ (bare `pages` matched `github-pages`) and require a Cloudflare creator on source 1. - lowercase pick()'s host — an uppercase CF_PROJECT matched nothing and turned every same-repo PR red; resolve the main-module guard through realpathSync. - correct three comments: pick() cites source 4 not 3, and the threat is a bot of some installed App rather than "anyone who can comment" (the Bot gate already blocks that); CF_PROJECT is a host match, not a substring. Records the one finding NOT fixed here: the URL harvest is unscoped by SHA and pick() accepts the branch alias, so the lane can verify the previous commit. Pre-existing, #122's territory, an explicit non-goal of this ticket, and tightening it blind would break discovery. Written down in tests.md. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Deploying sahajatlas-design with
|
| Latest commit: |
1fd0de8
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://169285da.sahajatlas-design.pages.dev |
| Branch Preview URL: | https://chore-preview-discovery-time.sahajatlas-design.pages.dev |
This PR's own CI disproved its headline finding. The discovery step logged `check run "Cloudflare Pages: sahajatlas" (in_progress)` on seven consecutive polls before the URL appeared — so Cloudflare DOES publish a building state, and the claim that it does not was wrong in the script header, in tests.md and in the PR body. The error was methodological, and worth recording because it is repeatable: Cloudflare sets `started_at` when it COMPLETES a check run, so every finished run reads `started_at == completed_at`. Sampling historical commits — what #124's evidence and my own 230-run sweep both did — cannot see the in-progress window and concludes it never existed. Only watching a live build shows it. No behaviour changes. The flat deadline stands on the duration data, which is unaffected, and now costs less than it seemed to: adaptive extension is genuinely available if the queue ever outgrows the cap. The correction also makes the `failed` guard's `status === 'completed'` test load-bearing rather than incidental — an in-progress run has a null conclusion. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Ardnived
added a commit
that referenced
this pull request
Aug 8, 2026
One conflict, in .claude/rules/tests.md: this branch and #101 each added a fourth jsdom spec to the same list, and both bumped its count to "Three". Kept both entries, corrected the count to Four, and fixed #101's "least optional of the three" to match. The ordinal in the report-form entry still reads correctly — with sanitize.test.ts second, it is the third cautionary tale. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
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.
Summary
The preview-discovery deadline was 6 minutes, which was not a margin over
Cloudflare's build time — it was that build time. Measured across 86
successful
Cloudflare Pages: sahajatlascheck runs on this repo (every commiton
mainplus every PR head from #58 to #128), push → check run posted:360s sat below the 95th percentile. #124 came in at 397s, and since #99 made
a missing preview hard-fail a same-repo PR, that showed up as a red check on a
healthy commit.
The tail is queueing, not build size — the slow samples cluster in windows
where several PRs deploy at once, which is exactly how this repo is worked:
An hour either side of that window, the same repo builds in 74–121s.
What changed
1. The deadline is 10 minutes, overridable via
PREVIEW_TIMEOUT_MS— ~1.3×the slowest sample ever observed, with headroom for a deeper queue. It fits
inside the Smoke job's existing
timeout-minutes: 15alongside install and thespecs, so that cap is untouched (with a comment on both sides saying the two move
together). The header comment records the measurement, not a restatement of the
constant.
2. "No preview" is no longer one outcome. A second output,
preview_status,names which path we took — and only one of them is a defect:
foundCF_PROJECTunreachablependingabsentfailederrorfailedis the row that has to exist, and it came out of code review: a failed Cloudflare build still posts a check run, so folding it into "a deploy exists" would tell the reader to re-run a job that fails identically — training the exact habit this ticket set out to break, and making the transient-rate-limit advice unreachable in the one case it was written for. Evidence is therefore read from the run matchingCF_PROJECT's own slug, not whichever run GitHub lists first: the-designsibling succeeding says nothing about the app's build.The #99 invariant is untouched: every empty-URL path still fails a same-repo
PR, so a green Smoke check still means the specs ran. Only the instruction
differs — and an unrecognised status takes the loud branch on purpose. Forked PRs
still warn and exit 0; the script still exits 0 on every path.
3. The step summary says how long it waited and what it last saw, so a slow
deploy is legible without opening the raw log.
Correction: there IS a "still building" signal — this PR's own CI disproved my finding
I first reported the opposite, and it was wrong. This PR's Smoke run logged
check run "Cloudflare Pages: sahajatlas" (in_progress)on seven consecutive polls before the URL appeared. Cloudflare does publish a building state.The error is worth recording because it is repeatable, and because it survived a full code review and a security review — only the live run caught it:
So the ticket's open design question resolves the other way: adaptive extension on a live signal is available. (The check suite is genuinely useless either way — GitHub pre-creates one per installed app on every push, so Cloudflare's is indistinguishable from the
vercel/railway/sentrysuites of apps that post nothing.)The flat deadline still stands, and the reason survives the correction: it is measured against the full duration distribution and clears the slowest build ever observed by ~1.3×, so extending adaptively would only change behaviour in cases a long-enough deadline already covers — at the price of a second timing rule. The door is now open if the queue ever outgrows the cap, and that is written down.
What the live state does buy is honest classification:
pendingis backed by our own project's run reportingin_progress, rather than only by the-designsibling or the bot comment. It also makes thefailedguard'sstatus === 'completed'test load-bearing rather than incidental — an in-progress run has a null conclusion and must never read as a failure.The duration measurements above are unaffected — they are
completed_atminus push time, which a retrospective query reports correctly.Non-goals honoured
pick()'s hostname-boundary matching is behaviourally unchanged — it gained anoptional
hostparameter defaulting to the module'sproject, purely so the newspec can exercise it. The four discovery sources (#122) and the bot/app author
restrictions on sources 3 and 4 are unchanged, and the new evidence gathering
never widens what reaches
pick().Verification
Exercised against the live GitHub API with
GITHUB_OUTPUT/GITHUB_STEP_SUMMARYpointed at temp files:
foundpreview_url=https://2bdf873b.sahajatlas.pages.dev, 3spendingpending, evidencecheck run "Cloudflare Pages: sahajatlas" (success)absentabsent, "no check run, no deployment, no bot comment"errorPR_HEAD_SHAunseterror, exit 0The ci.yml reporting step was extracted and run as a shell script for every
status plus an unknown one and a fork: the two instruction sets read differently,
all same-repo cases
exit 1, the fork warns and exits 0.scripts/get-cloudflare-preview-url.test.ts(new, 11 cases) pinspick()'slabel-boundary matching — previously untested, and the ticket's stated security
non-goal — alongside the classification and the two message registers.
pnpm lint && pnpm typecheck && pnpm test:rungreen.This PR is its own last acceptance criterion: the Smoke job should discover
the preview and run the specs on the first attempt.
Follow-up noticed, not fixed here
Source 4 harvests URLs from the bot comment unscoped by SHA, and that comment
also carries a branch preview URL that
pick()accepts — so in principle thelane could smoke-test a previous commit's build. Circumstantially it doesn't today
(on #124 attempt 1 discovery found nothing for 6 minutes, so the bot clears the URL
cells while deploying), but narrowing a discovery source is #122's territory and an
explicit non-goal here. Worth its own ticket.
Closes #132
🤖 Generated with Claude Code