Repository navigation
fix(sidebar): main's temporal owner reads the catalog the way the window does (dark) - #30166
Conversation
…and skips unchanged listings
… the window's equality
📝 Walkthrough
Priority: ⬇️ Low Merge Risk: 🔵 Low · up to
|
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
ba9a6772-6cd0-4964-a152-5a534824f6ec
📒 Files selected for processing: 6
config/tsconfig.tc.web.jsonsrc/main/runtime/sidebar-inputs/catalog-listing-change.tssrc/main/runtime/sidebar-inputs/orca-runtime-sidebar-temporal.tssrc/main/runtime/sidebar-inputs/sidebar-temporal-owner.test.tssrc/main/runtime/sidebar-inputs/sidebar-temporal-owner.tssrc/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.
| 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'), |
There was a problem hiding this comment.
🎯 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.tsRepository: 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 || trueRepository: 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-inputsRepository: 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
}| void this.listSidebarRows().then( | ||
| (worktrees) => this.sidebarTemporal.noteCatalogListing(worktrees, type === 'reposChanged'), |
There was a problem hiding this comment.
🎯 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/mainRepository: 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/runtimeRepository: 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/mainRepository: 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/mainRepository: 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 1Repository: 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.
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
🟡 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 winCompare 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()returnsnonebecause 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
📒 Files selected for processing: 3
config/tsconfig.tc.web.jsonsrc/main/runtime/sidebar-inputs/orca-runtime-sidebar-temporal.tssrc/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.
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
tests/e2e/sidebar-creation-registry.spec.tsfailed its shadow check on every run.catalog-listing-change.ts, using the window's own structural equality):sortOrderre-ranks only Manual and cold Smart.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.tsand in the window-vs-main fake-clock parity testuse-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-registryalso 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.
Agent skill upstream boundary
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
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)