You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The old manager computation included a second gate: if avg > CPU_USAGE_MAX { up &= true; } else { up &= false; break; }. The unified get_up_windows only checks the slope threshold, so the manager path no longer requires CPU usage above CPU_USAGE_MAX for a window to count as "up". This silently changes get_manager_count behavior: windows that were previously rejected due to low manager CPU usage are now accepted, which can produce a lower (and incorrect) mgr_power minimum. In the new code the computed avg is also now unused, which corroborates that the check was lost rather than intentionally relocated.
This slice panics if result.len() is not an exact multiple of WINDOWS, or if the float-equality-based break condition never matches before counter walks past the end of result. Use a bounds-checked slice and break cleanly when the data is exhausted, turning a potential panic into graceful termination.
- current_windows = result[(counter*WINDOWS) as usize..((counter+1)*WINDOWS) as usize].to_vec();+ let start = (counter * WINDOWS) as usize;+ if start >= result.len() {+ break;+ }+ let end = (((counter + 1) * WINDOWS) as usize).min(result.len());+ current_windows = result[start..end].to_vec();
Suggestion importance[1-10]: 7
__
Why: This addresses a real panic risk: the slice result[(counter*WINDOWS)..((counter+1)*WINDOWS)] will panic if result.len() is not an exact multiple of WINDOWS before the break condition triggers. The bounds-checked slice with a clean break converts a hard panic into graceful termination, matching the PR's refactored get_up_windows logic. Slightly reduced because the partial-window case could desync with the full-window avg_cpu_usage indexing, but the core fix is valid and important.
Medium
Prevent NaN from empty slope vectors
If current_windows is empty (e.g., when result is exhausted but the break condition hasn't triggered), the inner for loop never runs, up remains true, and an empty tmp_slope_vector is pushed. Downstream, dividing by tmp_slope_vector.len() as f64 yields NaN, and the later partial_cmp(...).expect(...) calls in get_recycler_count/get_manager_count will panic because NaN comparisons return None. Guard against empty windows before pushing.
- if up {+ if up && !tmp_slope_vector.is_empty() {
up_windows.push((counter, tmp_slope_vector.clone()));
}
Suggestion importance[1-10]: 3
__
Why: The downstream NaN/panic chain described (empty tmp_slope_vector producing NaN, then partial_cmp failing) is logically accurate, but an empty current_windows cannot actually occur here: result[(counter*WINDOWS)..((counter+1)*WINDOWS)] would panic on out-of-bounds rather than return an empty slice, so an empty tmp_slope_vector with up == true is effectively unreachable. The guard is a harmless defensive improvement with low practical impact.
Low
Author self-review: I have reviewed the PR code suggestions, and addressed the relevant ones.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Type
Enhancement
Description
Extract shared
get_up_windowswindow-detection logicAdd
get_window_cpu_average_vectorCPU averaging helperReuse unified logic in recycler and manager computations
Remove resolved duplication issue from
ISSUES.mdDiagram Walkthrough
File Walkthrough
flow_threads.rs
Unify recycler and manager window computationsrc/flow_threads.rs
get_up_windowswith
thresholdandaboveparametersget_window_cpu_average_vectorhelper for per-window CPU usageaveraging
get_recycler_countand manager computation to consume theshared function
upflag each iteration and useWINDOWSinstead of hardcoded3intail check
ISSUES.md
Remove resolved code duplication issueISSUES.md