Skip to content

refactor(pipeline): deduplicate scheduler constants and shared functions - #150

Merged
nh13 merged 1 commit into
mainfrom
refactor/nh/simplify-fgumi-pipeline
Mar 4, 2026
Merged

nh13 merged 1 commit into
mainfrom
refactor/nh/simplify-fgumi-pipeline

Conversation

@nh13

@nh13 nh13 commented Mar 3, 2026

Copy link
Copy Markdown
Member

Summary

  • Replace per-scheduler STEPS constant (11 copies) with existing PipelineStep::all() method
  • Replace per-scheduler step_index() method (10 copies) with existing PipelineStep::index() method
  • Extract shared balanced_chase_determine_role() to scheduler/mod.rs, replacing identical copies in balanced_chase.rs and balanced_chase_drain.rs

Net: -204 lines across 12 files.

Test plan

  • cargo nextest run -p fgumi --filter-expr 'test(scheduler) | test(pipeline) | test(unified)' — 339 tests pass
  • cargo ci-fmt — clean
  • cargo ci-lint — clean

@nh13
nh13 temporarily deployed to github-actions March 3, 2026 04:00 — with GitHub Actions Inactive
@codecov

codecov Bot commented Mar 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.66667% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.86%. Comparing base (3a460ea) to head (5a7c603).
⚠️ Report is 13 commits behind head on main.

Files with missing lines Patch % Lines
...c/lib/unified_pipeline/scheduler/balanced_chase.rs 66.66% 3 Missing ⚠️
...lib/unified_pipeline/scheduler/chase_bottleneck.rs 84.61% 2 Missing ⚠️
...c/lib/unified_pipeline/scheduler/epsilon_greedy.rs 50.00% 2 Missing ⚠️
...lib/unified_pipeline/scheduler/learned_affinity.rs 50.00% 2 Missing ⚠️
...unified_pipeline/scheduler/thompson_with_priors.rs 33.33% 2 Missing ⚠️
.../lib/unified_pipeline/scheduler/optimized_chase.rs 87.50% 1 Missing ⚠️
...unified_pipeline/scheduler/sticky_work_stealing.rs 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #150      +/-   ##
==========================================
+ Coverage   83.61%   83.86%   +0.25%     
==========================================
  Files         126      127       +1     
  Lines       51510    51148     -362     
==========================================
- Hits        43069    42895     -174     
+ Misses       8441     8253     -188     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai

coderabbitai Bot commented Mar 3, 2026 •

Copy link
Copy Markdown

Warning

Rate limit exceeded

@nh13 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 24 minutes and 33 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f6853a94-cf95-44e4-84f1-71b664867358

📥 Commits

Reviewing files that changed from the base of the PR and between 51b236c and 5a7c603.

📒 Files selected for processing (12)
  • src/lib/unified_pipeline/scheduler/backpressure_proportional.rs
  • src/lib/unified_pipeline/scheduler/balanced_chase.rs
  • src/lib/unified_pipeline/scheduler/balanced_chase_drain.rs
  • src/lib/unified_pipeline/scheduler/chase_bottleneck.rs
  • src/lib/unified_pipeline/scheduler/epsilon_greedy.rs
  • src/lib/unified_pipeline/scheduler/learned_affinity.rs
  • src/lib/unified_pipeline/scheduler/mod.rs
  • src/lib/unified_pipeline/scheduler/optimized_chase.rs
  • src/lib/unified_pipeline/scheduler/sticky_work_stealing.rs
  • src/lib/unified_pipeline/scheduler/thompson_sampling.rs
  • src/lib/unified_pipeline/scheduler/thompson_with_priors.rs
  • src/lib/unified_pipeline/scheduler/ucb.rs
📝 Walkthrough

Walkthrough

This pull request refactors scheduler implementations to use dynamic step resolution instead of static constants. Static STEPS arrays and helper methods like step_index() are removed across multiple scheduler files and replaced with PipelineStep::all() for runtime retrieval. Direct index access via step.index() replaces the previous lookup approach. A new non-public helper function balanced_chase_determine_role() is added to the scheduler module. Public API signatures remain unchanged; changes are internal implementation refactors affecting approximately 13 files with net reduction in lines of code.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed Title clearly and concisely summarizes the main refactoring goal: deduplicating scheduler constants and functions across the codebase.
Description check ✅ Passed Description accurately details the three main changes (STEPS deduplication, step_index replacement, shared function extraction) with test results and net line reduction.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/nh/simplify-fgumi-pipeline

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

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

@coderabbitai coderabbitai Bot 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/lib/unified_pipeline/scheduler/balanced_chase.rs (1)

39-58: ⚠️ Potential issue | 🟠 Major

Add num_threads > 0 guard to constructor before delegating to helper.

The helper balanced_chase_determine_role() evaluates num_threads - 1 and num_threads - 2 in conditions (lines 369, 373 in mod.rs). These expressions are evaluated before their corresponding guards (num_threads > 1, num_threads > 3), causing panics in debug builds if num_threads == 0. Adding a precondition in the constructor prevents this class of error at the call boundary.

