Skip to content

fix(editor): refresh WSL files opened from a forward-slash UNC terminal link - #13605

Closed
manuaudio wants to merge 1 commit into
stablyai:mainfrom
manuaudio:fix/wsl-unc-editor-refresh
Closed

manuaudio wants to merge 1 commit into
stablyai:mainfrom
manuaudio:fix/wsl-unc-editor-refresh

Conversation

@manuaudio

Copy link
Copy Markdown
Contributor

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.

getOpenFilesForExternalFileChange matched open tabs with raw string equality against a path rebuilt by joinPath(worktreePath, relativePath). joinPath takes 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 (mapTerminalFilePath returns //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 (mapTerminalFilePath does not lowercase the distro, which was a second way to miss the same file).

Two details worth calling out for review:

  • The target is normalized once outside the filter, not per candidate. That function is documented as not idempotent for WSL UNC paths (cross-platform-path.ts:77), so each side must fold exactly one raw value.
  • Exact equality is still tried first, so the common non-UNC case pays nothing.

The sibling diff branch was already immune — it compares relativePath, which carries neither the UNC prefix nor the separator style — and is untouched.

Screenshots

No visual change.

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test
  • pnpm build
  • Added or updated high-quality tests that would catch regressions, or explained why tests were not needed

New 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):

test files tests
base, no changes 4 failed / 4564 passed 10 failed / 49009 passed
this branch 4 failed / 4565 passed 10 failed / 49016 passed

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.ts and terminal-ime-xterm-resumed-preedit-visibility.test.ts among 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:

  • Over-matching. The main risk of loosening an equality is matching the wrong file. Covered by control cases: a different filename in the same worktree, and the same relative path under a different distro, both still correctly return no match.
  • Non-idempotent comparison key. normalizeRuntimePathForComparison folds //wsl.localhost/Ubuntu/A to //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.
  • Comparison key leaking into a real path. That function is explicitly documented as "comparison key only — never return this as, or splice it into, a real path" (:16). The result is used solely in a boolean; absolutePath and file.filePath are unchanged in every other use.
  • Cross-platform (macOS/Linux/Windows). This is Windows-shaped behaviour, so POSIX regression was the specific concern. normalizeRuntimePathForComparison only 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 worktree a/b.txt matches and a\b.txt does not. No shortcut, label, or shell behaviour is touched.
  • Performance. Called per external file change over open tabs. Kept the exact-equality fast path so the normal case is unchanged, and hoisted the target normalization out of the loop.

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-existing worktreeId and 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:

  1. 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.
  2. The diff branch 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

…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
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1b10a01a-c27c-4f46-ae17-49b6097c3ac6

📥 Commits

Reviewing files that changed from the base of the PR and between 56b6d84 and 4615f04.

📒 Files selected for processing (2)
  • src/renderer/src/components/editor/editor-autosave-wsl-unc-path.test.ts
  • src/renderer/src/components/editor/editor-autosave.ts

📝 Walkthrough

Walkthrough

The 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)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the WSL UNC terminal-link refresh fix, which is the primary change.
Description check ✅ Passed The description includes all required sections, testing results, review findings, security audit, and platform-specific notes.
Linked Issues check ✅ Passed The implementation and tests satisfy the linked issue objective of refreshing WSL files opened through forward-slash UNC terminal links [#13349].
Out of Scope Changes check ✅ Passed The changes are limited to WSL UNC path comparison logic and regression tests required for issue #13349.
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.

❤️ Share

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

@OrcaWin

OrcaWin commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

Superseded by #13798, which preserves the contributed work while combining terminal-open canonicalization with guarded legacy watcher and tab alias handling. #13798 has now merged. Thank you for the implementation and diagnosis that informed the final fix.

@OrcaWin OrcaWin closed this Aug 11, 2026
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.

[Bug]: WSL file opened from forward-slash UNC terminal link stays stale after edits

4 participants