Skip to content

Issue dispatch: make dedupe and retry race-free (single dispatch record per issue) #3873

Backlog

Description

@integry

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 generation they 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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions