Skip to content

fix(db): keep the free SQLite Cloud node from idling into a pause - #49

Merged
ralyodio merged 1 commit into
masterfrom
worktree-fix-db-keepalive
Aug 11, 2026
Merged

fix(db): keep the free SQLite Cloud node from idling into a pause#49
ralyodio merged 1 commit into
masterfrom
worktree-fix-db-keepalive

Conversation

@ralyodio

Copy link
Copy Markdown
Contributor

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:

$ curl -i https://c0upons.com/api/search?q=test
HTTP/2 503
{"error":"The coupon database is temporarily unavailable...","code":"database_paused"}

$ curl -X POST https://<node>.sqlite.cloud/v2/weblite/sql -H 'Authorization: Bearer <key>' ...
Your free node has been paused due to inactivity. To resume usage, please
restart your node from your dashboard: https://dashboard.sqlitecloud.io

Ruled out along the way: the credentials are fine. The prod vault's SQLITECLOUD_URL authenticates against the node, and prod reaches SQLite Cloud far enough to receive error 10010 — a missing env var would surface as a plain 500 from createClient() 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 — runs SELECT 1, force-dynamic + no-store so it always reaches the node. Reuses dbErrorResponse, so a parked node answers 503 / database_paused like 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.tsx catches 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 typecheck passes.
  • Ran the route locally against the real (still parked) prod node: returns 503, Retry-After: 60, {"code":"database_paused"}.
  • The 200 {"ok":true} path can't be exercised until the node is resumed — flagging rather than claiming it.
  • pnpm lint reports 12 errors, all pre-existing in privacy/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

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>
@github-actions

Copy link
Copy Markdown

ThreatCrush Security Scan

17 finding(s)

MEDIUM: 17

Severity Rule Location
MEDIUM sql-template-interpolation apps/web/app/api/bounties/[id]/claim/route.ts:18
MEDIUM sql-template-interpolation apps/web/app/api/bounties/[id]/claim/route.ts:34
MEDIUM sql-template-interpolation apps/web/app/api/bounties/[id]/claim/route.ts:43
MEDIUM sql-template-interpolation apps/web/app/api/bounties/route.ts:81
MEDIUM sql-template-interpolation apps/web/app/api/coupons/route.ts:68
MEDIUM sql-template-interpolation apps/web/app/api/coupons/route.ts:75
MEDIUM sql-template-interpolation apps/web/app/api/coupons/vote/route.ts:31
MEDIUM sql-template-interpolation apps/web/app/api/coupons/vote/route.ts:33
MEDIUM sql-template-interpolation apps/web/app/api/stores/[slug]/route.ts:9
MEDIUM sql-template-interpolation apps/web/app/api/webhooks/crawlproof/route.ts:83
MEDIUM sql-template-interpolation apps/web/app/api/webhooks/crawlproof/route.ts:90
MEDIUM js-open-redirect apps/web/app/bounties/new/page.tsx:57
MEDIUM js-unescaped-html-sink apps/web/app/layout.tsx:77
MEDIUM sql-template-interpolation apps/web/app/stores/[slug]/page.tsx:12
MEDIUM sh-predictable-temp-path apps/web/public/install.sh:37
MEDIUM sh-predictable-temp-path apps/web/public/install.sh:39
MEDIUM sql-template-interpolation apps/web/scripts/migrate.mjs:154

Snippets are redacted; ThreatCrush never prints matched credential material.

@ralyodio
ralyodio merged commit 37345b4 into master Aug 11, 2026
6 checks passed
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