Skip to content

fix(repos): keep the desktop-owned manual project order authoritative across paired clients and SSH catalog publishes (STA-4850) - #15538

Merged
Jinwoo-H merged 3 commits into
mainfrom
aug19-linear-sta4850-project-order-fable
Aug 20, 2026
Merged

Jinwoo-H merged 3 commits into
mainfrom
aug19-linear-sta4850-project-order-fable

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​419 $\color{#cf222e}{\Huge{\mathbf{−}}}$​7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​412
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​67 $\color{#cf222e}{\Huge{\mathbf{−}}}$​28 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​39

Fixes #15468

The reporter's manual project order was being lost two independent ways. Both are fixed here. Cross-host project grouping (#13986) is deliberately not addressed — see the last section.

Root cause 1 — a paired client's overlay overwrites the desktop's

ui.manualRepoOrder is a list of { hostId, repoId } entries, host-qualified since #7237 so the same repo id on two hosts stays two distinct rows. A paired client computes that list against its own execution hosts and then sends it to the desktop profile, which stores it verbatim:

  • src/renderer/src/web/web-runtime-environment.ts mints a per-pairing pseudo-host web-${createBrowserUuid()}, and withRuntimeRepoOwner in src/renderer/src/web/web-preload-api.ts:3567 restamps every repo with executionHostId: runtime:web-<uuid>.
  • reorderRepos (src/renderer/src/store/slices/repos.ts:3989-4020) derives the overlay via getRepoExecutionHostId and unconditionally calls window.api.ui.set({ manualRepoOrder }). On web every entry is therefore keyed runtime:web-<uuid>.
  • The web ui.set (src/renderer/src/web/web-preload-api.ts:2734-2742) stripped only hideWorkspacesFromOtherDevices and forwarded the rest.
  • The host ui.set (src/main/runtime/rpc/methods/client-ui.ts:56-62) stripped only hideWorkspacesFromOtherDevices and forwarded the rest.
  • updatePersistedUI (src/main/persistence/applying-settings/ui-state-update.ts:160-163) does a blind whole-array replace. Its neighbours contextualToursSeenIds and featureInteractions each grew a stale-client merge helper; manualRepoOrder never did.

The write is subtractive, not merely re-keyed: the web client only sees the desktop's local repos, so the desktop's runtime-host entries are erased outright. applyManualRepoOrder then matches nothing, no-ops silently, and the scramble appears at the next cold start — matching the report's "each time the site is closed and reopened" and "the update disrupted my order".

Root cause 2 — a direct-SSH catalog publish sinks SSH repos to the tail

mergeExactHostCatalog (src/renderer/src/hooks/direct-ssh-host-hydration.ts:61-73) filtered out the host's rows and re-appended the snapshot at the end of the array without re-applying the overlay. This runs on every connect, including the first after launch, so SSH repos fell to the bottom even when the persisted overlay was perfectly intact. Regression introduced after #8894 (#11003, 2026-07-28).

The fix — one authority model

The desktop profile owns ui.manualRepoOrder. Paired clients own only their host-local permutation, via repo.reorder. Every writer of the repos array applies the overlay.

Write path — a client's value never reaches host storage:

  1. src/main/runtime/rpc/methods/client-ui.ts — the ui.set handler strips the pairing-local fields before persisting.
  2. src/renderer/src/web/web-preload-api.ts — the web ui.set drops them from hostUpdates before callRuntimeResult, so an old host has nothing to persist either. The local write is unchanged.

Read path — the host's value never reaches a client (added in round 2, see below):

  1. client-ui.ts — ui.get, and the ui.set / ui.recordFeatureInteraction responses, omit the pairing-local fields.
  2. web-preload-api.ts — mergeHostWebUIState pins manualRepoOrder to the browser's own value, the pattern hideWorkspacesFromOtherDevices already used.

Hydration — every writer of the repos array re-applies the overlay:

  1. src/renderer/src/hooks/direct-ssh-host-hydration.ts — mergeExactHostCatalog applies applyManualRepoOrder(merged, state.manualRepoOrder) before returning.

All six boundary seams — the host ui.set strip, the host ui.get / ui.set / ui.recordFeatureInteraction response omissions, the web ui.set strip, and the web mergeHostWebUIState pin — consume one exported set, PAIRING_LOCAL_UI_FIELDS in src/shared/pairing-local-ui-fields.ts, rather than six hand-maintained field lists that drift apart. Its members:

field why it cannot cross the boundary what that prevents
manualRepoOrder keyed to hosts only the sending side owns; a web client keys every entry to its own runtime:web-<uuid> the scramble in root cause 1
workspaceHostOrder same shape, same poisoning: ui.ts:2107-2111 sends it on every host-section drag with the same runtime:web-<uuid> ids, and ui-state-update.ts:156-159 blind-replaces it the desktop's host-section order silently resetting on the next cold start — orderHostSectionOptions (host-section-order.ts:14-20) skips ids matching no host, so a poisoned array leaves plain discovery order. Sibling defect of the same class, found in review.
hideWorkspacesFromOtherDevices a per-device view filter by definition nothing new — it was already stripped and pinned; joining the set is a no-op for behavior

Enforcement is both compile-time and test-time. The host seams iterate the set directly, so a new member is covered automatically and the census it.each names it. The web pin is a literal (one member needs its own === true normalization), so it is constrained by satisfies Record<PairingLocalUiField, unknown>: dropping a member from it fails tsc and fails the named web-seam test for that field. Both signals were confirmed by mutation.

Adding workspaceHostOrder is inert in the directions that are not the bug: the web client's own host order is localStorage-backed, mobile references none of the three fields (ui.get's only mobile consumer, NewWorktreeModal.tsx:395, reads trustedOrcaHooks and nothing else), and an old client against a new host lands on the absent-key-preserves branch of the same spread merge.

A paired client's drag still reorders that client's own view; it just no longer rewrites the desktop's saved order.

Wire compatibility

manualRepoOrder is kept in the zod schema (client-ui-schemas.ts). UiUpdate is strict, so deleting the field would make the dispatcher reject an old client's entire ui.set payload with invalid_argument, taking every unrelated setting in that payload down with it. Stripping it inside the handler is the compatible shape, and it is the same pattern already used for hideWorkspacesFromOtherDevices.

Under docs/reference/remote-wire-compatibility.md this is a Rule 3 change — the host stops consuming a field it used to consume — so all four pairings are enumerated:

client host behaviour
old old unchanged (the bug)
old new client still sends the field; host accepts the payload and ignores that one key. This is the fix's main path — an un-updated web client can no longer corrupt an updated desktop.
new old client no longer sends the field; old host has nothing to overwrite with. This is why the strip is done at both ends rather than only on the host.
new new field never crosses the wire.

And the same four pairings on the read path (ui.get and the ui.set / recordFeatureInteraction responses):

client host behaviour
old old unchanged (the bug)
old new host omits the field; the old web client's merge is a plain spread, so an ABSENT key leaves its local value intact. This repairs old web clients with no client update.
new old host still sends it; the new client pins its local value in mergeHostWebUIState and ignores the response's.
new new field never crosses the wire.

Rule 3 applies to the read path since the host stops populating a field. It is safe for every reader: mobile reads only trustedOrcaHooks off ui.get, and the web client pins both members locally.

No opcode, no schema change, no protocol version bump. PersistedUIState still carries the field; only the client-to-host direction stops.

Evidence

Every assertion below was verified red→green→red: it fails with the production change reverted and passes with it applied (test-results/sta-4850/impl-logs/12-revert-check.log).

New/updated committed regression tests:

  • client-ui.test.ts — a ui.set carrying a runtime:web-<uuid>-keyed manualRepoOrder reaches runtime.updateUIState without the field while sidebarWidth still passes through. The existing full-payload pass-through case was updated to assert the same exclusion.
  • web-preload-api-ui.test.ts — the web ui.set forwards { sidebarWidth: 280 } only, while manualRepoOrder still lands in orca.web.ui.v1.
  • direct-ssh-host-hydration.test.ts — a snapshot publish over [bravo(ssh), alpha(local), delta(ssh)] preserves that order instead of yielding [alpha, bravo, delta]. The existing first test, which pins tail-append when no overlay is set, stays green: applyManualRepoOrder returns its input unchanged for an empty overlay.

Four throwaway diagnostic probes were written against main before the fix to pin the failure modes; they are not committed. Two are green on this branch and two stay red by design:

probe after fix why
ui.set forwards a paired client's manualRepoOrder green the durable protection: the host no longer accepts the field
direct-SSH publish sinks SSH repos to the tail green the overlay is re-applied on every catalog merge
an already-poisoned overlay still restores the saved order red, by design a pure-function demo of the consequence of root cause 1, not a target. It calls applyManualRepoOrder directly with hardcoded runtime:web-* entries; the only way to satisfy it is to fall back to matching on bare repoId, which deliberately breaks the #7237/#8894 host-qualification and would reorder the wrong host's row whenever a repo id exists on two hosts. Prevention at the ui.set boundary is the fix; tolerance of foreign keys is not.
the same canonical repo on two hosts renders two project headers red, by design invariant A, #13986 — see below

Round 2 added: a census test on PAIRING_LOCAL_UI_FIELDS; seam tests iterating that set for the ui.set strip, the ui.get omission and the response omissions; web ui.get round-trip tests covering a host that returns this browser's own stale runtime:web-* entries, a desktop-keyed array, an empty array, and a new host that omits the field; a store test pinning that an update omitting manualRepoOrder preserves it rather than clearing it (after the strip, that is every paired ui.set); and a partial-overlay case at the SSH site where ranked rows hold their order and an unranked newcomer sinks to the tail.

Round 3 added workspaceHostOrder to the set (picking up the host-side seam it.each automatically), converted the web-side merge coverage to an it.each over PAIRING_LOCAL_UI_FIELDS with a host sample that differs from the browser's for every field, made the web pin fail compile when a member is dropped, and extended the persistence preserve-branch test to cover both order fields.

Validation, all green: 11 related unit files (209 tests), pnpm run typecheck, pnpm run lint, check:code-quality:changed, and check:react-doctor:changed.

The E2E oracles were rerun byte-identically against the round-2 tree and both stay green: the B1 journey (web drag, cold relaunch, host restart, late/offline host, update-equivalent relaunch onto the same profile) keeps all six host-qualified entries in orca-data.json and the rendered header order stable at every checkpoint, and the B2 direct-SSH journey holds [ssh-one, alpha, ssh-two, bravo] across reconnect, cold start before connect, and cold start after connect.

Pre-merge E2E oracles (harness under test-results/sta-4850/harness/, gitignored) read two independent signals — the desktop profile's orca-data.json ui.manualRepoOrder, and the rendered sidebar header order over CDP — across a web-client drag, desktop cold relaunch, host restart, an update-equivalent relaunch onto the same profile, a late/offline host, and varied catalog arrival order. Checkpoint 05 is the sharpest: after a web drag legitimately changes the client's local permutation, the desktop overlay must still win at hydration.

Already-poisoned profiles are not migrated

A profile whose overlay was overwritten by a pre-fix web drag keeps that stale array on disk; it is not rewritten. What that costs depends on who is reading it, and an earlier revision of this description got the client half wrong:

  • On the desktop it is inert. Every entry names a runtime:web-<uuid> host the profile does not own, so applyManualRepoOrder matches nothing, every row sorts as unranked, and the identity check at manual-repo-order.ts:73 returns the input array untouched. The user sees arrival order.
  • On the web client that minted it, it was live, not inert. The environment id is persisted per pairing in orca.web.runtimeEnvironment.v1, so the same browser restamps its repos onto the same runtime:web-<uuid> host. Those entries came back over ui.get and matched, which meant the stale array beat every drag the user made after it — the reported symptom reappearing on each reload. The read-path seams above neutralize this: the host stops returning the field, and the client pins its own value even against a host that still sends it.

Recovery of the stored array is by user action. A desktop drag goes through the local ui:set IPC (src/main/ipc/ui.ts:66), not the runtime RPC, so getManualRepoOrder re-derives a clean host-qualified overlay from the profile's real repos and replaces the stale one wholesale.

No read-time cleanup pass is included on purpose. The overlay legitimately outlives the repos it names: #8894 retains entries for hosts that are offline or arrive late, precisely so a disconnected SSH host does not lose its position while away. A cleaner cannot distinguish a poisoned entry from a valid dormant one by looking at the data — it would have to guess from key shape (runtime:web-* looks client-minted) and prune on that heuristic, which would be a second, weaker authority rule on top of the one this PR establishes and would silently drop legitimate runtime:* entries for real remote runtimes.

Known limitations and follow-ups

  • repo.reorder still rejects a reorder on a catalog where two hosts' repos collapse onto one identity. This PR removes the user-visible consequence (the client's own order is now authoritative for the client), but the underlying rejection is unchanged and is tracked separately.
  • mergeExactHostCatalog rebuilds the repos array without reusing equal row identities, so a no-op republish still produces new object identities downstream. Pre-existing and orthogonal to ordering; not addressed here.
  • Every web drag still sends an ui.set whose payload is now empty after the strip. Harmless, and removing the round trip would be a contract change.

Not addressed here: cross-host grouping (#13986)

The same report also asks that one repo present on two hosts render as two project headers instead of one. That is not in this PR, and #13986 is deliberately left open.

Merging the same canonical repo across hosts is a deliberate, three-point contract: the project:<id> grouping key (project-grouping.ts:122), the store's project merge (repos.ts:605, repos.ts:1074), and the selector normalizer (project-host-setup-selector-normalization.ts:12). It is pinned by worktree-list-groups-project-host-setups.test.ts and was explicitly preserved by #8894. Splitting it is a product decision that reverses a shipped contract, not a bug fix, and it is a strictly separate change from ordering. A follow-up ticket carries the recommended design: host-qualify at the grouping layer only, emitting a host-qualified header key when a project spans more than one host, with reveal keys moving in lockstep — and specifically not host-qualifying getProjectIdentityKey, which would reach project groups, succession, cmd-J, and colors.

… (STA-4850)

The user's manual project order was lost two ways.

A paired client keys its manual order to its own execution hosts — a web
client restamps every repo onto runtime:web-<uuid> — and ui.set forwarded
that array to the host, where updatePersistedUI replaces ui.manualRepoOrder
wholesale. The desktop's local/ssh-keyed order was destroyed and the scramble
surfaced at the next cold start. Give the desktop profile sole ownership:
ui.set strips manualRepoOrder on the host, and the web client stops sending it
so old hosts are protected too. Paired clients keep their own host-local
permutation via repo.reorder. The field stays in the strict UiUpdate schema —
removing it would reject an old client's entire payload.

A direct-SSH catalog publish re-appended the host's rows at the tail of the
repos array without re-applying the overlay, sinking SSH repos on every
connect including the first after launch. mergeExactHostCatalog now applies
applyManualRepoOrder to the merged array.

Cross-host project grouping (#13986) is unchanged and tracked separately.

Fixes #15468
…nts (STA-4850)

Stripping manualRepoOrder on the write path left the read path open. ui.get
still returned the host's array, and the web client's merge let it win. On a
profile an old web client had already poisoned, the runtime:web-<uuid> entries
echoed back to the very browser that minted them — the environment id is
persisted per pairing — so they matched its restamped repos and overrode every
drag it made after. Even on a clean profile the desktop-keyed array (or [])
replaced the browser's own order on each reload.

Close both ends: the host omits these fields from every ui read response, and
the web client pins its local values when merging one. Either half alone fixes
one skew direction; both are needed because clients and hosts update apart.

Replace the hand-maintained destructures with PAIRING_LOCAL_UI_FIELDS, one
exported set consumed at all four seams, so a field added to it cannot be wired
into some seams and forgotten in others. A census test pins the membership and
the seam tests iterate it. hideWorkspacesFromOtherDevices joins the set with no
behavior change: the web client already pinned it locally, and mobile's only
ui.get consumer reads trustedOrcaHooks.

Also pin the preserve branch in the store: an update that omits manualRepoOrder
must keep the stored order, since after the strip that is every paired ui.set.
workspaceHostOrder crosses the pairing boundary exactly like manualRepoOrder did:
ui.ts:2107 sends it unconditionally, a web client's ids are runtime:web-* keyed, and
updatePersistedUI blind-replaces, so the desktop's host-section order silently resets
on the next cold start. Add it to PAIRING_LOCAL_UI_FIELDS so both seams cover it.

Make the web read seam census-enforced: the pinned literal is now constrained by
Record<PairingLocalUiField, unknown>, so a member added to the set without wiring
mergeHostWebUIState fails to compile as well as failing a named test on that seam.
@Jinwoo-H
Jinwoo-H marked this pull request as ready for review August 20, 2026 00:00
@coderabbitai

coderabbitai Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The change defines shared pairing-local UI fields and filtering utilities. Runtime UI RPC methods now filter these fields from persisted updates and responses. Browser-host synchronization preserves browser-local visibility and ordering state while excluding it from host updates. SSH host catalog hydration reapplies manual repository ordering after refreshes. Tests cover filtering, persistence, synchronization, and ordering behavior.

Merge Risk: ⚪ Minimal · up to 24008

This change is merge-ready after normal checks and review; no actionable merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% 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 The title clearly identifies the main fix: preserving desktop-owned project order across paired clients and SSH catalog publishes.
Description check ✅ Passed The description thoroughly explains the causes, fixes, testing, compatibility, limitations, and linked issue, although several template headings and visual proof are omitted.
Linked Issues check ✅ Passed The changes address the project-order disruption described in [#15468] by preserving manual order across paired clients and SSH catalog updates.
Out of Scope Changes check ✅ Passed The production and test changes remain focused on pairing-local UI state, manual ordering, and direct-SSH catalog hydration.
✨ Finishing Touches 💡 1
📝 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.

🧹 Nitpick comments (2)
src/shared/pairing-local-ui-fields.ts (1)

3-7: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Shorten this comment.

Replace the five-line explanation with one non-obvious sentence.

Proposed change
-// UI state each side of a pairing owns for itself. These fields describe a client's own view —
-// which workspaces it hides, what order it puts repos and host sections in — and are keyed to hosts
-// only that side knows about, so a value copied across the boundary in either direction overwrites
-// the receiver's answer with one computed for somebody else. They must be stripped on the way to a
-// host (ui.set) and pinned to the local value on the way back (ui.get).
+// Pairing-local fields describe client-owned hosts and must not cross the pairing boundary.

As per coding guidelines, comments must be concise, non-obvious, and brief.

Source: Coding guidelines

src/renderer/src/web/web-preload-api.ts (1)

4170-4175: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Shorten the compatibility comments.

Keep each comment to one concise sentence that states the compatibility invariant.

  • src/renderer/src/web/web-preload-api.ts#L4170-L4175: reduce the merge and satisfies explanations to concise invariant comments.
  • src/renderer/src/web/web-preload-api-ui.test.ts#L374-L377: state that the test covers legacy hosts that return pairing-local fields.
  • src/renderer/src/web/web-preload-api-ui.test.ts#L460-L462: state that the test covers every configured pairing-local field.

As per coding guidelines: “Comments must be concise, non-obvious, and brief—prefer one line; do not explain obvious behavior or walk through code.”

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d1093f8d-ebc1-462b-bd06-08d7d452788c

📥 Commits

Reviewing files that changed from the base of the PR and between 7675da3 and 24008c4.

📒 Files selected for processing (10)
  • src/main/persistence-ui-state.test.ts
  • src/main/runtime/rpc/methods/client-ui-pairing-local-fields.test.ts
  • src/main/runtime/rpc/methods/client-ui.test.ts
  • src/main/runtime/rpc/methods/client-ui.ts
  • src/renderer/src/hooks/direct-ssh-host-hydration.test.ts
  • src/renderer/src/hooks/direct-ssh-host-hydration.ts
  • src/renderer/src/web/web-preload-api-ui.test.ts
  • src/renderer/src/web/web-preload-api.ts
  • src/shared/pairing-local-ui-fields.test.ts
  • src/shared/pairing-local-ui-fields.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@Jinwoo-H
Jinwoo-H merged commit 0e5b348 into main Aug 20, 2026
136 of 138 checks passed
AmethystLiang pushed a commit that referenced this pull request Aug 20, 2026
… across paired clients and SSH catalog publishes (STA-4850) (#15538)
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 21, 2026
… across paired clients and SSH catalog publishes (STA-4850) (stablyai#15538)
dallascrilley pushed a commit to dallascrilley/orca that referenced this pull request Aug 27, 2026
… across paired clients and SSH catalog publishes (STA-4850) (stablyai#15538)
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
… across paired clients and SSH catalog publishes (STA-4850) (stablyai#15538)
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.

[Other]: Project Ordering

1 participant