Repository navigation
Description
Issue dispatch: make dedupe and retry race-free (single dispatch record per issue)
Split out of #3860 / PR #3862 after five review cycles kept finding new races in the job-replacement and retry lifecycle. PR #3862 now ships only the disk-pressure handling, the reporting and implement_plan error handling. This issue covers the dispatch redesign.
Findings to resolve (from #3862's reviews)
- F1: requests lost through enqueue races and failures.
- F2: a concurrent replacement can delete the new job.
- F3: a refusal resets historical plan issues.
- F4: "never started" reporting without evidence that no earlier attempt ran.
- F5: producers aren't fenced after a dispatch takeover.
- F6: plans aren't released when execution children are refused.
Design (write it down in the PR description first; review it before coding)
1. Never replace or delete BullMQ jobs.
- Each dispatch attempt gets a fresh jobId (
issue-<owner>-<repo>-<n>-<dispatchId>). - One durable SQLite row per issue,
issue_dispatch(issue, dispatch_id, state, started_at, generation, …), decides whether to enqueue. - Enqueue in a single transaction: insert or advance the row only if there is no row, or the existing one is terminal. Otherwise return "already queued".
- Producers carry the
generationthey read and are fenced by it, so a producer from an older generation can't act after a takeover (F5).
2. Disk-pressure deferral stays on the same attempt (delayed job), without consuming attempts.
3. Plan-issue updates apply only when the plan issue currently points at this dispatch_id and is non-terminal (F3).
- Refused matrix or execution children release their plan reservation through the same rule (F6).
4. Reports come from recorded facts (started_at) (F4).
5. One table-driven state-transition test covering F1–F6, plus a concurrency test with two producers.
Notes
- ProPR runs on SQLite only: do not add code or tests for other databases.
- Keep the user-visible behaviour PR [3860 by Claude Opus 5.5] # Issue jobs refused for disk pressure are dropped silently; implement_plan returns 500 with no log #3862 ships: deferral, free-space numbers in refusals, final refusal comments.
Addition (from #3862 F11/F12)
Also covers re-triggering after a final disk-pressure refusal. #3862 no longer removes the failed job, because a separate cleanup can delete a same-ID replacement (F11) and discards the failure evidence (F12). With fresh jobIds per dispatch, a later relabel or daemon re-detection simply creates a new dispatch while the failed job is kept for inspection.
Activity
fix: keep disk-pressure failed jobs instead of removing them