Skip to content

fix(queue): roll back PullWork RUNNING state when post-update Get fails (round-25 audit B.1) - #468

Merged
lusoris merged 2 commits into
masterfrom
fix/queue-pullwork-rollback-on-get-failure
May 31, 2026
Merged

lusoris merged 2 commits into
masterfrom
fix/queue-pullwork-rollback-on-get-failure

Conversation

@lusoris

@lusoris lusoris commented May 31, 2026 •

Copy link
Copy Markdown
Contributor

Fix Round 25 audit B.1: queue.PullWork orphans jobs in RUNNING state when post-UPDATE getUnlocked read fails.

Bug: 3-step state mutation (FIFO pop → SQL UPDATE jobs SET status=running → runningSet[matchID] insert) had no rollback when getUnlocked failed afterward. Job permanently stuck RUNNING until controller restart.

Fix: rollbackToPending(jobID) called on getUnlocked error path. Executes UPDATE jobs SET status='pending', assigned_node=NULL WHERE id=?, removes from runningSet, re-prepends FIFO. CRITICAL-level log if rollback SQL itself fails.

Test added: TestPullWork_GetUnlockedFailure_RollsBackToPending — uses new SetGetUnlockedHookForTest count-based escape hatch to inject failure, asserts SQL status pending, assigned_node empty, RunningCount==0, PendingCount==1, retry succeeds.

All 10 queue tests pass. gofmt + go vet clean.

no state delta: bug fix per CLAUDE.md §12 r8 (no ADR for bug fix); state.md row added in same PR for T-CONTROLLER-QUEUE-PULLWORK-ORPHAN-2026-05-31 is in the diff.

ADR-0108 deliverables checklist

🤖 Generated with Claude Code

@lusoris
lusoris marked this pull request as ready for review May 31, 2026 08:20
@lusoris
lusoris enabled auto-merge (squash) May 31, 2026 08:20
@lusoris
lusoris marked this pull request as draft May 31, 2026 09:01
auto-merge was automatically disabled May 31, 2026 09:01

Pull request was converted to draft

@lusoris
lusoris marked this pull request as ready for review May 31, 2026 11:34
@lusoris
lusoris enabled auto-merge (squash) May 31, 2026 11:34
@lusoris
lusoris force-pushed the fix/queue-pullwork-rollback-on-get-failure branch from d6b98c0 to a577385 Compare May 31, 2026 11:36
@lusoris
lusoris merged commit a933a04 into master May 31, 2026
52 of 54 checks passed
@lusoris
lusoris deleted the fix/queue-pullwork-rollback-on-get-failure branch May 31, 2026 11:39
lusoris added a commit that referenced this pull request May 31, 2026
…okForTest and #472 ListAll (both additions kept)
lusoris added a commit that referenced this pull request May 31, 2026
…nel (round-25 audit)

Round 25 audit B.3 + B.4 fixes for the vmafx-controller. Re-applied
cleanly on top of current master (PR #468 SetGetUnlockedHookForTest
+ PR #474 helm seccomp) after a previous quick-rebase left conflict
markers in cmd/vmafx-controller/queue/queue.go and the AGENTS.md
sidecar.

B.3 — controllerServer.StreamJobs snapshot:
  * queue.Queue interface gains ListAll(ctx, statuses) ([]*Job, error).
  * SQLiteQueue implements it with a status-IN filter (parameterised,
    bounded to the 5-element Status enum) and per-row copy semantics.
  * grpc_server.go StreamJobs sends a single snapshot via ListAll,
    converting Job.Status with protoStatusToQueue/queueStatusToProto
    helpers kept in lockstep.

B.4 — reaper goroutine stop signal:
  * nodes.NewRegistry(ctx, log) signature now takes a required context.
  * reaper goroutine selects on ctx.Done() + ticker.C and exits when
    the controller's shutdown context is cancelled.
  * registry gains Close() which cancels its own derived context.
  * main.go wires NewShutdownContext()'s context into NewRegistry and
    defers nodeRegistry.Close() after jobQueue.Close().

Tests, ADR, research digest, changelog fragment, AGENTS.md sidecar,
rebase-notes entry, ADR index update — all in this PR.

ADR-0962. Research: docs/research/0962-controller-streamjobs-reaper-fixes-2026-05-31.md.

Conflict resolution notes:
  * cmd/vmafx-controller/queue/queue.go — both #468's
    SetGetUnlockedHookForTest and #472's ListAll/repeatCommaQ kept,
    with the missing closing brace for SetGetUnlockedHookForTest
    restored (previous botched rebase had sed-stripped the marker
    and left a syntax error).
  * cmd/vmafx-controller/AGENTS.md — kept both halves additively:
    governance/queue invariants from master plus rebase-sensitive
    invariants from this PR, with ADR-0962 added to the Governing
    ADRs table and entries split across the queue / nodes / grpc
    server / main sections.
  * docs/adr/README.md, docs/adr/_index_fragments/_order.txt,
    docs/rebase-notes.md — additive (both halves preserved).
@lusoris lusoris added this to the 1.0.0 — First release milestone Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant