The ensureCloudM19Target and ensureCloudW17Target calls fire concurrently
at worker startup. During a deploy overlap (two workers live briefly), the
Postgres server hits max_connections and these one-shot queries get P2037.
The .catch() handler logged at warn with the raw error, which triggered
the reporter's logHooks and paged the error loop.
Follow the same pattern as develop/sports/archive workers: check
isPrismaTooManyConnections and log at info (below the reporter's warn
threshold) so the error loop stays quiet. The targets retry on the next
worker restart.
Also add tests for isPrismaTooManyConnections covering the P2037 code,
the bare message, the P2010/53300 raw-query variant, and negative cases.
Paperclip-Issue: BIT-33558
Two workers could pick the same due source from rebuildDue (the SELECT
has no locking), both call deleteMany + createMany in overlapping
transactions, and the second commit hit archive_team_sides_pkey with
P2002. Add pg_try_advisory_xact_lock(hashtext(sourceId)) at the start
of the transaction: the second worker skips instead of colliding.
Paperclip-Issue: BIT-33539
The RenderWorker tick only checked isPostgresAdminShutdown (57P01). Extended isPrismaTooManyConnections to also match the P2010/53300 raw-query variant, and added a branch in the tick catch that logs at info and lets the next tick retry.
Paperclip-Issue: BIT-33549
The rematch and takeOffFutureGames batch loops already stopped and
downgraded P1001/P2010 (unreachable) and 57P01 (admin shutdown) to info,
but P2037 (Too many database connections opened) fell through to log.warn
and paged the error loop for a transient pool-exhaustion blip.
Add isPrismaTooManyConnections checks to both catch blocks, mirroring the
BIT-33538 pattern in sports/service.ts: stop the batch and let the next
verifyAll retry once a slot frees.
Paperclip-Issue: BIT-33550
A pooled pg Client that had a connection error (socket closed, server
restart, network blip) is marked not-queryable by node-postgres before
Prisma's adapter-pg runs the next query on it. The message
"Client has encountered a connection error and is not queryable" has no
Prisma error code, so the existing isPrismaConnectionClosed (P1017) check
does not catch it. The rejection escapes to the SportsWorker fillRegister
and tick catch blocks, logs as warn, and pages the error loop.
- Add isPgClientNotQueryable to lib/pg.ts and downgrade the error to info
in fillRegister and tick (same pattern as BIT-32810, BIT-32083).
- Add the message to isTransientDatabaseError in reporter.ts so any other
code path that lets it propagate to a generic log.error is also
suppressed (same safety-net pattern as BIT-33537 for P2037).
- Add unit tests for the new helper and the reporter filter.
Paperclip-Issue: BIT-33527
Prisma P2037 ("Too many database connections opened: remaining connection
slots are reserved for roles with the SUPERUSER attribute") is pool
exhaustion under concurrent worker load — the next scheduled tick reclaims
a freed slot. syncEventSquads already downgrades P1001 (unreachable) and
P1017 (connection closed) to info; P2037 was missing, so it escaped to the
archive caller's log.warn and paged the error loop.
Add isPrismaTooManyConnections to lib/pg.ts and handle it in both catch
sites of syncEventSquads (the outer wrapper and the inner savePlayers
loop), following the same stop-and-retry-next-run pattern.
Paperclip-Issue: BIT-33538
ArchiveService.walk used a check-then-create pattern for cloudFolder,
cloudFile and cloudVideo. When two concurrent passes (overlapping scans
or a folder reachable through two paths) both query existing rows before
either creates, the second create hits P2002 on @@unique([sourceId,
fileId]) and aborts the whole scan, marking the source ERROR.
Wrap each create in try/catch for P2002 and fall back to an update on the
sourceId_fileId compound key, so a race no longer fails the scan.
Adds vitest cases proving the cloudFile fallback updates the compound key
and requeues, and that non-P2002 errors still rethrow.
Paperclip-Issue: BIT-33532
The realtime LISTEN/NOTIFY path uses pg.Client/pg.Pool directly (not
Prisma). When Postgres is completely down, Node's TCP layer throws
Error: connect ECONNREFUSED 127.0.0.1:5432 with code ECONNREFUSED.
The realtime listener already retries every 1 s (realtime.ts), but
each failed attempt was logged as 'realtime error' and reported to
errors.bitreport.pt because isTransientDatabaseError only filtered
Prisma codes (P1001/P1017) and SQLSTATE messages (57P01/57P03/53300),
not the raw Node TCP error.
Add ECONNREFUSED to the transient filter so a completely unreachable
Postgres does not trip the Error Loop with one-off incidents from
every realtime reconnect attempt.
Paperclip-Issue: BIT-33524
dbConnectionBudget reserved room for an API deploy overlap (apiReloadOverlap,
BIT-31550) but not for a worker deploy overlap. PM2 startOrReload on the
fork-mode photoreport-worker starts the new process before the old one finishes
its 25 s drain, so both Prisma pools and both broadcasters are open at once.
With defaults that is 2 * (47 + 1) + 26 = 122 > 100 max_connections, tipping
Postgres into error 53300 "sorry, too many clients already".
Add workerReloadOverlap (default 1) that divides the remaining budget by the
number of concurrent workers, so the total stays under max_connections even
during a reload. The worker's Prisma pool drops from 47 to 23 with defaults —
enough for the concurrent jobs the capacity planner sizes, and the headroom
and ad-hoc connection margin are preserved.
Paperclip-Issue: BIT-33530
Advisory-lock contention with 40-photo chunks from sendGalleryRest
expired the default 10 s transaction timeout (Prisma P2028). Pass an
explicit { timeout: 30_000 } so only the execution timeout is raised;
maxWait stays at the global 10 s default for pool acquisition.
Paperclip: BIT-33904
The /health endpoint ran db.$queryRaw`SELECT 1` with no error handling.
When PostgreSQL hits max_connections (error 53300), the query threw
PrismaClientKnownRequestError, the error handler logged it as 'unhandled
error', and the reporter sent it to errors.bitreport.pt — creating an
error loop of one-off incidents from every health check.
Two fixes:
- /health now catches DB failures and returns 503 { status: 'degraded' }
instead of throwing, so a connection-starved health check degrades
gracefully rather than generating an error report.
- isTransientDatabaseError now filters 53300 (pool exhaustion) alongside
the existing 57P01/57P03/P1001/P1017 filters, so even if a 53300 surfaces
through another code path it does not trip the error loop.
Paperclip-Issue: BIT-33548
Closed windows can leave while later frames are still being analysed. Picks that miss the galleries go to the rest destination: all of them until ten minutes before kick-off, then only home-team players.
Co-authored-by: Cursor <[email protected]>
One different frame goes to each export, a short burst rotates so every total can still be met, and a destination can share that same frame or take the camera original.
Race condition: between the desktop rendering a FAILED delivery row and the
user clicking "Repetir", the autopilot/queue worker can requeue, retry, or
retract the item. The retry endpoint's updateMany (where status=FAILED)
matched zero rows and threw notFound("failed_item_not_found") -> 404, and
the frontend promise had no .catch -> unhandledrejection -> error loop.
API: when the item no longer matches FAILED, fetch it; if it exists return
its current state (200, idempotent), only 404 when the row is gone.
Frontend: add a rejection handler that reloads the list so a stale FAILED
row refreshes instead of becoming an unhandled rejection.
Paperclip-BIT-33418
The recorded cut is refused so the player stays whole, and the scale is what still narrows the frame. The gallery tests get a longer budget now that each frame is actually planned.
Paperclip-Issue: BIT-33293
The suite keeps a 600 px JPEG so it does not time out, and the planner reads 6000×4000. That clears the delivery floor, so focus still ranks a burst and a learnt crop stays tighter. Those names were used before they existed.
Paperclip-Issue: BIT-33293
A buyer can still place the order. It stays unpaid until an admin records money collected out of band, and that admin is then responsible for delivering the work. No invoice goes out while invoicing is off.
A single figure with empty floor — someone walking, a suitcase beside them — is the subject. The crop keeps the body and what they carry. A conversation, a distant figure, and a frame that is already full stay as shot.
Fix the API build (exactOptionalPropertyTypes), read JPEG sidecars, apply marks from the indexed original instead of the stripped preview, and re-reconcile watched files so Veneto-style imports keep picks and soft crops.
Local FTP and hand import used to ignore Lightroom/Photo Mechanic marks on
the original; server ingest only saw stars. Arrival and the desktop watcher
now apply xmpDM:pick, Rating, Label and crs:Crop into the library.
A crop that only clears minLongEdge / the 3000 px floor is treated as a bad
read: leave the photograph as shot and down-rank that frame in the burst.
Learning from corrections already runs; the rules spell that out.
Soft/OOF stay out of the contest frame, lead room and edge clutter
steer the crop, wide-end zoom only levels, R1 roll feeds straighten
without chopping the subject, and bursts prefer a clear sharp face.
A tight crop was dropping a ball held out to the side and a second player, and a learnt cut could chop a body the frame had kept. Reportage stays open, open eyes win a sequence, and a Canon file that still has the camera level uses that roll. The library menu, sort, and event-day folder go out with the same change.
The 'Transaction already closed: A commit cannot be executed on a
transaction that was rolled back' error (P2028) fires when Prisma's
implicit transaction is rolled back mid-operation (connection blip,
deadlock) and a commit is then attempted on the closed transaction.
Like the P2028 'Unable to start a transaction' variant, it is transient
— the next scheduled tick reclaims a fresh connection and retries.
Add isPrismaTransactionClosed to pg.ts and check it before the broad
isPrismaTransactionTimeout (which matches all P2028 codes) in the
SportsWorker tick handler, so the closed-transaction variant logs at
info with an accurate message instead of warn-paging the error loop.
Paperclip-Issue: BIT-32810
The open() call was outside the try block, so a file deleted between the
scanner's walk and ingestFile's completeness check threw an uncaught ENOENT
instead of returning false. Move open() inside try and guard fh?.close().
Paperclip-Issue: BIT-32809
Paperclip-Cluster: 5beae514114c
The transactionOptions maxWait raise to 10s in db.ts (PR #207) reduced
frequency but did not eliminate the P2028 "Unable to start a transaction
in the given time" error — 1 recurrence in 13 days under brief pool
contention. The sports tick already swallows errors and reschedules, so
this is transient like 57P01/P1017/P1001 already downgraded in faces,
autopilot, develop and sports itself.
Add isPrismaTransactionTimeout to pg.ts (matches P2028 code or message)
and use it in SportsWorker.tick to log at info instead of warn, so the
error loop no longer pages on a single pool-contention blip.
Paperclip-Issue: BIT-32083
Cloudflare stops the datacentre from opening resultados.fpf.pt. The app API still returns the calendar and headshots, and a Liga squad is left as Liga published it.
A Taça fixture stored under the site season hid the Liga plantel. The sheet parser now keeps each side, the shirt number and the federation photo, and a later matchId updates the same fixture.
The cup is FPF (not Liga Portugal); without it the event picker only showed handball. Also fix kick-off parsing when day and time are stuck together in the HTML.