Skip to content

Refresh project worktrees created outside Orca - #6241

Merged
brennanb2025 merged 13 commits into
mainfrom
brennanb2025/issue-5104-worktree-list-refresh
Jun 28, 2026
Merged

brennanb2025 merged 13 commits into
mainfrom
brennanb2025/issue-5104-worktree-list-refresh

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #5104

Summary

  • Adds a main-process watcher for local project worktree roots and Git common-dir worktree metadata so externally-created Git worktrees trigger the existing worktrees:changed refresh path.
  • Keeps refresh targeted to affected repo IDs, skips SSH/runtime/folder repos, and skips WSL UNC local desktop watching with a one-time warning instead of adding polling.
  • Cleans up watcher handles during app shutdown and resyncs watchers on window attach, repo changes, and workspace settings changes.

UI State Behavior

  • Hiding N discovered worktrees is the initial hidden external-worktree review state for a repo. If another external worktree is created outside Orca while the repo is still in this state, it is folded into that same hidden-discovered count/list rather than shown as a separate inbox.
  • New externally-created worktrees appears only after the initial hidden-worktree baseline has been handled/dismissed. It represents hidden external worktrees detected after that baseline, so the two bars should not appear together for the same repo.

Design and Review

  • Design approach: event-driven local watcher, low-churn Git metadata completion signal, no renderer event-contract changes.
  • Design review outcome: prior reviewed scratch design had no actionable P0/P1 findings.
  • Implementation deviation: missing base roots use the Git common-dir metadata watcher and log unavailable base roots instead of parent sentinel watching, to avoid broad parent-directory watches.
  • Delegated Codex subagents could not run from this shell because codex exec fails with missing CODEX_LB_API_KEY; local review, perf audit, tests, and Electron validation were completed instead.

Perf Audit

  • Touched hot paths: filesystem watching and worktree/git refresh invalidation.
  • No polling and no subprocesses in watcher callbacks or watcher setup; Git common-dir is resolved from .git / gitdir: filesystem metadata.
  • One native watcher per unique configured base root and per unique Git common dir, with burst coalescing before existing targeted worktrees:changed events.
  • Focused tests cover deep checkout churn filtering, burst coalescing, non-local repo skips, and watcher unsubscribe on base-path changes.

Validation

  • Reproduced before implementation in Electron: raw git worktree add under configured worktrees/project/<name> did not appear until manual fetchWorktrees(repoId).
  • Electron validation after fix from this worktree: app identity issue-5104-worktree-list-refresh; disposable repo under /private/tmp/orca-5104-final.Zx8ZjB; baseline visible count 1; raw git worktree add .../worktrees/project/external-final-5104 -b external-final-5104; after watcher debounce, visible count 2 and branch refs/heads/external-final-5104 appeared without manual refresh.
  • Screenshot evidence captured locally: .playwright-cli/issue-5104-final-visible-worktrees.png.

Checks

  • pnpm run typecheck
  • pnpm run lint
  • git diff --check
  • pnpm exec vitest run --config config/vitest.config.ts src/main/ipc/worktree-base-directory-watcher.test.ts

Risks

  • WSL UNC project-root watching is explicitly skipped to avoid adding a polling project invalidator; WSL keeps existing manual/other refresh behavior until a WSL-native event design is added.
  • External non-Git directory creation under the workspace root is not surfaced; this change targets registered Git worktree metadata and checkout .git completion signals.

@coderabbitai

