Skip to content

feat(workflows): honor Snooze/RetryAfter body signals on wf steps - #702

Merged
rcbevans merged 3 commits into
mainfrom
feat/wf-snooze-passthrough
Oct 31, 2026
Merged

rcbevans merged 3 commits into
mainfrom
feat/wf-snooze-passthrough

Conversation

@rcbevans

Copy link
Copy Markdown
Contributor

What

  • A wf step body raising Snooze(delay) or RetryAfter(delay[, consume_budget]) defers the row instead of burning the attempt ladder: scheduled_at += delay, the attempt refunded (Snooze, and RetryAfter with consume_budget=False) or kept (consume_budget=True), matching the vanilla consumer's disposition law (mark_snoozed / mark_retry_after_*, backend/_sql_templates.py).
  • NODE_DEFER_SQL (workflows/_sql_finalize.py): one keyed statement, four verdicts (deferred / exhausted / cancel_fenced / zombie), registered in the bounded-writes audit. The cancel fences cover BOTH carriers (the wf metadata mark AND the vanilla cancel_phase column, reset on the deferred arm) — the operator's cancel can no longer be laundered by a mid-body deferral.
  • Loop iteration bodies defer the SAME way and resume at that iteration, counters untouched; the ladder still bounds loops (MaxAttemptsExceeded through the loop's own body-failure face).
  • Admin: the run page's node rows show the deferral state (the signal, the next fire, the count) live via SSE; the runs list badges a pathologically deferring run (the inventory's witness); the stamps are bounded/truncated and cast-safe on the read path.
  • Docs: docs/guides/workflows.md's control-flow-signals section (the semantics table, the carriers, the loop's route, the extension seam).

Receipts

  • Pins: 19 in tests/test_wf_snooze_pins.py + the web_admin family, red-first (11 failing pre-implementation).
  • Red-team round: five convictions (the cancel launder HIGH, the loop cliff MEDIUM, three LOW) — fixed, re-attacked, condition lifted.
  • Gates: ruff clean, format clean, pyright 0 errors; the wf battery, the attack rounds, and the fast tier green on the rebased head; the vanilla surface byte-identical (worker/, backend/).

…ferral disposition

A workflow body raising the vanilla surface's typed control-flow
signals — Snooze (reschedule, no retry budget) and RetryAfter(delay,
consume_budget=) — fell into the runner's body-failure catch and
LADDERED: the attempt budget burned on a deferral that never executed
(the OCR-429 exhaustion the vanilla consumer's own catch exists to
prevent for plain jobs). The workflow runner had no translation of the
signals; the vanilla path's row dispositions (mark_snoozed /
mark_retry_after_consume_{true,false}) were the law to mirror.

THE CURE, on the runner's step-body seam (api/_runner's catch, the
vanilla catch's own placement — around the body, before the ladder):

* a NEW bounded finalize disposition: NODE_DEFER_SQL
  (workflows/_sql_finalize.py) — one keyed statement (the finalize's
  own claim CAS + the cancel-mark fence + the budget gate) whose arms
  mirror the vanilla dispositions: scheduled_at = clock_timestamp() +
  delay, the attempt REFUNDED for the non-consuming faces (the vanilla
  ATTEMPT_REFUND_SQL law — max_attempts is never exhausted by snoozes
  alone, the ledger re-claims the SAME arbiter row), the increment KEPT
  for a consuming RetryAfter (the burn), the MIN_DEFERRAL_INTERVAL
  floor on the non-consuming delay (the vanilla monopolisation guard),
  snooze_count on the refunding faces only, the deferral stamp on the
  row's metadata (the run page's visibility);
* the budget-bounded consuming face: past max_attempts the EXHAUSTED
  verdict routes through the wf terminal door — the ledger's failed
  row + finalize_node + the T06 cascade — under the vanilla's own
  MaxAttemptsExceeded class + message; a cancel in flight wins (the
  cancel_fenced verdict — the node terminalises 'cancelled', the
  vanilla cancel ladder's face); a zombie's deferral records 'fenced'
  (H1) and touches nothing;
* the claim's ledger row rests 'awaited' (the hold's own
  resume-not-retry status — never a failed row the ladder counts); no
  terminal, no decrement — the join's accounting unchanged, the run
  stays live (the maintenance leg's has_unresolved already reads
  'scheduled' rows), the result capture stays empty;
* the NAMED-DISPOSITION EXTENSION SEAM (api/_runner_defer.py): the
  signals resolve to a DeferralDisposition literal — one statement arm
  + one resolver entry per disposition, never a per-signal branch at
  the catch; the ladder's own arms untouched;
