Skip to content

fix(projects): refuse a Git-to-folder type change while the project has other worktrees - #29265

Closed
brennanb2025 wants to merge 2 commits into
brennan/sta-10638-bug-folder-to-git-conversion-leaves-old-workspaces-orphanedfrom
brennan/sta-10638-pr-b-git-to-folder
Closed

brennanb2025 wants to merge 2 commits into
brennan/sta-10638-bug-folder-to-git-conversion-leaves-old-workspaces-orphanedfrom
brennan/sta-10638-pr-b-git-to-folder

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​20 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​20
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​71 $\color{#cf222e}{\Huge{\mathbf{−}}}$​20 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​51

ELI5

Switching a Git project to a plain folder project hides every extra Git worktree it has, and Orca then wipes those worktrees' saved tabs as if they had been deleted. Now Orca refuses that switch while the project has other worktrees, and says why.

Stacked on #29257 (the same fix for the folder-to-Git direction, which is the bug a user reported). Review only the top two commits.

What Changed

The problem. Which workspaces a project has is worked out from its type each time Orca lists them. A folder project lists exactly its main folder and its folder workspaces. A Git project's linked worktrees (other checkouts of the same repo) are not in that list, so after a switch to folder mode they drop out of the next refresh, and Orca's cleanup for deleted workspaces clears their tabs, layouts and sleeping agents. The user who reported #29257's bug tried exactly this switch as a workaround; it would have wiped the new Git worktrees they had just made.

The change. The single repo write that #29257 guards now also refuses a Git-to-folder change while the project has other worktrees on that host. Nothing is written, and the message says: "This Git project has N other worktrees that a folder project can't show, so its type was not changed. Delete those worktrees first, or keep it as a Git project."

How "other worktrees" is decided:

  • From the saved worktree records for the project's own host (local, SSH or paired server). Every worktree a Git listing shows gets one of these records, and the cleanup that removes records for vanished worktrees keeps any record that still has saved tabs, so the records cover every worktree with something to lose. A project with the same id on another host never blocks this one.
  • "Can't show" is compared exactly as the tab cleanup compares it: by the exact workspace id. Folder mode shows only the exact main-folder id and the folder-workspace ids.
  • Folder workspaces left over from an earlier folder-to-Git switch never block. Folder mode shows them again, so a project that was already converted can still go back to folder mode and get those workspaces back.

Known limit: Orca's 30-day startup cleanup removes the record of a worktree whose checkout has been missing that long, without looking at saved tabs. If that checkout is recreated at the same path and the type is changed before any listing runs, its leftover tabs are not counted. In practice a desktop launch already clears tabs for a missing checkout, so this only matters for a server running with no desktop attached.

What you see. Before: switching a Git project with linked worktrees to folder mode succeeds, and those worktrees' tabs are gone after the next refresh. After: the switch is refused with the message above. A Git project with no other worktrees converts as before.

Why

Same root cause as #29257: changing a project's type silently changes which workspaces it lists, and the cleanup treats "no longer listed" as "deleted". Keeping the decision in the one write every type change goes through covers both directions with one rule.

Alternatives considered:

  • Count only worktrees that have saved tabs. Review showed that needs a classifier over every kind of saved session data plus per-host attribution (about 250 lines), and it would need updating whenever a session field is added. The worktree records already answer the question with far less code.
  • Compare by folder location so the main checkout spelled differently (for example C:\repo versus C:/repo) still counts as shown. Rejected because the tab cleanup compares exact ids, so that case really would lose its tabs.

Linked Issue

Linear STA-10638

Visual Proof

Both requested branch scenarios passed real Electron QA on M4Air at 5c2bfd3270215a458df6e675b5451b16317a348b. With a linked worktree and two real terminal tabs, the CLI refused conversion with the expected message; after refresh, the worktree, both tabs, visible order and selection remained. With only a leftover folder-workspace row, the real CLI converted successfully; after reload, folder mode showed the root and leftover workspace.

Linked-worktree case before conversion

Linked worktree and tabs preserved after refusal and refresh

Leftover folder workspace hidden in Git mode

Leftover folder workspace visible after successful conversion

The fresh main comparison at 93095c2f67447474c1894e477f6695cdf5e98c16 is incomplete: repeated M4Air overload required stopping the test copy, and both Windows machines were below the free-memory threshold. An older main attempt accepted the command but restored Git kind and retained tabs after reload; no main tab-loss reproduction is claimed. The PR remains draft until the required comparison completes.

Testing

  • Exact-head M4Air named tests passed: 2 files, 37 tests (persistence-update-repo.test.ts and repo-update-host-guard.test.ts). CI remains the full lint and typecheck gate.
  • One real-store test: a Git project with a linked worktree record on an SSH host is refused for that host; the same-id local project (no such worktree) converts; surviving folder-workspace rows from an earlier switch don't block.
  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Review

Fresh correctness and readiness reviews on 5c2bfd3270215a458df6e675b5451b16317a348b found no new proven PR-caused defect in the top two commits. The earlier session-scanning findings no longer apply to the metadata-only replacement; the host ownership issue uses the existing ownership filter. Pre-existing setup host targeting and sibling-host folder-display limitations remain outside this PR. No review-loop code changes were committed or pushed. The exact-head full PR workflow completed successfully. Its aggregate job intentionally skips its runner after all selected required jobs succeed. Validation remains blocked on the fresh main comparison. The single review status comment carries the current evidence.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

No new saved field and no wire change. A record for a worktree deleted outside Orca can block the switch until the usual cleanup removes it; refusing is the safe side of that trade.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots attached; required fresh-main comparison remains incomplete as stated above
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

Author: @BrennanKB5

…ked worktrees with saved tabs (STA-10638)

A folder project lists only its main folder and its folder workspaces, so switching a Git project to folder drops every linked worktree from the next refresh, and Orca purges their saved tabs as if they had been deleted. The same repo write that already refuses the folder-to-Git case now also refuses this one, counting only ids with saved tabs or details on the project's own host, and comparing ids exactly as the purge does. Folder workspaces left over from an earlier switch never block, so a converted project can still go back to folder mode.
@brennanb2025

brennanb2025 commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor Author

Converting a Git project to a folder project hides linked worktrees from its next listing, allowing deleted-workspace cleanup to discard their saved tabs. This PR refuses that change before writing while the project's own host has worktree records that folder mode cannot show. Leftover folder-workspace rows do not block conversion and become visible again in folder mode.

Status: review clean; validation blocked on the fresh main comparison. Reviewed head 5c2bfd3270215a458df6e675b5451b16317a348b, PR B's top two commits only against PR A e5d3537866acf1a1bfb01222e0fe341c2bb47b87. Fresh correctness and readiness reviews found no new proven PR-caused defect. The PR remains draft.

The metadata-only replacement removes the earlier session-scanning failures and uses the existing host ownership filter. No review-loop code changes were committed or pushed. The larger uncommitted repair was saved locally then discarded under the author's ruling.

Verified:

  • Two named test files passed on M4Air: 37 tests.
  • Linked-worktree case: the real setup-update CLI refused conversion with the expected message. After refresh, the worktree and both real terminal tabs remained, with the same visible order and selected tab. A separately customized tab sort order was not exercised.
  • Leftover-folder case: the real CLI converted successfully. After reload, folder mode showed the root and leftover folder workspace; the other project's selected worktree and tabs remained unchanged.
  • The exact-head full PR Checks workflow, .github/workflows/pr.yml, completed successfully. All five test shards, relay integration, static analysis/typecheck, both package jobs and selection evidence passed. The aggregate runner was intentionally skipped by the workflow's canonical-success condition.

Unverified: the requested fresh main comparison at 93095c2f67447474c1894e477f6695cdf5e98c16. Its fixture reached linked-worktree creation, but repeated M4Air overload required stopping the test copy before the two-tab setup and conversion. Both Windows alternatives were below 30% free memory. An older main attempt at e9f1835b0b7330fbdb6742c5c60365acf100fa31 accepted conversion, then showed Git kind and retained tabs after reload; this is consistent with the existing automatic upgrade path, and does not reproduce tab loss. A fresh paired main/branch comparison is still required.

Intended: owned worktree records block conversion even after tabs close. Accepted author limit: startup cleanup can remove a record for a checkout absent over 30 days while headless saved sessions survive; recreating that path and converting before discovery can leave the residue uncounted. Deferred outside B: pre-existing setup host targeting and sibling-host folder-display limitations, plus manual folder-to-Git root proof. The pending option to show folder workspaces in Git projects was not built. Project-kind-dependent catalog membership remains a temporary architectural difference tracked in STA-10638; no broader catalog feature is authorized here.

For Brennan's review

Scenario Main evidence Branch evidence
Linked worktree with two terminal tabs Fresh comparison incomplete. Earlier attempt: before, after; tabs remained. Before, after refusal and refresh.
Only leftover folder-workspace rows Fresh comparison incomplete. Before, after successful conversion.

The two judgment points are the owned-record boundary and exact-ID exemptions, and the refusal/message before mutation.

Branch: linked worktree and tabs preserved

Before conversion

After refusal and refresh

Branch: leftover folder workspace becomes visible

Before conversion

After conversion and refresh

…orktree records only

Every worktree a Git listing shows gets a saved record, and the missing-worktree prune keeps any record that still has saved tabs, so the records already cover every workspace with something to lose. Drop the saved-session scan and its per-partition owner rules; count this host's owned worktree records instead, with the existing same-id sibling rule. Known limit: a record the 30-day startup cleanup removed for a checkout that was missing, then recreated at the same path before any listing, is not counted; a desktop launch clears that workspace's tabs anyway.
@brennanb2025 brennanb2025 changed the title fix(projects): refuse a Git-to-folder type change that would hide linked worktrees with saved tabs fix(projects): refuse a Git-to-folder type change while the project has other worktrees Oct 16, 2026
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Closing per Brennan: the Git-to-folder data loss this guards against could not be reproduced on main (a local project's automatic Git upgrade switches it straight back to Git, so the tabs survive). The branch is kept if it is ever needed.

@brennanb2025
brennanb2025 deleted the brennan/sta-10638-pr-b-git-to-folder branch October 16, 2026 23:07
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