Skip to content

fix(scheduler): compute overlap_ms via union, not pairwise sum - #757

Merged
EffortlessSteven merged 2 commits into
mainfrom
claude/bug-fix-review-rcflga
Jul 11, 2026
Merged

EffortlessSteven merged 2 commits into
mainfrom
claude/bug-fix-review-rcflga

Conversation

@EffortlessSteven

@EffortlessSteven EffortlessSteven commented Jul 11, 2026 •

Copy link
Copy Markdown
Member

Summary

  • overlap_ms (src/main.rs) computed investigation_proof_overlap_ms / model_proof_overlap_ms / proof_overlap_ms by summing overlap across every (left, right) interval pair. When either side already held multiple intervals that overlap each other (pipelined model/proof sub-phases — the same hazard union_wall_ms was written to guard against for wall_ms, see LoopAccumulator::record), the shared wall-clock window got counted once per overlapping pair, inflating the scheduler metric.
  • Rewrote overlap_ms to compute the overlap via inclusion-exclusion (union_wall_ms(left) + union_wall_ms(right) - union_wall_ms(combined)), reusing the existing union_wall_ms helper. This is exact regardless of self-overlap on either side, and mathematically identical to the old formula in the already-common non-self-overlapping case (verified against the existing run_loop_metrics_count_actual_model_proof_overlap test, which still passes unchanged).
  • Added run_loop_overlap_ms_does_not_double_count_self_overlapping_side, a regression test demonstrating the fix. Reworked its interval values so the three intermediate unions the formula combines are pairwise distinct (an earlier version had all three coincidentally equal to 150ms, a weak oracle that a wrong-operand mutation couldn't have failed under); with the stronger values, the old buggy pairwise sum gives 170ms against the correct union-based 120ms.
  • The self-hosted ub-review/gate CI run flagged both new saturating_add/saturating_sub call sites as RIPR "weakly exposed" (mutation-exposure) findings even with the strengthened test — RIPR 0.10.0 can't trace the assertion through the RunLoopTracker::metrics() -> overlap_ms() indirection to the function's private intermediate locals, the same known limitation already suppressed elsewhere in this repo for src/enable.rs under chore(tools): align RIPR 0.10.0 finding-ID contract #737. Added two matching .ripr/suppressions.toml receipts; verified locally with ripr check --diff ... --mode ready that unsuppressed_exposure_gaps drops from 2 to 0 (status: pass).

Policy receipts

If this PR adds or changes any controlled surface, link the TOML receipt here:

  • source-tree exceptions in policy/allow.toml: none added — .ripr/suppressions.toml is already covered by the existing non-rust-ripr-suppressions glob receipt (policy/allow.toml, review_after 2026-07-22)
  • expensive CI lanes or risk packs: none
  • ripr or unsafe-review suppressions, only if needed: added 2 ripr exposure-gap suppressions (probe:src_main.rs:return_value:54397ad5, probe:src_main.rs:return_value:d3368aab) — see .ripr/suppressions.toml, both linking issue chore(tools): align RIPR 0.10.0 finding-ID contract #737

Verification

Cheapest relevant proof first, deeper proof where it buys signal.

  • Rust fast gate — cargo fmt --all -- --check, cargo check --workspace --all-targets --locked, cargo clippy --workspace --all-targets --locked -- -D warnings all clean
  • cargo test --workspace --all-targets --locked — 626 + 54 + 18 tests pass (1 pre-existing ignored subprocess-driver test, unrelated)
  • policy ledger parse/check — cargo xtask policy-check passes (6 policy files, 11 allow receipts, 5 CI lanes, 2 risk packs; unchanged by this PR)
  • ripr check --root . --diff <local diff> --mode ready locally — confirmed unsuppressed_exposure_gaps: 0, status: pass after adding the suppression receipts (the first push failed the gate on this: new_unsuppressed=2 exceeds configured maximum 0)
  • deep lanes only when label/reason requires them — not needed, this is a pure-logic fix to a metrics helper with unit-test coverage

CI budget

  • Planned band: pennies
  • Reason for elevated or higher band: n/a — single-function fix + one unit test, no heavy witnesses touched

Agent notes

  • Prefer small SRP PRs.
  • Do not use bare #[allow]; use #[expect(..., reason = "...")] with a receipt.
  • ripr is static mutation-exposure analysis; runtime mutation remains the slower backstop.
  • unsafe-review owns unsafe/native reviewability; do not duplicate it in repo scripts.
  • xtask should orchestrate repo-local receipts and checks, not replace specialized tools.
  • CI cost discipline exists so we can afford more verification, not less.

overlap_ms summed overlap across every (left, right) interval pair, so
when either side already held multiple intervals that overlap each
other (pipelined model/proof sub-phases), the shared wall-clock window
got counted once per overlapping pair and inflated
investigation_proof_overlap_ms / model_proof_overlap_ms /
proof_overlap_ms in scheduler.json. union_wall_ms already guards the
same hazard for wall_ms (see LoopAccumulator::record); overlap_ms now
reuses it via inclusion-exclusion (|A| + |B| - |A ∪ B|), which is
exact whether or not either side self-overlaps.

Adds a regression test demonstrating the double-count the old
pairwise sum produced (200ms) versus the correct union-based overlap
(150ms).
@coderabbitai

coderabbitai Bot commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

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

Next review available in: 36 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: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 625cc2f6-4914-496a-9c02-be5f9f812443

📥 Commits

Reviewing files that changed from the base of the PR and between 9365f6a and f413b71.

📒 Files selected for processing (2)
  • .ripr/suppressions.toml
  • src/main.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/bug-fix-review-rcflga

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.

@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@github-actions github-actions 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.

Decision

  • Needs reviewer attention before upstream: findings remain.

Confirmed findings

  • overlap_ms now heap-allocates a Vec on every call (left+right len), replacing a pure saturating_add loop. For typical scheduler fan-out this is small, but the prior version was allocation-free; worth a note in PR or a SmallVec/reuse-buffer if metrics() is called frequently.
  • contract-mirror lane found no mirror-pair drift. overlap_ms is a Rust-internal scheduler metric with no Bun/Python verifier twin in docs/REVIEW_LEDGER.md. Late-phase cargo-check/clippy/test/doc receipts gate compilation and behavior; cross-language parity is not applicable to this diff.

Verification questions

  • Confirm single caller of overlap_ms is RunLoopTracker::metrics; union_wall_ms is the same file, no behavior drift beyond metrics helper.
  • Confirm pR claims 'mathematically identical to the old formula in the already-common non-self-overlapping case' but does not prove via test or proof receipt — only via one existing test name.
  • Confirm new regression test depends on union_wall_ms correctly handling multi-interval self-overlap, but no dedicated unit test exists for that helper in the visible diff/ledger.
  • Confirm pR author claims run_loop_metrics_count_actual_model_proof_overlap still passes unchanged — this is a Rust-side behavioral test, not a verifier mirror parity check; cannot be cross-checked mechanically by the Bun/Python verifier.
  • Confirm pR claims the existing run_loop_metrics_count_actual_model_proof_overlap test still passes unchanged — checks that pairwise-equivalence claim is also test-pinned, not merely argued.
  • Confirm three lane requests (proof-0005/0007/0008/0009) duplicate the same single-test proof already merged into the red-green task proof-red-green-40f04a925995; running them as separate focused tests would consume the max_focused_tests=4 budget without changing the gate outcome.

Refuted

  • Pairwise sum is correct in all cases; refuted because: Inclusion-exclusion via union_wall_ms is exact regardless of self-overlap; pairwise sum over-counts when a side has multiple overlapping intervals sharing the same wall window. Regression test demonstrates 200ms→150ms correction.
  • Bun/Python verifier must be updated to track overlap_ms union formula change; refuted because: docs/REVIEW_LEDGER.md mirror-pair map does not list any scheduler metrics or overlap_ms as a mirrored contract; scripts/verify-bun-review-artifacts.py pins phrase/schema mirrors listed in the ledger, none of which this diff touches.
  • Could overlap_ms feed gate_outcome or a reason-kind and thereby redden the gate if union_wall_ms is wrong?; refuted because: overlap_ms is consumed only by tracker.metrics() metric fields (investigation_proof_overlap_ms, model_proof_overlap_ms, proof_overlap_ms); these are report metrics, not gate_outcome inputs. Gate-semantics lane scope is gate_outcome/reason-kinds/[gate] policy keys/fail-on-gate resolution/pass policy; none are touched.

Proof results

Parked follow-ups

Evidence gaps

[review body truncated; see review artifacts]

@codecov

codecov Bot commented Jul 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

…PR gap

The overlap_ms regression test used interval values where the three
intermediate unions (model's, proof's, and their combination) all
happened to equal 150ms — a coincidental tie that a wrong-operand
mutation of the formula couldn't have failed under. Rework the
intervals so all three quantities (and the expected overlap) are
pairwise distinct, giving each operand in the inclusion-exclusion
formula its own value to be pinned against.

The self-review gate still flagged both saturating_add/saturating_sub
call sites as weakly exposed even with the stronger oracle: RIPR 0.10.0
cannot trace the assertion through the RunLoopTracker::metrics() ->
overlap_ms() indirection to the intermediate locals inside the helper
(the same limitation already suppressed for src/enable.rs under #737).
Add matching .ripr/suppressions.toml receipts for both probes; verified
locally with `ripr check --diff ... --mode ready` that this drops
unsuppressed_exposure_gaps from 2 to 0 (status: pass).
@EffortlessSteven
EffortlessSteven marked this pull request as ready for review July 11, 2026 22:24
@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@EffortlessSteven
EffortlessSteven merged commit 9838259 into main Jul 11, 2026
4 checks passed
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.

2 participants