Skip to content

fix(lsp): push budget must distinguish empty-selected from computation-failed (#2042 follow-up) - #2120

Merged
EffortlessSteven merged 1 commit into
mainfrom
codex/push-budget-empty-selected-fix
Jul 21, 2026
Merged

EffortlessSteven merged 1 commit into
mainfrom
codex/push-budget-empty-selected-fix

Conversation

@EffortlessSteven

Copy link
Copy Markdown
Member

Problem (found in post-merge review of #2042)

The push-delivery budget application in backend.rs used budget_selected_ids.is_empty() as the fallback signal. That check conflated two opposite cases:

  1. Budget computation failed (.ok() chain returned None → fallback). Falling back to 'publish everything' is correct here — there is no honest budget to apply.
  2. Budget computation SUCCEEDED but selected zero items (all ProfileFiltered, or the per-document/workspace cap dropped everything). The honest result is 'publish nothing for these items.' The is_empty() check instead published everything — the exact opposite of what the budget intended.

This is on the user-facing diagnostic delivery path: a tight budget that correctly selected zero items would silently publish all the diagnostics the budget was supposed to suppress.

Change

Return Option<BTreeSet<String>> from the budget step:

let budget_selected_ids: Option<BTreeSet<String>> = /* ... */;
// ...
let diagnostics_to_publish = match &budget_selected_ids {
    // Computation failed — no honest budget, fall back to publishing everything.
    None => batch.diagnostics.clone(),
    // Computed (even if empty) — apply it. An empty set means the budget
    // legitimately dropped everything; publish only items in the set.
    Some(selected_ids) => { /* filter */ }
};

An empty Some(set) now correctly publishes only items in the set (nothing), which is what a tight budget means.

Test

Add all_profile_filtered_yields_empty_selected_not_an_error to crates/ripr/src/lsp/diagnostic_budget.rs. It constructs two ProfileFiltered items, evaluates the budget, and asserts:

  • evaluation succeeds (returns Ok, not Err)
  • selected_ids is empty
  • eligible_items is 0
  • overflowed is false

This pins the contract the backend.rs fix depends on: empty-selected is a legitimate result, not a fallback signal.

Evidence

cargo build -p ripr                              PASS
cargo clippy -p ripr --all-targets -- -D warnings  PASS
cargo test -p ripr --lib diagnostic_budget       PASS (12 tests, 1 new)

Scope

Two-file change:

  • crates/ripr/src/lsp/backend.rs: budget step returns Option, match replaces is_empty check (~20 lines changed in the push block).
  • crates/ripr/src/lsp/diagnostic_budget.rs: one new regression test (~25 lines).

No schema change. No behavior change for the common case (budget succeeds with non-empty selected). Fixes the inversion bug for the empty-selected edge case. Follow-up to #2042 (merged).

Non-goals

  • Does NOT change the budget evaluation logic itself.
  • Does NOT add a full backend integration test for the push path (that would require a complete Backend fixture; the unit test at the budget layer pins the contract the fix depends on).

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Jul 21, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

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

Next review available in: 1 minute

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 Plus

Run ID: a1b1cd4d-ade7-4b83-bca9-b4126f05e374

📥 Commits

Reviewing files that changed from the base of the PR and between 99ef0ac and c2ab3e3.

📒 Files selected for processing (1)
  • crates/ripr/src/lsp/backend.rs

Walkthrough

Push diagnostic delivery now distinguishes unavailable budget results from successful empty selections. Unavailable budgets publish diagnostics unfiltered, while successful empty selections publish none. Regression coverage verifies all-profile-filtered budget input behavior.

Changes

Diagnostic budget delivery

Layer / File(s) Summary
Budget selection and push publication
crates/ripr/src/lsp/backend.rs, crates/ripr/src/lsp/diagnostic_budget.rs
Budget evaluation results are represented as unavailable or explicitly selected IDs; publication either sends full batches or filters by canonical IDs, and tests verify that all profile-filtered items produce an empty successful selection.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Poem

A bunny sees the budget’s sign:
Empty picks mean none shall shine.
If no budget can be found,
Every diagnostic hops around.
Clear rules make the delivery fine.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the change well, but it omits many required template sections like source links, rollback, traceability, and checks. Add the missing template sections, especially Swarm boundary, source links, scope classification, proof, rollback, traceability, and gate/checklists.
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the core fix: distinguishing empty-selected from computation-failed in LSP push budgeting.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/push-budget-empty-selected-fix

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

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request fixes a bug in the LSP diagnostic delivery budget application where a successfully computed empty budget (e.g., when all diagnostics are filtered out) was conflated with a failed budget computation. By changing budget_selected_ids to an Option, the code now correctly distinguishes between a failed computation (falling back to publishing everything) and a successful computation that legitimately selected zero items (publishing nothing). A regression test has also been added to verify this behavior. I have no feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

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

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 `@crates/ripr/src/lsp/diagnostic_budget.rs`:
- Around line 765-793: The regression test currently covers only
evaluate_diagnostic_budget, so it must be extended or complemented with a
backend-level test exercising the push publication path in backend.rs. Build an
all-ProfileFiltered batch, invoke the relevant push flow, and observe
publish_diagnostics receiving an empty vector rather than falling back to
publishing all diagnostics; retain assertions for the evaluator result and any
applicable output or metric contract.
🪄 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: ASSERTIVE

Plan: Pro Plus

Run ID: db0fd4db-f68a-49fb-b0b4-214d9190a9ab

📥 Commits

Reviewing files that changed from the base of the PR and between cecdbd5 and 4d23889.

📒 Files selected for processing (2)
  • crates/ripr/src/lsp/backend.rs
  • crates/ripr/src/lsp/diagnostic_budget.rs
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • EffortlessMetrics/ripr (auto-detected)
  • EffortlessMetrics/perl-lsp (auto-detected)
  • EffortlessMetrics/unsafe-review (auto-detected)
  • EffortlessMetrics/ub-review (auto-detected)

@codecov

codecov Bot commented Jul 21, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 60.00000% with 10 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/ripr/src/lsp/backend.rs 60.00% 10 Missing ⚠️

📢 Thoughts on this report? Let us know!

@EffortlessSteven
EffortlessSteven force-pushed the codex/push-budget-empty-selected-fix branch 2 times, most recently from c371261 to 99ef0ac Compare July 21, 2026 08:11

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

Actionable comments posted: 1

Caution

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

⚠️ Outside diff range comments (5)
crates/ripr/src/lsp/backend.rs (5)

1-1: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Multiple comments/test name still describe the pre-fix "empty selection = publish everything" semantics. This PR's whole point is to stop conflating budget failure with a successful empty selection, but the surrounding prose in four spots wasn't updated to match: only Unavailable/None now falls back to publishing everything; a successful Applied result with an empty selection publishes nothing.

  • crates/ripr/src/lsp/backend.rs#L2582-2613: update the doc comment on push_diagnostics_for_batch — it still says "An empty selected set keeps the #1911 fallback semantics: publish everything," contradicting the special-case removal in the function body directly below it.
  • crates/ripr/src/lsp/backend.rs#L463-474: update the inline comment — it says the "publish-everything fallback rule fires" when selection collapses, but this branch (Some(empty_set)) now publishes nothing.
  • crates/ripr/src/lsp/backend.rs#L2678-2695: move the "every diagnostic is published unfiltered" doc comment off push_budget_zero_selection_log_message (whose own message says "published nothing") and onto push_budget_unavailable_log_message, which actually has that behavior.
  • crates/ripr/src/lsp/backend.rs#L4730-4776: rename zero_selection_publishes_everything_and_names_the_fallback, whose body (Lines 4757-4767) asserts the opposite — that publishing is empty.
🤖 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 `@crates/ripr/src/lsp/backend.rs` at line 1, Update the stale documentation and
test naming around diagnostic selection to reflect current semantics: only
Unavailable/None falls back to publishing every diagnostic, while Applied with
an empty selection publishes nothing. Revise the push_diagnostics_for_batch doc
comment and inline Some(empty_set) comment, move the unfiltered-publication
documentation from push_budget_zero_selection_log_message to
push_budget_unavailable_log_message, and rename
zero_selection_publishes_everything_and_names_the_fallback to describe empty
publication.

2582-2613: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Doc comment on push_diagnostics_for_batch contradicts the behavior it documents.

Line 2582-2583 says "An empty selected set keeps the #1911 fallback semantics: publish everything," but the function body right below it (explicitly changed in this diff) removed that special case — an empty budget_selected_ids now filters to nothing. The doc needs to describe the current contract so callers relying on this comment don't reintroduce the old fallback here.

🤖 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 `@crates/ripr/src/lsp/backend.rs` around lines 2582 - 2613, The doc comment for
push_diagnostics_for_batch must match its current filtering behavior: remove the
claim that an empty budget_selected_ids publishes everything, and document that
diagnostics are returned only when their IDs are selected. Leave the function
implementation unchanged.

463-474: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Stale comment: says "publish-everything fallback" but this branch now publishes nothing.

This comment describes the old #1911 semantics. With this fix, result.selected.is_empty() (a successful Applied outcome) causes budget_selected_ids to be Some(empty_set), which the publish loop (Lines 501-513) filters to zero diagnostics — not "publish everything". Only the Unavailable branch (None) still publishes everything.

🤖 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 `@crates/ripr/src/lsp/backend.rs` around lines 463 - 474, Update the comment
above the result.selected.is_empty() warning in the publishing flow to describe
the current behavior: an Applied result with an empty selection publishes no
diagnostics, while only an Unavailable result triggers publish-everything
behavior. Remove the stale fallback wording without changing the surrounding
logging or selection logic.

4730-4776: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Test name contradicts its own assertions.

zero_selection_publishes_everything_and_names_the_fallback asserts the opposite of what its name says: Lines 4757-4767 fail the test if published is not empty, i.e. it verifies that a legitimate empty selection publishes nothing. The name is left over from the pre-fix behavior this PR is replacing.

📝 Proposed fix
-    fn zero_selection_publishes_everything_and_names_the_fallback() -> Result<(), String> {
+    fn zero_selection_publishes_nothing_and_names_the_collapse() -> Result<(), String> {
🤖 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 `@crates/ripr/src/lsp/backend.rs` around lines 4730 - 4776, Rename the test
function zero_selection_publishes_everything_and_names_the_fallback to reflect
its current behavior: a legitimate empty selection publishes nothing while the
fallback message identifies omitted items. Keep the test assertions and
implementation unchanged.

2678-2695: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Doc comment is attached to the wrong function.

The doc comment at Lines 2678-2680 ("every diagnostic is published unfiltered, so no delivery limit was enforced") describes the budget-unavailable fallback, but it sits above push_budget_zero_selection_log_message, whose own message body (Line 2685, changed in this diff) says the opposite: "published nothing for this round." That description belongs on push_budget_unavailable_log_message below it, which currently has no doc comment at all.

📝 Proposed fix
-/// Disclosure for the budget-error fallback: every diagnostic is published
-/// unfiltered, so no delivery limit was enforced — a partial state that must
-/// be named rather than presented as a normal complete publication.
+/// Disclosure for a successful evaluation that legitimately selected zero
+/// items: nothing is published this round — a partial state that must be
+/// named rather than presented as a normal complete publication.
 fn push_budget_zero_selection_log_message(
     result: &crate::lsp::diagnostic_budget::DiagnosticBudgetResult,
 ) -> String {
     format!(
         "ripr push diagnostic delivery budget selected zero of {} items; published nothing for this round: every item was omitted by the budget (profile filtering or delivery limits)",
         result.total_canonical_items
     )
 }

+/// Disclosure for the budget-error fallback: every diagnostic is published
+/// unfiltered, so no delivery limit was enforced — a partial state that must
+/// be named rather than presented as a normal complete publication.
 fn push_budget_unavailable_log_message(detail: &str) -> String {
🤖 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 `@crates/ripr/src/lsp/backend.rs` around lines 2678 - 2695, Move the existing
doc comment describing unfiltered publication and unenforced delivery limits
from push_budget_zero_selection_log_message to
push_budget_unavailable_log_message. Keep push_budget_zero_selection_log_message
without that misleading comment, and preserve both function bodies unchanged.
🤖 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 `@crates/ripr/src/lsp/backend.rs`:
- Around line 437-449: Extract the duplicated budget-to-selection conversion
into a `PushDeliveryBudgetOutcome::selected_ids` helper returning
`Option<BTreeSet<String>>`, preserving `Some(empty)` for an applied empty
selection and `None` for unavailable budgets. Replace both the production
`budget_selected_ids` match and the corresponding test match with
`push_budget.selected_ids()` so the test uses the shared implementation.

---

Outside diff comments:
In `@crates/ripr/src/lsp/backend.rs`:
- Line 1: Update the stale documentation and test naming around diagnostic
selection to reflect current semantics: only Unavailable/None falls back to
publishing every diagnostic, while Applied with an empty selection publishes
nothing. Revise the push_diagnostics_for_batch doc comment and inline
Some(empty_set) comment, move the unfiltered-publication documentation from
push_budget_zero_selection_log_message to push_budget_unavailable_log_message,
and rename zero_selection_publishes_everything_and_names_the_fallback to
describe empty publication.
- Around line 2582-2613: The doc comment for push_diagnostics_for_batch must
match its current filtering behavior: remove the claim that an empty
budget_selected_ids publishes everything, and document that diagnostics are
returned only when their IDs are selected. Leave the function implementation
unchanged.
- Around line 463-474: Update the comment above the result.selected.is_empty()
warning in the publishing flow to describe the current behavior: an Applied
result with an empty selection publishes no diagnostics, while only an
Unavailable result triggers publish-everything behavior. Remove the stale
fallback wording without changing the surrounding logging or selection logic.
- Around line 4730-4776: Rename the test function
zero_selection_publishes_everything_and_names_the_fallback to reflect its
current behavior: a legitimate empty selection publishes nothing while the
fallback message identifies omitted items. Keep the test assertions and
implementation unchanged.
- Around line 2678-2695: Move the existing doc comment describing unfiltered
publication and unenforced delivery limits from
push_budget_zero_selection_log_message to push_budget_unavailable_log_message.
Keep push_budget_zero_selection_log_message without that misleading comment, and
preserve both function bodies unchanged.
🪄 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: ASSERTIVE

Plan: Pro Plus

Run ID: fbe681db-c70f-4a1a-91a5-b66f0c51e942

📥 Commits

Reviewing files that changed from the base of the PR and between 4d23889 and c371261.

📒 Files selected for processing (1)
  • crates/ripr/src/lsp/backend.rs
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • EffortlessMetrics/ripr (auto-detected)
  • EffortlessMetrics/perl-lsp (auto-detected)
  • EffortlessMetrics/unsafe-review (auto-detected)
  • EffortlessMetrics/ub-review (auto-detected)

Comment thread crates/ripr/src/lsp/backend.rs Resolved

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

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 `@crates/ripr/src/lsp/backend.rs`:
- Around line 465-487: Update the diagnostics filtering branch around
budget_selected_ids and diagnostic_canonical_id to handle serialization failure
without unwrap_or_default. If serializing any diagnostic fails, treat the budget
as unavailable and publish batch.diagnostics unfiltered; otherwise continue
filtering by canonical IDs. Preserve the existing behavior for None and
successfully computed budgets.
🪄 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: ASSERTIVE

Plan: Pro Plus

Run ID: 0c7f29fd-42f0-4932-bbb6-28abe6ad91c2

📥 Commits

Reviewing files that changed from the base of the PR and between c371261 and 99ef0ac.

📒 Files selected for processing (2)
  • crates/ripr/src/lsp/backend.rs
  • crates/ripr/src/lsp/diagnostic_budget.rs
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • EffortlessMetrics/ripr (auto-detected)
  • EffortlessMetrics/perl-lsp (auto-detected)
  • EffortlessMetrics/unsafe-review (auto-detected)
  • EffortlessMetrics/ub-review (auto-detected)

Comment thread crates/ripr/src/lsp/backend.rs Resolved
… zero

Rebased onto #2116's structure. The empty-selected check conflated two
opposite cases: budget computation FAILED (publish everything is the
honest fallback) versus computation SUCCEEDED with an empty selection
(every item legitimately dropped by profile filtering or limits —
publishing anything defeats the budget). Selected ids are now Option:
None (unavailable) publishes everything with the named fallback
disclosure; Some(set) filters strictly, so a legitimately empty selection
publishes nothing and the zero-selection disclosure says so. The
budget-error fallback test now exercises the call-site Option semantics.
@EffortlessSteven
EffortlessSteven force-pushed the codex/push-budget-empty-selected-fix branch from 99ef0ac to c2ab3e3 Compare July 21, 2026 08:24
@EffortlessSteven
EffortlessSteven merged commit 1416a4e into main Jul 21, 2026
21 of 22 checks passed
@EffortlessSteven
EffortlessSteven deleted the codex/push-budget-empty-selected-fix branch July 21, 2026 08:47
@EffortlessSteven

Copy link
Copy Markdown
Member Author

Merged after reconciliation with #2116 (which landed first with the disclosure structure). Adopted semantic: selected ids are now Option — None (budget computation failed) publishes everything with the named fallback disclosure; Some(set) filters strictly, so a legitimately empty selection (all items profile-filtered or limit-dropped) publishes NOTHING, and the zero-selection disclosure says exactly that. Review note from the earlier round: the #2116 publish-everything-on-zero-selection behavior this PR corrects was preserved there deliberately as out-of-scope; this PR completes the fix. Zero-selection and fallback tests updated to the Option semantics; 22 backend tests + full precommit green.

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