Repository navigation
Conversation
…al link A file opened by clicking a terminal link kept its pre-edit contents after an external change, while the same file opened from the Files sidebar refreshed correctly. `getOpenFilesForExternalFileChange` matched open tabs with raw string equality against a path rebuilt by `joinPath(worktreePath, relativePath)`. `joinPath` takes its separator from the base path, so a worktree recorded as `\\wsl.localhost\Ubuntu\...` produces the backslash spelling — which is what the Files sidebar stored, and therefore matched. Terminal links open the forward-slash form (`mapTerminalFilePath` returns `//wsl.localhost/<distro>/...`), so those tabs never entered the reload set. Fold both sides through `normalizeRuntimePathForComparison`, which already exists for exactly this and also collapses the legacy `\\wsl$` alias and distro case. The target is normalized once outside the filter because that key is deliberately not idempotent for WSL UNC paths, and exact equality is still tried first so the common case pays nothing. Fixes stablyai#13349 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012ZcrKK54K7sRnSkT6a6Jut
Contributor
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe autosave external file-change matcher now normalizes the target path once and compares edit and markdown-preview tabs by exact or normalized path equality. Vitest coverage verifies WSL UNC paths with alternate separators, the legacy alias, case-insensitive distro names, mismatched paths, and POSIX backslash semantics. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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 |
1 task done
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #13349 — a WSL file opened by clicking a terminal link never refreshed after an external change, while the same file opened from the Files sidebar refreshed correctly.
getOpenFilesForExternalFileChangematched open tabs with raw string equality against a path rebuilt byjoinPath(worktreePath, relativePath).joinPathtakes its separator from the base path (lib/path.ts:77), so a worktree recorded as\\wsl.localhost\Ubuntu\…produces the backslash spelling — which is what the Files sidebar stored, so those tabs matched. Terminal links open the forward-slash form (mapTerminalFilePathreturns//wsl.localhost/<distro>/…), so those tabs never entered the reload set and kept stale contents indefinitely.Both sides are now folded through
normalizeRuntimePathForComparison, which already exists for exactly this and additionally collapses the legacy\\wsl$alias and distro case (mapTerminalFilePathdoes not lowercase the distro, which was a second way to miss the same file).Two details worth calling out for review:
cross-platform-path.ts:77), so each side must fold exactly one raw value.The sibling
diffbranch was already immune — it comparesrelativePath, which carries neither the UNC prefix nor the separator style — and is untouched.Screenshots
No visual change.
Testing
pnpm lintpnpm typecheckpnpm testpnpm buildNew file
editor-autosave-wsl-unc-path.test.ts(7 cases). I verified the tests fail without the source change: the 3 that exercise the bug (forward-slash form, legacy\\wsl$alias, distro case) fail on the unpatched function, and the 4 control cases pass both before and after — so the matcher has not been made over-permissive.Full-suite comparison against this branch's base (
d9e84d88ef):Exactly +1 file and +7 tests, all mine and all passing; the same 4 files / 10 tests fail on both. Those pre-existing failures (
src/relay/agent-exec-handler.test.tsandterminal-ime-xterm-resumed-preedit-visibility.test.tsamong them) reproduce identically on an unmodified checkout of the base commit — I confirmed the relay pair explicitly by stashing the change and re-running. They are unrelated to this PR.AI Review Report
Reviewed with Claude Opus 5. Risks checked and what came of them:
normalizeRuntimePathForComparisonfolds//wsl.localhost/Ubuntu/Ato//wsl/ubuntu/A, which a second pass would lowercase further. The review flagged that normalizing inside the filter, or normalizing an already-normalized value, would be a latent bug; the target is therefore folded once from the raw value and the per-file side folds its own raw value.:16). The result is used solely in a boolean;absolutePathandfile.filePathare unchanged in every other use.normalizeRuntimePathForComparisononly folds separators when the path proves Windows drive/UNC semantics — backslash stays a legal POSIX filename character. A control test asserts that on a POSIX worktreea/b.txtmatches anda\b.txtdoes not. No shortcut, label, or shell behaviour is touched.Security Audit
Basic audit with the same agent. No new input handling, command execution, auth, secrets, dependency, or IPC surface: the change adds one import of an existing in-repo pure function and one boolean comparison, entirely inside the renderer.
Path handling is the relevant category, and the direction is safe — the normalized value is used only to decide whether an already-open tab should reload. It is never passed to
fs, never used to open, read, or write a file, and never rendered. A hostile path cannot widen access through this comparison; the worst case is an incorrect match, which is bounded by the pre-existingworktreeIdand runtime-owner filters that run first and are unchanged. No follow-up needed.Notes
Windows/WSL only in practice — POSIX and native Windows drive paths already matched exactly and take the fast path.
Two adjacent things I did not change, deliberately:
mapTerminalFilePath(terminal-file-open-routing.ts:70) still emits a distro-cased forward-slash path. Normalizing at the comparison site fixes the reported symptom without changing what gets stored in a tab or shown to the user; making the two producers agree on one spelling is a larger change and would want its own PR.diffbranch of the same matcher is untouched for the reason given above.Reported by @aliuq. Diagnosis and fix by me; I do not have a Windows/WSL machine, so the failing and passing behaviour here is established by unit tests against the real helpers rather than by running the app on WSL — a confirmation from the reporter on a real WSL worktree would be worth having before release.
🤖 Generated with Claude Code
https://claude.ai/code/session_012ZcrKK54K7sRnSkT6a6Jut