Skip to content

fix(source-control): preserve section collapse state - #9405

Merged
nwparker merged 6 commits into
stablyai:mainfrom
just-zzp:fix/source-control-section-collapse-state
Oct 24, 2026
Merged

nwparker merged 6 commits into
stablyai:mainfrom
just-zzp:fix/source-control-section-collapse-state

Conversation

@just-zzp

@just-zzp just-zzp commented Jul 19, 2026 •

Copy link
Copy Markdown
Contributor

Collapsing a Source Control section (e.g. Changes) was lost after visiting Explorer or Checks, because the right sidebar unmounts <SourceControl/> on tab switch. Section disclosure now survives those remounts for the current worktree in this renderer session.

Part of #9403. Agent Session History is tracked separately in #9419, so this PR does not close the combined issue.

Scope:

  • use-panel-view-state.ts keeps a module-level BoundedMap (max 512 entries) of collapsed sections keyed by activeWorktreeId, the same key as the existing per-worktree reset. On mount and on worktree switch the reset reads that worktree's retained sections (or the defaults, including collapsed Commits); toggles write back.
  • Filter, tree directories and the base-ref dialog still reset on worktree switch exactly as before, so worktree B never inherits A's view.
  • Renderer memory only: no persisted settings, IPC or wire changes, so mixed client/server versions, SSH and folder workspaces behave as before. Choices reset on app reload.

Original work by @just-zzp; narrowed by maintainers to the existing worktree key.

Tests: SourceControl.virtual-file-list.test.tsx remount regression and use-panel-view-state.test.tsx (remount retention + no cross-worktree leak) fail on main and pass here.

@coderabbitai

coderabbitai Bot commented Jul 19, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

The panel view-state hook stores collapsed-section choices by worktree in a bounded renderer-session map with a limit of 512 entries. It restores stored choices when a worktree becomes active and uses defaults when no state exists or the worktree ID is null. Tests cover worktree isolation, persistence across remounts, and expansion of the virtualized Changes section after remount.

Priority: Low

Merge Risk: Low · up to 39dd7

Section choices can carry over to a different checkout or host with the same worktree ID. Correct the identity key before merging, or accept this bounded display-state risk.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check Warning The description clearly explains the problem, implementation, scope, compatibility impact, and automated tests. However, it does not follow the required template. It omits the required Visual Proof se… Update the description using the repository template. Add ELI5, What Changed, Why, Linked Issue with the actual issue link or required Fixes reference, Visual Proof with screenshots/videos or exactly N/A plus a reason, Testing with complete…
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title "fix(source-control): preserve section collapse state" names the main change. The PR keeps Source Control section collapse choices across panel remounts, and the diff matches that aim. The t…
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: Title check

Explanation

The title "fix(source-control): preserve section collapse state" names the main change. The PR keeps Source Control section collapse choices across panel remounts, and the diff matches that aim. The title uses a conventional-commit style and is specific enough for a reviewer scanning history.

Full details: Description check

Explanation

The description clearly explains the problem, implementation, scope, compatibility impact, and automated tests. However, it does not follow the required template. It omits the required Visual Proof section or an explicit N/A reason, the Testing checklist and platform details, and most checklist sections. It references issue #9403 but does not provide the required linked-issue format.

Resolution

Update the description using the repository template. Add ELI5, What Changed, Why, Linked Issue with the actual issue link or required Fixes reference, Visual Proof with screenshots/videos or exactly N/A plus a reason, Testing with completed checklist items and tested platforms, AI Disclosure when applicable, Review, Agent skill upstream boundary, Notes, and Checklist sections.

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

🧹 Nitpick comments (1)
src/renderer/src/components/right-sidebar/SourceControl.virtual-file-list.test.tsx (1)

371-375: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert the remounted header exists before clicking it. The first lookup already does this; the remounted one should mirror it so a missing/renamed "Changes" header fails here instead of turning the click into a silent no-op.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: f801338f-5e27-43ce-8712-bf87e4f44ba8

📥 Commits

Reviewing files that changed from the base of the PR and between ae1c943 and ef298d7.

📒 Files selected for processing (4)
  • src/renderer/src/components/right-sidebar/SourceControl.tsx
  • src/renderer/src/components/right-sidebar/SourceControl.virtual-file-list.test.tsx
  • src/renderer/src/components/right-sidebar/source-control-section-collapse-state.test.tsx
  • src/renderer/src/components/right-sidebar/source-control-section-collapse-state.ts

@brennanb2025

Copy link
Copy Markdown
Contributor

Taking a look!

@nwparker nwparker added the bug Something isn't working label Jul 27, 2026
nwparker and others added 2 commits October 23, 2026 05:48
Adapt just-zzp's stablyai#9405 fix to the current panel modules and existing bounded map, with runtime/host/occupant isolation. Part of stablyai#9403; Session History remains separate.

