Repository navigation
Conversation
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
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.
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.jsonschedulesGET /api/cron/expire-heartbeatsat 04:17 UTC. Vercel runs crons on the production deployment only.site/lib/heartbeat-retention.mjsdoes the work. On UTC day T it deletes everyheartbeats/<day>/folder dated T − 90 or earlier, oldest first. It skips anything outsideheartbeats/, any folder not named for a calendar date, and any bloblist()returns from outside the folder it asked for.@vercel/blobdoesn't retry a rate-limited call. The run deletes 50 blobs per call with a second between calls, waits out a rate limit (Blob'sRetry-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.Authorization: Bearer <CRON_SECRET>, compared as SHA-256 digests withtimingSafeEqual. WithoutCRON_SECRETit refuses everything. Outside production (canStorefrom Store waitlist and heartbeat writes only on production deployments #295) it deletes nothing.vercel.jsonschedules a cron andCRON_SECRETis unset:site/next.config.mjsrunsproductionBuildProblem(site/lib/deploy-checks.mjs) duringnext build. Vercel setsVERCEL_ENVat build time, so CI, a plainnext buildand preview builds skip the check; a localvercel build --prodruns it.deletedand 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.site/README.md,CLAUDE.mdand the heartbeat route's header describe the cron andCRON_SECRET.Before the deploy that ships this
CRON_SECRETto Production, for exampleopenssl rand -hex 32piped intovercel 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-projectsshould list it beforevercel deploy --prod.UPDATEDinsite/app/privacy/page.jsxto the ship date: the page promises a new date with every policy change."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 avercel.jsonchange.Tests
The Site Build check ran
bun run test(316 tests) andbun run buildon 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'ssite/tests/config.test.jscalledheaders()onnext.config.mjs's default export, which this PR makes a function of the build phase. The test now readsconfig(PHASE_PRODUCTION_SERVER), and the build-check test asserts a build gets the same object.bun run testlast 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 buildcan't run in this worktree, whosenode_modulesis a symlink Turbopack rejects.site/tests/heartbeat-retention.test.jsadds 14 tests andsite/tests/deploy-checks.test.jstwo:list()shape (folded mode, capped pages, cursors) and adel()that ignores missing URLs;waitlist/,heartbeatsx/,heartbeats/latest/,heartbeats/2026-02-30/and loose files;retryAfterof NaN (a header that doesn't start with a digit), capped waits, and no retry for other errors;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;CRON_SECRETagainst a rawBearerheader;@vercel/blobmocked, including thevercel.jsonschedule;RETENTION.heartbeatDays, and neither earlier wording that kept records indefinitely remains;CRON_SECRETfails, with the secret or without crons passes, any otherVERCEL_ENVpasses, andnext.config.mjsthrows 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 ignoresVERCEL_ENV, ignores whether crons exist, or never fires; anext.config.mjsthat never throws or checks in every phase. No test calls a deployment.🤖 Generated with Claude Code