Skip to content

feat(lsp): one stored diagnostic selection authority for push and pull (#1973) - #2134

Merged
EffortlessSteven merged 2 commits into
mainfrom
codex/lsp-selection-authority
Jul 21, 2026
Merged

EffortlessSteven merged 2 commits into
mainfrom
codex/lsp-selection-authority

Conversation

@EffortlessSteven

Copy link
Copy Markdown
Member

Summary

Fixes #1973. Standard push and pull diagnostic delivery now project from one immutable delivery selection computed once at refresh-transaction prepare time and stored on the committed AnalysisSnapshot — no transport re-runs ranking or re-evaluates the budget.

The stored selection (DiagnosticDeliverySelection in diagnostic_budget.rs) carries the issue's required set: budget/profile identity and selection version, complete-evidence identity (digest over full unfiltered payloads), selected canonical ids, per-document selected sets, omitted identities with per-item reasons, workspace/per-document overflow, selected and complete byte counts, and the retrieval route.

What each transport reads:

  • Push: the publish loop reads snapshot.delivery_selection instead of calling evaluate_push_delivery_budget at publish time. The disclosure behaviors from feat(lsp): disclose push-delivery budget omissions to the client (#1969) #2116/fix(lsp): push budget must distinguish empty-selected from computation-failed (#2042 follow-up) #2120 (bounded omission summary, zero-selection message, named unavailable fallback) are preserved, driven from the stored outcome.
  • Pull (textDocument/diagnostic, workspace/diagnostic): now serve the stored per-document selected sets instead of all snapshot diagnostics. Intended user-visible change (per the issue): pull-mode clients now receive exactly what push publishes — budget-selected items only; profile-filtered items are omitted-with-reason, never silently dropped. Pull result IDs (ripr-document-diagnostics-v2) hash the served payload plus the selection identity, so a budget/profile/input change flips IDs and overflow is never hidden by an unchanged result; the DiagnosticResultIdCache is retained. A bounded pull disclosure (pull_delivery_disclosure) names partial/zero/fallback states once per workspace report.
  • Workspace status: the diagnostic_budget projection mirrors the stored selection instead of re-running the budget; unavailable states keep their schema values.

Proof (independently re-verified after the builder run)

RUSTC_WRAPPER="" cargo test -p ripr                      # full suite green (5 parity tests)
cargo clippy -p ripr --all-targets -- -D warnings         # clean
cargo fmt --check                                         # clean
cargo run -p xtask --quiet -- precommit                   # full gate list green

Parity tests: identical selected sets on both transports (item-level and per-document); shared omitted identities/reasons; pull discloses the same overflow state and ripr/listActionableItems route (and repeats as unchanged); zero-selection serves nothing on both with disclosure; and a ptr_eq test proves pull serves the exact stored selection with no re-evaluation. One pre-existing pull test's fixture diagnostics were made budget-actionable since result IDs now derive from the served set.

Claim boundary

Selection-authority unification only. No change to what the budget selects (same evaluate_diagnostic_budget machinery, run once), to the snapshot analysis itself, or to any wire schema (the selection is in-memory). The pull serving change is the issue's explicit requirement, flagged in the PR body.

Rollback

Revert the commit; push returns to publish-time evaluation and pull returns to serving all snapshot diagnostics.

#1973)

At refresh-transaction prepare time the backend now computes one
immutable DiagnosticDeliverySelection (budget/profile identity, selection
version, complete-evidence identity, selected ids, per-document selected
sets, omitted ids+reasons, overflow, byte counts, retrieval route) and
stores it on the committed AnalysisSnapshot.

- Push publication reads the stored selection instead of re-evaluating
  the budget at publish time; disclosure behavior (bounded omission
  summary, zero-selection message, unavailable fallback) is preserved
  but driven from the stored outcome.
- textDocument/diagnostic and workspace/diagnostic now serve the stored
  per-document selected sets (previously all snapshot diagnostics):
  pull-mode clients see exactly what push publishes — profile-filtered
  items are omitted-with-reason, never silently dropped. Pull result IDs
  (ripr-document-diagnostics-v2) hash the served payload plus the
  selection identity, so overflow is never hidden by an unchanged result.
- The workspace-status diagnostic_budget projection mirrors the stored
  selection instead of re-running the budget.

Five parity tests: identical selected sets on both transports, shared
omitted identities/reasons, pull discloses the push overflow state and
retrieval route, zero-selection serves nothing on both with disclosure,
and pull provably reads the stored selection (ptr_eq, no re-evaluation).
@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

Summary by CodeRabbit

  • Bug Fixes
    • Diagnostic coverage selection is now computed once per refresh and reused consistently across push notifications and both document/workspace pull requests.
    • Pull responses and workspace status now reflect the stored selected diagnostic subset, with accurate unavailable/uncommitted reporting.
    • Diagnostic result identifiers were updated to align with delivered diagnostics (new v2 identity scheme).
  • Tests
    • Added end-to-end parity checks to ensure push and pull diagnostic payloads match, including omission/disclosure behavior.
    • Updated test fixtures to populate the snapshot delivery-selection state and eligibility markers where required.

Walkthrough

Changes

The LSP backend now computes diagnostic budget selection once per analysis snapshot. Push publication, document/workspace pull responses, workspace status, diagnostic result IDs, and fallback handling reuse that stored selection.

Diagnostic delivery selection

Layer / File(s) Summary
Selection outcome and document filtering
crates/ripr/src/lsp/diagnostic_budget.rs
Budget evaluation now produces reusable applied or unavailable outcomes and filters diagnostics by stored canonical IDs.
Snapshot storage and diagnostic identities
crates/ripr/src/lsp/state.rs, crates/ripr/src/lsp/diagnostics.rs
Snapshots store delivery selection; served diagnostics and document/workspace result IDs incorporate selected evidence.
Refresh, transport, and status integration
crates/ripr/src/lsp/backend.rs
Refresh commits selection before delivery, and push, pull, disclosure, and workspace-status paths consume it without recomputation.
Parity and fixture validation
crates/ripr/src/lsp/backend.rs, crates/ripr/src/lsp/tests.rs, crates/ripr/src/lsp/actions.rs, crates/ripr/src/lsp/hover.rs, crates/ripr/src/lsp/lens.rs, crates/ripr/src/lsp/state.rs
Tests cover selected, empty, unavailable, disclosure, and push/pull parity behavior while updating snapshot fixtures.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant RefreshTransaction
  participant AnalysisSnapshot
  participant PushPublisher
  participant DocumentPull
  participant WorkspacePull
  RefreshTransaction->>AnalysisSnapshot: commit stored delivery selection
  AnalysisSnapshot->>PushPublisher: serve selected diagnostics
  AnalysisSnapshot->>DocumentPull: serve selected document diagnostics
  AnalysisSnapshot->>WorkspacePull: serve selected workspace diagnostics
Loading

Possibly related issues

Possibly related PRs

Poem

A rabbit tucked the budget tight,
One choice now guides each route in flight.
Push and pull share every thread,
Empty or full, as carefully led.
“No re-counting!” hops the hare—
One snapshot selects with care.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is on-topic but omits most required template sections and checklists. Fill in the full template: Swarm boundary, source links, scope/classification, proof, traceability, checks, gates, CI economics, and engineering sections.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the stored diagnostic-selection change.
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.
✨ 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/lsp-selection-authority

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 introduces a shared, immutable diagnostic delivery selection (DiagnosticDeliverySelection) computed during the refresh-transaction prepare phase and stored on the AnalysisSnapshot. Both push publication and pull handlers now read from this stored selection instead of independently re-evaluating the budget, ensuring transport parity. Additionally, pull-side disclosures have been added to report partial delivery states, and diagnostic result IDs have been updated to incorporate the selection identity to prevent selection changes from being hidden by unchanged reports. Extensive parity tests have been added to verify these behaviors. There are no review comments to address, so no further feedback is provided.

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.

@codecov

codecov Bot commented Jul 21, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.76978% with 129 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/ripr/src/lsp/backend.rs 84.12% 107 Missing ⚠️
crates/ripr/src/lsp/diagnostic_budget.rs 87.03% 14 Missing ⚠️
crates/ripr/src/lsp/state.rs 70.00% 6 Missing ⚠️
crates/ripr/src/lsp/diagnostics.rs 95.23% 2 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

  • diagnostics_entry_for_uri introduces fuzzy URI matching (file_uris_match fallback) that the selection authority does not require and is unused elsewhere. Scope creep; the stored selection already keys on the stored URI string. Either justify the helper or remove and rely on direct BTreeMap lookup.
  • Replace string-prefix matching for unavailable-reason classification with a structured enum on DiagnosticDeliveryOutcome::Unavailable, or include the reason class explicitly in the selection. The current starts_with('budget item serialization failed') check is brittle and leaks the human-readable detail into the result-ID hash, so rewording any log detail silently invalidates client cache identities.

Confirmed findings

  • Stale selection risk: refresh_plan computes the selection from a batches-derived snapshot but the fallback at commit_refresh_snapshot recomputes if absent. If a code path mutates snapshot.diagnostics_by_uri between refresh_plan and commit_refresh_snapshot, the stored selection reflects the original batches, not the committed snapshot. Tests cover the normal path; an invariant that commit-time diagnostics_by_uri equals prepare-time diagnostics_by_uri is not asserted.
  • delivery_filter_reuses_budget_ids_without_reserializing now compares stored selection against an independently re-serialized set; the original 'reuse path diverged from reserialization' check no longer tests reuse vs reserialize but stored-vs-reserialize. Rename/comment to reflect new contract, or add an explicit reuse-path vs cold-path cross-check at unit scope.
  • Two compute guard sites (refresh_plan, commit_refresh_snapshot) recompute selection defensively; acceptable but is duplication risk and obscures authority.

Verification questions

  • Confirm delivery_selection field is populated before commit but commit_refresh_snapshot re-computes if None; this means a snapshot replaced via commit path can publish without the prepare-time selection.
  • Confirm workspace_diagnostic lacks the once-per-report disclosure deduplication when a single-document workspace is reported.
  • Confirm 'budget item serialization failed' detail string is used in two distinct DiagnosticDeliveryOutcome::Unavailable branches: build_budget_items_from_diagnostics failure vs evaluate_diagnostic_budget error.
  • Confirm diagnostics.rs renames version prefixes to v2 and folds delivery_selection_identity into document_diagnostic_result_id; complete_diagnostic_evidence_identity rebuilt as ripr-complete-diagnostic-evidence-v1.
  • Confirm commit_refresh_snapshot backfills snapshot.delivery_selection = Some(compute_delivery_selection(&snapshot)) if None; refresh_plan fills it before the plan is built, so two code paths compute the selection.
  • Confirm boundary duplication in commit_refresh_snapshot: both refresh_plan and commit_refresh_snapshot re-check and possibly recompute selection. Acceptable for fixtures but two is_none() guards is mild duplication risk.

Verification questions

Refuted

Evidence gaps

[review body truncated; see review artifacts]

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

Review on #2134: DiagnosticDeliveryOutcome::Unavailable now carries a
typed DiagnosticDeliveryUnavailableReason (ItemSerialization/Evaluation)
with as_status_reason() driving the workspace-status projection — no
string-prefix classification. The result-id cache now does exact-key URI
lookup only; the stored selection keys on the stored URI string, so
fuzzy matching is not part of the authority contract.

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

Caution

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

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

641-646: 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Build the push refresh plan from the served selection, not raw diagnostics.

last_diagnostics retains the complete raw map, and diagnostic_refresh_plan is built from raw batches. If only the budget/profile changes, raw diagnostics compare unchanged, so push publishes no update; pull immediately serves the new stored selection. Keep a prior delivered projection/selection for delta and rollback planning, and add a push-mode regression test for unchanged diagnostics with a changed selection.

🤖 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 641 - 646, Update the push
refresh planning flow around diagnostic_refresh_plan to compare the newly served
delivery_selection projection rather than raw batches or last_diagnostics.
Preserve the prior delivered selection/projection so delta and rollback planning
use the previous served state, and add a push-mode regression test covering
unchanged diagnostics with a changed budget/profile selection.
🤖 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.

Outside diff comments:
In `@crates/ripr/src/lsp/backend.rs`:
- Around line 641-646: Update the push refresh planning flow around
diagnostic_refresh_plan to compare the newly served delivery_selection
projection rather than raw batches or last_diagnostics. Preserve the prior
delivered selection/projection so delta and rollback planning use the previous
served state, and add a push-mode regression test covering unchanged diagnostics
with a changed budget/profile selection.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 2ccd021e-1636-4e17-b2c6-1e30f62a89fa

📥 Commits

Reviewing files that changed from the base of the PR and between 405e70a and a10bdd4.

📒 Files selected for processing (3)
  • crates/ripr/src/lsp/backend.rs
  • crates/ripr/src/lsp/diagnostic_budget.rs
  • crates/ripr/src/lsp/diagnostics.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)

@EffortlessSteven
EffortlessSteven merged commit c819ec0 into main Jul 21, 2026
27 of 28 checks passed
@EffortlessSteven
EffortlessSteven deleted the codex/lsp-selection-authority branch July 21, 2026 17:42
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.

slice(#1695): make push and pull consume one stored diagnostic selection authority

1 participant