← Back to Pull requests

queue: a retained wake never consumes a one-shot park timer, original or shared #1222

Closed
unknown closed this pull request without merging on Oct 13, 2026 11:55 UTC
View on GitHub
unknown unknown commented on Oct 13, 2026 10:52 UTC
Author

What changes

A one-shot --wake-after park timer whose wake is held back (a retained delivery: the typing guard kept it because the owner was typing) was not delivered. Until now the queue's wake records still treated that held-back attempt as the timer's one fire, which went wrong two ways:

  • The timer's own task. After one retained attempt, the timer delivered again at every interval for as long as the task stayed set aside. The next delivered attempt was never recorded against the task, so the timer was never retired. A run on main: retained, ok, ok, ok, with only the first attempt recorded and the job still active.

  • A task sharing the timer through --wake-watchdog, after the original task was handed off or stopped. If the one wake to it was retained, the shared timer was retired at its next check, and the wake was lost.
  • Now a retained attempt never consumes a one-shot wake, on the timer's own task or on a task attached to it.

  • The binding stays eligible, and the timer tries again at its interval. There's no retry limit or deadline; it's tried again while attempts keep being held back.

  • The first attempt that isn't retained (delivered, or failed) is recorded and consumes it, as before.

  • The task's status says what happened: the attempt shows as retained in its history, its backstop stays live, and nothing waits on the owner for an undelivered wake.
  • None of this is a delivery guarantee, and nothing bypasses permissions, the typing guard or the outbox.

    Also: a consumed shared one-shot is retired at once

    When the original task has been handed off or stopped, and an attempt (delivered or failed) consumes the last attachment of its one-shot timer:

  • Before: the job stayed active until its next check, and only then did the pre-delivery guard retire it. In that window, --wake-watchdog accepted a new attachment to it: the attach checks only that the job is active and targets the parked owner. That new task got another wake.

  • Now: recordWatchdogWakeAttempt retires the job right after recording that attempt, with the guard's own reason (park_timer_target_terminal), when no current generated binding and no live attachment remain. So a --wake-watchdog attach after that point is refused with wake_watchdog_not_live, where main accepted it in that window.

  • Scope:

  • - this applies to non-queue-wait jobs only, so repeating queue-wait jobs keep their lifecycle;
    - the timer's own-task path is unchanged;
    - a retained attempt still leaves the attachment live, so it doesn't retire anything.

    Where

    queue-wake-repository.ts, for one-shot timers (the isRepeatingTimer false branches), plus the immediate retirement above in recordWatchdogWakeAttempt (queue-repository.ts):

  • findBlockedQitemsByWatchdog: a retained fire no longer drops the row, so the attempt after it is recorded by recordWatchdogWakeAttempt. For the timer's own task, that retires the job (park_timer_fired_once); for an attached task, it consumes the attachment.

  • findLiveQitemsByAttachedWatchdog: a retained fire no longer consumes an attachment, so the pre-delivery guard (resolveWatchdogPreDeliveryTerminalReason) lets the attached task's next attempt through. A failed fire still consumes a one-shot attachment, as a failed fire already consumes the timer's own task.

  • getStatus: after a retained fire the backstop stays live and the wake isn't unconsumed, while phase: fired and deliveryStatus: retained keep the history. Because the status is live, leaving the set-aside state, or a new park, retires the old timer at once, as it does before any fire.
  • Unchanged:

  • Repeating queue-wait timers: their branches were already retrying failed and retained attempts, and are untouched.

  • Standalone operator-owned periodic watchdogs (tested: still repeating after a retained delivery).

  • Current-park selection, supersession by a new park, the ending of the original park, and shared-attachment retirement.
  • Every caller of the two predicates:

  • recordWatchdogWakeAttempt (bindings and targets): records the post-retained attempt.

  • retireParkGeneratedTimer (status live plus live attachments): an attachment with only retained attempts still protects the shared job, like an unfired one; the timer's own task now retires its timer on exit after a retained attempt.

  • Re-arm job reuse (previousJobId): an attachment with only retained attempts blocks reuse of the shared job, like an unfired one.

  • The pre-delivery guard: admits the attached task's next attempt.

  • evaluateWaitReminder: queue-wait (repeating) only, so unaffected.
  • Readers of the status (live, unconsumed) after a retained one-shot attempt, which now see a live, not-yet-used timer:

  • the wake ladder defers to that live timer instead of stepping in;

  • rig queue parked no longer flags the row as unhealthy.
  • The page (docs/reference/keeping-a-watch.md) now says what the code does: a held-back wake doesn't use the timer up; it's tried again at each interval until an attempt goes through (delivered or failed), which retires it; the same rule applies to a shared timer's attached task; and none of this is a delivery guarantee.

    Tests

    daemon/test/queue-park-wake.test.ts, through the real WatchdogScheduler (a test clock, one tick per interval), the queue's wake recorder and the status:

  • The timer's own task:

  • - a retained attempt, then a delivery that retires it;
    - three retained attempts then ok, and three retained then failed: each stays eligible, the last consumes it, and later ticks deliver nothing;
    - the status after a retained attempt (fired, retained, live, not unconsumed);
    - leaving the set-aside state retires it;
    - a new park supersedes it, with no further delivery.
  • A shared timer after the original task was stopped:

  • - a retained wake to the attached task, then a delivery that retires the job at that attempt;
    - two retained, then failed, retired at that attempt;
    - after the consuming attempt, a late --wake-watchdog attach is refused (wake_watchdog_not_live).
  • Controls:

  • - a delivered or failed first attempt still retires after one (own timer and shared);
    - a standalone operator watchdog keeps repeating;
    - the existing repeating (queue-wait) retained test still passes.

    Against main, the new retained, status, supersession and late-attach tests fail, and the controls pass.

    Existing test expectations that changed (queue-park-wake.test.ts), each for one-shot jobs only:

  • "keeps a shared watchdog deliverable after <exit>" (repeating=false), for claim, handoff, handoff-and-complete, cross-host, complete, auto-unpark and re-park. These asserted the job stays active after the attached task's delivery and is retired at the next evaluation. They now assert it's terminal right after that delivery, with reason park_timer_target_terminal. The repeating=true cases are unchanged.

  • "ONE SHARED JOB: a terminal timer row must not terminal an attached watchdog". This asserted the job is still active after the attachment's delivery; it now asserts terminal. It still asserts that the pre-delivery guard let the attachment's wake through.
  • Full gate on a8bf206d against a fresh baseline at main 005b0e05 on the same box:

  • npm run build and npm run lint: pass.

  • npm test, branch / main:

  • - repo checks: 290 / 290;
    - CLI: 4,265 / 4,265 (3 skipped each);
    - TUI: 941 / 941;
    - daemon: 15,153 passed and 9 failed / 15,143 passed and 9 failed (the 10 new tests).
  • On the final head 2c7ec6fe (the immediate retirement, added after the gate): queue-park-wake 71/71, and the queue and watchdog suites (park-wake, wake, parked-query, queue-repository, watchdog, stuck-sweep, queue-wait) 435/435. Lint passes.

  • The daemon failures are the same environment failures by signature on both: relay git-clean ×2, the scenario seed, the seat-launch Node probe ×3, terminal UTF-8, and the stub-cli-journeys verified-send pair, which differ only in their generated ids and ports.
  • A note on the commit log: the first commit (1bbafe8c, the tests on their own) says a retained wake "fires once more". The final semantics replace that: a retained attempt is retried at the interval with no retry limit, until an attempt goes through. The test titles and this description use the final wording.

    Hermetic only. Native: NOT RUN.

    🤖 Generated with Claude Code

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->

    Summary by CodeRabbit

    Bug Fixes
    Periodic reminders held back while you are typing are retried at each interval. A one-time timer retires after a delivery succeeds or fails; repeating timers retain their retry behavior.
    A shared watchdog remains active for its other task after a handoff or stop, and follows the same retry rule.
    Documentation
    * Clarified that these retry behaviors do not guarantee delivery.

    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: mvschwarz Review duration: 63m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #1222"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%