Skip to content

fix(worktree): match created worktrees through symlink roots - #10172

Closed
innocarpe wants to merge 1 commit into
stablyai:mainfrom
innocarpe:fix/worktree-symlink-home-path-match
Closed

innocarpe wants to merge 1 commit into
stablyai:mainfrom
innocarpe:fix/worktree-symlink-home-path-match

Conversation

@innocarpe

@innocarpe innocarpe commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • On Bazzite/Silverblue-style systems, /home is a symlink to /var/home. git worktree add with a /home/... path succeeds, but git worktree list returns the canonical /var/home/... path.
  • Orca compared those with string/path normalization only → Worktree created but not found in listing, even though the worktree exists on disk.
  • After local create, find the listed row with a realpath fallback when the direct match fails. WSL still uses string comparison only (host realpath is not authoritative for WSL paths). SSH create path unchanged.

Fixes #10170

Test plan

  • Unit: direct path match without realpath
  • Unit: /home → /var/home symlink resolve matches listing
  • Unit: resolveSymlinks: false skips realpath (WSL)
  • Manual (immutable Linux optional): workspace under /home/$USER, create worktree → registers in UI

ELI5

On systems where /home is a symlink (e.g. Bazzite), created worktrees existed but Orca said not found because list paths differed. Matching now falls back to realpath so symlink roots resolve correctly.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds findListedWorktreeByPath, which first compares paths directly and then optionally compares resolved realpaths. It supports platform selection, disabling symlink resolution, injectable realpath resolution, and failed-resolution handling. The helper is re-exported and used by local worktree creation and reconciliation flows, with symlink resolution enabled for native Git and disabled for WSL. Vitest coverage covers direct matches, symlinked paths, disabled resolution, and resolver errors.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers summary and testing, but it omits required Screenshots, AI Review Report, Security Audit, and Notes sections. Add the missing template sections, including screenshots/no visual change, AI review report, security audit, and notes; keep the testing checklist.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR adds realpath fallback for local worktree matching, preserves WSL/SSH behavior, and includes regression tests for the reported path mismatch.
Out of Scope Changes check ✅ Passed The changes stay focused on worktree path matching, related re-exports, and regression tests; no unrelated edits are evident.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title clearly describes the main change: matching created worktrees via symlink roots.

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.

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

🧹 Nitpick comments (1)
src/main/ipc/find-listed-worktree-by-path.test.ts (1)

52-70: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Cover stale listed-path resolution failures.

This only tests failure resolving requestedPath; add a case where the first listed path throws and a later canonical-path row still matches. That protects the per-row continuation behavior in the helper.

Suggested test
+  it('continues when a listed worktree path cannot be resolved', async () => {
+    const matching = { path: '/var/home/user/ws/repo/feature' }
+    const resolveRealPath = vi.fn(async (pathValue: string) => {
+      if (pathValue === '/stale/worktree') throw new Error('ENOENT')
+      return pathValue.replace(/^\/home\//, '/var/home/')
+    })
+
+    await expect(
+      findListedWorktreeByPath(
+        [{ path: '/stale/worktree' }, matching],
+        '/home/user/ws/repo/feature',
+        { platform: 'linux', resolveRealPath }
+      )
+    ).resolves.toBe(matching)
+  })

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 80ebe7e4-502e-4c19-a1ba-8209f937d78b

📥 Commits

Reviewing files that changed from the base of the PR and between 8a23618 and 8a2d719660c35e9eb27112e559ec15fec8bcf28a.

📒 Files selected for processing (5)
  • src/main/ipc/find-listed-worktree-by-path.test.ts
  • src/main/ipc/worktree-logic.ts
  • src/main/ipc/worktree-path-comparison.ts
  • src/main/ipc/worktree-remote.ts
  • src/main/runtime/orca-runtime.ts

@innocarpe innocarpe closed this Jul 24, 2026
@innocarpe
innocarpe force-pushed the fix/worktree-symlink-home-path-match branch from 8a2d719 to 981653f Compare July 24, 2026 08:40
On immutable Linux, /home is often a symlink to /var/home. git worktree
list reports the realpath while Orca still holds the /home request path,
so creation failed with "Worktree created but not found in listing".

After local worktree add, fall back to realpath when string comparison
misses. Keep WSL listings on string comparison only (host realpath is not
authoritative there).

Closes stablyai#10170
@innocarpe innocarpe reopened this Jul 24, 2026
@nwparker nwparker added the bug Something isn't working label Jul 27, 2026
@nwparker

nwparker commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Closing as superseded — the linked issue(s) for this PR were fixed by another change that has already been merged.

Superseding merge: #10266

Thank you for the contribution! If anything remains unaddressed, please open a new issue or PR against current main.

@nwparker nwparker closed this Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Worktree creation fails on immutable Linux when /home resolves to /var/home

3 participants