Skip to content

Show SSH worktrees immediately via persisted metadata - #12799

Merged
AmethystLiang merged 2 commits into
mainfrom
pr-12646-review-fixes
Aug 6, 2026
Merged

AmethystLiang merged 2 commits into
mainfrom
pr-12646-review-fixes

Conversation

@AmethystLiang

Copy link
Copy Markdown
Contributor

Problem

SSH worktrees were invisible until the SSH connection established and a full scan completed. Users had to wait for connectivity before seeing remote worktrees.

Solution

Added metadata-based fallback listing for SSH worktrees while connection is pending:

  • New IPC handlers listKnownForExecutionHost and forgetRemovedForExecutionHost read and retire persisted worktree metadata
  • Renderer calls metadata fallback when SSH authority isn't available
  • Session-scoped removal memory prevents resurrecting worktrees an authoritative scan proved deleted
  • Main process automatically retires metadata after authoritative scans complete
  • Folder workspaces exempt from retirement (metadata IS the workspace record)
  • Strict validation ensures only SSH hosts and correctly-owned repos can use this path

Screenshots

No visual change.

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test
  • pnpm build
  • Comprehensive test coverage: metadata-only reads, folder workspace handling, retirement after authoritative scans, authorization checks, coalescing of concurrent reads, interaction with local repos, hydration-time behavior

AI Review Report

TBD

Security Audit

TBD

Notes

Metadata-fallback results are marked authoritative: false so they don't suppress workspace session hydration or demote authoritative scans. Folder workspace instance IDs are synthesized without the suffix to match the git-worktree synthesizer's output format.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f47ec82f-d2bb-4dc4-9e0e-526540fb8e34

📥 Commits

Reviewing files that changed from the base of the PR and between 0848359 and c21d7a8.

📒 Files selected for processing (1)
  • src/renderer/src/store/slices/worktrees.test.ts

📝 Walkthrough

Walkthrough

The change adds typed SSH execution-host worktree retirement across shared contracts, IPC, preload, and renderer state. The IPC handler validates repository ownership and removes only matching metadata. The preload bridge forwards retirement requests. The renderer asynchronously retires persisted SSH metadata after authoritative removals while preserving local metadata cleanup behavior. Tests cover host and repository scoping, folder workspaces, fail-closed requests, forwarding, and renderer refresh behavior.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the primary change: showing SSH worktrees immediately by using persisted metadata.
Description check ✅ Passed The description covers the change, screenshots, testing, and notes, but the AI Review Report and Security Audit remain TBD.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

The metadata fallback's protection against resurrecting externally deleted
worktrees lived only in renderer module state, so it died on every reload
while the SSH WorktreeMeta it guarded against persists forever
(gcStaleWorktreeMeta exempts any repo with a connectionId, because a local
existsSync cannot probe a remote path). Repro: `git worktree remove` on the
SSH host, let the authoritative scan purge the row, restart — the startup
fetch runs before SSH connects and the fallback re-lists the deleted
worktree as a ghost row.

Chose option (a), deleting the stale persisted meta in main, over persisting
the removal memory: the metadata is the thing that outlives the worktree, and
Orca's own removals already delete it (removeWorktreeMetadataAndTransientState),
so external removals now converge on the same end state instead of accumulating
a second, parallel tombstone list that would itself need eviction. The
in-session memory stays for the window before the async delete lands.

New `worktrees:forgetRemovedForExecutionHost` only accepts SSH hosts, requires
an exact repo owner, skips metas owned by another host, and refuses folder
repos — a folder workspace's meta IS the workspace record (gcStaleWorktreeMeta
skips those keys for the same reason) and no remote scan can retire one. The
renderer only calls it from the authoritative-removal path, so a mere
disconnect never deletes anything.

Also:
- hoist resetAuthoritativelyRemovedWorktreeMemoryForTests into a top-level
  beforeEach; removeWorktree writes that memory too, so suppression could leak
  across describes and silently hide a row.
- cover the requireAuthoritative gate that skips the fallback, which had no test.
- replace the raw NUL byte committed inside the coalesce-key template literal
  with a \0 escape; it made the file scan as binary to grep/ripgrep.
@AmethystLiang
AmethystLiang force-pushed the pr-12646-review-fixes branch from 03ef3ab to 0848359 Compare August 6, 2026 01:00
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@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


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b2090e38-ae40-456e-8bbe-6482cbb554d7

📥 Commits

Reviewing files that changed from the base of the PR and between aa64ac9 and 0848359.

📒 Files selected for processing (8)
  • src/main/ipc/worktrees.test.ts
  • src/main/ipc/worktrees.ts
  • src/preload/api-types.ts
  • src/preload/index.ts
  • src/preload/ssh-authority-forwarding.test.ts
  • src/renderer/src/store/slices/worktrees.test.ts
  • src/renderer/src/store/slices/worktrees.ts
  • src/shared/detected-worktree-provider-contract.ts
🚧 Files skipped from review as they are similar to previous changes (7)
  • src/preload/ssh-authority-forwarding.test.ts
  • src/main/ipc/worktrees.ts
  • src/preload/api-types.ts
  • src/main/ipc/worktrees.test.ts
  • src/renderer/src/store/slices/worktrees.ts
  • src/preload/index.ts
  • src/shared/detected-worktree-provider-contract.ts

The non-authoritative fallback must not trigger worktree cleanup when it observes an absence — only an authoritative scan should. Tighten the expectation to ensure cleanup happens exactly once, when new data arrives after the connection state changes.
@AmethystLiang
AmethystLiang merged commit 1251e55 into main Aug 6, 2026
0 of 41 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* Retire SSH worktree metadata an authoritative scan proved gone

The metadata fallback's protection against resurrecting externally deleted
worktrees lived only in renderer module state, so it died on every reload
while the SSH WorktreeMeta it guarded against persists forever
(gcStaleWorktreeMeta exempts any repo with a connectionId, because a local
existsSync cannot probe a remote path). Repro: `git worktree remove` on the
SSH host, let the authoritative scan purge the row, restart — the startup
fetch runs before SSH connects and the fallback re-lists the deleted
worktree as a ghost row.

Chose option (a), deleting the stale persisted meta in main, over persisting
the removal memory: the metadata is the thing that outlives the worktree, and
Orca's own removals already delete it (removeWorktreeMetadataAndTransientState),
so external removals now converge on the same end state instead of accumulating
a second, parallel tombstone list that would itself need eviction. The
in-session memory stays for the window before the async delete lands.

New `worktrees:forgetRemovedForExecutionHost` only accepts SSH hosts, requires
an exact repo owner, skips metas owned by another host, and refuses folder
repos — a folder workspace's meta IS the workspace record (gcStaleWorktreeMeta
skips those keys for the same reason) and no remote scan can retire one. The
renderer only calls it from the authoritative-removal path, so a mere
disconnect never deletes anything.

Also:
- hoist resetAuthoritativelyRemovedWorktreeMemoryForTests into a top-level
  beforeEach; removeWorktree writes that memory too, so suppression could leak
  across describes and silently hide a row.
- cover the requireAuthoritative gate that skips the fallback, which had no test.
- replace the raw NUL byte committed inside the coalesce-key template literal
  with a \0 escape; it made the file scan as binary to grep/ripgrep.

* test(worktrees): verify non-authoritative fallback skips removal

The non-authoritative fallback must not trigger worktree cleanup when it observes an absence — only an authoritative scan should. Tighten the expectation to ensure cleanup happens exactly once, when new data arrives after the connection state changes.
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.

1 participant