Skip to content

Reconcile existing-folder project identity from canonical remotes (#10620) - #10809

Closed
AmethystLiang wants to merge 1 commit into
mainfrom
bug-existing-folder-fails-with-imported-folder-d
Closed

AmethystLiang wants to merge 1 commit into
mainfrom
bug-existing-folder-fails-with-imported-folder-d

Conversation

@AmethystLiang

Copy link
Copy Markdown
Contributor

Summary

Fixes #10620 by re-probing an existing folder's git remotes on its own host before accepting or rejecting a project link. When setup identity initially mismatches, Orca now:

  1. Probes the folder's current remotes (with 3s timeout) on local/SSH/runtime hosts
  2. Accepts the setup if a probed remote matches the selected project's canonical keys
  3. Persists the matching remote identity and project link on acceptance only
  4. Leaves the store untouched on rejection — no stale identity write behind

This handles two causes of "Imported folder does not match the selected project identity":

  • Stale/missing gitRemoteIdentity on existing records (add paths returned unchanged records, so detect never re-ran)
  • Asymmetric GitHub metadata across hosts (a clone on a host without GitHub credentials settles as git:, while the same repo on a credentialed host settles as github:)

The unified policy applies to local IPC, SSH IPC, and runtime-host setup paths; a fork checkout persists the matching origin rather than the primary upstream remote.

Testing

  • Reconciliation unit tests (40+ scenarios): remote matching, fork checkouts, GHES with endpoint ports, GitHub fallback, concurrent enrichment, rollback of writes that landed but failed verification, host routing (local/SSH/runtime), worktree meta remapping
  • Entry-point integration: local IPC (IPC setup) + SSH IPC (probes via SSH, never local git) + runtime setup (isolated git env, real probe)
  • Preserved: remote canonicalization, enrichment contract, projection tests

Platform-Specific & Security

  • SSH: Probes through the authorized connection; never runs local git for remote paths. Runtime service refuses SSH hosts (validates paths locally)
  • GitHub Enterprise: Preserves upstream.host in sanitization; migration (remapHostLessGitHubEnterpriseProjectIds) converges stale host-less project IDs on first load
  • Store atomicity: Rejected imports fully roll back identity writes; identity repairs re-key worktree meta in same store cycle
  • Timeout: 3s probe bounds inside 15s setup RPC budget; unbounded git calls degrade to unavailable rather than hang
  • Git baseline: Uses git remote -v (Git 2.25+) with optional timeout on local (execFile) and SSH (provider.exec) calls

Notes

  • DESIGN.md documents the full policy, failure contract, and known limitations (folder projects still need multi-host support)
  • GitHub fallback still applies: a probe that finds no match may still link through the selected project's GitHub metadata
  • No feature flag needed; records with stale non-null identities are repaired only by this flow (enrichment skips them)
  • One visible change at first launch: GHES repos now display under host-qualified IDs instead of being re-keyed to host-less by the renderer

Before rejecting a mismatched existing Git folder, synchronously re-probe its
current remotes on the host that owns it and decide acceptance from canonical
remote keys, not from projected project ids. Persist the authoritative result on
acceptance only; a rejected import leaves the store untouched.

The policy applies uniformly to local, SSH, and runtime-host setup paths. A
migration converges stale host-less GitHub Enterprise project IDs onto their
host-qualified equivalents.
@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The change adds multi-remote canonical Git identity probing with timeout handling, centralized existing-folder reconciliation, rollback support, worktree metadata repair, and GitHub Enterprise project-ID migration. Local IPC and runtime setup paths now use reconciliation with execution-host validation and conditional notifications. Persistence preserves upstream hosts and restores identity fields for rejected writes. Extensive unit and integration tests cover matching, fallback, routing, rollback, migration, and isolated Git behavior.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 41.67% 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 Clearly names the existing-folder identity reconciliation change and matches the main PR scope.
Description check ✅ Passed It covers the main summary, testing, security, and notes sections, though screenshots and the AI Review Report section are omitted.
Linked Issues check ✅ Passed The new reconciliation flow accepts matching existing folders and persists only on successful identity matches, matching #10620.
Out of Scope Changes check ✅ Passed The added tests, fixtures, and GHES remap logic are directly tied to the existing-folder reconciliation fix.
✨ 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.

@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

🧹 Nitpick comments (3)
DESIGN.md (1)

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

Tag the fenced block to satisfy MD040.

-```
+```text
 projectCanonicalKeys(project) =

Source: Linters/SAST tools

src/main/ipc/repos-remote.test.ts (1)

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

Prefer the channel-counting helper over not.toHaveBeenCalledWith('repos:changed').

toHaveBeenCalledWith('repos:changed') only matches an exact single-argument call. If notifyReposChanged ever sends a payload alongside the channel, this assertion silently passes even when a broadcast occurred. reposChangedNotifications() (Line 1765) filters on channel only and is immune to that.

♻️ Suggested tightening
-    // The store never changed, so the renderer must not be told it did.
-    expect(mockWindow.webContents.send).not.toHaveBeenCalledWith('repos:changed')
+    // The store never changed, so the renderer must not be told it did.
+    expect(reposChangedNotifications()).toBe(0)
src/main/persistence.test.ts (1)

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

Consider asserting getProjects()/getProjectHostSetups() survive the load-time remap too.

This test only checks worktreeMeta. The scenario the "Why" comment in persistence.ts calls out — a host-less GHES reference losing its project row when mergeProjectHostSetupCompatibilityState rebuilds repo-backed rows — is only unit-tested in isolation (github-enterprise-project-id-remap.test.ts), not through the full Store.load() pipeline. Adding a project/host-setup assertion here would cover the end-to-end path for the actual motivating bug (#10620).


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9863d362-9c9e-4f0c-9cfd-f36b43bc4ec8

📥 Commits

Reviewing files that changed from the base of the PR and between 4ada3f8 and 9725e59.

📒 Files selected for processing (20)
  • DESIGN.md
  • src/main/github-enterprise-project-id-remap.test.ts
  • src/main/github-enterprise-project-id-remap.ts
  • src/main/ipc/repos-remote.test.ts
  • src/main/ipc/repos.ts
  • src/main/persistence.test.ts
  • src/main/persistence.ts
  • src/main/project-host-existing-folder-reconciliation-fixture.ts
  • src/main/project-host-existing-folder-reconciliation.test.ts
  • src/main/project-host-existing-folder-reconciliation.ts
  • src/main/project-identity-repair-worktree-meta.ts
  • src/main/project-remote-identity-match.ts
  • src/main/repo-git-remote-identity-enrichment.test.ts
  • src/main/repo-git-remote-identity.test.ts
  • src/main/repo-git-remote-identity.ts
  • src/main/runtime/isolated-git-repo-fixture.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/shared/git-remote-identity.test.ts
  • src/shared/git-remote-identity.ts

Comment on lines +14936 to +14941
const ownedExecutionHostId = normalizeExecutionHostId(hostId) ?? LOCAL_EXECUTION_HOST_ID
if (parseExecutionHostId(ownedExecutionHostId)?.kind === 'ssh') {
throw new Error(
'SSH hosts must be set up through the desktop projectHostSetups.setupExistingFolder IPC.'
)
}

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.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
ast-grep run --pattern $'export function normalizeExecutionHostId($$$) { $$$ }' --lang typescript src/shared/execution-host.ts
rg -nP -C3 '\bnormalizeExecutionHostId\s*\(' src --type=ts

Repository: stablyai/orca

Length of output: 30207


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "## execution host parsing helpers"
sed -n '1,180p' src/shared/execution-host.ts | cat -n

echo
echo "## orca-runtime addExistingFolder context"
sed -n '14888,14998p' src/main/runtime/orca-runtime.ts | cat -n

echo
echo "## addRepo definitions/usages"
rg -n "function addRepo|addRepo\s*\(" src/main/src src/main --type=ts | sed -n '1,120p'
# locate implementation more robustly by filename/outline
fd -e ts . src/main | xargs -r rg -n "addRepo\\s*\\(|class .*Repo|executionHostId" | sed -n '1,140p'

Repository: stablyai/orca

Length of output: 23134


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "## implementation files containing addRepo"
rg -n "async .*addRepo|addRepo\s*\(" src/main/runtime src/main/persistence src/main/ipc --type=ts | sed -n '1,180p'

echo
echo "## exact orca-runtime addExistingFolder"
sed -n '14888,14998p' src/main/runtime/orca-runtime.ts | cat -n

echo
echo "## orca runtime repo methods around addRepo"
rg -n -C5 "addRepo\\s*\\(" src/main/runtime src/main --type=ts | sed -n '1,220p'

Repository: stablyai/orca

Length of output: 2132


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "## orca-runtime addRepo implementation"
sed -n '15400,15495p' src/main/runtime/orca-runtime.ts | cat -n

echo
echo "## setupProjectClone host resolution context"
sed -n '15690,15820p' src/main/runtime/orca-runtime.ts | cat -n

echo
echo "## imports/constants around addExistingFolder/top"
sed -n '1,80p' src/main/runtime/orca-runtime.ts | cat -n

Repository: stablyai/orca

Length of output: 13521


Stamp the repo with the canonical ownedExecutionHostId, not the raw args.hostId.

normalizeExecutionHostId can return null for unparseable values, which this code masks by treating the host as local while addRepo still stamps args.hostId on the persisted Repo. Pass ownedExecutionHostId to addRepo, and reject instead of coercing when normalization returns null.

🛡️ Proposed alignment
-    const repo = await this.addRepo(
-      args.path,
-      args.kind === 'folder' ? 'folder' : 'git',
-      args.hostId
-    )
+    const repo = await this.addRepo(
+      args.path,
+      args.kind === 'folder' ? 'folder' : 'git',
+      ownedExecutionHostId
+    )

Comment on lines +14996 to 15001
this.invalidateResolvedWorktreeCache()
// Reconciliation can move the repo between projects, and only an identity write does
// that — the setup-method stamp it always writes is already in the returned result.
if (!addRepoNotified || didReconciliationChangeRepoIdentity(repo, result.repo)) {
this.notifyReposChanged()
}

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.

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
ast-grep run --pattern 'export function didReconciliationChangeRepoIdentity($$$) { $$$ }' --lang typescript src/main/project-host-existing-folder-reconciliation.ts
rg -nP -C4 'projectHostSetupMethod' src/main/project-host-existing-folder-reconciliation.ts

Repository: stablyai/orca

Length of output: 1025


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Locate and inspect the relevant implementation and call sites without running repository code.
wc -l src/main/project-host-existing-folder-reconciliation.ts src/main/runtime/orca-runtime.ts

printf '\n--- project-host-existing-folder-reconciliation outline ---\n'
ast-grep outline src/main/project-host-existing-folder-reconciliation.ts \
  --view expanded | sed -n '1,220p'

printf '\n--- reconciliation function body ---\n'
sed -n '300,385p' src/main/project-host-existing-folder-reconciliation.ts

printf '\n--- didReconciliationChangeRepoIdentity definition/usages ---\n'
rg -n "didReconciliationChangeRepoIdentity|notifyReposChanged|addRepoNotified|result.repo" \
  src/main/src/main/runtime/orca-runtime.ts src/main/project-host-existing-folder-reconciliation.ts

printf '\n--- orca-runtime snippets around repo reconcile/add path ---\n'
sed -n '14960,15015p' src/main/runtime/orca-runtime.ts

Repository: stablyai/orca

Length of output: 5321


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- didReconciliationChangeRepoIdentity definition ---'
sed -n '260,285p' src/main/project-host-existing-folder-reconciliation.ts

printf '%s\n' '--- setup result definition ---'
sed -n '90,145p' src/main/project-host-existing-folder-reconciliation.ts

printf '%s\n' '--- reconciliation call sites ---'
rg -n -C3 "reconcileExistingFolderProjectIdentity|didReconciliationChangeRepoIdentity" src/main

printf '%s\n' '--- orca-runtime snippet ---'
sed -n '14960,15012p' src/main/runtime/orca-runtime.ts

printf '%s\n' '--- repo identity update sites ---'
rg -n -C2 "projectHostSetupMethod|setup-method|notification" src/main/project-store src/main/src/main 2>/dev/null || true

Repository: stablyai/orca

Length of output: 14887


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- notifyReposChanged definitions/usages ---'
rg -n -C3 "notifyReposChanged|repos-changed|getRepos|listRepos|getProjectHostSetups|listProjectHostSetups" src/main src/shared | sed -n '1,260p'

printf '%s\n' '--- shared types repo/projectHostSetup references ---'
rg -n -C2 "projectHostSetupMethod|ProjectHostSetup|RepoProjectHostSetupMethod|emitRepo|repos-changed" src/shared src/main | sed -n '1,260p'

Repository: stablyai/orca

Length of output: 34124


Broadcast the stale repo update from setupProjectExistingFolder when the same repo is already hosted.

Reconciliation writes updateRepo(repo.id, { projectHostSetupMethod }) after result is built, but the return gate skips notifyReposChanged() unless identity fields changed or this was the add broadcast. If the repo already existed on this host, other clients continue reading the old setup-method/link until an unrelated refresh.

@OrcaWin

OrcaWin commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

Moving this PR to draft because it has been untouched for more than 80 days (latest recorded PR activity or commit timestamp: 2026-07-27T00:38:26Z; checked on 2026-10-27). This keeps the review queue focused on active work while preserving the proposal. Please mark it ready for review when work resumes.

@nwparker

nwparker commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Closing as superseded — the linked issue (#10620) has been resolved on main by #10986 (c140a51118), #30785 (a201eacd06). Thanks for the contribution!

@nwparker nwparker closed this Nov 5, 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]: “Existing folder” fails with “Imported folder does not match the selected project identity” in Available Hosts

3 participants