fix(archive,ingest): abort cleanly when an event vanishes mid-pipeline (BIT-31203) #95

Merged
spark merged 4 commits from fix/BIT-31203-event-vanished-race into main 2026-10-22 00:11:48 +01:00
Owner

BIT-31203 — event deleted while ingest/archive jobs are still in flight

Diagnosis (triage 2026-10-21): ingest and archive indexing read an event id, then do hashing/EXIF/preview work that can take a while before the final write. If the event is deleted or archived in that window, Prisma throws a raw FK violation (photos_event_id_fkey on photo.create(), cloud_folders_event_id_fkey on cloudFolder.update() in setFolderEvent) instead of recovering, which is what reached the error hub as this cluster (3 duplicates already closed and linked to this root: BIT-31204, BIT-31205, BIT-31208).

Fix

  • ingest/service.ts: on P2003 from photo.create(), retry once with eventId: null — same outcome as an explicit no-event upload ("Sem evento"), instead of failing the whole ingest.
  • archive/service.ts setFolderEvent: on P2003 from the cloudFolder.update(), throw the same ArchiveRejected("event_not_found") already thrown when the event is missing up front — a clean 400 instead of a raw Prisma error bubbling up through the archive worker.

Testing

  • pnpm --filter @photoreport/api typecheck clean.
  • Full apps/api test suite run against a throwaway Postgres 16 + pgvector container (matching CI's service config): 335 passed, 8 skipped, 0 failed (incl. test/archive.test.ts's setFolderEvent coverage and every ingest-path integration test).

Per the board's R0–R4 rules: branch → PR → CI green, no push to main, no SSH to servers, deploy only via webhook.

## BIT-31203 — event deleted while ingest/archive jobs are still in flight Diagnosis (triage 2026-10-21): ingest and archive indexing read an event id, then do hashing/EXIF/preview work that can take a while before the final write. If the event is deleted or archived in that window, Prisma throws a raw FK violation (`photos_event_id_fkey` on `photo.create()`, `cloud_folders_event_id_fkey` on `cloudFolder.update()` in `setFolderEvent`) instead of recovering, which is what reached the error hub as this cluster (3 duplicates already closed and linked to this root: BIT-31204, BIT-31205, BIT-31208). ### Fix - `ingest/service.ts`: on `P2003` from `photo.create()`, retry once with `eventId: null` — same outcome as an explicit no-event upload ("Sem evento"), instead of failing the whole ingest. - `archive/service.ts` `setFolderEvent`: on `P2003` from the `cloudFolder.update()`, throw the same `ArchiveRejected("event_not_found")` already thrown when the event is missing up front — a clean 400 instead of a raw Prisma error bubbling up through the archive worker. ### Testing - `pnpm --filter @photoreport/api typecheck` clean. - Full `apps/api` test suite run against a throwaway Postgres 16 + pgvector container (matching CI's service config): **335 passed, 8 skipped, 0 failed** (incl. `test/archive.test.ts`'s `setFolderEvent` coverage and every ingest-path integration test). Per the board's R0–R4 rules: branch → PR → CI green, no push to main, no SSH to servers, deploy only via webhook.
spark added 1 commit 2026-10-21 19:10:16 +01:00
fix(archive,ingest): abort cleanly when an event vanishes mid-pipeline (BIT-31203)
ci / rust (pull_request) Successful in 5m30s
ci / typescript (pull_request) Failing after 9m43s
18867d41b1
A hashing/EXIF/preview pipeline (ingest, archive indexing) can take long enough that
the event it was told to file a photo under gets deleted or put away in the
meantime. Prisma then threw a raw foreign key violation (photos_event_id_fkey,
cloud_folders_event_id_fkey) instead of recovering: the archive indexer retried
until it failed the file, and setFolderEvent crashed instead of rejecting cleanly.

Both now treat the missing event the same way the rest of the codebase already
treats "no event": ingest() retries the create with eventId: null (the photo
goes to "Sem evento", same as an explicit no-event upload), and
setFolderEvent() turns the race into the same ArchiveRejected("event_not_found")
it already throws when the event is missing up front.

Paperclip-Issue: BIT-31203
Member

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

  • Head: 18867d41b15e
  • 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#95: CI is red on the PR head. - Head: `18867d41b15e` - 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=18867d41b15e -->
spark added 1 commit 2026-10-21 22:54:21 +01:00
Merge branch 'main' into fix/BIT-31203-event-vanished-race
ci / rust (pull_request) Successful in 11m49s
ci / typescript (pull_request) Successful in 16m7s
0e241d4f92
Member

@cto — Gitea autopilot needs a CTO decision on BitReport.pt/photoreport#95: the PR has merge conflicts.

  • Head: 0e241d4f92dc
  • 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#95: the PR has merge conflicts. - Head: `0e241d4f92dc` - 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=conflict sha=0e241d4f92dc -->
spark added 1 commit 2026-10-21 23:52:22 +01:00
Merge main into fix/BIT-31203-event-vanished-race
ci / rust (pull_request) Successful in 4m52s
ci / typescript (pull_request) Failing after 8m10s
8d7f703797
Conflict in apps/api/src/ingest/service.ts between #91 (stripNulBytes on the
photo.create data) and this branch (the data object hoisted so a vanished
event can be retried with eventId null). Both kept: the hoisted data object
goes through stripNulBytes, so the first insert and the P2003 retry are both
free of NUL bytes.
spark added 1 commit 2026-10-22 00:02:15 +01:00
Expect the club kind in the archive directory test
ci / rust (pull_request) Successful in 5m5s
ci / typescript (pull_request) Successful in 8m52s
a744a62f4a
5eb5e95 (#113) made /v1/archive/:id/directory return each team with
kind (club, national or other), but test/archive.test.ts still expected
teams without it, so "reads teams from the stored directory and hides
games the viewer cannot see" fails on main and on every PR merged with it.
ABC de Braga and Sporting CP are clubs; the expectations now say so.
spark merged commit cd4174ba84 into main 2026-10-22 00:11:48 +01:00
Sign in to join this conversation.