Skip to content

refactor(sidebar): one shared feed client for the desktop window and the phone - #31524

Merged
Jinwoo-H merged 6 commits into
mainfrom
sidebar-p4-feed-client
Oct 21, 2026
Merged

Jinwoo-H merged 6 commits into
mainfrom
sidebar-p4-feed-client

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​424 $\color{#cf222e}{\Huge{\mathbf{−}}}$​236 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​188
Prod 13 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​424 $\color{#cf222e}{\Huge{\mathbf{−}}}$​284 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​140

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 with mobile/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:

  • Reader (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.
  • Snapshot (sidebar-feed-snapshot.ts): every install becomes a new read-only snapshot. Anything that didn't change keeps the same object. sidebar-feed-domains.ts now 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 feeds (remembered-sidebar-feeds.ts): the phone's "show this host's last list while the new one loads" memory, now holding snapshots.
  • Not here yet: the drag/collapse gesture tracker and the view reporter land with their first callers (the view reporter with the workspace-records cut and its wire review, gestures with the view-and-collapse cut).

The window's desktop-sidebar-feed.ts keeps 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, and use-host-sidebar-feed.ts uses 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.ts still 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=main does. Two changes do run in every build, because their modules are also loaded with the switch off:

  • the per-entity parse memory in sidebar-feed-domains.ts, also used by a main-process test helper;
  • the per-row memory in 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:

  • Leaving the window's file in place and only adding the shared reader under it: that would keep two readers.
  • Deleting the window's file outright: that renames its exports for every caller and clashes with the in-flight host-keys PR, which edits its test.

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, mobile tsc and 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):

    • The sidebar, feed, renderer-lib and runtime sidebar-inputs suites all pass: 2,490 files.
    • The one failure is omp-draft-launch-shell under fish. It comes from the local shell config and is unrelated to this PR.
    • New suites: shared reader (ported from the phone's) and snapshot reuse.
  • 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=main build, ORCA_BACKGROUND_LAUNCH=1, 2 workers, hidden windows):

    • All 18 sidebar-inputs specs: 42 passed, 5 skipped.
    • After the last edit: sidebar-phone-feed-list, sidebar-desktop-reads-main, sidebar-inputs-feed and paired-server-rows-shadow again, 8 passed, 1 skipped.
    • The skips are the Docker-gated SSH phone feed spec (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): readDomain in sidebar-feed-domains.ts (both change its loop). The fix is small: its key-mapping readKeyedDomain takes the parser this PR adds. Nothing here touches the producer-prep PR (#31513).

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Cross-platform: no platform-specific code.
  • SSH and paired servers: reading is unchanged per host, and the SSH phone-feed spec ran.
  • Mobile: ships through an over-the-air update only, with no native change.
  • Wire format: unchanged.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

Jinwoo-H and others added 6 commits October 21, 2026 02:48
…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]>
# 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
@Jinwoo-H
Jinwoo-H changed the base branch from sidebar-p0 to main October 21, 2026 23:13
@coderabbitai

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

The change adds shared sidebar feed snapshots, a reader, and remembered-feed storage. It updates domain parsing and workspace indexing to reuse unchanged data. Desktop and mobile host feeds now use the shared reader and snapshot-based state. Tests cover reader lifecycle, snapshot updates, host read states, and updated feed-list behavior.

Priority: ➖ Normal

Merge Risk: 🔵 Low · up to a4e96

The shared sidebar feed reader could stall if a read callback ever throws, which would leave the feed stale until a manual refresh. The existing callers are unlikely to throw, so this is a small robustness gap and can be addressed before or after merge.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 55.17% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 29 functions across 17 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly identifies the main change: consolidating desktop and phone sidebar feed reading into one shared client.
Description check Passed The description is complete and focused. It explains the user impact, implementation, rationale, alternatives, testing, compatibility considerations, and checklist status. The linked issue is marked N…
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.
Full details: Description check

Explanation

The description is complete and focused. It explains the user impact, implementation, rationale, alternatives, testing, compatibility considerations, and checklist status. The linked issue is marked N/A with an internal-series explanation, which is consistent with the template's maintainer exception.

✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • 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.

@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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2e7f296e-df67-4ba2-a46b-27068bfa92bb
📥 Commits

Reviewing files that changed from the base of the PR and between d22fb0d and a4e96ae.

📒 Files selected for processing: 19
  • mobile/src/host-screen/host-list-first-frame.test.tsx
  • mobile/src/host-screen/host-sidebar-feed-connection.ts
  • mobile/src/host-screen/host-sidebar-feed-operations.ts
  • mobile/src/host-screen/host-sidebar-feed-reader.test.ts
  • mobile/src/host-screen/host-sidebar-feed-reader.ts
  • mobile/src/host-screen/use-host-sidebar-feed.test.ts
  • mobile/src/host-screen/use-host-sidebar-feed.ts
  • mobile/src/host-screen/use-host-worktree-catalog.ts
  • mobile/src/worktree/host-worktree-refresh.ts
  • src/renderer/src/components/sidebar/worktree-list/listing/use-main-list-model.ts
  • src/renderer/src/lib/desktop-sidebar-feed.ts
  • src/shared/sidebar-feed-client/remembered-sidebar-feeds.ts
  • src/shared/sidebar-feed-client/sidebar-feed-reader.test.ts
  • src/shared/sidebar-feed-client/sidebar-feed-reader.ts
  • src/shared/sidebar-feed-client/sidebar-feed-snapshot.test.ts
  • src/shared/sidebar-feed-client/sidebar-feed-snapshot.ts
  • src/shared/sidebar-list/sidebar-feed-domains.ts
  • src/shared/sidebar-list/sidebar-feed-index.ts
  • tests/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.

Comment on lines +97 to +103
const settledBy = answered !== null && !step.request && installed ? answered : null
if (installs || settledBy !== null) {
this.emit(settledBy)
}
if (step.request) {
this.send(step.request)
}

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.

🩺 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 in noticed.
  • retry() skips its refresh while inFlight !== 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.

Suggested change
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)
}

@Jinwoo-H
Jinwoo-H merged commit 98007cb into main Oct 21, 2026
55 of 81 checks passed
Jinwoo-H added a commit that referenced this pull request Oct 22, 2026
…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
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