Skip to content

fix(daemon): re-arm stuck sweep with live interval config on each pass (Refs #3635) - #4089

Open
shravansumanthanan wants to merge 1 commit into
mvschwarz:mainfrom
shravansumanthanan:fix/3635-stuck-sweep-dynamic-interval
Open

shravansumanthanan wants to merge 1 commit into
mvschwarz:mainfrom
shravansumanthanan:fix/3635-stuck-sweep-dynamic-interval

Conversation

@shravansumanthanan

@shravansumanthanan shravansumanthanan commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Replace setInterval in startStuckSweepScheduler (packages/daemon/src/index.ts) with a self-rearming setTimeout that calls resolveStuckSweepIntervalSeconds() after each pass finishes, so rig config set queue.stuck_sweep_interval_seconds takes effect on the next pass without a daemon restart and passes never overlap.
  • Return a { stop(): void } handle cleared during daemon shutdown, while keeping runningSince and skippedTicks (always 0) on stuckSweepStatus for /healthz compatibility.
  • Update packages/daemon/test/queue-stuck-sweep-scheduler.test.ts and add a regression test verifying dynamic interval updates and stop().

Verification

  • npm -w @openrig/daemon test -- test/queue-stuck-sweep-scheduler.test.ts (3/3 passed)
  • npm run lint (passed)

Refs #3635 (addresses item 3: interval read only at boot)

Summary by CodeRabbit

  • Bug Fixes
    • Queue checks now run sequentially, preventing overlapping passes when a check takes longer than expected.
    • The next check is scheduled after the current one finishes, and uses the latest configured interval.
    • Stopping the scheduler cancels any pending check and prevents future passes.

@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The stuck-sweep scheduler now runs its first pass immediately and schedules each next pass after the current pass settles. It returns a stop() handle, and shutdown uses that handle. Tests cover non-overlap, interval changes, status values, and stopping.

Changes: Stuck sweep scheduler

Layer / File(s) Summary
Scheduler lifecycle and validation
packages/daemon/src/index.ts, packages/daemon/test/queue-stuck-sweep-scheduler.test.ts
The scheduler replaces fixed-interval ticks with a timeout re-armed after each sweep settles. It returns a stop() handle, which shutdown uses to clear a pending timeout. Tests verify sequential passes, interval re-reading, skippedTicks values, and stopping.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Daemon
  participant Scheduler
  participant Sweep
  participant Timer
  Daemon->>Scheduler: Start scheduler
  Scheduler->>Sweep: Run initial pass
  Sweep-->>Scheduler: Pass settles
  Scheduler->>Timer: Arm timeout using current interval
  Timer-->>Scheduler: Timeout fires
  Scheduler->>Sweep: Run next pass
  Daemon->>Scheduler: Stop scheduler
  Scheduler->>Timer: Clear pending timeout
Loading

Possibly related issues

  • Issue 3635 describes the stuck-sweep interval being read only at daemon startup. This PR re-reads the interval when it schedules each new pass.

Possibly related PRs

  • mvschwarz/openrig#2705: This PR changes the same scheduler’s overlap behavior from skipped fixed-interval ticks to sequential, re-armed timeouts.
  • mvschwarz/openrig#2649: This PR also adds single-flight behavior and status fields for stuck sweeps, which this change retains while altering the scheduling method.

Suggested reviewers: billbenetti, openrig-review

Merge Risk: Minimal · up to e03c4

The stuck-sweep scheduler now picks up interval changes without a daemon restart and no longer overlaps passes. Shutdown stops it cleanly. No actionable merge risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: the stuck sweep scheduler now re-arms after each pass and reads the live interval config. It also names the daemon scope and the issue reference. The title is specific…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: the stuck sweep scheduler now re-arms after each pass and reads the live interval config. It also names the daemon scope and the issue reference. The title is specific and matches the summary and objectives.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 26cfc057-9913-457e-a3d9-b681cbd82f91
Commits

Reviewing files that changed from the base of the PR and between 54b02f6 and e03c4b4.

Files selected for processing: 2

  • packages/daemon/src/index.ts
  • packages/daemon/test/queue-stuck-sweep-scheduler.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

@mvschwarz mvschwarz moved this to In Progress in OpenRig roadmap Nov 28, 2026
@mvschwarz mvschwarz added this to the v0.7.26 milestone Nov 28, 2026
@mvschwarz

Copy link
Copy Markdown
Owner

Thanks, @shravansumanthanan, for this and for building on @billbenetti's #3635 report: a small change inside the existing scheduler, with no new setting, and a test for the live interval.

Two independent reviews read the source at e03c4b42. Reading the interval on each pass is right. One change, please, to keep the existing hang signal:

  • Keep the sweep loud while a pass hangs. On main, a tick that arrives while a pass is still running is skipped, logged as [stuck-sweep] tick skipped: the pass started at … is still running (N tick(s) skipped), and counted in skippedTicks on /healthz; its comment says "Never silent". Here the next pass is armed only in the running pass's finally, so a pass that never settles never re-arms, nothing is logged, and skippedTicks stays 0. Please keep the existing guard with its log and status lines as they are, and replace setInterval with a setTimeout that re-arms itself at the top of runOnce, before the guard, each time with a fresh resolveStuckSweepIntervalSeconds(). That keeps the live interval and no overlap, keeps a hung pass visible on every tick, and stop() still clears the pending timer. The status test's skippedTicks expectation goes back to main's, and your live-interval test still applies with its timer calls moved to the start of runOnce.

    If you'd rather keep re-arming on completion, the hang needs to show somewhere else, and skippedTicks should go rather than stay at 0.

This is from reading the source; I haven't run the PR locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

2 participants