* the ADMIN's deferral line (the run page's 'why is this step sitting
  here' answer): the signal, the next fire time, and the snooze count
  beside the status chip — the ROW's truth (the stamp's own
  post-attempt discriminator, so a later ladder repend never reads as
  a live deferral), rendered in the server snapshot and painted/cleared
  live on the SSE frames (the template + workflows.js, the page's own
  patterns).

Red-first: tests/test_wf_snooze_pins.py (the deferral, the burn, the
budget's bound, the budget law, the ladder's regression fence, the
join's accounting, the floor, the cancel/zombie fences) and
tests/web_admin/test_wf_snooze_run_page_pins.py (the line, the frame,
the clear) watched failing before the fix. NODE_DEFER_SQL registered in
the bounded-writes audit (keyed single node row). The vanilla surface
is byte-identical (worker/ and backend/ carry no diff; the vanilla
snooze batteries green).
…iterations through the deferral, and bound the record's faces

The red-team round on feat/wf-snooze-passthrough convicted five defects
in the deferral disposition and its record's faces. Each cure is
red-first (the pins watched failing before the fix).

* C1 — THE CANCEL LAUNDER: the deferral's fence armed only the wf
  cancel's METADATA mark (``metadata.cancel_phase``); the vanilla
  cancel's own COLUMN mark (the admin job-page cancel's ``cancel_running``
  arm — ``cancel_requested_at = now, cancel_phase = 1`` on the running
  row) fenced NOTHING: a mid-body vanilla cancel + a Snooze rescheduled
  the row (the body invoked twice, the run SUCCEEDED, the vanilla cancel
  door dead for life on that row). NODE_DEFER_SQL now fences BOTH
  carriers: the deferred and exhausted arms gain ``AND j.cancel_phase =
  0``, the cancel_fenced arm fires on EITHER mark, and the deferred SET
  carries the vanilla arms' own reset (``cancel_phase = 0 /
  cancel_requested_at = NULL``) — safe because the fence guarantees the
  resets only ever land on a clean row (never laundry).

* C2 — THE LOOP CLIFF: a loop ITERATION body raising Snooze/RetryAfter
  fell into the loop's body-failure catch — the run terminalized on the
  FIRST signal (LoopBodyFailure, one invocation). The loop's signals now
  route through the deferral disposition — the loop's iteration machinery
  already resumes a mid-iteration hold; the deferral is the same resume,
  later by the delay. The shared row law + ledger truth are ONE phase
  (``defer_row_law`` — the same NODE_DEFER_SQL arm: the reschedule, the
  refund, the fences, the 'awaited' rest); the LOOP's counters
  (``iteration``/``carry``) are the ADVANCE statement's own — untouched —
  so the loop resumes at THAT iteration, the ladder unburned. The bound
  holds: a loop body exhausting the budget via
  ``RetryAfter(consume_budget=True)`` past ``max_attempts`` takes the
  LOOP'S OWN body-failure face (``_exhaust_loop`` — the named state +
  STRANDED-FLOW + the escalation) under the vanilla's own
  ``MaxAttemptsExceeded`` class + message, the claim's ledger row the
  ATTEMPT's failed record.

* C3 — THE LABEL'S BOUND: the deferral stamp's ``signal`` is row-sourced
  free text; a hostile 10KB stamp rode the whole thing into the run
  page's DOM and every SSE frame. The label's signal now passes the
  node panel's own ``_truncate_error_text`` bound (H-C9's law at the
  deferral's face — the truncation honest, the marker naming the rest).

* C4 — THE VISIBILITY GAP: the runs LIST could not see a pathologically
  deferring run (the per-step line lives only on the detail page). The
  list's read gains one bounded lateral per root row — the sitting
  nodes' count (status 'scheduled' on a LIVE deferral stamp, the stamp's
  own attempt discriminator, regex-guarded so a hostile non-numeric
  stamp degrades to NULL — never a cast death), the earliest next fire,
  and the deferral depth — rendered as the runs-list badge
  (``data-wf-run-deferring``), the page's own patterns.

* C5 — THE ZOMBIE'S FENCE vs THE RE-MINT: the refund re-mints the
  ordinal — the arbiter re-use hands a LIVE winner the SAME ledger row a
  zombie once claimed — and the by-id fence (the status='running' guard
  alone) marked the winner's LIVE attempt 'fenced'. The fence now keys
  the caller's OWN claim instant (``claim_step_ledger``'s RETURNING
  updated_at — the claim's instance identity, threaded
  ``ledger_claimed_at`` from both claim doors through the shared tail):
  the re-mint re-stamps the row, the stale instant refuses the fence,
  and the winner's own terminal writes the row. The engine's fenced-out
  arm holds no claim instant and keeps the status-only fence (the NULL
  form); an un-re-minted zombie row still fences (H1).

