Skip to content

Sweep stale Hosted previews at deploy instead of at close - #1346

Merged
nedtwigg merged 3 commits into
mainfrom
hosted-preview-sweep
Oct 21, 2026
Merged

nedtwigg merged 3 commits into
mainfrom
hosted-preview-sweep

Conversation

@nedtwigg

@nedtwigg nedtwigg commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

The close-time cleanup job ran in the approval-gated hosted-preview environment, so every run waited for an approval nobody gave, until the mass cancel on 2026-10-21. Ten merged PRs' previews leaked (#748, #812, #815, #836, #865, #872, #887, #888, #1044, #1104).

The environment has to stay gated, because a pull_request job runs the PR's own workflow file. So cleanup now runs inside the deploy, whose approval already covers the preview credentials:

  • preview.mjs sweep lists the preview account's Workers and Hyperdrives and the preview project's Neon branches. It finds each *-pr-N, asks GitHub for that PR's state, and runs cleanup for every PR other than the deploy's own that is closed or no longer labeled hosted-preview.
  • The deploy job runs the sweep before it creates its Neon branch, and gains pull-requests: read for the lookup.
  • The cleanup job and the unlabeled and closed triggers are gone. A stale preview now lives until the next approved preview deploy.
  • Spec, README, rationale, and S69 updated; hosted.md's word budget ratcheted 4550 → 4600.

Labeling this PR hosted-preview and approving its deploy removed the leaked previews (#812 never had one; it shares #815's branch).

🤖 Generated with Claude Code

nedtwigg and others added 2 commits October 21, 2026 13:02
The close-time cleanup job ran in the approval-gated hosted-preview
environment, so it waited for an approval nobody gave and never ran; ten
merged PRs' previews leaked. Each preview deploy now first deletes the
Workers, Hyperdrive, and Neon branch of every other PR that is closed or
no longer labeled hosted-preview, and nothing runs at close.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Deploying mouseterm with  Cloudflare Pages  Cloudflare Pages

Latest commit: e0adbdf
Status: ✅  Deploy successful!
Preview URL: https://7b4a6742.mouseterm.pages.dev
Branch Preview URL: https://hosted-preview-sweep.mouseterm.pages.dev

View logs

@nedtwigg nedtwigg added the hosted-preview Deploy a Hosted PR preview (needs environment approval) label Oct 21, 2026

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

PRODUCTION_IDS / refuseProduction guards against a case nothing reachable produces, and it adds a spec rule (hosted.md -> "PR previews": Never let preview cleanup target production's Cloudflare account or Neon project) that must now be kept in sync by hand. Details inline.

Comment thread hosted/scripts/preview.mjs Outdated
@nedtwigg
nedtwigg marked this pull request as ready for review October 21, 2026 20:28
@nedtwigg
nedtwigg merged commit 1c4bb00 into main Oct 21, 2026
15 of 16 checks passed
@nedtwigg
nedtwigg deleted the hosted-preview-sweep branch October 21, 2026 20:41

This branch is waiting to be deployed

1 waiting deployment
hosted-preview — e0adbdf7 Waiting Oct 21, 2026 by nedtwigg via deploy #1914
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hosted-preview Deploy a Hosted PR preview (needs environment approval)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants