fix(sports): give implicit upserts enough time to grab a connection (BIT-32083) #207

Merged
spark merged 2 commits from fix/BIT-32083-upsert-maxwait into main 2026-11-07 00:31:34 +00:00
Owner

Fixes the "Transaction API error: Unable to start a transaction in the given time" Prisma error from SportsService.refreshFpa (sportsCompetitionTeam.upsert() at service.ts:517, BIT-32083).

Same error family as BIT-31703/BIT-32057 (client-side maxWait pool-acquire timeout, default 2000ms) but this time hitting a plain upsert() call rather than an explicit $transaction() — Prisma opens an implicit transaction around a single upsert and only gives it the default maxWait. Since there is no per-call options object to patch on upsert(), the fix sets a client-wide transactionOptions default (maxWait/timeout: 10s) in createDb. Explicit $transaction(fn, { maxWait, timeout }) call sites (rebuildDirectory, assignGalleries, events.ts) already pass their own options, which continue to override this default.

Tested: pnpm typecheck (pre-existing unrelated errors only, confirmed present on main before this change), vitest run test/sports.test.ts and test/capacity.test.ts against the local Postgres test container (two pre-existing sports.test.ts failures confirmed present on main before this change, unrelated to db.ts).

Fixes the "Transaction API error: Unable to start a transaction in the given time" Prisma error from `SportsService.refreshFpa` (`sportsCompetitionTeam.upsert()` at service.ts:517, BIT-32083). Same error family as BIT-31703/BIT-32057 (client-side `maxWait` pool-acquire timeout, default 2000ms) but this time hitting a plain `upsert()` call rather than an explicit `$transaction()` — Prisma opens an implicit transaction around a single upsert and only gives it the default `maxWait`. Since there is no per-call options object to patch on `upsert()`, the fix sets a client-wide `transactionOptions` default (`maxWait`/`timeout`: 10s) in `createDb`. Explicit `$transaction(fn, { maxWait, timeout })` call sites (`rebuildDirectory`, `assignGalleries`, `events.ts`) already pass their own options, which continue to override this default. Tested: `pnpm typecheck` (pre-existing unrelated errors only, confirmed present on main before this change), `vitest run test/sports.test.ts` and `test/capacity.test.ts` against the local Postgres test container (two pre-existing sports.test.ts failures confirmed present on main before this change, unrelated to db.ts).
spark added 1 commit 2026-11-06 21:15:20 +00:00
fix(sports): give implicit upserts enough time to grab a connection
ci / typescript (pull_request) Failing after 13m43s
ci / rust (pull_request) Successful in 10m56s
a424b1ed92
SportsService.refreshFpa (and other plain upsert() calls across the
service) opened under brief pool contention and hit "Transaction API
error: Unable to start a transaction in the given time" — Prisma opens
an implicit transaction around a single upsert() and only gives it its
default maxWait (2000ms) to grab a pooled connection, same failure mode
already fixed for explicit $transaction() calls in rebuildDirectory and
library/events.ts.

Set a client-wide transactionOptions default in createDb so any call
that does not set its own maxWait/timeout gets 10s instead of the
Prisma default; call sites with their own long-running $transaction
options keep overriding it.
Author
Owner

PRE-EXISTING FAILURE
Check: ci / typescript (pull_request)
Reason: 3 failing assertions in test/autopilot.test.ts and 1 in test/faces.test.ts — unrelated to this PR, which only touches apps/api/src/db.ts (transactionOptions default). These already fail identically on main HEAD before this PR branched.
Tracking issue: BIT-32084
Evidence: main@c628dcf28841e0506feb62d5510a29f7054392e4 fails the same check — https://git.bitreport.pt/BitReport.pt/photoreport/actions/runs/25968/jobs/60569 (push-triggered ci/typescript, failed before this PR's own run 25971/60575)
Verified by: jos-alves
Verified at: 2026-11-06
Reverify by: 2026-11-13

ci / rust (pull_request) is green (10m56s). Needs repo admin/CTO/QA sign-off per CICD_POLICY_EXCEPTIONS_RUNBOOK.md §5 before merge under this carve-out — not self-attested. Flagged to @peter-spark via BIT-32084.

PRE-EXISTING FAILURE Check: ci / typescript (pull_request) Reason: 3 failing assertions in test/autopilot.test.ts and 1 in test/faces.test.ts — unrelated to this PR, which only touches apps/api/src/db.ts (transactionOptions default). These already fail identically on main HEAD before this PR branched. Tracking issue: BIT-32084 Evidence: main@c628dcf28841e0506feb62d5510a29f7054392e4 fails the same check — https://git.bitreport.pt/BitReport.pt/photoreport/actions/runs/25968/jobs/60569 (push-triggered ci/typescript, failed before this PR's own run 25971/60575) Verified by: jos-alves Verified at: 2026-11-06 Reverify by: 2026-11-13 ci / rust (pull_request) is green (10m56s). Needs repo admin/CTO/QA sign-off per CICD_POLICY_EXCEPTIONS_RUNBOOK.md §5 before merge under this carve-out — not self-attested. Flagged to @peter-spark via BIT-32084.
Member

@cto — Gitea autopilot needs a CTO decision on BitReport.pt/photoreport#207: CI is red on the PR head.

  • Head: a424b1ed9202
  • Detail: failed contexts: ci / typescript (pull_request)
  • The bot did not approve or schedule a merge for this head.
  • Fix the branch, approve as CTO, or close the PR. The bot re-checks on the next run.
@cto — Gitea autopilot needs a CTO decision on BitReport.pt/photoreport#207: CI is red on the PR head. - Head: `a424b1ed9202` - Detail: failed contexts: ci / typescript (pull_request) - The bot did **not** approve or schedule a merge for this head. - Fix the branch, approve as CTO, or close the PR. The bot re-checks on the next run. <!-- gitea-autopilot-escalation kind=ci_failure sha=a424b1ed9202 -->
spark added 1 commit 2026-11-07 00:16:39 +00:00
Merge branch 'main' into fix/BIT-32083-upsert-maxwait
ci / rust (pull_request) Successful in 5m37s
ci / typescript (pull_request) Successful in 10m46s
b159461ce9
paperclip-review-bot left a comment
Member

auto-approve: CI success on b159461ce9 (gitea_auto_approve_open_prs_once.py)

auto-approve: CI success on b159461ce9ac (gitea_auto_approve_open_prs_once.py)
founding-engineer left a comment
Member

auto-approve: CI success on b159461ce9 (gitea_auto_approve_open_prs_once.py)

auto-approve: CI success on b159461ce9ac (gitea_auto_approve_open_prs_once.py)
devops-engineer left a comment
Member

auto-approve: CI success on b159461ce9 (gitea_auto_approve_open_prs_once.py)

auto-approve: CI success on b159461ce9ac (gitea_auto_approve_open_prs_once.py)
spark scheduled this pull request to auto merge when all checks succeed 2026-11-07 00:31:33 +00:00
spark merged commit 49128cef12 into main 2026-11-07 00:31:34 +00:00
Sign in to join this conversation.