Repository navigation
fix(lsp): reject ambiguous workspace roots - #1612
Conversation
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
WalkthroughThe LSP now uses typed workspace-root authority, rejects ambiguous or invalid roots, enforces root-contained projections, invalidates stale refresh work on root changes, gates repair actions, and reports root recovery metadata to the VS Code client. ChangesWorkspace-root authority
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant LSPClient
participant Backend
participant RefreshScheduler
participant VSCodeClient
LSPClient->>Backend: initialize or change workspace folders
Backend->>RefreshScheduler: invalidate obsolete input
Backend-->>LSPClient: analysis_status with root state and recovery route
LSPClient->>Backend: request refresh or repair action
Backend-->>LSPClient: contained diagnostics or gated response
LSPClient-->>VSCodeClient: analysis_status notification
VSCodeClient-->>LSPClient: display root selection or restart guidance
Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 42e90e7600
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Actionable comments posted: 5
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)
1897-1965: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win
collect_receipt_statusdoesn't gate onworkspace_root_authority().allows_analysis().Unlike
code_action,collect_workspace_status, andcollect_repair_packet, this readsself.rootandlatest_analysiswithout checking root authority. It happens to degrade safely today only becauselatest_analysisis cleared as a side effect whenever root authority changes meaningfully (Line 751) — there's no explicit gate here, so a future change to that clearing logic could silently reintroduce stale-root reads.🤖 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 1897 - 1965, Update collect_receipt_status to check workspace_root_authority().allows_analysis() before reading self.root or latest_analysis, returning the existing unavailable/no-snapshot response when analysis is not allowed. Match the authority-gating behavior used by code_action, collect_workspace_status, and collect_repair_packet, while preserving the current receipt-status construction for authorized analysis.
🤖 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 785-798: Centralize analysis health resetting by updating
shutdown() to call reset_health_for_input_change() instead of duplicating the
individual field assignments. Preserve the existing shutdown behavior and keep
reset_health_for_input_change() as the single source of truth for clearing
health state.
- Around line 744-777: Update apply_workspace_root_authority so the final
workspace-root authority is constructed once, preserving the RootChanged state
instead of overwriting it with authority afterward. Reuse the changed authority
when the selected root changes, then set_workspace_root_authority and
publish_analysis_status using that final value so collectWorkspaceStatus and
collectRepairPacket can observe RootChanged after the function completes.
In `@crates/ripr/src/lsp/uri.rs`:
- Around line 129-130: Update canonical_or_normalized to avoid treating
normalize_path as sufficient validation when canonicalize fails: resolve and
validate the nearest existing ancestor so ancestor symlinks cannot bypass the
workspace-root check, or defer validation until the actual filesystem access for
edit/command targets. Preserve canonical paths for targets that resolve
successfully.
In `@editors/vscode/src/client.ts`:
- Around line 924-944: Update the root recovery nextStep text in the status
handling branch of the client to make the root_changed refresh action explicit:
instruct users to refresh the saved workspace to obtain current evidence for the
new root, without implying that root selection was required. Preserve the
existing message for other recovery routes.
In `@editors/vscode/test/suite/extension.test.ts`:
- Around line 1037-1061: Add a test alongside the existing typed analysis status
test that emits an analysisStatus notification with root_state set to
root_changed, then assert the client maps it to the stale status and displays
the distinct next-step text. Reuse the existing createControllerTestContext
setup, startup, assertions, and disposal pattern to cover the root_changed
branch in the client status mapping.
---
Outside diff comments:
In `@crates/ripr/src/lsp/backend.rs`:
- Around line 1897-1965: Update collect_receipt_status to check
workspace_root_authority().allows_analysis() before reading self.root or
latest_analysis, returning the existing unavailable/no-snapshot response when
analysis is not allowed. Match the authority-gating behavior used by
code_action, collect_workspace_status, and collect_repair_packet, while
preserving the current receipt-status construction for authorized analysis.
🪄 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: 8b11b2e3-684f-4d17-832c-addad61b689a
📒 Files selected for processing (12)
.ripr/traceability.tomlcrates/ripr/src/lsp/actions.rscrates/ripr/src/lsp/backend.rscrates/ripr/src/lsp/capabilities.rscrates/ripr/src/lsp/gap_artifacts.rscrates/ripr/src/lsp/refresh_scheduler.rscrates/ripr/src/lsp/state.rscrates/ripr/src/lsp/tests.rscrates/ripr/src/lsp/uri.rsdocs/specs/RIPR-SPEC-0069-lsp-agent-feedback-use-case.mdeditors/vscode/src/client.tseditors/vscode/test/suite/extension.test.ts
🔗 Linked repositories identified
CodeRabbit considers these linked repositories for cross-repo context during reviews:
EffortlessMetrics/unsafe-review(auto-detected)EffortlessMetrics/perl-lsp(auto-detected)EffortlessMetrics/ub-review(auto-detected)
There was a problem hiding this comment.
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 (3)
crates/ripr/src/lsp/backend.rs (2)
1836-1838: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winRoot-authority denial reuses a health-staleness sentinel reason.
When
workspace_root_authority().allows_analysis()is false,collect_repair_packetreturns"analysis_snapshot_stale"andcollect_receipt_statusreturns"no_snapshot"/"not_available"— the same generic reasons used for ordinary snapshot staleness. A client can't distinguish "root is ambiguous/unavailable/removed, fix your workspace" from "just wait/refresh", undermining the recovery-guidance goal of the typed root status.Also applies to: 1899-1913
🤖 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 1836 - 1838, The root-authority denial path in collect_repair_packet must use a distinct sentinel reason from ordinary health staleness, and the corresponding collect_receipt_status branches must expose matching root-authority-specific reasons. Preserve the existing staleness reasons when health.allows_current_repairs() is false, while distinguishing ambiguous, unavailable, or removed workspace roots so clients can guide workspace recovery.
756-786: 🔒 Security & Privacy | 🟡 Minor | ⚡ Quick winInformation Disclosure (CWE-367): Time-of-check Time-of-use (TOCTOU) Race Condition
Reachability: External
● Entry crates/ripr/src/lsp/tests.rs:3 Backend │ ▼ ● Sink crates/ripr/src/lsp/backend.rsSerialize root swaps with refreshes
crates/ripr/src/lsp/backend.rs:756-786
apply_workspace_root_authority()invalidates the scheduler but awaits diagnostic clears before swapping authority, so an explicit refresh can still start against the old root and later repopulatelatest_analysis/publish stale diagnostics after the session has moved. Bind refreshes to a workspace-authority epoch, or recheck the current authority right before publish/commit.🤖 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 756 - 786, Serialize workspace-root changes with refresh execution in apply_workspace_root_authority and the refresh commit/publish path: invalidate or advance a workspace-authority epoch before any awaited diagnostic clearing, then have refreshes validate that epoch/current authority immediately before updating latest_analysis or publishing diagnostics. Discard results from refreshes started under an older authority so stale-root analysis cannot be committed or published.crates/ripr/src/lsp/uri.rs (1)
262-285: 🔒 Security & Privacy | 🟡 Minor | ⚡ Quick winPath Traversal (CWE-22): Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
Reachability: Internal
Add a regression test for the symlink-ancestor escape The current tests still only cover lexical
..traversal and foreign absolute paths; add a case that creates a real symlink inside the root pointing outside, then resolves a missing leaf beneath it socanonicalize_with_missing_tailis exercised.🤖 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/uri.rs` around lines 262 - 285, Extend the URI/path tests with a temporary root containing a symlink directory that points outside the root, then check a missing file beneath that symlink through the relevant path validation flow. Ensure the case exercises canonicalize_with_missing_tail and asserts the symlink-ancestor escape is rejected, while retaining the existing lexical and foreign-path assertions.
🤖 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 115-129: The workspace-root authority transitions in
refresh_diagnostics and apply_workspace_root_authority are vulnerable to stale
read-then-write updates. Make each transition atomic under the same
synchronization mechanism, or condition the write on the exact observed
authority/version so a newer did_change_workspace_folders update cannot be
overwritten; preserve the existing transition behavior when no concurrent update
intervenes.
---
Outside diff comments:
In `@crates/ripr/src/lsp/backend.rs`:
- Around line 1836-1838: The root-authority denial path in collect_repair_packet
must use a distinct sentinel reason from ordinary health staleness, and the
corresponding collect_receipt_status branches must expose matching
root-authority-specific reasons. Preserve the existing staleness reasons when
health.allows_current_repairs() is false, while distinguishing ambiguous,
unavailable, or removed workspace roots so clients can guide workspace recovery.
- Around line 756-786: Serialize workspace-root changes with refresh execution
in apply_workspace_root_authority and the refresh commit/publish path:
invalidate or advance a workspace-authority epoch before any awaited diagnostic
clearing, then have refreshes validate that epoch/current authority immediately
before updating latest_analysis or publishing diagnostics. Discard results from
refreshes started under an older authority so stale-root analysis cannot be
committed or published.
In `@crates/ripr/src/lsp/uri.rs`:
- Around line 262-285: Extend the URI/path tests with a temporary root
containing a symlink directory that points outside the root, then check a
missing file beneath that symlink through the relevant path validation flow.
Ensure the case exercises canonicalize_with_missing_tail and asserts the
symlink-ancestor escape is rejected, while retaining the existing lexical and
foreign-path assertions.
🪄 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: 76b8bc29-e600-4831-a541-b8d0b169fd58
📒 Files selected for processing (7)
crates/ripr/src/lsp/actions.rscrates/ripr/src/lsp/backend.rscrates/ripr/src/lsp/capabilities.rscrates/ripr/src/lsp/tests.rscrates/ripr/src/lsp/uri.rseditors/vscode/src/client.tseditors/vscode/test/suite/extension.test.ts
🔗 Linked repositories identified
CodeRabbit considers these linked repositories for cross-repo context during reviews:
EffortlessMetrics/unsafe-review(auto-detected)EffortlessMetrics/perl-lsp(auto-detected)EffortlessMetrics/ub-review(auto-detected)
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (4)
crates/ripr/src/lsp/uri.rs (1)
167-182: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winWindows containment check breaks for drive-root workspaces; prefer component-wise comparison over manual string concatenation.
If
root's canonical form already ends in a separator (e.g.C:\), appending another"\\"/"/"beforestarts_withproduces a double separator that will never match real children, causing every path under a drive-root workspace to be (incorrectly) rejected as outside the root. UsingPath/Component-based comparison (lowercasing components) avoids this and matches the non-Windows branch's cleanerstarts_withidiom.♻️ Suggested refactor
fn paths_equal_or_below(root: &Path, candidate: &Path) -> bool { - if cfg!(windows) { - root.to_string_lossy() - .eq_ignore_ascii_case(&candidate.to_string_lossy()) - || candidate - .to_string_lossy() - .to_ascii_lowercase() - .starts_with(&(root.to_string_lossy().to_ascii_lowercase() + "\\")) - || candidate - .to_string_lossy() - .to_ascii_lowercase() - .starts_with(&(root.to_string_lossy().to_ascii_lowercase() + "/")) - } else { - candidate == root || candidate.starts_with(root) - } + if cfg!(windows) { + let root_components: Vec<_> = root + .components() + .map(|c| c.as_os_str().to_string_lossy().to_ascii_lowercase()) + .collect(); + let candidate_components: Vec<_> = candidate + .components() + .map(|c| c.as_os_str().to_string_lossy().to_ascii_lowercase()) + .collect(); + candidate_components.len() >= root_components.len() + && candidate_components[..root_components.len()] == root_components[..] + } else { + candidate == root || candidate.starts_with(root) + } }🤖 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/uri.rs` around lines 167 - 182, Update paths_equal_or_below for Windows to compare normalized Path components case-insensitively instead of lowercased string prefixes with manually appended separators. Preserve equality and descendant containment, including children of drive-root paths such as C:\, while keeping the existing non-Windows behavior unchanged.crates/ripr/src/lsp/backend.rs (3)
768-806: 🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy liftMove the root-transition side effects behind the epoch guard
apply_workspace_root_authoritycan still invalidate the scheduler, clear diagnostics, and reset health even when a concurrent call wins the epoch race and this update returns early. That leaves a superseded transition able to commit destructive side effects with no later republish to restore them. Serialize the full read/decide/write sequence, or delay those side effects until after the stable epoch check.🤖 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 768 - 806, The root-transition side effects in apply_workspace_root_authority currently occur before confirming that authority_epoch is still current. Serialize the full read/decide/write sequence or move refresh_scheduler.invalidate_input, clear_all_diagnostic_uris/diagnostic publishing, and reset_health_for_input_change after the stable epoch guard, ensuring superseded updates return without destructive side effects.
118-132: 🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy liftRe-selecting the root here should go through
apply_workspace_root_authority
self.set_workspace_root_authority(WorkspaceRootAuthority::selected(root.clone()))bypassesworkspace_root_epoch, so a concurrentdid_change_workspace_folderscan still overwrite a newer root selection between the read and this write. That reintroduces the race this refactor was meant to close.🔧 Suggested fix
- self.set_workspace_root_authority(WorkspaceRootAuthority::selected(root.clone())); - self.publish_analysis_status().await; + self.apply_workspace_root_authority(WorkspaceRootAuthority::selected(root.clone())) + .await;🤖 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 118 - 132, Update the RootChanged/Full branch in the analysis flow to re-select the workspace root through apply_workspace_root_authority instead of calling set_workspace_root_authority directly. Preserve the existing root value and publish_analysis_status behavior, while ensuring the centralized epoch-aware application path prevents concurrent workspace-folder changes from overwriting the selection.
83-99: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winAvoid seeding the root as already-selected here
crates/ripr/src/lsp/backend.rs:83-99IfBackend::newstarts from the process cwd andinitialize()resolves a different workspace root, the first authority update becomesRootChanged, which blocks the first interactive refresh until an explicit full refresh. Seed it as unavailable, or skip change classification for the constructor bootstrap root.🤖 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 83 - 99, Initialize Backend::new’s workspace_root authority as unavailable rather than selected from the constructor’s root, so initialize() can classify the resolved workspace root as the initial authority without producing a blocking RootChanged update. Preserve the existing root storage and workspace-root update behavior for subsequent changes.
🤖 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 768-806: The root-transition side effects in
apply_workspace_root_authority currently occur before confirming that
authority_epoch is still current. Serialize the full read/decide/write sequence
or move refresh_scheduler.invalidate_input, clear_all_diagnostic_uris/diagnostic
publishing, and reset_health_for_input_change after the stable epoch guard,
ensuring superseded updates return without destructive side effects.
- Around line 118-132: Update the RootChanged/Full branch in the analysis flow
to re-select the workspace root through apply_workspace_root_authority instead
of calling set_workspace_root_authority directly. Preserve the existing root
value and publish_analysis_status behavior, while ensuring the centralized
epoch-aware application path prevents concurrent workspace-folder changes from
overwriting the selection.
- Around line 83-99: Initialize Backend::new’s workspace_root authority as
unavailable rather than selected from the constructor’s root, so initialize()
can classify the resolved workspace root as the initial authority without
producing a blocking RootChanged update. Preserve the existing root storage and
workspace-root update behavior for subsequent changes.
In `@crates/ripr/src/lsp/uri.rs`:
- Around line 167-182: Update paths_equal_or_below for Windows to compare
normalized Path components case-insensitively instead of lowercased string
prefixes with manually appended separators. Preserve equality and descendant
containment, including children of drive-root paths such as C:\, while keeping
the existing non-Windows behavior unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: a1da9db9-6008-486b-9572-f540cbe386c8
📒 Files selected for processing (2)
crates/ripr/src/lsp/backend.rscrates/ripr/src/lsp/uri.rs
🔗 Linked repositories identified
CodeRabbit considers these linked repositories for cross-repo context during reviews:
EffortlessMetrics/unsafe-review(auto-detected)EffortlessMetrics/perl-lsp(auto-detected)EffortlessMetrics/ub-review(auto-detected)
|
Verified the current head against the remaining root-authority review inputs and pushed commit 681418b. The refresh request now carries the workspace-authority epoch; root transitions are serialized with final diagnostic publication/commit; constructor state is unavailable until initialize; RootChanged recovery uses the central authority transition; Windows containment compares normalized path components; test harnesses explicitly initialize authority. Full LSP tests: 287 passed. Clippy, formatting, and diff checks pass. Existing review threads are all resolved; advisory Codecov/rate-limit signals remain non-blocking. |
What this does
The LSP now rejects ambiguous or unavailable workspace roots instead of selecting a possibly wrong repository. It keeps root changes, diagnostic publication, repair actions, and related-test navigation bound to the current selected root, including symlink and Windows containment cases.
Fix: establish one typed root authority, invalidate prior analysis on root transitions, suppress stale publication, and expose root-specific recovery status. The constructor root remains bootstrap storage until initialize establishes client authority.
Verification
Review map
Closes #1597