Skip to content

fix(renderer): a created or lineage-refreshed worktree replaces only its own host's copy - #30447

Merged
nwparker merged 1 commit into
mainfrom
nwparker/r3-host-scoped-row-merges
Oct 18, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/r3-host-scoped-row-merges

Conversation

@nwparker

@nwparker nwparker commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​92 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​92
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​37 $\color{#cf222e}{\Huge{\mathbf{−}}}$​20 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​17

ELI5

A project can exist both on this computer and on a paired Orca server, sometimes with a worktree at the same path on each. These are two different worktrees that happen to share an id. Two places in Orca updated "the worktree with this id" without checking which machine it was on, so an update for one copy could overwrite or relabel the other.

What Changed

  • Creating a worktree (store/slices/worktrees/create/created-worktree-state-merge.ts).
    • Before: the new row was merged into any existing row with the same id. A local create could inherit the server twin's "owned by server hub" stamp, or a server create could wipe the local copy.
    • After: it merges only into the copy on the host the create ran on, and otherwise adds a row.
  • Refreshing worktree lineage from a server (store/slices/worktrees/metadata/worktree-lineage-refresh.ts).
    • Before: the server's reply was stamped with whichever host the "Active Server" focus pointed at, then replaced every same-id row. That could overwrite the local twin with the server's data.
    • After: the reply is stamped with the server it actually came from, and only that server's copy is replaced.
  • replaceWorktreeInRepoLists (listing/worktree-owner-settings.ts), whose only caller is lineage refresh, now takes the host and matches with the existing worktreeMatchesHost rules.
  • The focus-read ratchet loses one entry, because lineage refresh no longer reads focus.

Why

These are point fixes P2 and P3 of the SSH-hardening round 3 design (round3-design.md §1.2). Both adversarial reviewers flagged them as writers that break the "rows are stamped by the transport they came from" proof that the owner-resolver folds rely on.

Matching uses the same predicate the host-scoped listing merge already uses (worktreeMatchesHost with worktreeHostMatchOptions), so pre-host unstamped rows keep their existing treatment. This reuses existing code rather than adding a new rule.

Wire impact: none (renderer state only).

Linked Issue

None (internal hardening; maintainer PR).

Visual Proof

N/A: no UI change. Twin rows are no longer overwritten in the store.

Testing

  • New store/slices/worktrees/host-scoped-row-merges.test.ts. All 3 tests fail on main and pass with the fix:

    • a local create keeps the server twin and its stamp;
    • a server create keeps the local twin;
    • a server's lineage reply updates its own copy and leaves the local twin alone.
  • Unit tests, single worker: all of src/renderer/src/store/slices (395 files, 3,867 tests).

  • pnpm tc:web and the full local pr.yml static job (0 failures, focus-read ratchet pruned 1082 → 1081).

  • Managed-orcad Docker lane dispatched on this head; the link is added when it finishes.

  • No separate live-host run: twins of the same id across hosts are covered by the unit tests and the Docker lane.

  • Codex review (gpt-6.1-sol, high), twice (before and after the ratchet-neutral loop rewrite): no findings.

  • I manually tested these changes locally

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

…its own host's copy

applyCreatedWorktree merged a create into any same-id row, so a local create could inherit a
server twin's stamp (or wipe it). Lineage refresh stamped a server's reply with the focused host and
replaced every same-id row, overwriting the local twin. Both now match id and host, and the lineage
reply is stamped with the transport it came from.
@coderabbitai

coderabbitai Bot commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 7 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f414cc24-1229-439e-b171-8a0f9157495c
📥 Commits

Reviewing files that changed from the base of the PR and between b66c98f and af3fcb5.

📒 Files selected for processing: 5
  • config/focus-setting-read-baseline.txt
  • src/renderer/src/store/slices/worktrees/create/created-worktree-state-merge.ts
  • src/renderer/src/store/slices/worktrees/host-scoped-row-merges.test.ts
  • src/renderer/src/store/slices/worktrees/listing/worktree-owner-settings.ts
  • src/renderer/src/store/slices/worktrees/metadata/worktree-lineage-refresh.ts
  • Autofix · 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.

@nwparker
nwparker merged commit 859e359 into main Oct 18, 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.

1 participant