fix(search): open content-search matches through the worktree's owning runtime
Problem
Clicking a content-search match in a remote worktree opens the file through the client machine's local fs:readFile path instead of the worktree's owning runtime, failing with Error: Access denied: path resolves outside allowed directories. The same file opens fine from the remote worktree's File Explorer.
Closes #9185
Root cause
openMatchResult in search-match-open.ts called openFile(...) without a runtimeEnvironmentId, so the open fell back to the active/local runtime. File Explorer had this exact bug fixed in #6562 (which explicitly scoped the search path out), passing runtimeEnvironmentId + suppressActiveRuntimeFallback — the search path was left behind.
Fix
Mirror the File Explorer pattern: useFileSearchPanel resolves the owner via getRuntimeEnvironmentIdForWorktree (the same resolver FileExplorer.tsx uses) and openMatchResult threads runtimeEnvironmentId through, setting suppressActiveRuntimeFallback when resolution returns null so we never silently fall back to the wrong machine.
Testing
New search-match-open.test.ts covering: remote match opens with the owning runtime id, local match keeps current behavior, null resolution suppresses fallback. Full right-sidebar suite: 154 files / 1302 tests passing; oxlint and tsc clean.
X: @mark86202384100
[!CAUTION]
Review failed
The pull request is closed.
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: ebe8a500-e6ca-47af-8427-86d5549f5585
📥 Commits
Reviewing files that changed from the base of the PR and between 77414673c9b5c93d5fff061b11a02d5380c3d964 and 25b754f67daf925de7005f22edf7dcde6aef2e3a.
📒 Files selected for processing (11)
src/renderer/src/components/right-sidebar/search-match-open.test.tssrc/renderer/src/components/right-sidebar/search-match-open.tssrc/renderer/src/components/right-sidebar/useFileSearchPanel.tssrc/renderer/src/components/right-sidebar/useFileSearchRunner.test.tsxsrc/renderer/src/components/right-sidebar/useFileSearchRunner.tssrc/renderer/src/lib/file-search-result-owner.test.tssrc/renderer/src/lib/file-search-result-owner.tssrc/renderer/src/store/slices/editor.tssrc/renderer/src/store/slices/store-cascades.test.tssrc/renderer/src/store/slices/worktrees.test.tssrc/renderer/src/store/slices/worktrees.ts
📝 Walkthrough
Walkthrough
Search results now retain the worktree and runtime environment that produced them. Search execution stores this ownership with results, the search panel defers ownership with result data, and match opening uses it to control runtime fallback. Worktree identity migration updates stored ownership. A new store method purges state associated with removed runtime hosts, including affected worktrees, repositories, session mappings, and UI filters.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Description check | ⚠️ Warning | The description covers the problem, fix, and tests, but it misses most required template sections like Screenshots, AI Review Report, Security Audit, and Notes. | Reformat the PR description to include Summary, Screenshots, Testing checklist, AI Review Report, Security Audit, and Notes, with the requested details in each. |
✅ Passed checks (4 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title check | ✅ Passed | The title clearly and concisely describes routing search matches through the owning runtime. |
| Linked Issues check | ✅ Passed | The changes route content-search opens through the worktree owner, suppress ambient fallback when unresolved, and add tests for remote/local/null cases. |
| Out of Scope Changes check | ✅ Passed | The diff is narrowly focused on search-result opening logic and a matching test, with no unrelated changes visible. |
| Docstring Coverage | ✅ Passed | No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. |
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.
Comment @coderabbitai help to get the list of available commands.
Reworked this from click-time active-worktree resolution to result-bound ownership.
The search runner now commits the exact worktree/runtime route used by files.search alongside its results. Result clicks reuse that captured owner, so active-worktree changes, ambient runtime changes, or later catalog loss cannot retarget a match. Explicit local and SSH routes remain non-runtime without inheriting an ambient paired runtime, and Retry preserves the opened tab's owner.
Validation:
- Reproduced on current main with isolated paired Electron/headless runtimes: owner
files.search, localfs:readFilefailure on click and Retry, ownerfiles.readsuccess from File Explorer. - Fixed Electron run: owner
files.readfor initial click and Retry, zero localfs:readFile; Monaco content andOpenFile.runtimeEnvironmentIdindependently confirmed the owner. - 322 focused tests plus worktree-rename ownership migration passed.
- Full typecheck, scoped lint, max-lines ratchet, and changed React Doctor passed.