fix(db): keep the free SQLite Cloud node from idling into a pause - #49
Merged
Conversation
Submitting a coupon fails with "The coupon database is temporarily unavailable" because the SQLite Cloud node is parked: every query, and every new connection, answers error 10010 until someone restarts it from the dashboard. The 503 mapping added in #45 reports that state correctly — but nothing stops it happening, and it cannot be recovered in-process because a parked node refuses new sockets too. Prevention is the automatable half. /api/health/db runs a SELECT 1, and a scheduled workflow calls it every 15 minutes, so the node never accumulates enough idle time to be parked. The same endpoint doubles as monitoring: an outage now fails a workflow run loudly instead of silently emptying pages that swallow their own DB errors. The schedule is best-effort by nature — GitHub delays scheduled runs under load and disables them after 60 days of repo inactivity — so it reduces the odds of a pause rather than eliminating them. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
ThreatCrush Security Scan17 finding(s) MEDIUM: 17
Snippets are redacted; ThreatCrush never prints matched credential material. |
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 broke
Adding a coupon on c0upons.com fails with "The coupon database is temporarily unavailable and should be back shortly."
That message is accurate, not a bug in the submit path. The SQLite Cloud node is parked, and every endpoint that touches the DB is down with it:
Ruled out along the way: the credentials are fine. The prod vault's
SQLITECLOUD_URLauthenticates against the node, and prod reaches SQLite Cloud far enough to receive error 10010 — a missing env var would surface as a plain 500 fromcreateClient()instead. So this is not an env/secret sync problem.What this PR does
A parked node refuses new sockets, so it can't be revived in-process — only a human restart from the dashboard clears it. The automatable half is making sure it never gets parked again:
GET /api/health/db— runsSELECT 1,force-dynamic+no-storeso it always reaches the node. ReusesdbErrorResponse, so a parked node answers 503 /database_pausedlike every other route..github/workflows/db-keepalive.yml— calls it every 15 minutes. The query is the activity that keeps the node awake; a failing run is also the outage alarm, which the pages don't give us today (app/page.tsxcatches DB errors and renders "No coupons").Honest limitation, also noted in the workflow: GitHub delays scheduled runs under load and disables them after 60 days of repo inactivity, so this lowers the odds of a pause rather than eliminating them. A paid node or an external uptime pinger would be the airtight version.
Verification
pnpm typecheckpasses.503,Retry-After: 60,{"code":"database_paused"}.200 {"ok":true}path can't be exercised until the node is resumed — flagging rather than claiming it.pnpm lintreports 12 errors, all pre-existing inprivacy/terms/about/offline/page.tsx; none in the new files. CI runs typecheck, not lint.Still needs a human
This PR does not bring the site back. Restarting the parked node at https://dashboard.sqlitecloud.io is an account action — no account-level SQLite Cloud credential exists in any vault, only the database key. Once it's restarted, submitting a coupon works again and this keep-alive stops it recurring.
🤖 Generated with Claude Code