Red-first pins: tests/test_wf_snooze_pins.py (the vanilla-cancel fence,
the exhausted arm's fence, the reset's residue shape, the re-mint guard
+ the classic arm beside it, the loop's deferral resume, the loop's
budget exhaustion) and tests/web_admin/test_wf_snooze_run_page_pins.py
(the label's bound, the runs-list badge). Gates: the wf family
(873), the vanilla snooze batteries + the sweepaudit (101), the
web_admin suite (969) — green; ruff, format, pyright clean. The vanilla
surface carries no diff (worker/, backend/ untouched); the docs' deferral
law updated (the loop's route + both cancel carriers + the runs-list
badge).
… and bound the runs list's stamp cast

The re-review's APPROVE-conditional residuals on the deferral's
re-review round — two required (both proven live by the reviewer) and
the three quality-bar items.

REQUIRED:

* THE C5 GUARD WAS DEAD ON THE LOOP ROUTE: the re-mint threading the
  step route carried stopped at ``_execute_claimed`` — the loop branch
  called ``_run_loop_node`` WITHOUT the claim instant, the loop's catch
  passed ``ledger_claimed_at=None`` to ``_defer_loop_step``, the fence
  fell back to status-only, and the reviewer's rig re-fenced the
  re-minted LIVE winner's row (the same dragon C5 closed for the step
  route, alive one seam deeper). ``ledger_claimed_at`` now threads the
  full chain: ``_execute_claimed`` → ``_run_loop_node`` → ``_drive_loop``
  → ``_defer_loop_step`` → ``defer_row_law`` — the loop's zombie fence
  keys the claim's own instant exactly like the step's. Red-first: the
  reviewer's loop re-mint rig driven through the REAL claim tail
  (``_execute_claimed``) red 'fenced' on the winner's live row, green
  'running' after.

* THE RUNS-LIST 500: the badge's attempt discriminator admitted any
  digit count (``^[0-9]+$``) — the reviewer's 11-day overflow-shaped
  stamp (``{"wf_deferral": {"attempt": 99999999999}}``) died the
  ``::int`` cast and 500'd the WHOLE Workflows list. The regex now
  bounds the cast to NINE digits (``^[0-9]{{1,9}}$`` — int4's own domain
  tops at 2147483647 / 10 digits; the ordinal's estate ceiling is 32767
  / 5; a 10+-digit stamp is hostile by construction): the CASE degrades
  it to NULL, NULL never matches the row's attempt, the row drops out
  of the sitting count — the page renders, the badge's law keeps its
  discriminator, the degrade is honest (an unverifiable stamp never
  reads as a live deferral). Red-first: the seeded overflow stamp 500'd
  the render, green after; the clean badge beside it unchanged.

QUALITY BAR:

* THE LOOP'S CANCEL-FENCED FACE, pinned: the loop route's deferral
  fences the vanilla cancel's COLUMN mark (the admin job-page cancel's
  own arm) and routes the loop's node through the wf terminal door
  'cancelled' — the cancel's vocabulary, never the loop's named state
  (the exhaust door never ran), the ledger row the cancel's record.

* THE TWO NEAR-IDENTICAL TERMINAL BLOCKS, factored: the ledger's
  terminal + finalize_node + the projection — the ONE mechanics both
  doors' terminal verdicts run — is now ``route_defer_terminal``
  (``api/_runner_defer``); the DOORS' semantics stay at their own call
  sites (the step's exhaustion finalizes through the door, the loop's
  rides ``_exhaust_loop``'s named state — the helper is the shape they
  share, never a decision). Neither door's writes changed.

* THE EXTENSION-SEAM DOC LINE, corrected (the module docstring + the
  guide): the "three things, never a third special case" law holds for
  the next deferral DISPOSITION; a new TERMINAL verdict additionally
  needs a per-door route in BOTH mixin methods — the doors' semantics
  differ by law, and the docs no longer overclaim.

Gates: the snooze pins (19), the web_admin snooze + cures + page
families, the wf family (875) — green; ruff, format, pyright clean.
@rcbevans
rcbevans merged commit 90944e8 into main Oct 31, 2026
36 checks passed
rcbevans added a commit that referenced this pull request Oct 31, 2026
…e — C4 the Snooze/RetryAfter passthrough) — the fills, the gates' captures, the verifier's receipt — measurement-only
rcbevans added a commit that referenced this pull request Nov 1, 2026
…s content — this restores it, keeping #701's mark (#703)

The #701 branch was cut from pre-#702 main; its squash-merge took that
stale tree as the whole tree and silently reverted C4 (the Snooze/
RetryAfter passthrough) on main. The staged tree here is 90944e8's
(the #702 squash) plus exactly one line — the load_sensitive mark
(proven: git diff 90944e8 = the mark line only).

THE LAW THIS ENCODES: a squash merge of a branch whose base is behind
main is a REVERT of everything between the base and main. No PR merges
without its branch rebased on the merge-time main.
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