Proposed fix
 pub fn new(thread_id: usize, num_threads: usize, active_steps: ActiveSteps) -> Self {
+    assert!(num_threads > 0, "num_threads must be > 0");
     let (current_step, exclusive_role) = Self::determine_role(thread_id, num_threads);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/lib/unified_pipeline/scheduler/balanced_chase.rs` around lines 39 - 58,
In the constructor new(thread_id, num_threads, active_steps) add a precondition
that num_threads > 0 before calling determine_role to avoid downstream underflow
in balanced_chase_determine_role; e.g., validate (panic/assert) with a clear
message or return an error when num_threads == 0, then call
Self::determine_role(thread_id, num_threads) as before so determine_role and
balanced_chase_determine_role never see num_threads == 0.
🧹 Nitpick comments (1)
src/lib/unified_pipeline/scheduler/backpressure_proportional.rs (1)

85-87: Hoist PipelineStep::all() outside the loop.

Small readability/perf improvement: avoid rebuilding the step array each iteration.

♻️ Proposed refactor
-        for (priority, (_, step_idx)) in weighted.iter().enumerate() {
-            self.priority_buffer[priority] = PipelineStep::all()[*step_idx];
-        }
+        let steps = PipelineStep::all();
+        for (priority, (_, step_idx)) in weighted.iter().enumerate() {
+            self.priority_buffer[priority] = steps[*step_idx];
+        }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/lib/unified_pipeline/scheduler/backpressure_proportional.rs` around lines
85 - 87, The loop repeatedly calls PipelineStep::all(), rebuilding the same
array each iteration; hoist that call out of the for-loop by assigning let
all_steps = PipelineStep::all() before iterating and then use
all_steps[*step_idx] when populating self.priority_buffer[priority] (the loop
over weighted, the priority_buffer assignment and the weighted/step_idx
variables identify the spot to change).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@src/lib/unified_pipeline/scheduler/balanced_chase.rs`:
- Around line 39-58: In the constructor new(thread_id, num_threads,
active_steps) add a precondition that num_threads > 0 before calling
determine_role to avoid downstream underflow in balanced_chase_determine_role;
e.g., validate (panic/assert) with a clear message or return an error when
num_threads == 0, then call Self::determine_role(thread_id, num_threads) as
before so determine_role and balanced_chase_determine_role never see num_threads
== 0.

---

Nitpick comments:
In `@src/lib/unified_pipeline/scheduler/backpressure_proportional.rs`:
- Around line 85-87: The loop repeatedly calls PipelineStep::all(), rebuilding
the same array each iteration; hoist that call out of the for-loop by assigning
let all_steps = PipelineStep::all() before iterating and then use
all_steps[*step_idx] when populating self.priority_buffer[priority] (the loop
over weighted, the priority_buffer assignment and the weighted/step_idx
variables identify the spot to change).

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3a460ea and 51b236c.

📒 Files selected for processing (12)
  • src/lib/unified_pipeline/scheduler/backpressure_proportional.rs
  • src/lib/unified_pipeline/scheduler/balanced_chase.rs
  • src/lib/unified_pipeline/scheduler/balanced_chase_drain.rs
  • src/lib/unified_pipeline/scheduler/chase_bottleneck.rs
  • src/lib/unified_pipeline/scheduler/epsilon_greedy.rs
  • src/lib/unified_pipeline/scheduler/learned_affinity.rs
  • src/lib/unified_pipeline/scheduler/mod.rs
  • src/lib/unified_pipeline/scheduler/optimized_chase.rs
  • src/lib/unified_pipeline/scheduler/sticky_work_stealing.rs
  • src/lib/unified_pipeline/scheduler/thompson_sampling.rs
  • src/lib/unified_pipeline/scheduler/thompson_with_priors.rs
  • src/lib/unified_pipeline/scheduler/ucb.rs

Replace per-scheduler STEPS constant (11 copies) with PipelineStep::all()
and per-scheduler step_index() method (10 copies) with PipelineStep::index(),
both of which already exist on PipelineStep. Extract shared
balanced_chase_determine_role() function to scheduler/mod.rs, replacing
identical copies in balanced_chase.rs and balanced_chase_drain.rs.
@nh13
nh13 force-pushed the refactor/nh/simplify-fgumi-pipeline branch from 51b236c to 5a7c603 Compare March 4, 2026 06:15
@nh13
nh13 temporarily deployed to github-actions March 4, 2026 06:15 — with GitHub Actions Inactive
@nh13
nh13 merged commit e7fe89c into main Mar 4, 2026
6 of 7 checks passed
@nh13
nh13 deleted the refactor/nh/simplify-fgumi-pipeline branch March 4, 2026 06:22
@nh13 nh13 mentioned this pull request Mar 4, 2026

This branch was previously deployed

1 inactive deployment
github-actions — 5a7c6037 Deployed Mar 4, 2026 by nh13 via coverage #561
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