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.tssetFolderEvent: 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.
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
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 -->
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 -->
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.
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 main2026-10-22 00:11:48 +01:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
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_fkeyonphoto.create(),cloud_folders_event_id_fkeyoncloudFolder.update()insetFolderEvent) 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: onP2003fromphoto.create(), retry once witheventId: null— same outcome as an explicit no-event upload ("Sem evento"), instead of failing the whole ingest.archive/service.tssetFolderEvent: onP2003from thecloudFolder.update(), throw the sameArchiveRejected("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 typecheckclean.apps/apitest 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'ssetFolderEventcoverage 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.
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@cto — Gitea autopilot needs a CTO decision on BitReport.pt/photoreport#95: CI is red on the PR head.
18867d41b15e@cto — Gitea autopilot needs a CTO decision on BitReport.pt/photoreport#95: the PR has merge conflicts.
0e241d4f92dc