Fix race condition in announce endpoint causing missing platform artifacts#63
Conversation
…facts Replace find-then-create pattern with Prisma atomic upsert in both upsertVersion and upsertArtifact to eliminate P2002 race window when concurrent platform builds announce simultaneously. Closes #62
JoeCardoso13
left a comment
There was a problem hiding this comment.
APPROVE WITH COMMENTS
The find-then-create → upsert refactor is the right fix for the P2002 race. Clean change that aligns both methods with the existing upsertPackage pattern. A few things to consider:
-
Write-once backfill fields dropped from update path (non-blocking): The old
upsertVersionupdate conditionally setreleaseTag,releaseUrl, andreadmewhen the existing record had nulls. The newupdateblock omits them — so a version created before its GitHub release exists can no longer have these backfilled by a later announce. If intentional, a comment would help clarify; if not, they can be re-added with conditional spreads or a follow-up update using the pre-fetchedexisting. -
createdflag may be inaccurate under concurrent calls (non-blocking): Both methods derivecreated: !existingfrom afindUniquebefore theupsert. Two racers can both seeexisting === nulland both returncreated: true. Fine if the flag is informational; worth checking if it triggers side effects. -
Staging verification (non-blocking): The test plan's staging checkbox is unchecked. Unit tests confirm logic correctness, but the actual failure mode (concurrent platform builds) can only be validated end-to-end. Worth completing before merge.
Summary
upsertinupsertVersionandupsertArtifactto eliminate P2002 race windowupsertPackageapproach which was already correctTest plan
pnpm typecheckpassespnpm lintpassespnpm test— 93/93 tests passCloses #62