Skip to content

fix: honor canonical SSH ownership in worktree listings - #23198

Merged
OrcaWin merged 11 commits into
mainfrom
nwparker/perf-09-25-canonical-ssh-listing-owner
Sep 26, 2026
Merged

OrcaWin merged 11 commits into
mainfrom
nwparker/perf-09-25-canonical-ssh-listing-owner

Conversation

@nwparker

@nwparker nwparker commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​241 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​241
Prod 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​165 $\color{#cf222e}{\Huge{\mathbf{−}}}$​73 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​92

ELI5

Repositories stored with the newer SSH host field now use the same remote listing rules as older SSH repositories. Losing contact no longer makes a cached local-path answer look authoritative, and a listing that finishes after a mutation cannot remove newer worktree lineage.

What Changed

Listing adapters resolve the repository's execution host before selecting SSH providers, capturing provider authority, or admitting local scan-cache/root-registration work. Both catalog listing methods capture the existing mutation/root-revision token before awaiting SSH, so cleanup rejects an overtaken answer. Generic runtime-host refusal remains.

Controlled behavior Before After
Canonical SSH host-qualified / known-catalog read Rejected Existing supported response
Canonical SSH result sent to local-root registration 1 call 0
Detected read after provider disconnect Cached authoritative result Non-authoritative fallback
Listing overtaken by a mutation/root revision Legacy SSH could prune newer lineage Cleanup suppressed for both SSH spellings
Two direct canonical SSH scans within five seconds 1 provider listing 2

This is a correctness fix found during the performance audit. The counts describe routing and request work, not a CPU, latency or heap improvement.

Why

Reuse the existing host resolver and side-effect guard. Adding another SSH cache would require provider-scoped invalidation and separate proof. This is a separate trade-off PR because fresh provider reads cost more than the improper local cache.

Linked Issue

N/A — PR only, as requested by the maintainer.

Visual Proof

N/A — provider routing and cleanup authority; deterministic handler/lineage assertions, no UI markup or app launch.

Shared hourly CI prerequisite

The branch also carries the shared hourly-build fixture correction from #23274. Historical package-version inputs are explicit, with exact version/build-number assertions retained and a newer-package control. Default build commands still read package.json; the dedicated no-module-mocking lint rule stays enabled.

Testing

  • Manual native-app/live-SSH test — not run
  • Automated tests added

All tests use ORCA_BACKGROUND_LAUNCH=1. The permanent suite has 26 cases; original source fails 13 and passes 13 controls. Independent review adds 14 cases, including actual in-memory lineage pruning, for 40 passing cases on isolated current main. The initial candidate failed the lineage race; it was repaired and re-reviewed before publication.

The eight related suites pass all 61 cases on current main. Node typecheck, scoped lint/format and the isolated 127-entry reliability manifest pass. The shared changed-code quality gate passed across 198 files. Linux/Windows, live SSH/WSL, actual Git processes and deployed mixed-version integration remain untested. Fixtures mock provider/Git/store/IPC boundaries and perform no user-path writes.

AI Disclosure

Review

Independent review approved after repair. Merge risk: moderate, because six listing adapters change routing and cleanup authority. The changed files are unchanged upstream from the audit baseline; this PR is isolated on freshly fetched main.

Reliability class/gate: worktree-listing.execution-host-ownership (experimental). Invariant: SSH-owned reads stay on their provider, avoid local-root/cache admission, and cannot prune newer lineage after a mutation. The motivating path is a canonical SSH repo without legacy connectionId. Read, provider-call, cache-size, root-registration and lineage assertions are the diagnostics/oracles. No new polling; list-all concurrency remains eight.

Agent skill upstream boundary

  • Not applicable; no upstream skill content copied.

Notes

Negative user-facing trade-off: repeated canonical SSH listings now reach the provider rather than reusing the improper five-second local cache. Two direct connected scans change from one provider read to two, matching existing legacy SSH behavior.

Local/daemon PTYs, terminal output and mobile wire are unaffected. WSL command construction, Git options and folder-workspace paths are unchanged; generic remote-runtime rows retain refusal. Native macOS unit execution is covered; native Linux/Windows and live remote integrations remain gaps.

Catalog list/listAll can still return an older plain-array snapshot; this change fences its cleanup, not every stale response. Canonical forgetRemovedForExecutionHost remains outside scope. The separate filesystem classifier and root-registry repairs are not claimed fixed by this listing change. No physical cancellation claim.

Checklist

  • Focused change with its trade-off isolated
  • Before/after, mechanism and alternative explained
  • Visual N/A explained
  • Independently reviewed for correctness and performance
  • Platform, SSH/remote, folder workspace and compatibility impact considered
  • Full lint/typecheck/test/build matrix — scoped checks above; broader checks remain to CI

@coderabbitai

coderabbitai Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: a6b7ed99-2838-42e0-a23d-44eb2c7b5b74

📥 Commits

Reviewing files that changed from the base of the PR and between 1bfedd9 and 71958e8.

📒 Files selected for processing (3)
  • config/reliability-gates.jsonc
  • src/main/ipc/worktrees/listing/host-qualified-worktree-listing.ts
  • src/main/ipc/worktrees/listing/register-host-catalog-handlers.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main/ipc/worktrees/listing/host-qualified-worktree-listing.ts
  • src/main/ipc/worktrees/listing/register-host-catalog-handlers.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

Worktree-listing handlers now derive SSH routing from repository execution-host identity. Non-local repositories bypass the local scan cache and local root registration. SSH catalog listings record scan-generation and registered-roots revisions in side-effect tokens. New tests cover provider routing, authority changes, stale side effects, and runtime repositories. The reliability-gate configuration records the gate scope, evidence, and remaining coverage gaps.

Priority: ⬇️ Low

Merge Risk: 🔵 Low · up to 71958

Canonical SSH repositories can still retain metadata for removed worktrees. This issue predates the change; the PR is otherwise mergeable with owner awareness of that limitation.

Security Architecture Review

Security architecture risk: 🟡 Moderate · up to 71958

Canonical SSH repositories gain working listings, but a catalog listing can still accept a result returned after its SSH provider loses authority and use it to update worktree lineage. A related cleanup operation also continues to reject these repositories, so removed worktrees may remain in fallback listings. No credential exposure or cross-repository access was established.

Retained concerns

  • Medium · security · inferred: Newly reachable canonical SSH catalog listings can accept a successful response after provider authority changes and use its rows for lineage cleanup. Mutation and root-revision tokens do not establish that the provider remains authoritative.
  • Low · reliability · inferred: The known-host listing now accepts canonical SSH ownership, but its related removal operation still requires the legacy connectionId. For a canonical-only repository, scan-proven removals cannot retire metadata that fallback listings may continue to show.
Security review details

Security Blast Radius

  • inferred — The newly reachable authority gap is limited by the evidence to worktree results and lineage for affected SSH repositories; listAll can encounter multiple such repositories. No credential access or cross-repository authorization gain was established.

Security Findings and Attack Paths

  • inferred — If an SSH provider successfully returns an in-flight listing after its authority changes, a catalog handler can treat its rows as current and prune lineage, provided no mutation-generation or root-revision change has fenced the scan. This is a conditional trust-boundary failure, not a demonstrated attacker exploit.

Trust Boundaries and Controls

  • observed — Direct host-qualified listings bind results to captured repository and provider authority, while catalog listings retain mutation and root-revision fencing and disconnected fallback without the corresponding post-await authority check.

Resilience and Maintainability Implications

  • inferred — Canonical SSH metadata can remain after scan-proven removal because cleanup still requires a legacy connectionId, while the newly accepted known-host path can display metadata fallback rows.

Hardening Proposals

  • proposed — Apply the captured provider-authority and repository-ownership checks to catalog responses before accepting rows or performing side effects; align removal authorization with canonical execution-host ownership.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 7 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly and concisely describes the main change: routing canonical SSH worktree listings according to SSH ownership.
Description check ✅ Passed The description covers the required sections, explains the user-facing behavior and implementation, documents testing and known gaps, and marks visual proof as not applicable. The missing linked issue…
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 7 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

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.

Caution

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

⚠️ Outside diff range comments (1)

🟠 Major · Apply the canonical SSH owner check in… · register-host-catalog-handlers.ts:127

src/main/ipc/worktrees/listing/register-host-catalog-handlers.ts:127
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Apply the canonical SSH owner check in worktrees:forgetRemovedForExecutionHost.

The renderer calls this handler when an authoritative SSH scan proves worktrees removed. findExactRepoOwner accepts a repository with executionHostId: 'ssh:<target>' and no connectionId, but the legacy check then returns nothingForgotten. gcStaleWorktreeMeta skips off-host rows, so the metadata can persist and reappear in fallback listings after reload.

Suggested fix
-      if (!repo || (parsedHost.kind === 'ssh' && repo.connectionId !== parsedHost.targetId)) {
+      if (
+        !repo ||
+        (parsedHost.kind === 'ssh' &&
+          getSshTargetIdForExecutionHost(getRepoExecutionHostId(repo)) !== parsedHost.targetId)
+      ) {
         return nothingForgotten
       }

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: cf94d1d5-cfb6-4a6e-8666-9d554e8c6a9a

📥 Commits

Reviewing files that changed from the base of the PR and between 711bacd and 93f50c8.

📒 Files selected for processing (8)
  • config/reliability-gates.jsonc
  • src/main/ipc/worktrees-canonical-ssh-listing.test.ts
  • src/main/ipc/worktrees/listing/detected-provider-listing.ts
  • src/main/ipc/worktrees/listing/detected-worktree-scan-cache.ts
  • src/main/ipc/worktrees/listing/host-qualified-worktree-listing.ts
  • src/main/ipc/worktrees/listing/register-detected-worktree-handlers.ts
  • src/main/ipc/worktrees/listing/register-host-catalog-handlers.ts
  • src/main/ipc/worktrees/listing/register-worktree-catalog-handlers.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

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

Important

The changed-code quality gate fails on this PR — two duplicate execution-host imports. The routing and side-effect-fence changes themselves check out; details inline.

Reviewed changes

  • Canonical SSH routing — the six listing adapters now resolve the host (getSshTargetIdForExecutionHost(getRepoExecutionHostId(repo))) instead of reading raw repo.connectionId, so executionHostId: 'ssh:<target>' rows reach their SSH provider rather than the local scan path.
  • Local root/cache admission — listDetectedGitWorktrees and rememberLocalWorktreeRoots gate on the resolved host, so a remote path is no longer registered as a local root or served from the 5s local cache.
  • Catalog side-effect fence — worktrees:list / listAll capture a generation + roots-revision token before the SSH provider listing, so a mutation that overtakes a listing can no longer prune newer lineage.
  • Tests and gate manifest — new 26-case suite plus the worktree-listing.execution-host-ownership reliability gate.

I verified the new suite passes (26/26), the 12 related suites pass (111 tests), the neighboring execution-host suites pass (55 tests), and typecheck:node passes. I also mutation-checked the new suite: reverting the host guard and one token capture makes 10 of the 26 cases fail, so the coverage is real. The resolver choice is correct for every reachable row shape (canonical, legacy, runtime:<env> with a nested connectionId, WSL, contradictory); runtime rows terminate in WorktreeCatalogUnavailableError and never hit a local git scan.

The only blocker is the import duplication below: pnpm run check:code-quality:changed reports Changed-code quality gate failed with 2 finding(s), so the PR's claim that the changed-code gate passed does not reproduce on this head.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

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

✅ No new issues found.

Reviewed changes

This run re-reviewed the commits since the prior pullfrog review (93f50c8): the import-consolidation fix, a cosmetic test rename, and merges with main.

  • Single execution-host import per adapter — host-qualified-worktree-listing.ts, register-host-catalog-handlers.ts, register-detected-worktree-handlers.ts, and register-worktree-catalog-handlers.ts now import each shared/execution-host symbol once, resolving the import/no-duplicates gate failure from the prior review.
  • Test parameter rename — describe.each in worktrees-canonical-ssh-listing.test.ts renamed shape → hostEncoding; no behavioral change.
  • Merge with main — the worktree-listing.execution-host-ownership reliability gate is preserved, and unrelated i18n diff-note catalog entries are restored (all locales consistent).

Verification on this head: pnpm run check:code-quality:changed reports 0 findings across 7 changed files (was 2), the new suite passes 26/26, pnpm run check:reliability-gates validates 129 gates, and oxlint on the changed listing/test files is clean. Both prior review threads are addressed and resolved.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

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

✅ No new issues found.

Reviewed changes

This run re-reviewed the commits since the prior pullfrog review (1ddf36e): the hourly build-version injection seam and its test conversion. The SSH listing files were untouched by the new commits.

  • Hourly build-version injection seam — getHourlyBuildIdentity now takes an optional packageVersion and falls back to reading package.json, so the identity can be exercised without module mocking. The CLI caller passes no packageVersion, so production behavior is unchanged.
  • Module-mocking removal — hourly-build-version.test.mjs dropped vi.mock('node:fs'); anti-slop/no-module-mocking is an error for .mjs tests because its override only matches **/*.test.{ts,tsx}, so this was required, not optional. Both identity cases now pass explicit packageVersion values.
  • Newer-package floor control — added a case asserting a package version above the published floor still wins.

Verification on this head: the suite passes 17/17; removing the injection privilege (packageVersion ??) fails the unpublished-release case, so the seam is genuinely covered; pnpm run check:code-quality:changed reports 0 findings across 9 changed files. Both prior review threads remain resolved.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@OrcaWin
OrcaWin merged commit b4717f0 into main Sep 26, 2026
39 checks passed
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.

2 participants