Skip to content

fix(workflows): fence fresh hold mints on claim_epoch to prevent stale-claim parks (#769) - #781

Merged
rcbevans merged 3 commits into
mainfrom
fix/769-hold-mint-epoch-fence
Nov 26, 2026
Merged

rcbevans merged 3 commits into
mainfrom
fix/769-hold-mint-epoch-fence

Conversation

@rcbevans

Copy link
Copy Markdown
Contributor

What changed

Fences fresh hold mints in register_hold on the executing claim's positive claim_epoch so a step body whose lock lease lapsed before its first wait cannot park a newer claim's running node or commit an orphan wf_signals hold row.

  • Epoch-fenced park before signal insert (src/taskq/workflows/api/_hitl.py):
    • Requires a positive claim_epoch on fresh hold mints and drops the nullable bypass from _HOLD_HOLD_NODE_SQL (status = 'running' AND claim_epoch = ).
    • Executes the node park before inserting the wf_signals row and raises HoldMintFencedError when the park matches zero rows so the transaction rolls back cleanly with no orphan hold or create notification.
  • Caller threading and unwind (_ctx_wait.py, _ctx_timer.py, _childflow.py, _runner.py, _runner_loop.py, _worker_execution.py):
    • Threads claim_epoch through signal, timer, and child-join fresh hold mint paths.
    • Catches HoldMintFencedError before generic body-failure boundaries in both plain-step and loop execution tails, fences only the stale claim's ledger rows, and propagates "fenced" through execute_flow_job.
  • Integration pins (tests/test_wf_hold_mint_epoch_fence.py): Covers stale-claim races with live successors and re-pended rows across signal, timer, child-join, loop, and fleet execution door paths, plus notification silence on fenced mints.

Verification

  • .venv/bin/pytest tests/test_wf_hold_mint_epoch_fence.py -q: passing
  • .venv/bin/ruff check, .venv/bin/ruff format --check, .venv/bin/pyright on changed files: 0 errors, 0 warnings

Closes #769

@rcbevans
rcbevans requested a review from XBeg9 November 26, 2026 01:18
…'s row

Prevents a step body whose lock lease lapsed before its first wait from parking a newer claim's running node, or committing a hold row that no node stands on:

- Requires the executing claim's positive `claim_epoch` on the fresh hold mint and drops the nullable bypass in the park's SQL fence, so only the claim that holds the running row can park it; a non-positive epoch is refused before any write.
- Parks the node before inserting the signal row and raises a dedicated fenced-mint error when the park matches nothing, so the signal insert and the create broadcast roll back with the park instead of leaving an orphan hold behind.
- Threads the epoch through the three fresh-mint wait doors (signal, timer, child join) and unwinds a fenced mint as `"fenced"` in the plain-step and loop tails, fencing the stale claim's own ledger rows instead of reporting it as held.
- Adds Postgres integration pins for the stale-claim races across all three wait surfaces, the loop node, and the production fleet execution door, and realigns the hold-staging pins to the closed orphan window.
… and map-sibling wake lookup (#769)

- Return bool from reassert_hold and raise HoldMintFencedError on missed re-parks across signal, timer, and child-join wait doors so stale re-entries unwind fenced instead of held.
- Fence _HOLD_HOLD_NODE_SQL against cooperatively cancelled nodes (cancel_phase = 0 AND NOT metadata ? 'cancel_phase') and type HoldMintFencedError.node_id as JobId.
- Narrow _defer_loop_step / _drive_loop / _run_loop_node return types to Literal outcomes and propagate cancelled/laddered/fenced verdicts through FlowRunner._execute_claimed_tail.
- Remove the = 0 default on claim_epoch across the six tail/loop forwarding parameters and switch sweep_due_timers and sweep_child_joins to exact hold-id lookup (_HELD_NODE_BY_HOLD_SQL).
- Log wf-hold-mint-park-missed at INFO with attempted_hold_id, add seed_running_claim to tests/_wf_fixtures.py, pin fenced non-consumption in test_worker_execution_seam.py, and add regression pins.
@rcbevans
rcbevans force-pushed the fix/769-hold-mint-epoch-fence branch from 295fbfb to bfcc16d Compare November 26, 2026 08:59
…old-mint fencing (#769)

- Thread claim_epoch into _flow_job in tests/test_wf_flow_rate_limit_pins.py so the synthetic JobRow matches the Postgres row's claim_epoch=1 when testing hold-slot release.
- Reclaim the node row to status='running' at claim_epoch=2 before re-waiting on the standing hold in tests/probes_coverage_closers.py::test_the_re_wait_while_a_hold_stands_raises_node_held.
@rcbevans
rcbevans merged commit 01728e3 into main Nov 26, 2026
54 checks passed
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.

a body whose lease lapsed can park a newer claim's running row at its first wait, because the hold mint has no claim-epoch fence

1 participant