fix(archive): stop rematch and downgrade P1001 unreachable-database errors to info (BIT-32462) #272

Merged
spark merged 1 commits from fix/BIT-32462-archive-pg-unreachable into main 2026-11-18 20:31:57 +00:00
Owner

What

A Postgres restart or a downed route makes the database unreachable (Prisma P1001: Can't reach database server at <host>:<port>) mid-rematch, inside eventForName's findUnique (apps/api/src/archive/service.ts:857). The per-folder catch logged it at warn, which paged the error loop for a transient blip — and every remaining folder in the batch would fail the same way, producing redundant failing queries.

Fix

  • Add isPrismaServerUnreachable(err) to lib/pg.ts (detects P1001 / Can't reach database server), next to isPrismaConnectionClosed / isPostgresAdminShutdown from BIT-32448/32460.
  • In ArchiveService.rematch, when a folder fails with P1001, log at info and break out of the folder loop — the next verifyAll (on start, every six hours) retries once the server is back.
  • Reuses the same downgrade-to-info pattern as the faces/develop/autopilot workers (BIT-32448/32449/32450).

Tests

  • src/lib/pg.test.ts: isPrismaServerUnreachable matches P1001, rejects P1017/57P01/other.
  • src/archive/service.test.ts: rematch logs at info and stops the batch on P1001 (second folder never queried); still warns on a real per-folder error.
  • Full unit suite: 43 files, 149 passed, 3 skipped. pnpm typecheck clean.

Paperclip-Issue: BIT-32462

## What A Postgres restart or a downed route makes the database unreachable (Prisma `P1001`: `Can't reach database server at <host>:<port>`) mid-`rematch`, inside `eventForName`'s `findUnique` (`apps/api/src/archive/service.ts:857`). The per-folder catch logged it at `warn`, which paged the error loop for a transient blip — and every remaining folder in the batch would fail the same way, producing redundant failing queries. ## Fix - Add `isPrismaServerUnreachable(err)` to `lib/pg.ts` (detects `P1001` / `Can't reach database server`), next to `isPrismaConnectionClosed` / `isPostgresAdminShutdown` from BIT-32448/32460. - In `ArchiveService.rematch`, when a folder fails with P1001, log at `info` and `break` out of the folder loop — the next `verifyAll` (on start, every six hours) retries once the server is back. - Reuses the same downgrade-to-info pattern as the faces/develop/autopilot workers (BIT-32448/32449/32450). ## Tests - `src/lib/pg.test.ts`: `isPrismaServerUnreachable` matches P1001, rejects P1017/57P01/other. - `src/archive/service.test.ts`: `rematch` logs at info and stops the batch on P1001 (second folder never queried); still warns on a real per-folder error. - Full unit suite: 43 files, 149 passed, 3 skipped. `pnpm typecheck` clean. Paperclip-Issue: BIT-32462
spark added 1 commit 2026-11-18 20:22:28 +00:00
fix(archive): stop rematch and downgrade P1001 unreachable-database errors to info (BIT-32462)
ci / rust (pull_request) Successful in 4m29s
ci / typescript (pull_request) Successful in 9m14s
0be8d27ffe
A Postgres restart or a downed route makes the database unreachable
(Prisma P1001: "Can't reach database server at <host>:<port>") mid-rematch,
inside eventForName's findUnique. The per-folder catch logged it at warn,
which paged the error loop for a transient blip — and every remaining folder
in the batch would fail the same way, producing redundant failing queries.

Detect P1001 with a shared isPrismaServerUnreachable helper (lib/pg.js, next
to isPrismaConnectionClosed/isPostgresAdminShutdown from BIT-32448/32460),
log it at info and break out of the folder loop. The next verifyAll (on
start, every six hours) retries once the server is back. Reuses the same
downgrade-to-info pattern as the faces/develop/autopilot workers (BIT-32448/
32449/32450).

Paperclip-Issue: BIT-32462
spark merged commit f43be9f978 into main 2026-11-18 20:31:57 +00:00
Sign in to join this conversation.