Skip to content

refactor(node): collapse the five periodic GC/log runners into one spawn_periodic helper (#1250) - #1272

Merged
thiras merged 1 commit into
mainfrom
refactor/1250-spawn-periodic
Jul 17, 2026
Merged

thiras merged 1 commit into
mainfrom
refactor/1250-spawn-periodic

Conversation

@thiras

@thiras thiras commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #1250. The five periodic runners in crates/node/src/runtime/mod.rs — run_dispatch_gc, run_region_accounting_log, run_record_store_gc, run_dht_rate_limit_gc, run_probe_rate_limit_gc — were byte-identical modulo their tick body: an interval ticker with a burned first tick and a loop { select! { biased; stop | tick } }. This collapses them into one helper:

fn spawn_periodic(&mut tasks, name, interval, tick: impl FnMut()) -> oneshot::Sender<()>

which mints the oneshot internally, spawns onto the JoinSet, and returns the stop sender. The tick bodies become closures at the call sites in run(); a shared log_keyspace_gc helper absorbs the DHT/probe two-layer log arms.

Net −276 lines (173 insertions, 449 deletions).

Behavior preserved verbatim

  • biased; stop-before-tick select ordering (prompt shutdown)
  • First-tick burn + MissedTickBehavior::Delay
  • Per-runner intervals, log levels, log field names and messages
  • Region opt-out (region_accounting_interval_sec == 0 disables + logs info)
  • Shutdown fire order (the block is untouched — same stop_tx binding names)

The load-bearing doc comments — the record-store per-publisher-quota rationale and the DHT-GC panic contract + gauge-alerting note — are relocated to their call sites rather than dropped.

One observable change (call out for log-scrapers)

The shutdown-received debug line is now a single message with a task=<name> field (task=dispatch_gc, task=record_store_gc, …) instead of five distinct strings. Debug-level only; no metric/series/log-level change.

Tests

The five duplicated shutdown-promptness tests collapse into spawn_periodic_exits_promptly_on_shutdown (which also newly pins the burned first tick), plus a new spawn_periodic_fires_the_tick_body pinning the positive path — closing a pre-existing gap where a broken tick arm would leave all five GC tasks silently dead with no failing test.

Verification

  • cargo fmt -- --check, cargo clippy -p decdn-node --all-targets, cargo build — all clean
  • cargo nextest run -p decdn-node — 835 passed, 0 failed
  • Reviewed by the pr-review-toolkit suite (code / tests / comments / silent-failure); the two test-review follow-ups (docstring accuracy + positive-path test) are folded into this branch.

Out of scope

The watcher backoff/cycle recorders (#1266), the WatcherHandle ownership inversion (#1236), and the broader teardown registry — all deferred by #1250 itself.

🤖 Generated with Claude Code

…awn_periodic helper (#1250)

The five periodic runners (run_dispatch_gc, run_region_accounting_log,
run_record_store_gc, run_dht_rate_limit_gc, run_probe_rate_limit_gc) were
byte-identical modulo their tick body: an interval ticker with a burned first
tick and a `loop { select! { biased; stop | tick } }`. Collapse them into a
single `spawn_periodic(&mut tasks, name, interval, tick)` helper that mints the
oneshot internally, spawns onto the JoinSet, and returns the stop sender. The
tick bodies become closures at the call sites in run(); a shared log_keyspace_gc
helper absorbs the DHT/probe two-layer log arms.

Behavior is preserved verbatim: biased stop-before-tick ordering, first-tick
burn, MissedTickBehavior::Delay, per-runner intervals and log levels/fields, the
region opt-out, and the shutdown fire order. The load-bearing doc comments (the
record-store per-publisher-quota rationale and the DHT-GC panic contract +
gauge-alerting note) are relocated to their call sites. The only observable
change is the shutdown debug line, now one message with a `task=<name>` field
instead of five distinct strings.

The five duplicated shutdown-promptness tests collapse into
spawn_periodic_exits_promptly_on_shutdown (which also newly pins the burned
first tick), plus spawn_periodic_fires_the_tick_body pinning the positive path.

Net -276 lines.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings July 17, 2026 20:07
@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@thiras, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 33 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Free

Run ID: 3653de93-2f47-405c-9f97-41f8908cb410

📥 Commits

Reviewing files that changed from the base of the PR and between 14f65a4 and ff2ff90.

📒 Files selected for processing (1)
  • crates/node/src/runtime/mod.rs

Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the node runtime’s periodic maintenance/logging tasks by collapsing five nearly identical “interval + burned first tick + biased stop-before-tick select” runners into a single spawn_periodic helper. This reduces duplication in crates/node/src/runtime/mod.rs while preserving the shutdown promptness contract and existing tick behavior, and it consolidates tests to cover both the shutdown path and the positive “tick body actually runs” path.

Changes:

  • Introduced spawn_periodic to encapsulate the shared periodic-task loop (burn first tick, MissedTickBehavior::Delay, biased stop-before-tick select) and return a stop sender.
  • Replaced the five prior periodic runner functions with call-site closures in run(), including a small shared log_keyspace_gc helper for DHT/probe rate-limiter sweep logs.
  • Consolidated duplicated shutdown-promptness tests into spawn_periodic_exits_promptly_on_shutdown and added spawn_periodic_fires_the_tick_body to assert the tick arm executes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions

Copy link
Copy Markdown

Coverage report

Total: 81.49% (was 81.52%, ▼ 0.03%) — 48593/59628 lines

File Coverage Lines Δ
crates/node/src/runtime/mod.rs 47.29% 967/2045 ▼ 2.78%
History
Commit Total Δ vs base
ff2ff90 (HEAD) 81.49% ▼ 0.03%

@thiras
thiras merged commit 0fed5c7 into main Jul 17, 2026
24 checks passed
@thiras
thiras deleted the refactor/1250-spawn-periodic branch July 17, 2026 20:19
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.

refactor(node): collapse the five periodic GC/log runners into one spawn_periodic helper

2 participants