Skip to content

Wait for Aurora to resume from auto-pause instead of failing - #22

Merged
DHYEY166 merged 1 commit into
mainfrom
fix/aurora-resume-retry
Oct 3, 2026
Merged

DHYEY166 merged 1 commit into
mainfrom
fix/aurora-resume-retry

Conversation

@DHYEY166

@DHYEY166 DHYEY166 commented Oct 3, 2026

Copy link
Copy Markdown
Owner

Both EventBridge rules (cleanstack-reconciler-5min, cleanstack-purge-guests-hourly) now run on cron(0 */4 * * ? *). The cluster database-1 (Serverless v2, min 0 ACU, auto-pause after 300 s) never paused under the 5-minute reconciler, which cost about $45 a month. Now it pauses, and the first request after a pause fails while the cluster resumes (~15 s, 30 s+ after a pause longer than 24 h). This PR makes callers wait instead.

Web app (src/lib/db.ts, RDS Data API)

  • New src/lib/db-resume.ts withResumeRetry(). It wraps ExecuteStatement, BeginTransaction, CommitTransaction and RollbackTransaction.
  • It retries only DatabaseResumingException. The Data API reference describes this error as "a request was cancelled because the Aurora Serverless v2 DB instance was paused… wait a few seconds and try again", so the statement never ran and retrying writes is safe. It is a 400 client fault, so the SDK's own retry strategy doesn't retry it.
  • BadRequestException ("Communications link failure") is documented for Serverless v1 only and is not retried. Nor are StatementTimeoutException, DatabaseUnavailableException or SQL errors, which can happen after a statement was sent.
  • The backoff is 1, 2, 4, 8, 8, 8 s, with a 35 s budget, and logs one warn line per call that waits: database is resuming from auto-pause; retrying Data API call with op.
  • The pg test driver path (DB_DRIVER=pg) is unchanged.
  • maxDuration goes from 30 to 60 for /api/cron/reconcile-runs and from 60 to 120 for /api/cron/purge-guests. Both now almost always hit a paused cluster. The other routes with an explicit value already have 60–300 s.

Lambdas

None of the Lambdas use the Data API. profiler, executor and drift connect with psycopg2 and IAM auth, and ai-trigger only calls the app over HTTP. A direct connection to a paused cluster normally waits for the resume. AWS still recommends retrying failed connects, because a burst of connections during a resume can fail. Each of those three handlers gets the same small _connect_with_resume_retry(), used by get_db_conn():

  • It retries psycopg2.OperationalError raised by connect, where no SQL has run. Authentication failures are not retried.
  • The budget is 35 s, and it logs one line: [db] connect failed, database may be resuming from auto-pause.

Tests

  • src/lib/db-resume.test.ts covers retry then succeed, no retry for other errors, giving up after the budget, and the single log line.
  • src/lib/db.test.ts checks that every Data API command goes through the retry.
  • lambdas/tests/test_db_resume_retry.py runs the same cases against each of the three handlers.
  • Lint (0 errors), tsc, vitest (275), pytest (143 + 6 integration), TS integration (26) and e2e (12) pass locally.

Docs

docs/operations.md has a new "Aurora auto-pause" section and updated runbook rows: a stuck run can now take about 4 h 20 min to be failed, and the purge erases about 120 guests a day. docs/deployment.md, the README and docs/security-model.md have the new schedule and why.

After merge: redeploy the profiler, executor and drift Lambdas with the zip-swap. ai-trigger is unchanged.

Both EventBridge rules now run every 4 hours (cron(0 */4 * * ? *)) so the
Serverless v2 cluster can auto-pause; it never paused under the 5-minute
reconciler (about $45 a month). The first request after a pause has to wait
for the resume (~15s, 30s+ after a day).

- src/lib/db-resume.ts: retry Data API calls only on DatabaseResumingException
  (the request was cancelled before it ran, so writes are safe to retry), with
  1/2/4/8s backoff for up to 35s and one warn log line. Wraps ExecuteStatement,
  Begin/Commit/RollbackTransaction in src/lib/db.ts. The pg test driver is
  unchanged. Other errors are never retried.
- profiler, executor, drift Lambdas (psycopg2, not the Data API): retry a
  failed connect for up to 35s, except authentication failures.
- reconcile-runs maxDuration 30 -> 60, purge-guests 60 -> 120.
- Docs: new schedule, why, and the resume behaviour (operations.md).
@vercel

vercel Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
clean-stack Ready Ready Preview Oct 3, 2026 6:21pm UTC
cleanstack Ready Ready Preview, v0 Oct 3, 2026 6:21pm UTC

@DHYEY166
DHYEY166 merged commit 2bbb62b into main Oct 3, 2026
9 checks passed

This branch was successfully deployed

2 active deployments
Preview – clean-stack — 4af488e0 Deployed Oct 3, 2026 by vercel[bot]
Preview – cleanstack — 4af488e0 Deployed Oct 3, 2026 by vercel[bot]
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