Skip to content

refactor(duplex-metrics): replace dead Binomial::new Err arm with expect - #363

Merged
nh13 merged 1 commit into
mainfrom
nh/drop-dead-binomial-err-arm
May 22, 2026
Merged

nh13 merged 1 commit into
mainfrom
nh/drop-dead-binomial-err-arm

Conversation

@nh13

@nh13 nh13 commented May 21, 2026

Copy link
Copy Markdown
Member

Summary

In calculate_ideal_duplex_fraction, the match Binomial::new(0.5, size as u64) { Err(_) => continue, … } arm is statically unreachable — statrs::distribution::Binomial::new(p, n) only returns Err(BinomialError::ProbabilityInvalid) when p is NaN or outside [0, 1] (see statrs-0.18.0/src/distribution/binomial.rs:67-70), and every call site here passes the literal 0.5.

Replace the match with .expect(\"…\") so that any future refactor letting p become dynamic surfaces the panic immediately instead of silently dropping families from the ideal-fraction calculation.

Diff

One file, 4 lines net:

- let binomial = match Binomial::new(0.5, size as u64) {
-     Ok(b) => b,
-     Err(_) => continue, // Skip if binomial creation fails
- };
+ // `Binomial::new(p, n)` only returns `Err` when `p` is NaN or
+ // outside `[0, 1]` (statrs 0.18 `BinomialError::ProbabilityInvalid`).
+ // With `p = 0.5` hardcoded the `Err` arm is statically unreachable;
+ // expect rather than silently skip so a future refactor that lets
+ // `p` become dynamic surfaces immediately instead of silently
+ // dropping families from the ideal-fraction calculation.
+ let binomial = Binomial::new(0.5, size as u64)
+     .expect(\"p = 0.5 is always a valid probability for Binomial::new\");

Behaviour

None — the replaced arm could not have fired on any input. Spotted during review of #359; sized as a separate PR per reviewer guidance to keep that PR's diff focused on the OOM fix.

Test plan

  • `cargo test --release --lib duplex_metrics` — 20 passed
  • `cargo ci-fmt`, `cargo ci-lint` clean

@nh13
nh13 temporarily deployed to github-actions May 21, 2026 01:42 — with GitHub Actions Inactive
@coderabbitai

coderabbitai Bot commented May 21, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4ba90d59-d4cf-4f0e-a5c3-ff19370e59d4

📥 Commits

Reviewing files that changed from the base of the PR and between cffd59b and 6c98524.

📒 Files selected for processing (1)
  • src/lib/commands/duplex_metrics.rs

📝 Walkthrough

Walkthrough

In calculate_ideal_duplex_fraction_per_size, Binomial::new(0.5, size as u64) was changed from a match that skipped families on Err to an expect that panics on Err. The code now assumes Binomial::new cannot fail and will abort if it does.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed Title accurately summarizes the main change: replacing an unreachable error branch with expect() in the duplex metrics code.
Description check ✅ Passed Description clearly explains the change, provides context about why the Err arm is unreachable, and documents the behavioral impact.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch nh/drop-dead-binomial-err-arm

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

@codecov

codecov Bot commented May 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.00%. Comparing base (c3b6dc6) to head (6c98524).
⚠️ Report is 7 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #363      +/-   ##
==========================================
+ Coverage   90.93%   91.00%   +0.06%     
==========================================
  Files          78       78              
  Lines       51046    51045       -1     
==========================================
+ Hits        46421    46451      +30     
+ Misses       4625     4594      -31     

☔ 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.

`statrs::distribution::Binomial::new(p, n)` returns
`BinomialError::ProbabilityInvalid` *only* when `p` is NaN or outside
`[0, 1]` (see statrs 0.18 `binomial.rs:67-70`). In
`calculate_ideal_duplex_fraction` every call site passes the literal
`0.5`, so the `Err` arm is statically unreachable — the existing
`Err(_) => continue` was harmless but silently masked the contract
that `p` is fixed at 0.5.

Replace the `match` with an `.expect(...)` so any future refactor that
lets `p` become dynamic surfaces the panic immediately rather than
silently dropping families from the ideal-fraction calculation. No
behaviour change on any current code path.
@nh13
nh13 force-pushed the nh/drop-dead-binomial-err-arm branch from cffd59b to 6c98524 Compare May 21, 2026 23:26
@nh13
nh13 had a problem deploying to github-actions May 21, 2026 23:26 — with GitHub Actions Failure
@nh13

nh13 commented May 22, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 22, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@nh13

nh13 commented May 22, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 22, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@nh13

nh13 commented May 22, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 22, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@nh13

nh13 commented May 22, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 22, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@nh13
nh13 temporarily deployed to github-actions May 22, 2026 02:08 — with GitHub Actions Inactive
@nh13

nh13 commented May 22, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 22, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@nh13
nh13 merged commit 61df264 into main May 22, 2026
16 of 17 checks passed
@nh13
nh13 deleted the nh/drop-dead-binomial-err-arm branch May 22, 2026 03:10
@nh13 nh13 mentioned this pull request May 22, 2026

This branch was previously deployed

1 inactive deployment
github-actions — 6c985241 Deployed May 22, 2026 by nh13 via coverage #1491
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