Repository navigation
refactor(sidebar): one shared feed client for the desktop window and the phone - #31524
Conversation
…lip) The fixes found while the sidebar ran from main's feed, without turning that on: ORCA_SIDEBAR_INPUTS_IS_MAIN stays false, and none of flip-a's stop-gaps come along. - Main stops counting a closed tab's terminal once it was asked to stop and no pane shows it; a failed or refused stop takes the request back, and a host out of contact stays unverifiable. - Main fetches a paired server's rows with the transport's normal bound, so a server slower than 5 s still lists. - A deferred unread raise flips the folder row it was decided for, and a read while the owner check is out cancels it. - Phone: no worktree.ps flash before the feed; a host's last installed feed stands in while a fresh read is out; it highlights its own last-opened workspace and a fold never scrolls; projects file under their project group with the desktop's indent; the collapse spinner shows only after 500 ms; "Reopen to update" keeps the rows on screen. - e2e helpers and journeys for the switch-on suite.
…d prune pending unread raises - A stop-and-wait that throws takes its stop request back, like one that fails. - A final stop the legacy relay still owes stays marked, since the relay retries it. - Pending unread raises are tracked only while one waits, so the map no longer grows. - The paired-server fallback poll test gives its third fetch a reply and asserts live.
…brary on desktop and phone The window and the phone each had their own feed reader. Both now use one reader under src/shared/sidebar-feed-client: paging, notices, retries and the snapshot it installs. A snapshot reuses each unchanged entity's parsed object, so one row's change re-parses one row instead of its whole domain. Adds the gesture and view-report pieces later cuts wire up. Lists are unchanged on both sides. Co-Authored-By: Claude <[email protected]>
…allers land Co-Authored-By: Claude <[email protected]>
# Conflicts: # mobile/src/host-screen/host-list-first-frame.test.tsx # mobile/src/host-screen/host-sidebar-feed-sections.test.ts # mobile/src/host-screen/use-host-sidebar-feed.ts # src/shared/sidebar-list/sidebar-feed-domains.ts
…'s feed types now do Co-Authored-By: Claude <[email protected]>
📝 Walkthrough
Priority: ➖ Normal Merge Risk: 🔵 Low · up to
|
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
2e7f296e-df67-4ba2-a46b-27068bfa92bb
📒 Files selected for processing: 19
mobile/src/host-screen/host-list-first-frame.test.tsxmobile/src/host-screen/host-sidebar-feed-connection.tsmobile/src/host-screen/host-sidebar-feed-operations.tsmobile/src/host-screen/host-sidebar-feed-reader.test.tsmobile/src/host-screen/host-sidebar-feed-reader.tsmobile/src/host-screen/use-host-sidebar-feed.test.tsmobile/src/host-screen/use-host-sidebar-feed.tsmobile/src/host-screen/use-host-worktree-catalog.tsmobile/src/worktree/host-worktree-refresh.tssrc/renderer/src/components/sidebar/worktree-list/listing/use-main-list-model.tssrc/renderer/src/lib/desktop-sidebar-feed.tssrc/shared/sidebar-feed-client/remembered-sidebar-feeds.tssrc/shared/sidebar-feed-client/sidebar-feed-reader.test.tssrc/shared/sidebar-feed-client/sidebar-feed-reader.tssrc/shared/sidebar-feed-client/sidebar-feed-snapshot.test.tssrc/shared/sidebar-feed-client/sidebar-feed-snapshot.tssrc/shared/sidebar-list/sidebar-feed-domains.tssrc/shared/sidebar-list/sidebar-feed-index.tstests/e2e/helpers/phone-feed-list.ts
💤 Files with no reviewable changes: 2
- mobile/src/host-screen/host-sidebar-feed-reader.test.ts
- mobile/src/host-screen/host-sidebar-feed-reader.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
| const settledBy = answered !== null && !step.request && installed ? answered : null | ||
| if (installs || settledBy !== null) { | ||
| this.emit(settledBy) | ||
| } | ||
| if (step.request) { | ||
| this.send(step.request) | ||
| } |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Send the next page before calling onRead. If onRead throws, the reader stops for good.
apply sets this.state = step.state first. At that point state.inFlight already holds step.request.id. Then apply calls emit, and only after that send. If the onRead callback throws, send(step.request) never runs. inFlight then keeps an id that no reply will ever settle:
changed()only stores the notice innoticed.retry()skips its refresh whileinFlight !== null.- Only a manual
refresh()gets the reader moving again.
The throw happens inside the fulfilled handler of .then(onFulfilled, onRejected). onRejected does not catch errors from that handler, so the error also becomes an unhandled rejection.
A fix is to start the request before you emit, or to wrap the call to onRead.
🛡️ Proposed fix
--- "a/src/shared/sidebar-feed-client/sidebar-feed-reader.ts"
+++ "b/src/shared/sidebar-feed-client/sidebar-feed-reader.ts"
@@ -94,14 +94,14 @@
this.failures = 0
this.snapshot = installSidebarFeedSnapshot(installed, this.snapshot)
}
const settledBy = answered !== null && !step.request && installed ? answered : null
- if (installs || settledBy !== null) {
- this.emit(settledBy)
- }
if (step.request) {
this.send(step.request)
}
+ if (installs || settledBy !== null) {
+ this.emit(settledBy)
+ }
}
/** Reads again from what is installed, which the host answers past every notice so far. */
private retry(): void {📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const settledBy = answered !== null && !step.request && installed ? answered : null | |
| if (installs || settledBy !== null) { | |
| this.emit(settledBy) | |
| } | |
| if (step.request) { | |
| this.send(step.request) | |
| } | |
| const settledBy = answered !== null && !step.request && installed ? answered : null | |
| if (step.request) { | |
| this.send(step.request) | |
| } | |
| if (installs || settledBy !== null) { | |
| this.emit(settledBy) | |
| } |
…tore-view-attach apply-mobile-session-tab-navigation.ts takes main's renamed selection-projection import; C1c's numbered-record lookup keeps replacing the stable-key read, so main's makePaneKey import is unused and dropped. Claude-Session: W5b
ELI5
The desktop window and the phone both read the same sidebar data from the desktop's main process, but each had its own copy of the code that reads it. This PR puts that reading code in one shared place that both use. The lists people see are the same as before; only the plumbing underneath changed.
What Changed
Before: the window read the sidebar feed with
src/renderer/src/lib/desktop-sidebar-feed.ts, and the phone read it withmobile/src/host-screen/host-sidebar-feed-reader.ts. They were two separate loops around the same paging logic. Each time anything in one category changed (say, one workspace was marked unread), every workspace in that category was parsed and rebuilt again. The phone also rebuilt everything on every update, because it never reused its last read.After: one library under
src/shared/sidebar-feed-client/handles the reading for both sides:sidebar-feed-reader.ts): reads one host's feed one request at a time, waits for every page of a batch, follows change notices, and retries a failed read. Each platform passes in how it sends a request and how often it retries. The window keeps a fixed 1 s retry; the phone keeps its 1/2/4/8/16 s backoff.sidebar-feed-snapshot.ts): every install becomes a new read-only snapshot. Anything that didn't change keeps the same object.sidebar-feed-domains.tsnow remembers each entity's parse by the object it came from, so one changed workspace is the only one parsed again. The feed index does the same per row (sidebar-feed-index.ts).remembered-sidebar-feeds.ts): the phone's "show this host's last list while the new one loads" memory, now holding snapshots.The window's
desktop-sidebar-feed.tskeeps its exports but is now just the window's wiring: how it calls main, and its React hook. The phone's reader file is deleted.host-sidebar-feed-connection.ts(not a hook) builds the shared reader for one host connection, anduse-host-sidebar-feed.tsuses it.One internal difference: the window now decodes every install, including one that is followed straight away by another read. It still draws only the settled one. The values drawn are the same, and the cost is small because unchanged entities are reused from the cache.
Not changed: how the list is put together.
use-main-list-model.tsstill takes the same pending, creation, catalog and view inputs. The list builder and the main-process producers are untouched.What runs with the switch off: the main process never runs the sidebar feed reader with the switch off; only a window or phone page built with
ORCA_SIDEBAR_INPUTS=maindoes. Two changes do run in every build, because their modules are also loaded with the switch off:sidebar-feed-domains.ts, also used by a main-process test helper;sidebar-feed-index.ts.Both only return the same result object for the same input object. They change no value.
Why
The design gives the window and the phone one client library, so they can't drift apart and later steps have one place to build on. Reusing parsed objects by identity is what lets a single unread change rebuild one workspace instead of all of them (a test measures this: 1 parse instead of 1000).
Alternatives considered:
Keeping the exports and replacing the inside avoids both.
Linked Issue
N/A (internal sidebar series; design
sidebar-one-owner-design.md§2, §6, §8, P4).Visual Proof
N/A: no visual or interaction change. Both lists are built from the same inputs; the parity end-to-end specs below compare the phone's rows with the desktop's.
Testing
Run locally on macOS (arm64), in a separate checkout based on
sidebar-p0. After the review round (unused modules removed, no other behaviour change) these were re-run and pass:pnpm tc, mobiletscand its ratchet, the mobile host-screen tests, and the node sidebar, renderer-lib and sidebar-inputs suites (1,145 files).pnpm tc: passes. The mobile typecheck (tsc, plus the tests-typecheck ratchet) also passes.Unit tests (node project):
omp-draft-launch-shellunder fish. It comes from the local shell config and is unrelated to this PR.Mobile tests: 1,074 files / 11,059 tests pass.
Measurement: with 1,000 workspaces, one unread change runs the row parser once (1,000 times before this change; checked by disabling the reuse). Only that workspace's parsed row and index entry are new objects, and the untouched review domain keeps its map.
Static gate: the full pr.yml static-analysis set, 39/39 pass.
Switch-on e2e (
ORCA_SIDEBAR_INPUTS=mainbuild,ORCA_BACKGROUND_LAUNCH=1, 2 workers, hidden windows):sidebar-phone-feed-list,sidebar-desktop-reads-main,sidebar-inputs-feedandpaired-server-rows-shadowagain, 8 passed, 1 skipped.ssh-orcad-phone-feed-list). It needs the linux orcad template, so it runs in CI's managed-SSH leg; it uses the same phone reader as the local spec.I manually tested these changes locally
Automated tests added/updated, or explained why not below
Review
Expected rebase overlap with the host-keys PR (#31517):
readDomaininsidebar-feed-domains.ts(both change its loop). The fix is small: its key-mappingreadKeyedDomaintakes the parser this PR adds. Nothing here touches the producer-prep PR (#31513).Agent skill upstream boundary
Notes
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)