fix(matchmaker): stale-reaper queries claimed not running status

Jobs remain in 'claimed' status until completed — the reaper was
querying 'running' (which is the match status, not job status) so
stale claimed jobs were never recycled.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
jedarden 2026-04-24 17:24:57 -04:00
parent f4baa4b817
commit ea2f1b50b7

View file

@ -560,7 +560,7 @@ func (m *Matchmaker) tickStaleReaper(ctx context.Context) {
rows, err := m.db.QueryContext(ctx,
`SELECT job_id FROM jobs
WHERE status = 'running' AND claimed_at < $1`,
WHERE status = 'claimed' AND claimed_at < $1`,
time.Now().Add(-threshold))
if err != nil {
log.Printf("stale-reaper: query error: %v", err)
@ -581,7 +581,7 @@ func (m *Matchmaker) tickStaleReaper(ctx context.Context) {
for _, jobID := range staleJobs {
result, err := m.db.ExecContext(ctx,
`UPDATE jobs SET status = 'pending', worker_id = NULL, claimed_at = NULL
WHERE job_id = $1 AND status = 'running'`, jobID)
WHERE job_id = $1 AND status = 'claimed'`, jobID)
if err != nil {
log.Printf("stale-reaper: update error for %s: %v", jobID, err)
continue