Skip to content

chore(build): make preview discovery survive a slow cloudflare deploy #132

Closed

Description

@Ardnived

Summary

scripts/get-cloudflare-preview-url.mjs polls for the Cloudflare Pages preview URL with TIMEOUT_MS = 6 * 60_000 (line 50) and a 15-second interval (POLL_MS, line 51). On PR #124 that deadline was eight seconds short of a healthy deploy: Cloudflare posted its check run for 10cfc8f at 2026-08-08T00:18:35Z, and the discovery step — which started at 00:12:31Z — gave up at 00:18:43Z, one poll interval too early. Since #99 made a missing preview hard-fail a same-repo PR (.github/workflows/ci.yml:126-139), that produced a red Smoke check on a good commit; a manual re-run passed 90 seconds later (attempt 2, 00:20:08Z → 00:20:31Z). A timeout tuned this close to the observed build time means random red checks on good commits, and it trains people to re-run a failing gate rather than read it. This is about the deadline, not the source — #122 already added the check-run source (discover() source 3, lines 133-150) that makes discovery work at all on this repo.

Current behavior

Measured on PR #124, run 31229421304, attempt 1 (the failing one):

Event Time (UTC)
Smoke job starts 00:12:17Z
"Discover Cloudflare Pages preview URL" starts 00:12:31Z
Cloudflare Pages: sahajatlas-design check run posted 00:18:02Z
Cloudflare Pages: sahajatlas check run posted 00:18:35Z
Discovery gives up, emits an empty preview_url 00:18:43Z
"Report a missing preview" fails the job 00:18:43Z
Attempt 2 (manual re-run) discovers it and passes 00:20:08Z → 00:20:31Z

So the deploy took 6m04s from the discovery step's start to the check run appearing, against a 6m00s budget. The margin is not a margin.

Two behaviours compound it:

  • Every unhappy path collapses into one output. fail() (lines 56-60) and the timeout (line 199) both emit('') and exit 0, by design — discovery problems are the workflow's call, not the script's. But that means "Cloudflare never posted anything", "we timed out before it posted" and "it posted but never became reachable" are indistinguishable downstream, and ci.yml gives all three the same red error. Only the first is a real failure.
  • The error text argues against itself. The ::error:: message (ci.yml:138) tells the reader to check which stage failed and mentions the transient-rate-limit case, but the script has already discarded the distinction it is asking about.

Context: same-repo PRs only. Forked PRs have no preview by design and stay a graceful, annotated skip (ci.yml:141) — that must not change.

Proposed changes

  • Raise TIMEOUT_MS, and justify the number against a measurement rather than a feeling. 6 minutes is roughly the observed Cloudflare build time on this repo, not a margin over it. Gather a few build durations from recent PRs and set the deadline well clear of the slowest, or make it configurable via an environment variable with the default documented alongside the evidence. A longer wait costs idle runner minutes and nothing else; the job already sleeps for most of its life.
  • Distinguish "not finished yet" from "never posted", and let the workflow treat them differently. Emit a second GitHub Actions output beside preview_url — a status the script can honestly report (found / pending / absent / unreachable). Then:
    • absent — no Cloudflare signal of any kind for the SHA. A real failure on a same-repo PR: the deploy did not happen. Keep the hard fail.
    • pending / unreachable — positive evidence a deploy exists but we stopped waiting. Still red (a green Smoke that ran nothing is exactly the hole chore(build): add audit gate, size budget, and embed smoke tests #99 closed), but with a message that says re-run this, not investigate this, and that names how long it waited and what it last saw.
  • Consider waiting adaptively on positive evidence — once any Cloudflare signal is seen for the SHA, extend the deadline up to a hard cap rather than giving up on a fixed clock. Verify before building on it: on feat(seo): prevent direct indexing of the standalone build #124 the app's check run arrived with started_at == completed_at == 00:18:35Z, i.e. Cloudflare posted it already completed, so there may be no in-progress check run to observe during a build. The design-project check landed 33s earlier and is not a valid substitute (pick() correctly refuses its host). Confirm what Cloudflare's app actually posts mid-build on a live PR before assuming an early signal exists.
  • Say how long it waited. The step summary should carry the elapsed time and the last observed state, so the next person to hit this can tell a slow deploy from a dead one without opening the raw log.

Non-goals: the discovery sources (#122's work), and the pick() hostname allowlist (lines 95-107), which is a security property — pages.dev subdomains are first-come-first-served, and a substring match would let anyone who can comment aim the smoke lane at a host they control. Both stay exactly as they are.

Acceptance criteria

  • TIMEOUT_MS is raised to a value justified against measured Cloudflare build durations on this repo, and the comment at scripts/get-cloudflare-preview-url.mjs:50 records the measurement rather than restating the constant.
  • The script distinguishes at least "no Cloudflare signal for this SHA" from "a signal was seen but no usable URL within the deadline", and surfaces that distinction to the workflow as a separate output.
  • .github/workflows/ci.yml gives the two cases visibly different messages, and a same-repo PR with no Cloudflare signal still hard-fails — the chore(build): add audit gate, size budget, and embed smoke tests #99 invariant holds: a green Smoke check can never mean "nothing ran".
  • The script still exits 0 on every path, and a forked PR still skips with a warning rather than a failure.
  • pick()'s hostname-boundary matching and the bot/app author restrictions on sources 3 and 4 are unchanged.
  • The step summary reports elapsed wait time and the last observed state.
  • Any claim about what Cloudflare posts during a build is verified against a live PR run, not inferred — the feat(seo): prevent direct indexing of the standalone build #124 evidence (check run posted already-completed) is the counter-example to check against.
  • Verified on a real PR: the Smoke job discovers the preview and runs the specs against it on the first attempt.
  • pnpm lint && pnpm typecheck && pnpm test:run pass.
  • Write an implementation report to .claude/reports/<issue-number>-<short-slug>.md — in the MAIN checkout at /Users/devindra/Documents/Projects/SahajAtlasWeb even when implementing from a worktree (the folder is gitignored) — including the build-duration measurements behind the new timeout.

Files affected

  • scripts/get-cloudflare-preview-url.mjs — the timeout, the loop, the emitted outputs, the header comment
  • .github/workflows/ci.yml — the Smoke job's "Discover…" and "Report a missing preview" steps (lines 97-141)
  • .claude/rules/tests.md / CLAUDE.md — only if the smoke lane's documented behaviour changes

Parallel implementation: this ticket OWNS the two files above. Sibling tickets may run concurrently — avoid edits outside owned files except strictly additive ones. Note that ci.yml is a shared surface: touch only the Smoke job's discovery and reporting steps, not the lint/typecheck/build or audit jobs.

References

Activity

  1. added 2 commits that reference this issue on Aug 8, 2026
    88e2ceb
    8039e1f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Hold Until

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions