Skip to content

fix(worktrees): a phone or CLI create keeps a sparse preset only when its folders match - #26104

Merged
brennanb2025 merged 3 commits into
mainfrom
brennanb2025/host-create-sparse-preset-check
Oct 7, 2026
Merged

brennanb2025 merged 3 commits into
mainfrom
brennanb2025/host-create-sparse-preset-check

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​110 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​109
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​53 $\color{#cf222e}{\Huge{\mathbf{−}}}$​38 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​15

ELI5

When you create a workspace with a sparse checkout (only some folders checked out), Orca saves which sparse preset you started from in the workspace's record, but only when the folders you actually checked out are exactly that preset's. If you picked a preset and then changed the folder list, the workspace isn't that preset any more.

The desktop's own create already applies that rule. A create that goes through the host instead (the worktree.create call used by the phone, the CLI and agent.launch) saved whatever preset id it was sent. This PR makes the host's create apply the same rule, so the two create paths agree before desktop creates move onto the host.

What Changed

The problem.

  • The host's create (createManagedWorktree → materializeRuntimeLocalWorktree) wrote the request's sparsePresetId without checking it: a stale id, another repo's preset, or a preset whose folders had been edited was saved as-is.
  • The window's create path (worktree-remote.ts) keeps the id only when the preset belongs to the repo and its folders match, and it did that in two copied blocks.

User-facing change.

  • None visible today. Nothing in the desktop, phone or web UI displays the saved preset id, and no current client sends one to the host: the phone's create passes no sparse settings, the CLI has no sparse option, and the web client has no preset list.
  • What changes is the saved workspace record: a host create with a mismatched or unknown preset id no longer stores it, which matches desktop creates. A create whose folders match the preset (in any order) still stores it.
  • Desktop creates are unchanged.

The mechanism.

  • One function, attributedSparsePresetId(readPresets, repoId, presetId, directories), holds the existing rule: the preset must belong to this repo and its folders must equal the checked-out ones as a set.
  • It reads the saved presets only when a preset id was sent, as the desktop code did before. A failed read or corrupt preset data records no preset and never fails the create. On the host this matters because the record is written after git has already created the worktree.
  • The window's create path calls it in place of its two inline copies, and the host's create calls it when it writes the worktree's record.

Why

  • Why share the existing check rather than write a second one. It's the rule desktop creates already follow; one function keeps the two create paths from drifting again.
  • This is one of the differences found while lining up the host's create with the desktop's, before desktop creates move onto the host.

Linked Issue

Part of the new-workspace launch unification (parity fixes before the desktop composer moves onto agent.launch).

Visual Proof

These images are the raw RPC results from the live QA run (M4Air, main c8dcffc vs PR 8243c74): each row sends the same worktree.create to main and to the PR, then reads the saved sparsePresetId back from worktree.list.

pr26104-row1.png
pr26104-row2.png
pr26104-row3.png
pr26104-row4.png

Testing

  • sparse-preset-attribution.test.ts (new): a preset whose folders match in any order (or with a trailing slash) is kept; an edited selection, a duplicated folder list, another repo's preset, a deleted preset, a corrupt preset, or no preset records none; the presets aren't read when no preset id was sent; a failed read records none.

  • runtime-local-worktree-create.test.ts: the host's create records the preset for exactly its folders, none for an edited selection, and still succeeds (with no preset) when reading presets fails.

  • The window's existing tests (worktrees-setup-launch-sparse-checkout.test.ts, worktrees-windows.test.ts) pass unchanged.

  • tc:node, oxlint.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

Notes

  • SSH: host SSH creates already go through the window's createRemoteWorktree, which now uses the same function.
  • Folder workspaces: no sparse checkout, unaffected.

Author: @BrennanKB5

… directories match

The window's create records a sparse preset on the new worktree only when the
checked-out directories are exactly that preset's, so an edited selection is
not shown as the preset it began as. The host's create wrote whatever preset
id it was sent. Both now share one check (moved out of the two copies in the
window's create path).
…d never fail the create on them

The shared preset check took the preset list up front, so every create read
the presets even with no preset chosen (the window's create used to skip the
read), and a read that threw failed the create - on the host after
`git worktree add` had already run. The check now takes a reader, returns early
when no preset was sent, and reads inside its try so unreadable presets record
no preset instead of blocking the create. Repeated checked-out directories no
longer match a preset with a different set of directories.
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review and QA summary (8243c74)

The problem. Orca saves which sparse-checkout preset a new workspace came from (sparsePresetId in the workspace record). Desktop creates save it only when the preset belongs to the repo and its folders exactly match the folders checked out. Creates that go through the host (worktree.create, used by the phone, the CLI and agent.launch) saved whatever id they were sent: a stale id, another repo's preset, or a preset whose folder list had been edited.

The user-facing change. Nothing visible today: no screen displays the saved preset id, and no current client sends one to the host (the phone's create sends no sparse settings, the CLI has no sparse option). What changes is the saved record. A host create with a mismatched or unknown preset id no longer stores it, which matches desktop creates ahead of desktop creates moving onto the host. Desktop creates behave the same as before. The PR description has been corrected to say this; it previously said the workspace was "labelled" with the preset.

Fixed during review (commit 8243c74).

  • P1: the first version read the saved presets on every desktop create, even ones with no preset. That broke 6 existing tests in worktrees-windows.test.ts. It also meant unreadable preset data could block every create in a repo. On the host, that read happened after git had already made the worktree, so a failure there would have left a worktree with no record. Now the presets are read only when a preset id was sent (as before), and a failed read records no preset instead of failing the create.
  • P3: a folder list with a repeated entry could falsely match a preset with two different folders. Both sides are now compared as sets. No current caller passes repeated entries.
  • P3: added tests for: no preset id (presets not read), a failed read, a corrupt preset, a trailing-slash preset, and a host create that still succeeds when the read fails.

Deferred (not this PR).

  • worktree.set still accepts any sparsePresetId without checking it (pre-existing).
  • A desktop window pointed at a remote runtime lists and saves presets against the local store, and the phone's preset picker is never shown (pre-existing).
  • One test row could be stronger (nit).

Verified.

  • Desktop create path: for every input, gives the same result as the two blocks it replaces, and reads presets in the same cases. The one intended difference is that a failed preset read no longer fails the create.
  • Tests: the 4–7 named test files pass, and CI on 8243c74 is green (5 test shards, static analysis and typecheck, packaging). tc:node passes.
  • Live QA on a Mac, main (c8dcffc) vs this PR, using raw worktree.create calls to an isolated host. The preset id was read back from worktree.list.
row request main PR
1 preset P = [apps/web, packages/ui], folders in another order P P
2 preset P, folders edited to [apps/web] P none
3 unknown preset id, [apps/web] does-not-exist none
4 no preset, [apps/web] none none

In every row, on both builds, the create succeeded, the worktree exists on disk, and the sparse checkout holds exactly the requested folders. Nothing was worse than main.

Not verified. The desktop-window path was not exercised in a running app, since it's a pure refactor covered by its existing tests and has no UI. No mobile emulator run: the phone sends no sparse settings and nothing on the phone shows the preset. No screenshots, since nothing on screen changes; the RPC transcripts are the evidence.

@brennanb2025
brennanb2025 marked this pull request as ready for review October 7, 2026 10:08
@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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: aaf79fea-872a-4003-b1e2-1048bdc044aa
📥 Commits

Reviewing files that changed from the base of the PR and between 5b0d387 and e98c69e.

📒 Files selected for processing (5)
  • src/main/ipc/sparse-preset-attribution.test.ts
  • src/main/ipc/sparse-preset-attribution.ts
  • src/main/ipc/worktree-remote.ts
  • src/main/runtime/runtime-local-worktree-create.test.ts
  • src/main/runtime/runtime-local-worktree-materialization.ts

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


📝 Walkthrough

Walkthrough

A shared attributedSparsePresetId helper now checks that a selected preset belongs to the repository and has the same normalized directory set as the worktree selection. SSH and local worktree creation paths and runtime local worktree materialization use the helper to determine the preset ID stored in metadata. Tests cover matching and edited selections, repository and directory mismatches, missing presets, and preset-read errors.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to e98c6

Host-created worktrees now keep a sparse preset ID only when the preset belongs to the repository and its folders match the checked-out folders. A failed preset read no longer fails the create. The change is tested and I found no merge-blocking risk.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 5 files. 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 identifies the worktree change and the condition for retaining a sparse preset ID.
Description check ✅ Passed The description explains the problem, behavior change, implementation, and tests, and includes visual proof. It does not link an actual issue in the Linked Issue section, and some checklist items rema…
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@brennanb2025
brennanb2025 merged commit c2f3229 into main Oct 7, 2026
30 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.

1 participant