Co-authored-by: just-zzp <264744947+just-zzp@users.noreply.github.com>
@nwparker
nwparker requested a review from Jinwoo-H as a code owner October 23, 2026 12:50
Narrow the remount fix to the existing per-worktree reset: a bounded
renderer-session map keyed by activeWorktreeId restores section disclosure
after the panel unmounts, while a worktree switch still never inherits
another worktree's view.

@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
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9b42cd73-1097-40c7-b667-61730ff7a8f0
Commits

Reviewing files that changed from the base of the PR and between 8c3bf6a and 39dd7a4.

Files selected for processing: 3
  • src/renderer/src/components/right-sidebar/SourceControl.virtual-file-list.test.tsx
  • src/renderer/src/components/right-sidebar/source-control/panel/use-panel-view-state.test.tsx
  • src/renderer/src/components/right-sidebar/source-control/panel/use-panel-view-state.ts

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

}

// Why: the panel unmounts on sidebar tab switch; retain per-worktree disclosure for this renderer session.
const collapsedSectionsByWorktree = new BoundedMap<string, Set<string>>({ maxEntries: 512 })

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,180p' src/renderer/src/components/right-sidebar/source-control/panel/use-panel-view-state.ts
sed -n '1,220p' src/renderer/src/components/right-sidebar/source-control/panel/use-panel-state.ts
rg -n 'activeWorktreeInstanceId|useSourceControlPanelViewState|worktreeId' src/renderer/src/components/right-sidebar/source-control/panel

Repository: stablyai/orca

Length of output: 11878


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- identity references ---'
rg -n -F --glob '*.{ts,tsx}' -e 'activeWorktreeInstanceId' -e 'executionHost' -e 'ownerId' -e 'owner' -e 'worktreeInstanceId' -e 'instanceId' src/renderer/src/components/right-sidebar/source-control src/renderer/src | head -n 240
printf '%s\n' '--- context declaration and related types ---'
rg -n -F --glob '*.{ts,tsx}' -e 'useSourceControlWorktreeContext' -e 'SourceControlWorktreeContext' -e 'activeWorktreeInstanceId' src/renderer/src/components/right-sidebar/source-control src/renderer/src/store src/shared | head -n 240
printf '%s\n' '--- replacement and locator references ---'
rg -n -F --glob '*.{ts,tsx}' -e 'worktree replacement' -e 'replaceWorktree' -e 'recreated' -e 'locator' -e 'worktreeInstance' -e 'executionHostId' src/renderer/src src/shared | head -n 300
printf '%s\n' '--- relevant diff ---'
git diff --find-renames 92ccacd7373147a07cd26ab81ac296b5b102912a 39dd7a464a6876c3d119fcf5f0ada414be7f639e -- src/renderer/src/components/right-sidebar/source-control/panel/use-panel-view-state.ts src/renderer/src/components/right-sidebar/source-control/panel/use-panel-state.ts

Repository: stablyai/orca

Length of output: 41439


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- source-control worktree context ---'
sed -n '1,280p' src/renderer/src/components/right-sidebar/source-control/listing/use-worktree-context.ts
printf '%s\n' '--- context imports and worktree types ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'instanceId?:' -e 'instanceId:' -e 'interface Worktree' -e 'type Worktree' -e 'executionHostId' src/shared src/renderer/src/store src/renderer/src/lib src/renderer/src/components/right-sidebar/source-control/listing | head -n 320
printf '%s\n' '--- exact instance-id definitions and consumers ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'activeWorktree?.instanceId' -e 'instanceId' src/renderer/src/components/right-sidebar/source-control/listing src/renderer/src/store/slices src/shared | head -n 320
printf '%s\n' '--- locator and identity helpers ---'
rg -n -i --glob '*.ts' --glob '*.tsx' 'host.?qualified|qualified.?locator|locator.*fallback|fallback.*locator|worktree.*locator|locator.*worktree|worktree.*identity|identity.*worktree' src | head -n 320
printf '%s\n' '--- tests for the changed hook and replacement behavior ---'
sed -n '1,260p' src/renderer/src/components/right-sidebar/source-control/panel/use-panel-view-state.test.tsx
rg -n -i --glob '*.{ts,tsx}' 'recreat|replace.*worktree|worktree.*replace|same.*worktree.*host|same.*id.*host|instanceId' src/renderer/src/components/right-sidebar/source-control src/renderer/src/store | head -n 320

Repository: stablyai/orca

Length of output: 45661


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- worktree declarations ---'
rg -n -U --glob '*.ts' --glob '*.tsx' 'export (interface|type) Worktree|interface Worktree|type Worktree\\s*=' src | head -n 80
printf '%s\n' '--- instance ID lifecycle ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'instanceId: crypto' -e 'instanceId: random' -e 'instanceId: uuid' -e 'instanceId: generate' -e 'instanceId ??' -e 'instanceId ||' -e 'worktree.instanceId' -e 'instanceId = ' src/shared src/renderer/src/store src/main | head -n 240
printf '%s\n' '--- same-ID host tests ---'
sed -n '1,150p' src/renderer/src/store/slices/worktree-catalog-reconciliation.test.ts
sed -n '210,270p' src/renderer/src/store/slices/purge-stale-runtime-host-state.test.ts
sed -n '200,250p' src/renderer/src/store/slices/worktree-listing-branch-switch.test.ts
printf '%s\n' '--- worktree ID construction and recreation comments ---'
rg -n -i --glob '*.ts' --glob '*.tsx' 'recreated at the same path|worktree ids are recycled|id.*repo.*path|repo.*path.*id|new.*instance' src/shared src/renderer/src/store src/main | head -n 240
printf '%s\n' '--- disclosure/fallback terms in full repository ---'
rg -n -i --glob '*.ts' --glob '*.tsx' 'collapsedSectionsByWorktree|host-qualified locator|locator fallback|occupant metadata|checkout occupant|section disclosure|disclosure state' . | head -n 240

