Skip to content

Store waitlist and heartbeat writes only on production deployments - #295

Draft
MaxGhenis wants to merge 6 commits into
site/rebuild-2026-10from
site/preview-writes-off
Draft

MaxGhenis wants to merge 6 commits into
site/rebuild-2026-10from
site/preview-writes-off

Conversation

@MaxGhenis

@MaxGhenis MaxGhenis commented Nov 18, 2026 •

Copy link
Copy Markdown
Owner

Draft, stacked on #283. The base is site/rebuild-2026-10, merged in at #283's settled head e7f7498; retarget to main once #283 merges. An independent review goes on Subfleet before this leaves draft.

What this does

Preview deployments of openmessage.ai carried production's BLOB_READ_WRITE_TOKEN, so a POST to /api/waitlist or /api/heartbeat on any preview wrote into production's Blob store. A default vercel env pull also writes that token into .env.local, so a local next dev could do the same. With a change to one Vercel setting, new previews and a next dev on a default pull now store nothing. A .env.local made by a production pull still sets VERCEL_ENV=production, so the docs now say never to make one and to delete one.

  • canStore(env) in site/lib/public-writes.mjs lets the routes touch Blob only when the deployment has a token and VERCEL_ENV is production. Vercel sets VERCEL_ENV at build and at runtime, the project exposes system environment variables (autoExposeSystemEnvs: true), and production's env carries VERCEL_ENV="production". A preview gets preview, vercel dev gets development, and a default development pull sets none, so all three store nothing.
  • Outside production, POST /api/heartbeat answers {"ok":true,"persisted":false}, so the app doesn't retry, and POST /api/waitlist answers 503 with the "can't take sign-ups" message.
  • GET /api/heartbeat now also returns "persists", so a GET can check a deployment: production answers true, any other deployment false, and code without the check (production today, and Rebuild openmessage.ai around verified claims #283's previews) sends no persists key.
  • The README's production pull for scripts/read-waitlist.mjs now writes .env.waitlist.local, which next dev doesn't load and .gitignore covers. A test parses every vercel env pull in site/README.md, CLAUDE.md and the script's comment, and fails if one pulls production (-e, --environment or --environment=) into a file next dev loads: .env, .env.local, .env.development or .env.development.local. With no file named, the pull writes .env.local. A second test pins those parsing cases.
  • CLAUDE.md and site/README.md describe this and the GET check.

Vercel setting (changed 2026-11-18, outside git)

BLOB_READ_WRITE_TOKEN now targets Production and Development. A PATCH to the env record (editProjectEnv, body {"target":["production","development"]}) removed Preview and kept the value. vercel env rm BLOB_READ_WRITE_TOKEN preview would have deleted the whole record, production included: CLI 56.2.1 sends a DELETE for the record whatever environment it names. To undo, PATCH the record's target back to all three.

Env changes reach only new deployments. Of the 14 previews that existed when the setting changed, the three #283 built on 2026-11-18 before the change (17:14, 17:27 and 18:03 UTC) list BLOB_READ_WRITE_TOKEN among their env names and run its write routes without canStore. The 11 from March and April 2026 have no Blob token and no write routes. Vercel Authentication keeps the public off all of them. Until #283's three previews go, the docs keep "never POST to any preview".

Tests

The Site Build check ran bun run test (300 tests) and bun run build on the locked versions at e4a637f, which merges #283's head 2bc905a (the later merge of e7f7498 changes one blog sentence); the merge kept #283's JSON Content-Type check, address character rules and messages beside canStore. bun run test last ran locally at fb22303 (180 tests, before the merge), on an installed tree behind the lockfile (next 16.4.0 against 16.4.6, @vercel/blob 2.8.1 against 2.8.2). The new tests:

  • a canStore truth table;
  • a Blob stand-in that fails on any call: heartbeat and waitlist requests with VERCEL_ENV set to preview, development or nothing never reach it, with production's token set, and the same requests on production write;
  • a fast-check property: for any VERCEL_ENV other than production, unset included, and any mix of up to 12 heartbeat and waitlist requests, no request reaches Blob;
  • route tests through the Next.js handlers with @vercel/blob mocked, including the GET flag.

With the VERCEL_ENV check removed, or with an unset VERCEL_ENV allowed through, the six new guard tests fail. No test posts to a deployment.

After the production deploy

curl -s https://openmessage.ai/api/heartbeat should return {"ok":true,"schema_version":1,"persists":true}. A false means production stopped storing heartbeats and sign-ups.

🤖 Generated with Claude Code

MaxGhenis and others added 2 commits November 18, 2026 13:43
Preview deployments carry production's BLOB_READ_WRITE_TOKEN, so a POST to
any preview wrote into production's Blob store. canStore() now refuses every
write when VERCEL_ENV names an environment other than production, whatever
token the deployment has; outside Vercel (tests, plain next dev) the token
alone decides, as before.

GET /api/heartbeat reports "persists" for the deployment it reaches, so a
deploy can be checked with a GET instead of a POST.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…l out of next dev

A default `vercel env pull` writes production's Blob token into .env.local
with no VERCEL_ENV, so the earlier "unset means allow" branch let a local
`next dev` write into production. canStore() now needs VERCEL_ENV to be
"production"; the project exposes system env vars and production's env
carries it, and GET /api/heartbeat shows "persists": false if a deploy ever
loses it.

The README's production pull for read-waitlist now goes to
.env.waitlist.local, which next dev doesn't load and .gitignore covers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MaxGhenis and others added 4 commits November 18, 2026 14:38
… pulls into .env.local

Only the three previews built on 2026-11-18 before 18:45 UTC carry
production's Blob token; the docs dated the cutoff to the day. A
.env.local from a production pull sets VERCEL_ENV=production, and next dev
loads it, so the docs now say never to make one and to delete one, and a
test fails if any doc pulls production into a file next dev loads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The doc guard now parses each `vercel env pull` command: it finds
production pulls by -e, --environment or --environment=, takes the first
positional argument as the file (default .env.local), and checks its
basename against every file next dev loads; a self-test pins those forms.
The docs name all four files and how to spot a production pull, the
README explains a GET answer with no persists key, and two test titles no
longer say a plain next dev stores nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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