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 and pushing nextScanAt 15 min out — so the loop recurs.
Fix
Wrap each create in try/catch for P2002 and fall back to an update on the sourceId_fileId compound key. The three-branch logic (new / changed etag / moved) is preserved; only the new-branch create is hardened.
apps/api/src/archive/service.test.ts — vitest proving the cloudFile fallback updates the compound key and requeues, and that non-P2002 errors still rethrow
No schema change, no migration. Blast radius: archive scan only.
Paperclip-Issue: BIT-33532
## Problem
`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` and pushing `nextScanAt` 15 min out — so the loop recurs.
## Fix
Wrap each `create` in try/catch for P2002 and fall back to an update on the `sourceId_fileId` compound key. The three-branch logic (new / changed etag / moved) is preserved; only the new-branch create is hardened.
- `apps/api/src/archive/service.ts` — `cloudFolder.create` (walk self), `cloudFile.create`, `cloudVideo.create`
- `apps/api/src/archive/service.test.ts` — vitest proving the `cloudFile` fallback updates the compound key and requeues, and that non-P2002 errors still rethrow
No schema change, no migration. Blast radius: archive scan only.
Paperclip-Issue: BIT-33532
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
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.
Problem
ArchiveService.walkused a check-then-create pattern forcloudFolder,cloudFileandcloudVideo. When two concurrent passes (overlapping scans or a folder reachable through two paths) both query existing rows before either creates, the secondcreatehits P2002 on@@unique([sourceId, fileId])and aborts the whole scan, marking the sourceERRORand pushingnextScanAt15 min out — so the loop recurs.Fix
Wrap each
createin try/catch for P2002 and fall back to an update on thesourceId_fileIdcompound key. The three-branch logic (new / changed etag / moved) is preserved; only the new-branch create is hardened.apps/api/src/archive/service.ts—cloudFolder.create(walk self),cloudFile.create,cloudVideo.createapps/api/src/archive/service.test.ts— vitest proving thecloudFilefallback updates the compound key and requeues, and that non-P2002 errors still rethrowNo schema change, no migration. Blast radius: archive scan only.
Paperclip-Issue: BIT-33532
auto-approve: CI success on
5287afb508(gitea_auto_approve_open_prs_once.py)auto-approve: CI success on
5287afb508(gitea_auto_approve_open_prs_once.py)auto-approve: CI success on
5287afb508(gitea_auto_approve_open_prs_once.py)