coderabbitai Bot commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This PR adds an external worktree inbox flow and a worktree base directory watcher flow. It introduces shared external-worktree path and eligibility helpers, repo state and update fields, renderer inbox rows and actions, and locale strings. It also adds event filtering, watcher subscription and sync logic, main-process wiring for watcher lifecycle events, and tests covering the new behavior.

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (3 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is detailed but does not follow the required template and omits several required sections. Rewrite the PR description using the repository template and add the missing Screenshots, Testing, AI Review Report, Security Audit, and Notes sections.
Out of Scope Changes check ⚠️ Warning The PR adds a broad external-worktree inbox and suppression UI flow beyond #5104's refresh bug. Move the inbox UI, suppression, and persistence work to a separate PR unless it is required for the bug fix.
Docstring Coverage ⚠️ Warning Docstring coverage is 4.11% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed Title clearly summarizes the main change: refreshing project worktrees created outside Orca.
Linked Issues check ✅ Passed The watcher and sync changes address #5104 by refreshing affected repos when new worktrees appear in the configured directory.

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.

Actionable comments posted: 3

🧹 Nitpick comments (4)
src/main/ipc/worktree-base-directory-watcher.test.ts (1)

32-168: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use Node path utilities for fixture paths to keep tests cross-platform.

These tests currently hardcode / path separators in many fixtures. Please build paths with path.join (or a small helper) so the suite remains portable across platforms.

♻️ Suggested pattern
+import { join, sep } from 'node:path'
+
+const p = (...parts: string[]) => join(sep, ...parts)
+const WORKTREE_ROOT = p('workspace', 'worktrees')
+const PROJECT_ROOT = p('workspace', 'projects', 'project')
+const PROJECT_GIT_COMMON = join(PROJECT_ROOT, '.git')

 const settings = {
-  workspaceDir: '/workspace/worktrees',
+  workspaceDir: WORKTREE_ROOT,
   nestWorkspaces: true
 } as GlobalSettings

 function makeRepo(overrides: Partial<Repo> = {}): Repo {
   return {
     id: 'repo-1',
-    path: '/workspace/projects/project',
+    path: PROJECT_ROOT,
     displayName: 'Project',
@@
-    emit('/workspace/worktrees', [
-      { type: 'create', path: '/workspace/worktrees/project/external-5104' },
-      { type: 'create', path: '/workspace/worktrees/project/external-5104/.git' }
+    emit(WORKTREE_ROOT, [
+      { type: 'create', path: join(WORKTREE_ROOT, 'project', 'external-5104') },
+      { type: 'create', path: join(WORKTREE_ROOT, 'project', 'external-5104', '.git') }
     ] as WatcherEvent[])

As per coding guidelines, “Use path.join or Electron/Node path utilities for file paths — never assume / or \ for cross-platform compatibility.”

Source: Coding guidelines

src/main/window/attach-main-window-services.ts (1)

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

Add a short Why: for the attach-time watcher sync.

This hook is easy to remove as “redundant” because repo and settings changes also resync watchers. A one-line rationale here would preserve the lifecycle contract.

As per coding guidelines, “When writing or modifying code driven by a design doc or non-obvious constraint, add a comment explaining why the code behaves the way it does.”

Source: Coding guidelines

src/main/ipc/worktree-base-directory-event-filter.ts (1)

33-54: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a short why comment for the shallow matching rules.

These predicates encode the key design constraint: only completion/root-delete/common-dir metadata signals should refresh worktrees, while deeper churn is ignored.

Suggested comment placement
+// Why: root creation can fire before checkout is usable; `.git` marks completion.
 function isRootCompletionEvent(parts: string[], config: WorktreeBaseRepoWatchConfig): boolean {
+// Why: Git registers linked worktrees under the common dir's `worktrees` metadata.
 function matchingGitCommonRepoIds(target: WorktreeBaseWatchTarget, eventPath: string): string[] {

As per coding guidelines, **/*.{ts,tsx,js,jsx} code driven by a design doc or non-obvious constraint should include a short comment explaining why.

Also applies to: 78-83

Source: Coding guidelines

src/main/ipc/worktree-base-directory-watcher.ts (1)

166-174: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Document why WSL UNC roots are skipped.

The warning says what happens, but not why this intentionally avoids watching/polling those roots.

Suggested comment
+  // Why: local desktop file watching is unreliable for WSL UNC roots; avoid polling.
   if (isWslUncPath(workspaceRoot) || isWslUncPath(repo.path)) {

As per coding guidelines, **/*.{ts,tsx,js,jsx} code driven by a design doc or non-obvious constraint should include a short comment explaining why.

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5a8baade-1b15-4eed-b15d-acf68f6b794a

📥 Commits

Reviewing files that changed from the base of the PR and between 5106e33 and e516737.

📒 Files selected for processing (7)
  • src/main/index.ts
  • src/main/ipc/repos.ts
  • src/main/ipc/settings.ts
  • src/main/ipc/worktree-base-directory-event-filter.ts
  • src/main/ipc/worktree-base-directory-watcher.test.ts
  • src/main/ipc/worktree-base-directory-watcher.ts
  • src/main/window/attach-main-window-services.ts

Comment thread src/main/index.ts Resolved
Comment thread src/main/ipc/settings.ts Resolved

@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 (4)
src/main/ipc/worktree-base-directory-watcher.ts (1)

208-214: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a short why-comment for the stale-generation unsubscribe path.

This cleanup is guarding a subtle async race, so it deserves an in-code reason before someone “simplifies” it away in a later refactor. As per coding guidelines, “When writing or modifying code driven by a design doc or non-obvious constraint, add a comment explaining why the code behaves the way it does.”

Source: Coding guidelines

src/main/ipc/worktree-common-git-directory.ts (1)

21-23: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Document the worktrees/../.. fallback.

This branch depends on Git’s linked-worktree metadata layout and is not self-explanatory from the expression alone. A one-line why-comment would make the contract much safer to maintain. As per coding guidelines, “When writing or modifying code driven by a design doc or non-obvious constraint, add a comment explaining why the code behaves the way it does.”

Source: Coding guidelines

src/main/ipc/repos.ts (1)

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

Add a short why-comment for the watcher resync side effect.

notifyReposChanged() now does more than IPC fanout, and that extra watcher sync is design-driven rather than obvious from the callsite. A brief reason here would help preserve the contract. As per coding guidelines, “When writing or modifying code driven by a design doc or non-obvious constraint, add a comment explaining why the code behaves the way it does.”

Source: Coding guidelines

src/main/ipc/settings.ts (1)

113-118: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a why-comment for the post-settings watcher resync.

The relationship between workspaceDir/nestWorkspaces, prepareLocalWorktreeRootsForRepos(store), and this watcher reschedule is policy-heavy and not obvious from control flow alone. As per coding guidelines, “When writing or modifying code driven by a design doc or non-obvious constraint, add a comment explaining why the code behaves the way it does.”

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 885aca72-9964-4885-a802-f6f4c4473c2c

📥 Commits

Reviewing files that changed from the base of the PR and between e516737 and 7f05305.

📒 Files selected for processing (8)
  • src/main/index.ts
  • src/main/ipc/repos.ts
  • src/main/ipc/settings.ts
  • src/main/ipc/worktree-base-directory-event-filter.ts
  • src/main/ipc/worktree-base-directory-watcher.test.ts
  • src/main/ipc/worktree-base-directory-watcher.ts
  • src/main/ipc/worktree-common-git-directory.ts
  • src/main/window/attach-main-window-services.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main/window/attach-main-window-services.ts
  • src/main/ipc/worktree-base-directory-event-filter.ts

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/renderer/src/components/sidebar/WorktreeList.tsx (1)

6517-6524: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

filtersHideAllRows doesn't account for inbox candidates.

buildRows includes newExternalWorktreesInboxByRepo, so a repo with only an inbox row (no visible worktrees, placeholders, or imported-card candidates) produces a non-empty rows. But filtersHideAllRows ignores the inbox map, so when filters are active this evaluates true and the early return renders the "No workspaces found" empty state, hiding the inbox row entirely. Since inbox candidates already honor filterRepoIds, include them in the guard.

🐛 Proposed fix
   const filtersHideAllRows =
     hasFilters &&
     worktrees.length === 0 &&
     placeholderRepoIds.size === 0 &&
-    importedWorktreesByRepo.size === 0
+    importedWorktreesByRepo.size === 0 &&
+    newExternalWorktreesInboxByRepo.size === 0
🧹 Nitpick comments (1)
src/renderer/src/components/sidebar/worktree-list-groups.ts (1)

1105-1138: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Deduplicate the per-group repoIds computation.

repoIdsInGroup (Lines 1106-1113) repeats the exact repoIds fallback computed a few lines above (Lines 1077-1084 in the imported-card/pending block). Computing it once and reusing it avoids the two copies drifting apart later.

Also note the per-repo split changes ordering for multi-repo project groups: previously orderMainWorktreeFirst(group.items) ordered the whole group together; now worktrees are segregated by repoId in group.repoIds insertion order, which may not match the manual/repoOrder ranking. Please confirm this ordering is intended.

♻️ Hoist the shared repoIds list
       if (!isCollapsed) {
+        const repoIds =
+          groupBy === 'repo'
+            ? group.repoIds.size > 0
+              ? [...group.repoIds]
+              : repo
+                ? [repo.id]
+                : key.startsWith('repo:')
+                  ? [key.slice('repo:'.length)]
+                  : []
+            : []
         if (groupBy === 'repo') {
-          const repoIds =
-            group.repoIds.size > 0
-              ? [...group.repoIds]
-              : repo
-                ? [repo.id]
-                : key.startsWith('repo:')
-                  ? [key.slice('repo:'.length)]
-                  : []
           for (const repoId of repoIds) {

Then reuse repoIds for repoIdsInGroup at Line 1106.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: e3b3ec73-b293-47da-a817-b2af9044781e

📥 Commits

Reviewing files that changed from the base of the PR and between 5b79ef0 and 52a86f2.

📒 Files selected for processing (32)
  • src/main/ipc/repos.ts
  • src/main/persistence.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/rpc/methods/repo.ts
  • src/preload/api-types.ts
  • src/renderer/src/components/sidebar/NewExternalWorktreesInboxLine.tsx
  • src/renderer/src/components/sidebar/SuppressExternalWorktreeInboxDialog.tsx
  • src/renderer/src/components/sidebar/WorktreeList.tsx
  • src/renderer/src/components/sidebar/WorktreeVisibilityDialog.tsx
  • src/renderer/src/components/sidebar/host-section-rows.ts
  • src/renderer/src/components/sidebar/imported-worktrees-card-actions.test.ts
  • src/renderer/src/components/sidebar/imported-worktrees-card-actions.ts
  • src/renderer/src/components/sidebar/imported-worktrees-card-candidates.ts
  • src/renderer/src/components/sidebar/new-external-worktrees-inbox-actions.test.ts
  • src/renderer/src/components/sidebar/new-external-worktrees-inbox-actions.ts
  • src/renderer/src/components/sidebar/new-external-worktrees-inbox-candidates.test.ts
  • src/renderer/src/components/sidebar/new-external-worktrees-inbox-candidates.ts
  • src/renderer/src/components/sidebar/worktree-drag-units.ts
  • src/renderer/src/components/sidebar/worktree-list-groups.test.ts
  • src/renderer/src/components/sidebar/worktree-list-groups.ts
  • src/renderer/src/components/sidebar/worktree-list-virtual-rows.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/zh.json
  • src/renderer/src/store/slices/repos.ts
  • src/shared/external-worktree-inbox.test.ts
  • src/shared/external-worktree-inbox.ts
  • src/shared/types.ts
  • src/shared/worktree-ownership.test.ts
  • src/shared/worktree-ownership.ts
✅ Files skipped from review due to trivial changes (2)
  • src/renderer/src/i18n/locales/zh.json
  • src/renderer/src/i18n/locales/ja.json

Comment thread src/main/persistence.ts Resolved
brennanb2025 and others added 11 commits June 26, 2026 14:37
Adds a second-stage inbox in the worktree sidebar for repos that already
dismissed the initial imported-worktrees prompt. Users can import new
externals, keep them hidden, import all, or permanently opt out with
recovery via Non-Orca worktrees settings.
Co-authored-by: Orca <help@stably.ai>
Co-authored-by: Orca <help@stably.ai>
Co-authored-by: Orca <help@stably.ai>
Co-authored-by: Orca <help@stably.ai>
Co-authored-by: Orca <help@stably.ai>
Co-authored-by: Orca <help@stably.ai>
Co-authored-by: Orca <help@stably.ai>
@brennanb2025
brennanb2025 force-pushed the brennanb2025/issue-5104-worktree-list-refresh branch from f294374 to 24c3506 Compare June 26, 2026 21:38
Co-authored-by: Orca <help@stably.ai>

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/main/runtime/rpc/methods/repo-update-schema.ts (1)

54-54: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Remove the redundant .finite() calls from these z.number() schemas. z.number() already rejects non-finite values in Zod 4, so the chain is just noise. Same applies to the other .finite() on this object.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: c187ff4c-9cfb-4c31-9165-1e5b48f439a6

📥 Commits

Reviewing files that changed from the base of the PR and between 52a86f2 and f1ed081.

📒 Files selected for processing (14)
  • src/main/index.ts
  • src/main/ipc/repos.ts
  • src/main/ipc/settings.ts
  • src/main/ipc/worktree-base-directory-event-filter.ts
  • src/main/ipc/worktree-base-directory-watch-targets.ts
  • src/main/ipc/worktree-base-directory-watcher.test.ts
  • src/main/ipc/worktree-base-directory-watcher.ts
  • src/main/ipc/worktree-common-git-directory.ts
  • src/main/persistence.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/rpc/methods/repo-update-schema.ts
  • src/main/runtime/rpc/methods/repo.ts
  • src/main/window/attach-main-window-services.ts
  • src/preload/api-types.ts
🚧 Files skipped from review as they are similar to previous changes (9)
  • src/main/ipc/settings.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/window/attach-main-window-services.ts
  • src/main/ipc/worktree-common-git-directory.ts
  • src/preload/api-types.ts
  • src/main/index.ts
  • src/main/ipc/worktree-base-directory-event-filter.ts
  • src/main/ipc/repos.ts
  • src/main/ipc/worktree-base-directory-watcher.test.ts

Co-authored-by: Orca <help@stably.ai>
@brennanb2025
brennanb2025 merged commit 8ed8903 into main Jun 28, 2026
1 check passed
@brennanb2025
brennanb2025 deleted the brennanb2025/issue-5104-worktree-list-refresh branch June 28, 2026 20:09
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 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]: macOS project worktree list does not refresh after an agent creates a new worktree

1 participant