Repository: stablyai/orca

Length of output: 41753


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- checkout identity contract ---'
sed -n '1,220p' src/shared/worktree/identity.ts
printf '%s\n' '--- persisted locator aliases ---'
sed -n '55,125p' src/shared/persisted-state-types.ts
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'Host-qualified locator aliases' -e 'worktreeLocatorAliases' -e 'locatorAliases' -e 'canonical identity keys' src | head -n 160
printf '%s\n' '--- alias declarations and consumers ---'
rg -n -i --glob '*.ts' --glob '*.tsx' 'locator.*alias|alias.*locator|canonical.*identity|identity.*key' src/shared src/renderer/src/store src/renderer/src/lib | head -n 240
printf '%s\n' '--- worktree ID and host construction ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'repo.id}::' -e 'repoId}::' -e 'hostId:' -e 'id: worktreeId' -e 'worktreeId = ' src/main src/shared src/renderer/src/store | head -n 260
printf '%s\n' '--- exact source-control owner key patterns ---'
sed -n '35,75p' src/renderer/src/components/right-sidebar/source-control/sync/use-git-history.ts
sed -n '145,180p' src/renderer/src/components/right-sidebar/source-control/sync/use-git-history.ts
sed -n '1,140p' src/renderer/src/components/right-sidebar/source-control/worktree-git-owner-target.ts

Repository: stablyai/orca

Length of output: 41649


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- canonical identity consumers ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'canonicalWorktreeIdentity' -e 'createWorktreeIdentity' -e 'WorktreeIdentityRef' -e 'worktreeIdentityAliases' src
printf '%s\n' '--- identity helper modules ---'
find src/shared/worktree -maxdepth 2 -type f -print | sort
for f in src/shared/worktree/id.ts src/shared/sidebar-list/workspace-rows.ts src/shared/sidebar-list/paired-server-rows.ts; do
  if test -f "$f"; then
    printf '%s\n' "--- $f ---"
    sed -n '1,240p' "$f"
  fi
done
printf '%s\n' '--- active worktree host and type evidence ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'activeWorktree.hostId' -e 'activeWorktree?.hostId' -e 'hostId: activeWorktree' -e 'Pick<Worktree' src/renderer/src src/shared | head -n 220
printf '%s\n' '--- worktree model imports ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'from.*types' -e 'from.*models' src/shared | grep -E 'Worktree|worktree' | head -n 120

Repository: stablyai/orca

Length of output: 41930


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- host-qualified identity contract ---'
sed -n '1,180p' src/shared/worktree/host-qualified-identity.ts
printf '%s\n' '--- active worktree host and execution-host alias ---'
sed -n '1,140p' src/renderer/src/lib/worktree-execution-host-alias.ts
sed -n '285,315p' src/shared/execution-host.ts
printf '%s\n' '--- canonical alias projection ---'
sed -n '1,125p' src/main/persistence/loading-store/worktree-meta-alias-projection.ts
sed -n '1,125p' src/main/persistence/loading-store/worktree-identity-metadata.ts

Repository: stablyai/orca

Length of output: 17183


Key disclosure state by checkout occupant and execution host.

activeWorktreeId is only a repoId::path locator. It is not host-qualified. The hook must key state by the canonical occupant identity: the active worktree’s execution host and activeWorktreeInstanceId. Use composeWorktreeHostIdentity(executionHostId, activeWorktreeId) only when instance metadata is unavailable. Use the same key for the cache lookup, write, and switch comparison.

A recreated checkout receives a new durable instance ID, but the current hook ignores it. A same-ID checkout on another host also shares the current key. The host-qualified fallback matches the repository contract for legacy rows, but it cannot distinguish two occupants that both lack instance metadata on the same host.

@nwparker

Copy link
Copy Markdown
Contributor

Maintainer follow-up (39dd7a4): merged main and narrowed the fix. Retained section disclosure is now a bounded (512) renderer-session map keyed by activeWorktreeId, the same key as the existing per-worktree reset in use-panel-view-state.ts. That replaces the separate collapse-state hook and the runtime-owner/host/occupant key. Filter, tree dirs and the base-ref dialog still reset on worktree switch, so worktree B never inherits A's view. Added a remount + no-cross-worktree-leak test. CI green. Thanks @just-zzp!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants