Repository navigation
fix(repos): keep the desktop-owned manual project order authoritative across paired clients and SSH catalog publishes (STA-4850) - #15538
Conversation
… (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.
📝 WalkthroughWalkthroughThe 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 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)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/shared/pairing-local-ui-fields.ts (1)
3-7: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winShorten 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 winShorten 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 andsatisfiesexplanations 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
📒 Files selected for processing (10)
src/main/persistence-ui-state.test.tssrc/main/runtime/rpc/methods/client-ui-pairing-local-fields.test.tssrc/main/runtime/rpc/methods/client-ui.test.tssrc/main/runtime/rpc/methods/client-ui.tssrc/renderer/src/hooks/direct-ssh-host-hydration.test.tssrc/renderer/src/hooks/direct-ssh-host-hydration.tssrc/renderer/src/web/web-preload-api-ui.test.tssrc/renderer/src/web/web-preload-api.tssrc/shared/pairing-local-ui-fields.test.tssrc/shared/pairing-local-ui-fields.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
… across paired clients and SSH catalog publishes (STA-4850) (#15538)
… across paired clients and SSH catalog publishes (STA-4850) (stablyai#15538)
… across paired clients and SSH catalog publishes (STA-4850) (stablyai#15538)
… across paired clients and SSH catalog publishes (STA-4850) (stablyai#15538)
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.manualRepoOrderis 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.tsmints a per-pairing pseudo-hostweb-${createBrowserUuid()}, andwithRuntimeRepoOwnerinsrc/renderer/src/web/web-preload-api.ts:3567restamps every repo withexecutionHostId: runtime:web-<uuid>.reorderRepos(src/renderer/src/store/slices/repos.ts:3989-4020) derives the overlay viagetRepoExecutionHostIdand unconditionally callswindow.api.ui.set({ manualRepoOrder }). On web every entry is therefore keyedruntime:web-<uuid>.ui.set(src/renderer/src/web/web-preload-api.ts:2734-2742) stripped onlyhideWorkspacesFromOtherDevicesand forwarded the rest.ui.set(src/main/runtime/rpc/methods/client-ui.ts:56-62) stripped onlyhideWorkspacesFromOtherDevicesand forwarded the rest.updatePersistedUI(src/main/persistence/applying-settings/ui-state-update.ts:160-163) does a blind whole-array replace. Its neighbourscontextualToursSeenIdsandfeatureInteractionseach grew a stale-client merge helper;manualRepoOrdernever 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.
applyManualRepoOrderthen 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
Write path — a client's value never reaches host storage:
src/main/runtime/rpc/methods/client-ui.ts— theui.sethandler strips the pairing-local fields before persisting.src/renderer/src/web/web-preload-api.ts— the webui.setdrops them fromhostUpdatesbeforecallRuntimeResult, 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):
client-ui.ts—ui.get, and theui.set/ui.recordFeatureInteractionresponses, omit the pairing-local fields.web-preload-api.ts—mergeHostWebUIStatepinsmanualRepoOrderto the browser's own value, the patternhideWorkspacesFromOtherDevicesalready used.Hydration — every writer of the repos array re-applies the overlay:
src/renderer/src/hooks/direct-ssh-host-hydration.ts—mergeExactHostCatalogappliesapplyManualRepoOrder(merged, state.manualRepoOrder)before returning.All six boundary seams — the host
ui.setstrip, the hostui.get/ui.set/ui.recordFeatureInteractionresponse omissions, the webui.setstrip, and the webmergeHostWebUIStatepin — consume one exported set,PAIRING_LOCAL_UI_FIELDSinsrc/shared/pairing-local-ui-fields.ts, rather than six hand-maintained field lists that drift apart. Its members:manualRepoOrderruntime:web-<uuid>workspaceHostOrderui.ts:2107-2111sends it on every host-section drag with the sameruntime:web-<uuid>ids, andui-state-update.ts:156-159blind-replaces itorderHostSectionOptions(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.hideWorkspacesFromOtherDevicesEnforcement 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.eachnames it. The web pin is a literal (one member needs its own=== truenormalization), so it is constrained bysatisfies Record<PairingLocalUiField, unknown>: dropping a member from it failstscand fails the named web-seam test for that field. Both signals were confirmed by mutation.Adding
workspaceHostOrderis 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, readstrustedOrcaHooksand 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
manualRepoOrderis kept in the zod schema (client-ui-schemas.ts).UiUpdateis strict, so deleting the field would make the dispatcher reject an old client's entireui.setpayload withinvalid_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 forhideWorkspacesFromOtherDevices.Under
docs/reference/remote-wire-compatibility.mdthis is a Rule 3 change — the host stops consuming a field it used to consume — so all four pairings are enumerated:And the same four pairings on the read path (
ui.getand theui.set/recordFeatureInteractionresponses):mergeHostWebUIStateand ignores the response's.Rule 3 applies to the read path since the host stops populating a field. It is safe for every reader: mobile reads only
trustedOrcaHooksoffui.get, and the web client pins both members locally.No opcode, no schema change, no protocol version bump.
PersistedUIStatestill 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— aui.setcarrying aruntime:web-<uuid>-keyedmanualRepoOrderreachesruntime.updateUIStatewithout the field whilesidebarWidthstill passes through. The existing full-payload pass-through case was updated to assert the same exclusion.web-preload-api-ui.test.ts— the webui.setforwards{ sidebarWidth: 280 }only, whilemanualRepoOrderstill lands inorca.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:applyManualRepoOrderreturns its input unchanged for an empty overlay.Four throwaway diagnostic probes were written against
mainbefore the fix to pin the failure modes; they are not committed. Two are green on this branch and two stay red by design:ui.setforwards a paired client'smanualRepoOrderapplyManualRepoOrderdirectly with hardcodedruntime:web-*entries; the only way to satisfy it is to fall back to matching on barerepoId, 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 theui.setboundary is the fix; tolerance of foreign keys is not.Round 2 added: a census test on
PAIRING_LOCAL_UI_FIELDS; seam tests iterating that set for theui.setstrip, theui.getomission and the response omissions; webui.getround-trip tests covering a host that returns this browser's own staleruntime:web-*entries, a desktop-keyed array, an empty array, and a new host that omits the field; a store test pinning that an update omittingmanualRepoOrderpreserves it rather than clearing it (after the strip, that is every pairedui.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
workspaceHostOrderto the set (picking up the host-side seamit.eachautomatically), converted the web-side merge coverage to anit.eachoverPAIRING_LOCAL_UI_FIELDSwith 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, andcheck: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.jsonand 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'sorca-data.jsonui.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:
runtime:web-<uuid>host the profile does not own, soapplyManualRepoOrdermatches nothing, every row sorts as unranked, and the identity check atmanual-repo-order.ts:73returns the input array untouched. The user sees arrival order.orca.web.runtimeEnvironment.v1, so the same browser restamps its repos onto the sameruntime:web-<uuid>host. Those entries came back overui.getand 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:setIPC (src/main/ipc/ui.ts:66), not the runtime RPC, sogetManualRepoOrderre-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 legitimateruntime:*entries for real remote runtimes.Known limitations and follow-ups
repo.reorderstill 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.mergeExactHostCatalogrebuilds 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.ui.setwhose 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 byworktree-list-groups-project-host-setups.test.tsand 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-qualifyinggetProjectIdentityKey, which would reach project groups, succession, cmd-J, and colors.