Skip to content

fix(lsp): enforce diagnostic budget on push delivery (#1911) - #2042

Merged
EffortlessSteven merged 7 commits into
mainfrom
codex/budget-push-enforcement-1911
Jul 20, 2026
Merged

EffortlessSteven merged 7 commits into
mainfrom
codex/budget-push-enforcement-1911

Conversation

@EffortlessSteven

Copy link
Copy Markdown
Member

Summary

The diagnostic budget selector was computed for status reporting only. The push publication loop published every batch unbounded. Now the push loop filters published diagnostics to only budget-selected IDs.

Change

backend.rs (+47): Before publishing each batch, compute the workspace-wide budget, collect selected canonical IDs, then filter each batch diagnostics to only include items whose canonical ID is in the selected set. Falls back to unfiltered publish on budget computation error.

diagnostic_budget.rs (+1): Lift diagnostic_canonical_id from private to pub(crate) so the push loop can compute canonical IDs for filtering.

Proof

cargo check --lib (exit 0); cargo clippy --all-targets -D warnings (exit 0); cargo test -p ripr --lib lsp:: (365 passed, 0 failed).

Non-goals

  • Does not add overflow disclosure to the status notification (separate follow-up)
  • Does not affect pull diagnostics (pull path already uses snapshot-level identity)

Codex added 7 commits July 19, 2026 06:22
…ase audit (2026-07-19)

Add 9 entries to LEARNINGS.md covering:
- Gate blocking is non-functional (hardcoded seam_id None)
- Static receipts are advisory (fabrication is trivial)
- Every save re-runs the full pipeline (cache not wired in)
- continue-on-error on every CI step makes green meaningless
- Result<_, String> is the highest-leverage refactor target
- Cross-language consistency needs a shared vocabulary layer
- File-policy gate breaks main on new file types
- Duplicate run-status logic drifts
- The session's structural learnings document

Each entry follows the existing LEARNINGS.md format: date, title,
load-bearing lesson, and concrete evidence references.
…ed diagnostics to budget-selected IDs (#1911)

The diagnostic budget selector (evaluate_diagnostic_budget) was
computed for workspace status reporting only. The push publication
loop published every batch unbounded. Now the push loop:

1. Builds budget items from all publish batches
2. Evaluates the budget to get the selected canonical IDs
3. Filters each batch diagnostics to only include selected IDs
4. Falls back to unfiltered publish if budget computation fails

Also lifts diagnostic_canonical_id from private to pub(crate) so the
push loop can compute the canonical ID for filtering.

Proof: cargo check --lib (exit 0); cargo clippy --all-targets -D
warnings (exit 0); cargo test -p ripr --lib lsp:: (365 passed).
@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 20, 2026 •

Copy link
Copy Markdown

Review Change Stack

Summary by CodeRabbit

  • New Features

    • Added diagnostic delivery budgeting for push-based refreshes.
    • Diagnostics are now selectively published according to the configured delivery budget.
  • Bug Fixes

    • Preserved full diagnostic publication when budget evaluation is unavailable or produces no selections.

Walkthrough

Push diagnostic refresh publication now evaluates the default diagnostic budget, selects canonical diagnostic IDs, and filters each published batch. If budget computation produces no selection, the existing full-batch publication behavior remains. The canonical ID helper is crate-visible for backend use.

Changes

Push Diagnostic Budget Filtering

Layer / File(s) Summary
Budget selection and push publication
crates/ripr/src/lsp/backend.rs, crates/ripr/src/lsp/diagnostic_budget.rs
The refresh path evaluates the push_delivery budget, derives selected canonical IDs, filters pushed diagnostics by those IDs, and falls back to unfiltered batches when no selection is available. The canonical ID helper is now crate-visible.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Backend
  participant DiagnosticBudget
  participant LSPClient
  Backend->>DiagnosticBudget: Evaluate push_delivery budget
  DiagnosticBudget-->>Backend: Return selected canonical IDs
  Backend->>LSPClient: Publish filtered diagnostic batches
Loading

Possibly related PRs

Poem

A rabbit reviews each warning with care,
Budgeted blossoms now bloom in the air.
Canonical IDs hop into line,
Push batches publish just fine.
If budgets fade, all diagnostics stay—
Safe fallback magic saves the day!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description covers summary, change, proof, and non-goals, but omits most required template sections like scope, links, rollback, and traceability. Add the missing template sections, especially Swarm/Source Boundary, source links, scope/classification, rollback, traceability, and remaining policy/gate items.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly states the main change: enforcing diagnostic budget on push delivery.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/budget-push-enforcement-1911

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

@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: 2

🤖 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 428-445: The delivery-budget filtering is applied only to forward
diagnostics publication, while rollback republishes the full previous
diagnostics. Extract the filtering logic from the visible diagnostics
publication block into a shared helper, then reuse it in
rollback_refresh_transaction when restoring previous_diagnostics so rollback
emits the same budget-filtered vectors and does not reintroduce omitted
diagnostics.
- Around line 403-416: Update the budget selection computation around
evaluate_diagnostic_budget to preserve the distinction between evaluation
failure and a successful empty selection. Return None when building or
evaluating the budget fails, but wrap the collected selected IDs in Some even
when empty; ensure the later publication logic only bypasses filtering for None
and publishes no diagnostics for Some(empty).
🪄 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: 0dc103e8-5349-43ed-b57a-8d4b59c379b9

📥 Commits

Reviewing files that changed from the base of the PR and between 9434f61 and 0e06c6f.

📒 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
Comment thread crates/ripr/src/lsp/backend.rs Resolved

@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 integrates the diagnostic delivery budget into the LSP backend's push path, filtering diagnostics based on evaluated budget items. Feedback highlights a performance concern regarding redundant serialization and canonical ID computation. Additionally, using JSON serialization for deterministic hashing is discouraged due to potential key ordering issues, and the error handling for serialization failures should be made consistent to prevent diagnostics from being silently dropped.

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.

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

codecov Bot commented Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.22222% with 1 line in your changes missing coverage. Please review.

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

📢 Thoughts on this report? Let us know!

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

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

  • No test exercises the new push-path budget filter. Add a test asserting that with DiagnosticBudget overridden to a tight per-document cap, publish_diagnostics receives a strict subset sized to the cap and that fully-filtered budgets publish zero items, distinguishing Some(empty) (valid empty selection) from budget failure (full publish).
  • rollback_refresh_transaction republishes full previous_diagnostics unfiltered; if budget filter is authoritative for push, rollback reintroduces omitted diagnostics. Extract shared filter helper and apply in rollback, or document rollback scope explicitly.
  • Distinguish eval failure (None -> publish all) from a successful empty selection (Some(empty) -> publish nothing). Replace unwrap_or_default with Option<BTreeSet> and gate the fallback on is_none, not is_empty.
  • Replace unwrap_or_default with Option; only None (computation failure) should publish unfiltered. A legitimate empty selected set must publish zero diagnostics, not fall through to the is_empty() branch at line 428.

Confirmed findings

  • unwrap_or_default confuses eval failure (None) with successful empty selection (Some(empty)) so an all-ProfileFiltered batch falls back to unfiltered publish, contradicting the budget contract.
  • unwrap_or_default at line 410 conflates evaluation failure with valid empty selection; empty selection then falls into the .is_empty() branch at line 428 and publishes unfiltered.
  • rollback_refresh_transaction republishes previous_diagnostics unmodified, so after filtering is introduced, omitted diagnostics reappear post-cancel/workspace-transition.
  • diagnostic_canonical_id uses serde_json::to_vec for hashing; JSON map key ordering non-determinism can yield unstable canonical IDs across runs/features, undermining budget set membership.
  • Two serialized-to-canonical-ID passes per publish plus non-deterministic serde_json map ordering could produce unstable IDs across clients; not blocked but warrants a perf+determinism microbench before merge.

Verification questions

  • Confirm no test in diff covers new push-path budget filtering; green claim rests on pre-existing lsp:: suite.
  • Confirm coderabbit flagged two material test gaps already in seeded thread (empty-selection vs None, rollback path).

Verification questions

Refuted

Evidence gaps

[review body truncated; see review artifacts]

[review body truncated; see review artifacts]

Comment thread crates/ripr/src/lsp/backend.rs Resolved
Comment thread crates/ripr/src/lsp/backend.rs Resolved
Comment thread crates/ripr/src/lsp/backend.rs Resolved
Comment thread crates/ripr/src/lsp/backend.rs Resolved
@EffortlessSteven
EffortlessSteven merged commit 9ad8f67 into main Jul 20, 2026
30 of 31 checks passed
@EffortlessSteven
EffortlessSteven deleted the codex/budget-push-enforcement-1911 branch July 20, 2026 21:44
EffortlessSteven pushed a commit that referenced this pull request Jul 21, 2026
…n-failed (#2042 follow-up)

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.

## Change

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

- None  → computation failed → fall back to publishing everything
- Some(set) → computation succeeded → apply the set (even if empty)

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

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

This is a follow-up to #2042 (merged) flagged in the post-merge review.
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