Skip to content

Delete install reports after 90 days with a daily cron - #296

Draft
MaxGhenis wants to merge 9 commits into
site/preview-writes-offfrom
site/heartbeat-retention
Draft

MaxGhenis wants to merge 9 commits into
site/preview-writes-offfrom
site/heartbeat-retention

Conversation

@MaxGhenis

@MaxGhenis MaxGhenis commented Nov 18, 2026 •

Copy link
Copy Markdown
Owner

Draft: waits on Max's call on the retention period, and on #295. The base is site/preview-writes-off (#295); retarget to main once #295 and #283 merge. Merge nothing here before that call. If the period changes, change RETENTION.heartbeatDays and the /privacy sentence together (a test fails until they match). If records stay indefinitely, close this PR.

What changes

Install reports (heartbeats/<day>/<install_id>.json) never expired, and /privacy said "Nothing deletes them automatically." A daily Vercel cron now deletes each record once it is 90 days old.

  • site/vercel.json schedules GET /api/cron/expire-heartbeats at 04:17 UTC. Vercel runs crons on the production deployment only.
  • site/lib/heartbeat-retention.mjs does the work. On UTC day T it deletes every heartbeats/<day>/ folder dated T − 90 or earlier, oldest first. It skips anything outside heartbeats/, any folder not named for a calendar date, and any blob list() returns from outside the folder it asked for.
  • Blob counts each deleted blob toward the Pro limit of 75 advanced operations a second, which the site's writes share, and @vercel/blob doesn't retry a rate-limited call. The run deletes 50 blobs per call with a second between calls, waits out a rate limit (Blob's Retry-After, or 1 s when it is missing or doesn't start with a digit, at most 10 s, up to 3 retries), and stops at 5,000 records. The heartbeat route stores at most 1,000 a day, so one run clears a day's folder, and later runs shrink any backlog by at least 4,000 a day. The route allows 300 s: a full run spends about 100 s in pauses, more if Blob rate-limits it, and a run cut off at 300 s leaves the rest for the next day.
  • The route answers 401 unless the request carries Authorization: Bearer <CRON_SECRET>, compared as SHA-256 digests with timingSafeEqual. Without CRON_SECRET it refuses everything. Outside production (canStore from Store waitlist and heartbeat writes only on production deployments #295) it deletes nothing.
  • A production build stops when vercel.json schedules a cron and CRON_SECRET is unset: site/next.config.mjs runs productionBuildProblem (site/lib/deploy-checks.mjs) during next build. Vercel sets VERCEL_ENV at build time, so CI, a plain next build and preview builds skip the check; a local vercel build --prod runs it.
  • Vercel doesn't retry a failed cron run and can deliver one twice. Two runs at once delete each record once, but both count it in deleted and together delete at twice the paced rate, which the rate-limit backoff absorbs. A missed run's records go a day late, in the next one.
  • /privacy now says "A daily job deletes each record once it is 90 days old." in place of Rebuild openmessage.ai around verified claims #283's "The site keeps them until I delete them." site/README.md, CLAUDE.md and the heartbeat route's header describe the cron and CRON_SECRET.

Before the deploy that ships this

  1. Add CRON_SECRET to Production, for example openssl rand -hex 32 piped into vercel env add CRON_SECRET production --scope max-ghenis-projects. Without it the production build fails, which keeps a cron that can't run, and a /privacy page that says records expire, from shipping. vercel env ls production --scope max-ghenis-projects should list it before vercel deploy --prod.
  2. If this ships on a later day than the policy text Rebuild openmessage.ai around verified claims #283 dated, set UPDATED in site/app/privacy/page.jsx to the ship date: the page promises a new date with every policy change.
  3. After the deploy, Schedules → Cron Jobs lists the job. The first run's log should show a 200 with "complete":true; "deleted" stays 0 until the oldest records reach 90 days.

Cost

Vercel charges no separate cron fee on Pro; a run bills as a function invocation plus its CPU and memory time, and most runs delete nothing and end quickly. Deletes are free. Each run spends Blob list operations ($5 per million in iad1): one folded list of heartbeats/, plus one list per 1,000 records in each expired folder. That is about 60 a month, a fraction of a cent. Vercel labels Cron Jobs a legacy feature it will migrate to Schedules, with no date given; the migration is a vercel.json change.

Tests

The Site Build check ran bun run test (316 tests) and bun run build on the locked versions at 59ade87, after merging #295 with #283's head 2bc905a (the later merge of #283's e7f7498 changes one blog sentence). That merge left one semantic conflict: #283's site/tests/config.test.js called headers() on next.config.mjs's default export, which this PR makes a function of the build phase. The test now reads config(PHASE_PRODUCTION_SERVER), and the build-check test asserts a build gets the same object. bun run test last ran locally at a8d5c6c (196 tests, before the merges), on an installed tree behind the lockfile (next 16.4.0 against 16.4.6, @vercel/blob 2.8.1 against 2.8.2); next build can't run in this worktree, whose node_modules is a symlink Turbopack rejects. site/tests/heartbeat-retention.test.js adds 14 tests and site/tests/deploy-checks.test.js two:

  • an in-memory Blob with the SDK's list() shape (folded mode, capped pages, cursors) and a del() that ignores missing URLs;
  • cutoff dates across month, year and leap-day boundaries;
  • deletes only day folders on or before the cutoff, and keeps waitlist/, heartbeatsx/, heartbeats/latest/, heartbeats/2026-02-30/ and loose files;
  • a per-run budget that stops mid-folder and across folders, a page longer than the budget, and a budget that ends exactly on the last folder;
  • batches of at most 50 with a pause before every call but the first; rate-limit backoff, a 1 s wait for a retryAfter of NaN (a header that doesn't start with a digit), capped waits, and no retry for other errors;
  • folder listing across cursor pages;
  • a fast-check property: for any mix of dated, nested, undated, impossible-date and loose files inside and outside heartbeats/, a retention of 1 to 365 days and list pages of 1 to 5 entries, a run removes exactly the expired records, and a second run removes nothing;
  • the bearer check, including an empty CRON_SECRET against a raw Bearer header;
  • the handler (401, non-production, 502 on a storage error) and the Next.js route with @vercel/blob mocked, including the vercel.json schedule;
  • the /privacy sentence names RETENTION.heartbeatDays, and neither earlier wording that kept records indefinitely remains;
  • the build check: production with a cron and no CRON_SECRET fails, with the secret or without crons passes, any other VERCEL_ENV passes, and next.config.mjs throws only in the build phase.

Each of these faults fails at least one test: no pause between calls; no retry; retrying any error; uncapped waits; an exclusive cutoff; no calendar-date check; no production check; accepting an empty secret; deleting past the run's budget; deleting blobs outside the folder; a 30-day constant with the 90-day sentence; batches of 1,000; a zero wait for a NaN retryAfter; a build check that ignores VERCEL_ENV, ignores whether crons exist, or never fires; a next.config.mjs that never throws or checks in every phase. No test calls a deployment.

🤖 Generated with Claude Code

MaxGhenis and others added 9 commits November 18, 2026 14:03
A Vercel cron calls /api/cron/expire-heartbeats each day at 04:17 UTC. On
UTC day T it deletes every heartbeats/<day>/ folder dated T - 90 or earlier,
oldest first, up to 20,000 records a run, and touches nothing else. It runs
only with Vercel's CRON_SECRET bearer header and only on production. The
privacy page now states the period, and a test ties that sentence to
RETENTION.heartbeatDays.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Blob counts each deleted blob toward the Pro limit of 75 advanced
operations a second, and @vercel/blob doesn't retry a rate-limited call,
so one 1,000-URL del() could fail every run. The cleanup now deletes 50
per call with a second between calls, waits out a rate limit (Retry-After,
at most 10 s, 3 tries), and stops at 5,000 records a run. The route allows
300 s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Without CRON_SECRET the cleanup route refuses every run, so records would
never expire while /privacy says they do. next.config.mjs now runs
productionBuildProblem during next build and fails a production build
(VERCEL_ENV=production) whose vercel.json schedules a cron while
CRON_SECRET is unset; CI, local and preview builds skip the check.

Also: a non-integer Retry-After (NaN) now waits a second instead of none;
the property test covers nested paths and impossible dates; comments and
the README no longer overstate recovery or run time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Two runs at once delete each record once but both count it and together
double the delete rate; deleted counts records sent to del(). The SDK's
retryAfter is parseInt of the header, NaN only when it doesn't start with
a digit. A local vercel build --prod runs the CRON_SECRET check too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#283 added tests that call headers() on the default export, which this
branch made a function of the build phase. config.test.js now reads the
server phase's config, deploy-checks.test.js asserts a build gets that same
object, and the privacy test also rejects #283's "keeps them until I delete
them" wording.

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