Fix #123: Use correct pooled standard deviation formula in multi-worker aggregation#142
Fix #123: Use correct pooled standard deviation formula in multi-worker aggregation#142mcurrier2 wants to merge 1 commit into
Conversation
…er aggregation The previous implementation computed std_dev as sqrt(sum(n_i * sigma_i^2) / N), which only accounts for within-group variance. When workers have different mean latencies, this significantly underestimates the true combined standard deviation. Apply the law of total variance: Var(X) = E[Var(X|G)] + Var(E[X|G]), which adds between-group variance (weighted squared deviation of each worker's mean from the combined mean) to the within-group variance. - Fix pooled std_dev formula in aggregate_latency_metrics() - Add test verifying between-group mean differences are captured - Add test verifying same-mean case still produces correct result - All existing tests passing, clippy clean AI-assisted-by: Claude Opus 4.6 Co-authored-by: Cursor <cursoragent@cursor.com>
📝 WalkthroughSummary by CodeRabbit
WalkthroughAdds three planning/documentation Markdown files (release-polish-plan.glow, release-polish-plan.md, tier1-pr-diffs.md) recording a release-polish review pass, filed issues, and Tier 1 PR diffs. Separately, corrects the pooled standard deviation formula in metrics.rs multi-worker latency aggregation and adds two unit tests. ChangesRelease Polish Planning Documentation
Pooled Standard Deviation Fix
Estimated code review effort: 3 (Moderate) | ~25 minutes Related issues: Suggested labels: documentation, bug, metrics Suggested reviewers: (none identified) 🐰 A pooled variance once ran astray, 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.cursor/plans/release-polish-plan.md:
- Around line 108-115: The release validation summary is inconsistent between
the plan documents, with mismatched test totals and modified-file counts. Update
the Validation summary in the release-polish plan using the same authoritative
numbers as the corresponding release-polish-plan.glow entry, and ensure both
summaries in the release-plan documents reflect identical counts. Keep the fix
localized to the Validation section and the release summary fields so the two
files stay synchronized.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Enterprise
Run ID: 692b7130-f254-4965-b23c-1b0a49e6dac7
⛔ Files ignored due to path filters (6)
.cursor/plans/benchmark-chore-release-polish.csvis excluded by!**/*.csv.cursor/plans/benchmark-fix-121-blocking-forward-duration.csvis excluded by!**/*.csv.cursor/plans/benchmark-fix-122-blocking-roundtrip-first-message.csvis excluded by!**/*.csv.cursor/plans/benchmark-fix-124-async-server-flag-forwarding.csvis excluded by!**/*.csv.cursor/plans/benchmark-fix-129-server-exit-status-check.csvis excluded by!**/*.csv.cursor/plans/benchmark-fix-131-shm-direct-mutex-init-checks.csvis excluded by!**/*.csv
📒 Files selected for processing (4)
.cursor/plans/release-polish-plan.glow.cursor/plans/release-polish-plan.md.cursor/plans/tier1-pr-diffs.mdsrc/metrics.rs
| ## Validation | ||
|
|
||
| ``` | ||
| cargo fmt ✓ (no changes) | ||
| cargo clippy ✓ (0 warnings with -D warnings) | ||
| cargo test ✓ (42 passed, 0 failed) | ||
| cargo build ✓ | ||
| ``` |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '--- files ---\n'
git ls-files '.cursor/plans/release-polish-plan.md' '.cursor/plans/release-polish-plan.glow' || true
printf '\n--- md lines 100-150 ---\n'
sed -n '100,150p' .cursor/plans/release-polish-plan.md | cat -n
printf '\n--- glow lines 100-150 ---\n'
sed -n '100,150p' .cursor/plans/release-polish-plan.glow | cat -nRepository: redhat-performance/rusty-comms
Length of output: 259
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '--- file stats ---\n'
wc -l .cursor/plans/release-polish-plan.md .cursor/plans/release-polish-plan.glow
printf '\n--- md validation/search ---\n'
rg -n "cargo (fmt|clippy|test|build)|passed|modified|files" .cursor/plans/release-polish-plan.md
printf '\n--- glow validation/search ---\n'
rg -n "cargo (fmt|clippy|test|build)|passed|modified|files" .cursor/plans/release-polish-plan.glowRepository: redhat-performance/rusty-comms
Length of output: 259
🏁 Script executed:
#!/bin/bash
set -euo pipefail
python3 - <<'PY'
from pathlib import Path
for p in [Path('.cursor/plans/release-polish-plan.md'), Path('.cursor/plans/release-polish-plan.glow')]:
print(f'--- {p} ---')
text = p.read_text()
for needle in ['42 passed', '472 passed', '17', '16', 'cargo fmt', 'cargo clippy', 'cargo test', 'cargo build']:
if needle in text:
print('contains', needle)
PYRepository: redhat-performance/rusty-comms
Length of output: 499
🏁 Script executed:
#!/bin/bash
set -euo pipefail
python3 - <<'PY'
from pathlib import Path
for p in [Path('.cursor/plans/release-polish-plan.md'), Path('.cursor/plans/release-polish-plan.glow')]:
print(f'FILE: {p}')
try:
text = p.read_text()
except Exception as e:
print('ERROR:', e)
continue
for i, line in enumerate(text.splitlines(), 1):
if 100 <= i <= 150:
print(f'{i:4d}: {line}')
PYRepository: redhat-performance/rusty-comms
Length of output: 9171
Reconcile the release summary across .cursor/plans/release-polish-plan.md and .cursor/plans/release-polish-plan.glow. The validation totals and modified-file counts diverge (42 passed vs 472 passed, 17 vs 16 files), so one authoritative summary needs to be synced in both places.
🧰 Tools
🪛 markdownlint-cli2 (0.22.1)
[warning] 110-110: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In @.cursor/plans/release-polish-plan.md around lines 108 - 115, The release
validation summary is inconsistent between the plan documents, with mismatched
test totals and modified-file counts. Update the Validation summary in the
release-polish plan using the same authoritative numbers as the corresponding
release-polish-plan.glow entry, and ensure both summaries in the release-plan
documents reflect identical counts. Keep the fix localized to the Validation
section and the release summary fields so the two files stay synchronized.
📈 Changed lines coverage: 100.00% (9/9)✅ All new and modified lines are covered by tests!📊 Code Coverage Summary
|
Summary
aggregate_latency_metrics()to use the law of total variance:Var(X) = E[Var(X|G)] + Var(E[X|G]), which accounts for between-group mean differencessqrt(sum(n_i * sigma_i^2) / N)only computed within-group variance, underestimating combined std_dev when workers have different mean latenciesTest plan
test_pooled_stddev_between_group_varianceverifies between-group differences are capturedtest_pooled_stddev_same_meansverifies same-mean case still worksFixes #123
Made with Cursor