Skip to content

fix(sidebar): main's temporal owner reads the catalog the way the window does (dark) - #30166

Merged
Jinwoo-H merged 4 commits into
mainfrom
jinwoo/sidebar-temporal-create-shadow
Oct 18, 2026
Merged

Jinwoo-H merged 4 commits into
mainfrom
jinwoo/sidebar-temporal-create-shadow

Conversation

@Jinwoo-H

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

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​113 $\color{#cf222e}{\Huge{\mathbf{−}}}$​7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​106
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​134 $\color{#cf222e}{\Huge{\mathbf{−}}}$​33 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​101

ELI5

The background process keeps its own copy of the sidebar's "when do we re-sort" rules. This copy is dark and only compared against the window's copy in builds with the sidebar switch on. While a new workspace was being created, the two copies disagreed about the order in Recent mode. The window was right. This fixes main's copy.

What Changed

  • Before (switch on only): main kept no starting row count for the sort's "did rows come or go" check. Only catalog events carried a count. So the first worktree listing after the list mounted looked like rows had appeared (0 to 2), and main re-sorted at once. The window was still waiting out its three-second settle. tests/e2e/sidebar-creation-registry.spec.ts failed its shadow check on every run.
  • Also before: main restarted its settle window on every catalog event, even when nothing changed. A sort-order save or a repo edit also restarted it. The window does neither.
  • After:
    • The session's first rows set main's starting count and listing, the way the window's starting point is the catalog it already holds. Those first rows come from whichever lands first: the first sample or a listing. A listing that lands first re-samples.
    • Each new listing is read the way the window's catalog merge reads it (new catalog-listing-change.ts, using the window's own structural equality):
      • A row change restarts the settle window.
      • A save that only moved sortOrder re-ranks only Manual and cold Smart.
      • A repo change re-sorts at once and starts no timer.
      • An identical listing does nothing.
    • Catalog events list rows only. They no longer build the Smart sort's inputs.
  • Switch off: no change. The built main and renderer bundles are byte-identical to the base, ignoring sourcemaps.

Why

This fixes main's own disagreement with the window rather than loosening the shadow check. Main now uses the same baseline and the same "what counts as a bump" rule as the window, so it settles at the same moments.

Linked Issue

N/A (internal series; follow-up to #30104)

Visual Proof

N/A. Dark code only: with the switch off, the bundles are identical.

Testing

  • Regression tests in sidebar-temporal-owner.test.ts and in the window-vs-main fake-clock parity test use-sort-order.main-parity.test.tsx. The two baseline regressions fail on the old owner and pass now. Further owner tests cover sort-order-only saves, repo changes, and a listing that lands before the first sample.

  • Hidden-app e2e with ORCA_SIDEBAR_INPUTS=main (ORCA_BACKGROUND_LAUNCH=1, CDP only): all 7 specs that assert no shadow mismatches pass with 0 mismatches. sidebar-creation-registry also passes 3 of 3 repeats, where it failed 3 of 3 before.

  • pnpm tc, the changed-code quality gate, the anti-slop lint, and the max-lines ratchet all pass.

  • I manually tested these changes locally

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

Review

Two Opus review rounds, both run in the foreground.

  • Round one found that sort-order saves, repo changes and unchanged listings still bumped main where the window does not, and that a listing landing before the first sample used a stale baseline. All of these are fixed here.
  • Round two found no must-fix. Applied: a seeding listing re-samples, listings are compared with the window's equality function, and repo lookups are deduplicated.

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

This is the same whether the host is local, SSH or a paired server. Rows still use host-qualified ids, and paired-server rows stay out of the comparison.

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)

@coderabbitai

coderabbitai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

The temporal owner now compares catalog listings instead of relying only on live row counts. It distinguishes row changes from sort-order-only changes and uses the first listing as a session baseline. Runtime worktree and repository events submit sidebar rows to the owner, with missing host IDs resolved from repository execution hosts. Tests cover settling behavior and Recent-sort parity between the main owner and window.

Priority: ⬇️ Low

Merge Risk: 🔵 Low · up to 2d485

Sidebar sorting can briefly diverge from the window after reordered or delayed catalog listings. The change is mergeable with owner awareness, though correcting the listing handling before merge would reduce that risk.

Pre-merge checks: Passed 4 · Failed 1

Failed 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%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 5 files. (1 skipped: 1… 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 primary change: aligning main's sidebar temporal owner with the window's catalog behavior. The scope is concise and specific.
Description check Passed The description covers the required sections, explains the user-facing behavior and implementation, provides rationale, documents testing, and addresses visual proof and compatibility considerations. …
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 covers the required sections, explains the user-facing behavior and implementation, provides rationale, documents testing, and addresses visual proof and compatibility considerations. The linked issue is identified as an internal follow-up, which is allowed by the template's maintainer exception.

Full details: Docstring Coverage

Explanation

Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 5 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Fix all pre-merge checks with AI
✨ 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: 2


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ba9a6772-6cd0-4964-a152-5a534824f6ec
📥 Commits

Reviewing files that changed from the base of the PR and between 3d03c33 and 825bbf3.

📒 Files selected for processing: 6
  • config/tsconfig.tc.web.json
  • src/main/runtime/sidebar-inputs/catalog-listing-change.ts
  • src/main/runtime/sidebar-inputs/orca-runtime-sidebar-temporal.ts
  • src/main/runtime/sidebar-inputs/sidebar-temporal-owner.test.ts
  • src/main/runtime/sidebar-inputs/sidebar-temporal-owner.ts
  • src/renderer/src/components/sidebar/worktree-list/listing/use-sort-order.main-parity.test.tsx

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

Comment on lines +53 to +58
private noteSidebarCatalogChange(type: 'worktreesChanged' | 'reposChanged'): void {
if (!this.sidebarTemporal.running) {
return
}
void this.listResolvedWorktreeSnapshot().then(
({ worktrees }) =>
this.sidebarTemporal.noteRowsChange(
worktrees.filter((worktree) => !worktree.isArchived).length
),
(error: unknown) => console.warn('[sidebar-temporal] could not count rows', error)
void this.listSidebarRows().then(
(worktrees) => this.sidebarTemporal.noteCatalogListing(worktrees, type === 'reposChanged'),

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '1,215p' src/main/runtime/sidebar-inputs/orca-runtime-sidebar-temporal.ts
sed -n '75,210p' src/main/runtime/sidebar-inputs/sidebar-temporal-owner.ts

Repository: stablyai/orca

Length of output: 12246


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- owner declarations and implementation ---'
rg -n -F --glob '*.ts' -e 'class SidebarTemporalOwner' -e 'beginSession(' -e 'noteCatalogListing(' -e 'dispose()' -e 'sampleSeq' -e 'running' src/main/runtime/sidebar-inputs
printf '%s\n' '--- complete owner source ---'
sed -n '1,420p' src/main/runtime/sidebar-inputs/sidebar-temporal-owner.ts
printf '%s\n' '--- temporal lifecycle callers ---'
rg -n -F --glob '*.ts' -e 'beginSidebarListSession(' -e 'attachSidebarAgentStatusStore(' -e 'getSidebarTemporalSnapshot(' -e 'sidebarFactsRuntime(' -e 'sidebarTemporal' src | head -240
printf '%s\n' '--- relevant tests ---'
rg -n -F --glob '*.{ts,tsx}' -e 'beginSidebarListSession' -e 'noteCatalogListing' -e 'stale' -e 'stop' -e 'restart' src test tests 2>/dev/null || true

Repository: stablyai/orca

Length of output: 45646


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- RPC entrypoint ---'
sed -n '1,120p' src/main/runtime/rpc/methods/sidebar-inputs.ts
printf '%s\n' '--- runtime attachment lifecycle ---'
sed -n '250,325p' src/main/orcad/orcad-entry.ts
sed -n '120,170p' src/main/startup/main-process-runtime-service.ts
printf '%s\n' '--- renderer session callers ---'
rg -n -F --glob '*.{ts,tsx}' -e 'beginSidebarListSession' -e 'sidebar-temporal' -e 'sessionId' src/renderer/src src/main/runtime | head -160
printf '%s\n' '--- relevant PR diff ---'
git diff --unified=35 33e6785fe2c36730bc0dfcdf1db6208d471df833 825bbf31e7ab0ef731f930cfb39945c8936a96e3 -- src/main/runtime/sidebar-inputs/orca-runtime-sidebar-temporal.ts src/main/runtime/sidebar-inputs/sidebar-temporal-owner.ts src/main/runtime/rpc/methods/sidebar-inputs.ts src/renderer
printf '%s\n' '--- focused tests and names ---'
rg -n -F --glob 'sidebar-*.test.ts' -e 'session' -e 'catalog' -e 'listing' -e 'stale' src/main/runtime/sidebar-inputs

Repository: stablyai/orca

Length of output: 41888


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- exact line-numbered runtime and owner excerpts ---'
nl -ba src/main/runtime/sidebar-inputs/orca-runtime-sidebar-temporal.ts | sed -n '45,75p'
nl -ba src/main/runtime/sidebar-inputs/sidebar-temporal-owner.ts | sed -n '100,165p'
nl -ba src/main/runtime/sidebar-inputs/sidebar-temporal-owner.ts | sed -n '180,250p'
printf '%s\n' '--- exact session RPC usages ---'
rg -n -F --glob '*.{ts,tsx}' -e 'sidebarSession.begin' -e 'beginSidebarListSession' -e 'sidebarSession' src/renderer src/main | head -120
printf '%s\n' '--- focused owner tests ---'
nl -ba src/main/runtime/sidebar-inputs/sidebar-temporal-owner.test.ts | sed -n '175,325p'

Repository: stablyai/orca

Length of output: 14385


Reject catalog listings from an earlier sidebar session.

When sidebarSession.begin starts a new session, a pending listSidebarRows() promise from the previous session can still resolve. noteCatalogListing checks only running, so it can replace the new session’s listing baseline and apply the old reposChanged flag. sampleSeq protects sort samples only, not catalog listings.

Capture the session identity before listing and ignore callbacks from older sessions.

Suggested fix
   private noteSidebarCatalogChange(type: 'worktreesChanged' | 'reposChanged'): void {
     if (!this.sidebarTemporal.running) {
       return
     }
+    const sessionId = this.sidebarTemporal.snapshot().sessionId
+    if (sessionId === null) {
+      return
+    }
     void this.listSidebarRows().then(
-      (worktrees) => this.sidebarTemporal.noteCatalogListing(worktrees, type === 'reposChanged'),
+      (worktrees) =>
+        this.sidebarTemporal.noteCatalogListing(worktrees, type === 'reposChanged', sessionId),
       (error: unknown) => console.warn('[sidebar-temporal] could not list rows', error)
     )
   }
-  noteCatalogListing(worktrees: readonly Worktree[], repoChanged: boolean): void {
-    if (!this.running) {
+  noteCatalogListing(
+    worktrees: readonly Worktree[],
+    repoChanged: boolean,
+    sessionId: string | null = this.sessionId
+  ): void {
+    if (!this.running || sessionId !== this.sessionId) {
       return
     }

Comment on lines +57 to +58
void this.listSidebarRows().then(
(worktrees) => this.sidebarTemporal.noteCatalogListing(worktrees, type === 'reposChanged'),

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
# Inspect whether concurrent snapshot reads are serialized and when they capture rows.
rg -n -C 8 -g '*.ts' '\blistResolvedWorktreeSnapshot\s*\(' src/main

Repository: stablyai/orca

Length of output: 13630


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- temporal file ---'
nl -ba src/main/runtime/sidebar-inputs/orca-runtime-sidebar-temporal.ts | sed -n '1,190p'
printf '%s\n' '--- workspace catalog ---'
nl -ba src/main/runtime/workspaces/workspace-catalog.ts | sed -n '1,150p'
printf '%s\n' '--- resolved worktree cache references ---'
rg -n -C 10 -g '*.ts' -e 'class .*Resolved' -e 'resolvedWorktrees' -e 'getSnapshot' -e 'noteCatalogListing' src/main/runtime

Repository: stablyai/orca

Length of output: 42501


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- cache declaration and implementation ---'
rg -n -C 15 -g '*.ts' -e 'class RuntimeResolvedWorktreeCache' -e 'export class RuntimeResolvedWorktreeCache' -e 'getSnapshot\s*\(' src/main/runtime
printf '%s\n' '--- temporal owner ---'
nl -ba src/main/runtime/sidebar-inputs/sidebar-temporal-owner.ts | sed -n '1,230p'
printf '%s\n' '--- cache file candidates ---'
rg --files src/main/runtime | rg 'resolved-worktree-cache|worktree.*cache'

Repository: stablyai/orca

Length of output: 41836


🏁 Script executed:

nl -ba src/main/runtime/runtime-resolved-worktree-cache.ts
printf '%s\n' '--- cache imports and construction ---'
rg -n -C 8 -g '*.ts' 'RuntimeResolvedWorktreeCache|resolvedWorktrees\s*=' src/main

Repository: stablyai/orca

Length of output: 41512


🏁 Script executed:

rg -n -C 12 -g '*.ts' -e 'invalidateResolved\s*\(' -e 'getWorktreeScanMutationRevision\s*\(' -e 'bump.*Worktree|worktree.*Mutation|scanMutation' src/main

Repository: stablyai/orca

Length of output: 42370


🏁 Script executed:

printf '%s\n' '--- exact resolved-cache invalidation call sites ---'
rg -n -F -- 'invalidateResolved(' src/main || test "$?" -eq 1
printf '%s\n' '--- mutation revision implementation ---'
nl -ba src/main/local-worktree-scan-generation.ts
printf '%s\n' '--- relevant scan refresh invalidation ---'
rg -n -C 15 -F -- 'resolvedWorktrees.invalidateResolved' src/main || test "$?" -eq 1

Repository: stablyai/orca

Length of output: 10667


Preserve catalog event order when applying listings.

noteSidebarCatalogChange applies every completed listing without an ordering check. RuntimeResolvedWorktreeCache can run scans for different inventory revisions concurrently, and an older scan can resolve after a newer scan. The older result can then replace this.listing and restart settling for an already-processed row change.

Serialize these reads or discard stale results. If events are coalesced, preserve reposChanged with a pending OR flag.

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

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

🟡 Minor · Compare catalog order before returning none. · catalog-listing-change.ts:39-54

src/main/runtime/sidebar-inputs/catalog-listing-change.ts:39-54
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Compare catalog order before returning none.

A worktree refresh can preserve the same rows with a different linked-worktree order. parseWorktreeList() preserves Git’s record order. Its only ordering guarantee is that the main worktree is first. The resolved-cache path does not add a stable sort.

The window treats this reorder as a catalog change and starts its three-second settling period. classifyCatalogListingChange() returns none because it compares rows by identity. Main therefore keeps stale settling state and can process a later Smart-sort input before the window settles.

Suggested fix
   if (previous.size !== next.size) {
     return 'rows'
   }
+  const previousIdentities = [...previous.keys()]
+  let index = 0
   let sortOrderMoved = false
   for (const [identity, entry] of next) {
+    if (previousIdentities[index] !== identity) {
+      return 'rows'
+    }
     const before = previous.get(identity)
     if (!before || !structuralValuesEqualIgnoringUndefined(before.row, entry.row)) {
       return 'rows'
     }
     sortOrderMoved ||= before.sortOrder !== entry.sortOrder
+    index += 1
   }

ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 334d77b4-40b3-4166-8c37-4a39a9cfceb9
📥 Commits

Reviewing files that changed from the base of the PR and between 825bbf3 and 2d48538.

📒 Files selected for processing: 3
  • config/tsconfig.tc.web.json
  • src/main/runtime/sidebar-inputs/orca-runtime-sidebar-temporal.ts
  • src/main/runtime/sidebar-inputs/sidebar-temporal-owner.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.

@Jinwoo-H
Jinwoo-H merged commit 303c7c9 into main Oct 18, 2026
33 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