fix(autopilot): downgrade 57P01 admin-shutdown poll errors to info (BIT-32448) #268

Merged
spark merged 1 commits from fix/BIT-32448-autopilot-pg-admin-shutdown into main 2026-11-18 17:52:28 +00:00
Owner

Fix

A Postgres restart or pg_terminate_backend (error 57P01) kills the autopilot worker's pooled client mid-$queryRaw in AutopilotWorker → decideBursts. Prisma surfaces it as P2010 wrapping the server message, and the tick catch logged it at warn as autopilot: poll failed — which fed the error loop on every tick during a DB restart.

The next tick re-claims a fresh client, so this is a transient blip: detect 57P01 / terminating connection due to administrator command and log at info (autopilot: poll skipped, db connection was reset), keeping the warn path for real poll failures.

Sibling of #267 (BIT-32447), which already guards the realtime pg.Pool idle-client error event.

Evidence

  • Issue: BIT-32448 (ERRCLUSTER 5019795ae39d)
  • Location: apps/api/src/autopilot/service.ts:210 (decideBursts raw query), caught in AutopilotWorker.start tick.

Tests

  • New apps/api/src/autopilot/service.test.ts: isPostgresAdminShutdown matches the Prisma-wrapped 57P01 message and rejects unrelated errors; AutopilotWorker logs 57P01 at info (not warn) and keeps looping, and still warns on a real poll failure.
  • pnpm --filter @photoreport/api typecheck ✅
  • vitest run src/autopilot → 5 files, 14 tests ✅
## Fix A Postgres restart or `pg_terminate_backend` (error **57P01**) kills the autopilot worker's pooled client mid-`$queryRaw` in `AutopilotWorker` → `decideBursts`. Prisma surfaces it as `P2010` wrapping the server message, and the tick catch logged it at `warn` as `autopilot: poll failed` — which fed the error loop on every tick during a DB restart. The next tick re-claims a fresh client, so this is a transient blip: detect `57P01` / `terminating connection due to administrator command` and log at `info` (`autopilot: poll skipped, db connection was reset`), keeping the `warn` path for real poll failures. Sibling of #267 (BIT-32447), which already guards the realtime `pg.Pool` idle-client `error` event. ## Evidence - Issue: BIT-32448 (ERRCLUSTER `5019795ae39d`) - Location: `apps/api/src/autopilot/service.ts:210` (`decideBursts` raw query), caught in `AutopilotWorker.start` tick. ## Tests - New `apps/api/src/autopilot/service.test.ts`: `isPostgresAdminShutdown` matches the Prisma-wrapped 57P01 message and rejects unrelated errors; `AutopilotWorker` logs 57P01 at `info` (not `warn`) and keeps looping, and still `warn`s on a real poll failure. - `pnpm --filter @photoreport/api typecheck` ✅ - `vitest run src/autopilot` → 5 files, 14 tests ✅
spark added 1 commit 2026-11-18 17:42:34 +00:00
fix(autopilot): downgrade 57P01 admin-shutdown poll errors to info so they stop paging the error loop (BIT-32448)
ci / rust (pull_request) Successful in 3m49s
ci / typescript (pull_request) Successful in 9m21s
50699fa675
A Postgres restart or `pg_terminate_backend` (error 57P01) takes the autopilot's pooled client mid-`$queryRaw`. Prisma surfaces it as P2010 wrapping the server message, and the catch in `AutopilotWorker.start` logged it at warn as "autopilot: poll failed" — which fed the error loop on every tick during a DB restart. The next tick re-claims a fresh client, so this is a transient blip: detect 57P01 and log at info instead, keeping the warn path for real poll failures.

Paperclip-Issue: BIT-32448
Paperclip-Cluster: 5019795ae39d
spark merged commit e242c8e45f into main 2026-11-18 17:52:28 +00:00
Sign in to join this conversation.