Skip to content

a Snooze after an answered wait, a fired timer or an expired join puts the node back on hold, because the cursors are keyed on the attempt number the Snooze refunds #760

Done

Description

@XBeg9

The wait sites record how far each execution has read the node's answer queue in jobs.metadata, under keys built from the attempt number alone: hold_cursor_{attempt}_{seq} for ctx.wait_signal (_ctx_wait.py:330, advanced at _ctx_wait.py:403), hold_cursor_{attempt}_{signal_name} for ctx.wait_until (_ctx_timer.py:240, advanced at _ctx_timer.py:297), and child_join_face_{attempt} for a child join's Expired face (_childflow.py:290-311, with the attempt passed in at _childflow.py:554). A Snooze or RetryAfter(consume_budget=False) refunds the claim's attempt increment (_runner_defer.py:26-31, _sql_finalize.py:1365-1367). The comment in _sql_finalize.py justifies that with "a non-consuming deferral did not execute", after which "the re-claim re-mints the same attempt ordinal" (_sql_finalize.py:1286-1294). A body that raises Snooze after its wait returned has executed, though, and has already moved the marker. The next claim runs the body again under the same ctx.attempt and reads that marker. For wait_signal and wait_until the cursor now equals the queue length, so the cursor < len(queue) branch is skipped (_ctx_wait.py:385, _ctx_timer.py:280). No held row stands, so the site mints a new hold with a new epoch and raises NodeHeldError. For a child join the marker already equals the abandoned row's epoch, so the site skips Expired and registers a second join hold.

Reproduced on ffcb61f against a real Postgres. Nothing under src/ changed between it and main at 9b9fa72. The shape:

class Approval(BaseModel):
    approved: bool

async def publish(ctx: StepContext) -> bool:
    approval = await ctx.wait_signal(Approval)
    if not await quota_available():  # say, a downstream rate limit
        raise Snooze(timedelta(seconds=30))
    return approval.approved

The first run holds at attempt 1 and the operator answers once. The resume runs at attempt 2, consumes the answer and raises Snooze once. After the refund takes the row back to attempt 1, the next claim runs at attempt 2 again and parks on a new hold. At the end the node is pending (held) at attempt 2 with hold_cursor_2_0: 1 in its metadata, and wf_signals has the original delivered row (epoch 1, call:1:0) plus a new held row (epoch 2, call:2:0). So the body used the answer once, and the operator is asked for it a second time.

The timer behaves the same way. After ctx.wait_until(600, key="remind") fired and the next execution consumed the wake and snoozed, the re-run registered a second __timer__remind hold at epoch 2 (hold_cursor_2___timer__remind: 1) and went back to sleep. For a join, the body was ctx.spawn_flow(..., key="only") followed by handle.wait(timeout_s=600), and the expiry sweep abandoned the hold. The resume got Expired and snoozed. The re-run then registered a new held join row at epoch 2 next to the abandoned epoch-1 row (child_join_face_2: 1). With RetryAfter(timedelta(0), consume_budget=False) in place of Snooze, all three park the same way. With a consuming RetryAfter(timedelta(0)), all three succeed: the retry runs at attempt 3, finds no cursor under its key and replays the answer. The tip of PR 755 still reproduces all three.

The guide describes the delivered holds as an answer queue that a retry replays, so "the operator never re-answers" (workflows.md:2435-2443) and "the operator's re-run never re-sleeps" (workflows.md:2967-2970). The wait_until docstring says the hold "fires exactly once" and a replay re-consumes the wake (_ctx_timer.py:144-149). The guide also says a snoozed claim's ledger row rests awaited, "the hold's own resume-not-retry status" (workflows.md:1615-1617). Snoozing after a wait is an ordinary thing to write: wait for approval, then back off on a rate limit or a busy dependency. Nothing fails when it goes wrong, so the run just sits pending on a question that was already answered, or sleeps another full period, until someone notices and acts again.

The join case is less clear-cut. Its docstring says Expired fires "once per abandoned row per attempt" (_childflow.py:61-64, _childflow.py:249-251), and the code does exactly that. But every other re-execution of a join gets Expired again, the guide says the timeout face "NEVER mints an automatic new epoch" (workflows.md:2631-2633), and wait_signal already removed the same per-attempt marker (timeout_face_{attempt}_{seq}) because "its only remaining effect was a same-attempt re-execution minting past the face" (_ctx_wait.py:433-445).

This is the same attempt-number reuse that produces the second child in issue 748, where the spawn slot spawn_cursor_{attempt} has already moved when the body re-runs at the same attempt. PR 755 re-keys the spawn slot and leaves these three markers as they are. Not checked: the fleet dispatch path, which runs the same context code, and loop bodies, which index the queue by iteration counter and are probably unaffected.

Probably wants: the two cursors and the join face marker keyed per execution the way PR 755 keys the spawn slot, with a per-attempt key whose value carries the claim's claim_epoch and restarts at 0 when the epoch differs. A re-claim at a refunded attempt then replays from the start of the queue, and no metadata key is added per claim. The timer cursor has to keep counting within one execution, since two wait_until calls with the same key share it.

Activity

  1. added
    bug
    important
    on Nov 24, 2026
  2. XBeg9 commented on Nov 24, 2026

    @XBeg9
    ContributorAuthor

    This is a regression from PR 702 (90944e8b6), which made workflow steps honor Snooze and RetryAfter(consume_budget=False) by refunding the claim's attempt (_sql_finalize.py:668-670). The attempt-keyed markers are older. Blame traces the wait cursor, the timer cursor and the join face marker back to the original workflows drop in PR 681. PR 715 later changed the wait cursor's suffix to the call ordinal and kept the attempt prefix.

    Before 702, a Snooze raised in a step body went down the failure ladder and used up a retry. That was the bug 702 fixed. The retry ran at attempt 3, found no marker under its own key and replayed the answer, the wake or the Expired face. I ran the reproduction for all three sites twice at the parent f0d8e2582 and twice at 702's commit. At the parent all three passed: each body ran at attempts 2 and 3, each node succeeded at attempt 3, and each node had one signal row. At 702 all three failed both times. Each node was parked pending at attempt 2 with a second held row at epoch 2, as this issue describes. The parent's green therefore depended on the Snooze costing a retry.

    Blame on the refund lines points at PR 703 (9a2ab0118). The squash of PR 701 (b56f33ee7) left src/ identical to the parent, and 703 put back 702's tree unchanged.

    Related: in issue 748 a held row is claimed again and re-runs under the same attempt number, so the per-attempt spawn cursor mints a second child. PR 755 moves the spawn slot to a counter that restarts per claim epoch, and it also tests the Snooze and RetryAfter(consume_budget=False) re-run for that slot. At its current head the two hold cursors and child_join_face_* are still keyed on the attempt. Issue 769 covers the same wait sites minting a hold with no claim-epoch fence. PR 755 already threads claim_epoch into WaitHost and JoinSite, and the fix suggested here would need that. Issue 344 was the plain-job version of this: an example gated on ctx.attempt after deferrals stopped advancing it.

  3. added
    regression
    on Nov 24, 2026
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

    bugimportantregression

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions