Skip to content

fix(editor): reuse a parked diff preview across tab groups, plus opt-in side-split diffs - #11866

Closed
dcieslak19973 wants to merge 1 commit into
stablyai:mainfrom
dcieslak19973:dcieslak19973/bug-diff-preview-replacement-is-group-scoped-par
Closed

dcieslak19973 wants to merge 1 commit into
stablyai:mainfrom
dcieslak19973:dcieslak19973/bug-diff-preview-replacement-is-group-scoped-par

Conversation

@dcieslak19973

@dcieslak19973 dcieslak19973 commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

What: A diff preview parked in a split no longer breaks when cycling files from Source Control — plus an opt-in "Open Diffs in a Side Split" setting.
Risk: Behavior fix on the preview-replacement path; the new setting is opt-in, default off.
State: Rebased clean onto current main (MERGEABLE); one squashed commit re-homed onto the post-split module layout. Typecheck (web + node) and the PR's targeted suites green locally; full matrix on CI.


Fixes #11839.

ELI5

If you park a diff preview in a side split next to your agent terminal, clicking through changed files in Source Control used to misfire: after touching the terminal, the next click stacked a brand-new diff tab over the terminal instead of updating the parked preview. Fixed — clicks now find and reuse the parked preview wherever it lives. Optionally, a new Settings → Git switch (off by default) makes Source Control diff clicks open straight into a right-hand split, skipping a manual move-the-tab ritual.

Summary

The review layout this addresses: agent terminal in the left tab group, a diff preview parked in a right split, clicking through changed files in Source Control to cycle that preview.

Preview replacement resolved the target group before looking for a replaceable preview, so the lookup was group-scoped. After focusing the terminal group — i.e. after every interaction with the agent — the next Source Control click resolved to the terminal's group, found no preview there, and opened a new diff tab over the terminal, orphaning the preview parked in the split. Two live "preview" tabs also arguably violates preview semantics on its own.

What changed:

  1. Worktree-scoped preview reuse. resolveReplaceablePreviewSlot finds the replaceable preview anywhere in the worktree and returns the openFiles index plus the group holding it, so the tab open is retargeted there instead of duplicating into the active group. openWorkspaceEditorItem takes an options object so callers can distinguish a resolved target group from a caller-pinned one. A caller-pinned targetGroupId keeps the previous group scoping, so a split-open in group B still cannot evict group A's preview — the existing shared-preview-across-splits behavior is unchanged and still covered by its test.
  2. Opt-in "Open Diffs in a Side Split". Off by default. When enabled, Source Control diff opens target the worktree's diff column: the parked preview's group, else a non-active group already holding diff tabs, else a freshly created right split (resolveSideSplitDiffColumn). This removes the per-worktree ritual of click file → get center tab → right-click → Move Tab to Split → Right. The worktree records the diff column it settles on, so the column stops moving with focus. Modifier-click still forces a brand-new split with a permanent tab; double-click pin behavior is untouched. Reachable from both Settings → Git and the Source Control panel overflow menu.
  3. Review follow-ups — localized search aliases and a shared editor-tab predicate (see AI Review Report).

Commit structure

One squashed commit, re-homed onto the module layout main grew after this branch was cut (store/slices/editor/**, right-sidebar/source-control/**). The re-home drops this branch's own src/shared/editor-tab-content-type.ts and its duplicate source-control-split-open.ts in favour of main's equivalents (store/slices/editor/tabs/editor-tab-content-type.ts, source-control/listing/split-open.ts), keeping only resolveSideSplitDiffColumn, which main lacks. The squashed commit message records the original eight-commit mapping.

Screenshots

No visual change from the reuse fix or the review follow-ups. The side-split feature adds one switch to Settings → Git ("Open Diffs in a Side Split", default off) and, when enabled, causes Source Control diff clicks to open in a right split instead of the active group — no new chrome, existing split/tab rendering. Real-Electron CDP proof (parked-preview reuse, pinned-open regression guard, and the opt-in side split) is captured in the reviewer readiness comments below.

Testing

  • pnpm tc:web — pass
  • pnpm tc:node — pass
  • PR-added suites via vitest — editor-parked-preview-reuse.test.ts, open-diffs-in-side-split-search.test.ts, header-overflow-menu.test.tsx (10/10)
  • Broad renderer/store/settings regression + real-Electron validation — verified by reviewer at the pre-rebase head (content-identical after this rebase; conflicts were additive only)
  • Full test matrix — CI (node 24 + 26, Windows package)

Rebase touched exactly two files by hand, both additive: the new sourceControlOpenDiffsInSideSplit default moved into buildDefaultSettings (its post-refactor home on main), and the openDiffsInSideSplit i18n key added alongside main's Create-PR strings. An orphan createPrIntentEmptyGeneratedBody key with no code references was dropped rather than resurrected.

AI Review Report

Reviewed with Claude Code, plus the CodeRabbit and Greptile passes on this PR. Risks checked: preview/tab state mutation across split groups, regression of the pre-existing pinned-target behavior, settings persistence and defaults, and search/i18n wiring.

Changed as a result:

  • Localized search aliases (CodeRabbit). The Git pane catalog indexes localized aliases through translateSearchKeyword, but this setting's matcher passed only the English keyword list — a localized query could match the catalog and then render nothing. The matcher now derives translated keywords; SearchableSetting keeps the English list. Added a regression test that injects a zh translation.
  • Duplicated content-type predicate (CodeRabbit). A private reimplementation of the editor-content-type check was removed in favour of importing the single predicate from its real module.

Verified and not changed:

  • Orphaned split group from the resolver side effect (Greptile, P2). Traced every path: the activeWorktreeId/worktreePath guards run before the placement resolver, and all three following branches (openConflictFile, markdown openFile, openDiff) consume the returned group. No reachable orphan short of an exception inside an open call.
  • Any editor-content preview anchoring the diff column (Greptile, P2). Load-bearing rather than incidental. The returned group is passed as a pinned targetGroupId, which makes preview replacement group-scoped for that open. Restricting the heuristic to diff-only previews would target a different group than the one where the parked preview actually lives — reintroducing the exact bug this PR fixes.

Cross-platform: no platform-dependent code paths added. No metaKey/ctrlKey hardcoding (the existing isSourceControlSplitOpenModifier already branches on isMac), no new path handling, no shell invocation, no Electron platform APIs. Tab-group state is in-renderer and platform-neutral.

Security Audit

Low risk surface. No IPC channels, command execution, path handling, auth, secrets, or dependencies added or changed. The one new persisted value is a boolean setting (sourceControlOpenDiffsInSideSplit) flowing through the existing settings store with no new validation surface. Group ids are internally generated UUIDs, never user input. No follow-up needed.

Notes

Cross-refs #11840, which scopes the parked preview to what changed since you last looked.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds a setting for opening Source Control diff previews in a dedicated side split. Adds target-group selection that prioritizes preview groups and existing non-active diff groups. Updates Source Control diff flows to use shared placement logic. Updates editor preview handling to reuse parked previews across groups while keeping explicitly pinned opens group-scoped. Adds per-worktree diff-column state, toolbar controls, and tests.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes satisfy issue #11839 by reusing worktree previews, adding opt-in side-split diffs, and preserving placement and pinning behavior.
Out of Scope Changes check ✅ Passed The implementation, settings wiring, shared predicate, state handling, and tests are all directly related to the linked issue objectives.
Title check ✅ Passed The title clearly summarizes both primary changes: cross-group reuse of parked diff previews and the opt-in side-split setting.
Description check ✅ Passed The description is detailed and relevant. It explains the problem, implementation, rationale, linked issue, UI impact, testing, compatibility, security, and review findings. Some template headings and…
Full details: Description check

Explanation

The description is detailed and relevant. It explains the problem, implementation, rationale, linked issue, UI impact, testing, compatibility, security, and review findings. Some template headings and checklist items are omitted, but the required information is substantially covered.


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

🧹 Nitpick comments (2)
src/renderer/src/components/right-sidebar/source-control-split-open.ts (1)

50-57: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Duplicate content-type predicate already exists in editor.ts.

isEditorContentTab reimplements the same four-way check as isEditorTabContentType in src/renderer/src/store/slices/editor.ts (lines 780-787). Both list 'editor' | 'diff' | 'conflict-review' | 'check-details' as the editor-family content types. If a new content type is added to this family later, a maintainer can update one copy and miss the other, silently breaking either side-split target selection or preview-slot replacement.

Extract one shared predicate (or a shared EDITOR_TAB_CONTENT_TYPES array) into src/shared/types.ts or a small shared module, and import it from both files.

♻️ Proposed shared predicate
+// src/shared/types.ts
+export const EDITOR_FAMILY_CONTENT_TYPES = ['editor', 'diff', 'conflict-review', 'check-details'] as const
+export function isEditorFamilyContentType(contentType: TabContentType): boolean {
+  return (EDITOR_FAMILY_CONTENT_TYPES as readonly string[]).includes(contentType)
+}
-function isEditorContentTab(tab: SideSplitCandidateTab): boolean {
-  return (
-    tab.contentType === 'editor' ||
-    tab.contentType === 'diff' ||
-    tab.contentType === 'conflict-review' ||
-    tab.contentType === 'check-details'
-  )
-}
+function isEditorContentTab(tab: SideSplitCandidateTab): boolean {
+  return isEditorFamilyContentType(tab.contentType)
+}
src/renderer/src/components/right-sidebar/SourceControl.tsx (1)

4414-4457: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Local activeGroupId shadows the component-scoped activeGroupId.

Line 4435 declares a new const activeGroupId inside resolveDiffOpenPlacement. This shadows the outer activeGroupId from useAppStore at line 807, but the two have different semantics: the outer one has no fallback, while this local one falls back to groupsByWorktree[activeWorktreeId]?.[0]?.id. The shadowing is legal and the logic itself is correct (verified against findSideSplitDiffTargetGroupId and the create-split fallback), but a reader who only recalls the outer definition can misjudge what value is used when debugging placement issues.

Rename the local variable (for example resolvedActiveGroupId) to avoid confusion with the outer render-scoped activeGroupId.

✏️ Proposed rename
-      const activeGroupId =
+      const resolvedActiveGroupId =
         activeGroupIdByWorktree[activeWorktreeId] ?? groupsByWorktree[activeWorktreeId]?.[0]?.id
-      const existingGroupId = findSideSplitDiffTargetGroupId(tabs, activeGroupId)
+      const existingGroupId = findSideSplitDiffTargetGroupId(tabs, resolvedActiveGroupId)
       if (existingGroupId) {
         return { targetGroupId: existingGroupId, preview }
       }
-      if (!activeGroupId) {
+      if (!resolvedActiveGroupId) {
         return { targetGroupId: undefined, preview }
       }
       return {
-        targetGroupId: createEmptySplitGroup(activeWorktreeId, activeGroupId, 'right') ?? undefined,
+        targetGroupId:
+          createEmptySplitGroup(activeWorktreeId, resolvedActiveGroupId, 'right') ?? undefined,
         preview
       }

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a6bd7846-b068-4a6f-97cd-27e20d06e58e

📥 Commits

Reviewing files that changed from the base of the PR and between 072133f and 509e47f.

📒 Files selected for processing (11)
  • src/renderer/src/components/right-sidebar/SourceControl.tsx
  • src/renderer/src/components/right-sidebar/source-control-split-open.test.ts
  • src/renderer/src/components/right-sidebar/source-control-split-open.ts
  • src/renderer/src/components/settings/GitPane.tsx
  • src/renderer/src/components/settings/OpenDiffsInSideSplitSetting.tsx
  • src/renderer/src/components/settings/git-search.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/store/slices/editor.test.ts
  • src/renderer/src/store/slices/editor.ts
  • src/shared/constants.ts
  • src/shared/types.ts

@greptile-apps

greptile-apps Bot commented Aug 1, 2026 •

Copy link
Copy Markdown

Greptile Summary

This PR fixes a preview-duplication bug (#11839) where openDiff resolved its target group before searching for a replaceable preview, making the lookup group-scoped — so any focus shift to another group (e.g. the agent terminal) caused Source Control clicks to open a second preview in the wrong group instead of recycling the one parked in the split. It also adds an opt-in "Open Diffs in a Side Split" setting that routes Source Control diff opens to a per-worktree recorded column rather than the active group.

  • editor.ts — resolveReplaceablePreviewSlot now accepts pinnedGroupId; without a pinned target it searches all worktree tabs and returns the preview's actual group as retargetGroupId, so the open is redirected to the split where the preview lives. A caller-pinned group restores the original group-scoped behavior.
  • source-control-split-open.ts / SourceControl.tsx — resolveSideSplitDiffColumn resolves a stable diff column via three tiers: live recorded ID, one-time inference from a non-active-group preview or diff tab (recorded immediately to stop re-splitting), then a fresh right split.
  • shared/editor-tab-content-type.ts — Deduplicates the isEditorTabContentType predicate that was previously copied privately in both editor.ts and source-control-split-open.ts.

Confidence Score: 5/5

Safe to merge — the fix is narrowly scoped to preview-replacement routing and the new setting is off by default with no change to existing behavior.

All five diff/file open call sites are updated consistently, cleanup of diffColumnGroupIdByWorktree covers all three removal paths (purge, delete, rename-rekey), and the isSharedEntity guard that prevents mutating a shared OpenFile across groups is preserved. The new feature is gated behind a boolean setting, test coverage spans unit, integration, and search-localization layers, and no platform-specific or IPC-touching code was added.

Files Needing Attention: No files require special attention.

Important Files Changed

Filename Overview
src/renderer/src/store/slices/editor.ts Core fix: resolveReplaceablePreviewSlot now accepts pinnedGroupId and searches all worktree tabs when unpinned, retargeting the open to the preview's actual group via retargetGroupId. All five diff/file open paths updated consistently.
src/renderer/src/components/right-sidebar/source-control-split-open.ts New resolveSideSplitDiffColumn implements three-level resolution: live recorded column wins, one-time inference from non-active-group preview or diff tab, then undefined so caller creates a fresh split.
src/renderer/src/components/right-sidebar/SourceControl.tsx New resolveDiffOpenPlacement callback wraps modifier-click handling and the side-split column resolver. Reads unifiedTabsByWorktree imperatively via useAppStore.getState() at call time (correct Zustand pattern).
src/renderer/src/store/slices/tabs.ts Adds diffColumnGroupIdByWorktree state and setDiffColumnGroupId action. The action is a no-op when value is unchanged, avoiding spurious re-renders.
src/renderer/src/store/slices/worktrees.ts diffColumnGroupIdByWorktree correctly added to all three cleanup paths: WORKTREE_ID_KEYED_MAP_KEYS, buildWorktreePurgeState, and the worktree-delete block.
src/renderer/src/components/settings/OpenDiffsInSideSplitSetting.tsx New setting component with localized keyword matching via translateSearchKeyword, fixing the catalog-hit-but-render-nothing gap.
src/shared/editor-tab-content-type.ts New shared isEditorTabContentType predicate replacing two private copies in editor.ts and source-control-split-open.ts.

Sequence Diagram

sequenceDiagram
    participant SC as SourceControl
    participant rDP as resolveDiffOpenPlacement
    participant rSDC as resolveSideSplitDiffColumn
    participant Store as TabsSlice
    participant Editor as createEditorSlice

    SC->>rDP: handleOpenDiff(event)
    rDP->>rDP: resolveSplitTargetGroupId(event)
    alt modifier-click
        rDP-->>SC: targetGroupId newSplitId preview false
    else normal click setting off
        rDP-->>SC: targetGroupId undefined preview true
    else normal click setting on
        rDP->>Store: read diffColumnGroupIdByWorktree
        rDP->>rSDC: tabs activeGroupId liveGroupIds recordedGroupId
        alt recorded column is live
            rSDC-->>rDP: groupId recordedId shouldRecord false
        else preview in non-active group
            rSDC-->>rDP: groupId previewGroupId shouldRecord true
            rDP->>Store: setDiffColumnGroupId
        else no suitable group
            rSDC-->>rDP: groupId undefined shouldRecord true
            rDP->>Store: createEmptySplitGroup
            rDP->>Store: setDiffColumnGroupId splitGroupId
        end
        rDP-->>SC: targetGroupId groupId preview true
    end
    SC->>Editor: openDiff with targetGroupId and preview
    Editor->>Editor: resolveReplaceablePreviewSlot
    alt preview tab exists in worktree
        Editor->>Editor: retarget to previewTab groupId if unpinned
        Editor->>Editor: replace preview OpenFile in-place
    else no preview tab
        Editor->>Editor: create new preview tab in targetGroupId
    end
Loading

Reviews (5): Last reviewed commit: "fix(source-control): track the diff colu..." | Re-trigger Greptile

dcieslak19973 added a commit to dcieslak19973/orca that referenced this pull request Aug 1, 2026
…redicate

Review follow-ups on stablyai#11866.

The Git pane's search catalog indexes localized keyword aliases, but the
setting's own matcher knew only English. A localized query could match the
catalog and then render nothing. The matcher now derives its keywords through
translateSearchKeyword; SearchableSetting keeps the English list.

isEditorContentTab duplicated editor.ts's isEditorTabContentType, so adding a
content type to the editor family meant updating two private copies or
silently breaking one of side-split targeting or preview replacement. Both now
import one predicate from shared/.

Co-Authored-By: Claude Opus 5 <[email protected]>

@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 (2)
src/renderer/src/components/settings/open-diffs-in-side-split-search.test.ts (2)

22-25: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Shorten the explanatory comment.

Keep only the non-obvious reason for injecting the alias, for example: // Inject the alias because this key is not yet in the locale catalog.

As per coding guidelines, comments in TypeScript files must be concise, limited to non-obvious information, and preferably one line.

Source: Coding guidelines


9-11: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Restore all mutated i18n state after the test.

i18n.addResourceBundle(..., true, true) mutates the imported application instance. The cleanup changes only the active language to 'en'; it does not restore the previous language or remove the injected resource. Later tests can observe the Chinese alias or an overwritten value. Snapshot and restore the previous state, or use an isolated i18n instance.

Verify the cleanup mechanism against the repository's i18next 26.3.1 API.

Also applies to: 27-28


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 668b7147-87cb-4f90-812c-9c02851e4fa4

📥 Commits

Reviewing files that changed from the base of the PR and between 509e47f and c1ab572.

📒 Files selected for processing (5)
  • src/renderer/src/components/right-sidebar/source-control-split-open.ts
  • src/renderer/src/components/settings/OpenDiffsInSideSplitSetting.tsx
  • src/renderer/src/components/settings/open-diffs-in-side-split-search.test.ts
  • src/renderer/src/store/slices/editor.ts
  • src/shared/editor-tab-content-type.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/renderer/src/components/settings/OpenDiffsInSideSplitSetting.tsx
  • src/renderer/src/components/right-sidebar/source-control-split-open.ts
  • src/renderer/src/store/slices/editor.ts

dcieslak19973 added a commit to dcieslak19973/orca that referenced this pull request Aug 1, 2026
Review follow-up on stablyai#11866: the preview branch matches any editor-family
preview because the returned group is pinned by the caller, which makes
preview replacement group-scoped; the fallback is narrower on purpose.

Co-Authored-By: Claude Opus 5 <[email protected]>

@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/source-control-header-overflow-menu.tsx (1)

81-82: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Make both JSX comments one line.

  • src/renderer/src/components/right-sidebar/source-control-header-overflow-menu.tsx#L81-L82: Replace the two-line rationale with one concise line.
  • src/renderer/src/components/right-sidebar/source-control-header-overflow-menu.test.tsx#L41-L42: Replace the two-line rationale with one concise line.

As per coding guidelines, comments must be concise and preferably one line.

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 39e95f92-5ef7-48d9-87a6-83776ff1ea3c

📥 Commits

Reviewing files that changed from the base of the PR and between 4974cc6 and 8209e23.

📒 Files selected for processing (6)
  • src/renderer/src/components/right-sidebar/SourceControl.tsx
  • src/renderer/src/components/right-sidebar/source-control-header-overflow-menu.test.tsx
  • src/renderer/src/components/right-sidebar/source-control-header-overflow-menu.tsx
  • src/renderer/src/components/right-sidebar/source-control-header-toolbar-identity.test.tsx
  • src/renderer/src/components/right-sidebar/source-control-header-toolbar.tsx
  • src/renderer/src/i18n/locales/en.json
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/renderer/src/components/right-sidebar/SourceControl.tsx
  • src/renderer/src/i18n/locales/en.json

@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/source-control-split-open.ts (1)

70-73: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Shorten the added comments.

  • src/renderer/src/components/right-sidebar/source-control-split-open.ts#L70-L73: Keep one short statement of the recorded-group precedence invariant.
  • src/renderer/src/components/right-sidebar/source-control-split-open.ts#L80-L89: Retain only the non-obvious reason that recorded state prevents repeated splits.
  • src/renderer/src/components/right-sidebar/source-control-split-open.ts#L96-L97: Keep one short statement for the diff-tab fallback.
  • src/renderer/src/store/slices/tabs.ts#L67-L67: Reduce the state rationale to one concise sentence.

As per coding guidelines, comments must be concise, limited to non-obvious information, and preferably one line.

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 73943a78-a339-44cd-97a0-37d16be16096

📥 Commits

Reviewing files that changed from the base of the PR and between 8209e23 and 5177115e71d599490f7f87e4a9c5ea659cc70e24.

📒 Files selected for processing (8)
  • src/renderer/src/components/right-sidebar/SourceControl.preview-open.test.tsx
  • src/renderer/src/components/right-sidebar/SourceControl.tsx
  • src/renderer/src/components/right-sidebar/source-control-split-open.test.ts
  • src/renderer/src/components/right-sidebar/source-control-split-open.ts
  • src/renderer/src/store/slices/editor.test.ts
  • src/renderer/src/store/slices/tabs.test.ts
  • src/renderer/src/store/slices/tabs.ts
  • src/renderer/src/store/slices/worktrees.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/renderer/src/components/right-sidebar/SourceControl.tsx
  • src/renderer/src/store/slices/editor.test.ts

@greptile-apps

greptile-apps Bot commented Aug 2, 2026

Copy link
Copy Markdown

Want your agent to iterate on Greptile's feedback? Try greploops.

@dcieslak19973
dcieslak19973 force-pushed the dcieslak19973/bug-diff-preview-replacement-is-group-scoped-par branch 2 times, most recently from 5aef0a7 to 7bdccb9 Compare August 3, 2026 14:54
@dcieslak19973
dcieslak19973 force-pushed the dcieslak19973/bug-diff-preview-replacement-is-group-scoped-par branch 2 times, most recently from 88897d1 to e596d94 Compare August 5, 2026 00:15
@dcieslak19973
dcieslak19973 force-pushed the dcieslak19973/bug-diff-preview-replacement-is-group-scoped-par branch from e596d94 to 29b8387 Compare August 5, 2026 04:15
@dcieslak19973
dcieslak19973 force-pushed the dcieslak19973/bug-diff-preview-replacement-is-group-scoped-par branch from 29b8387 to 7239f20 Compare August 5, 2026 19:05
@dcieslak19973

Copy link
Copy Markdown
Contributor Author

Upstream PR Checks is still awaiting workflow approval, so I ran the identical suite on my fork against this PR's exact head (6ac005d1f):

https://github.com/dcieslak19973/orca/actions/runs/31215862833 — all 43 jobs green: typecheck, static analysis, packaging (linux + windows), Git compatibility, shell contracts, cross-version wire compatibility, and all 16 test shards.

Posting so the suite result is visible without needing the approval click first.

@dcieslak19973
dcieslak19973 force-pushed the dcieslak19973/bug-diff-preview-replacement-is-group-scoped-par branch from 14b6ec1 to a56b331 Compare August 12, 2026 01:37
@dcieslak19973
dcieslak19973 force-pushed the dcieslak19973/bug-diff-preview-replacement-is-group-scoped-par branch from a56b331 to 4239385 Compare August 13, 2026 02:19
@dcieslak19973
dcieslak19973 force-pushed the dcieslak19973/bug-diff-preview-replacement-is-group-scoped-par branch from 4239385 to 93159e8 Compare August 15, 2026 00:25
@dcieslak19973
dcieslak19973 force-pushed the dcieslak19973/bug-diff-preview-replacement-is-group-scoped-par branch from 93159e8 to 2a42a02 Compare August 15, 2026 16:00
@dcieslak19973
dcieslak19973 force-pushed the dcieslak19973/bug-diff-preview-replacement-is-group-scoped-par branch from 2a42a02 to ad08dda Compare August 19, 2026 01:53
@nwparker nwparker removed the P1 label Aug 19, 2026
@nwparker
nwparker force-pushed the dcieslak19973/bug-diff-preview-replacement-is-group-scoped-par branch 2 times, most recently from 90c9bb1 to b80eb91 Compare August 23, 2026 23:30
@nwparker

Copy link
Copy Markdown
Contributor

Readiness check — head b80eb91

Force-pushed a refreshed head (was 90c9bb1). Two changes vs. that head, both non-behavioral: comment tightening across the touched files, and SettingsSidebar's search field extracted into a SettingsSearchField child that subscribes to settingsSearchInputQuery directly, so keystrokes no longer re-render the whole Settings tree. Rebased onto current main (b89b58b), 0 conflicts.

Gates (local, macOS arm64)

Gate Result
pnpm typecheck ✅ pass
pnpm lint ✅ pass (incl. code-quality native + type-aware, max-lines ratchet, localization catalog/extraction/coverage)
pnpm test (renderer store slices, source-control, settings, shared) ✅ 4,177 / 4,178 across 467 files
pnpm build:desktop ✅ pass — closes the one unchecked box in the PR description

The single test miss was github-pr-refresh-states-leak.test.ts › caps prRefreshStates when driven past the cap by the real writer, a wall-clock-bounded perf test untouched by this PR; it passes in isolation (13/13) and only failed while an Electron dev build was competing for CPU.

Real-Electron verification

Driven through the actual UI in a dev build of this branch (CDP-attached), not store mutation. Screenshots are uncropped full-window.

1. Parked preview reuse across tab groups — the #11839 fix. Setting off. Opened split-open.ts from Source Control, moved it to a right split via Tab → Move Tab to Split → Right, then clicked back into the terminal group so the preview sat parked in a non-active group:

before

Then clicked tabs.ts in Source Control. The parked preview in the right split was recycled in place — tab count stayed at 2, and no second preview appeared over the terminal in the left group. Pre-fix this is exactly where the duplicate landed:

after

2. Opt-in side split. Toggled from the Source Control overflow menu, then clicked constants.ts from a single-group layout: a right split was created, the diff preview opened there, and diffColumnGroupIdByWorktree recorded that column. Focus was then moved back to the terminal group and git-search.ts clicked — the preview recycled in the recorded column rather than following focus, which is the behavior the per-worktree recording exists to guarantee:

side split

3. Both entry points. Overflow menu checkbox item, and Settings → Git & Source Control reached via the search term side split — the toggle reflects the state set from the panel, confirming both surfaces write the same setting:

overflow menu

settings

Notes for the reviewer

  • The PR description still describes the pre-rebase layout (editor.ts, src/shared/editor-tab-content-type.ts, "three commits"). The head is now one squashed commit re-homed onto the store/slices/editor/** + right-sidebar/source-control/** split that landed on main after this branch was cut; it reuses main's editor/tabs/editor-tab-content-type.ts and source-control/listing/split-open.ts instead of this branch's duplicates, keeping only resolveSideSplitDiffColumn. The commit message records the mapping.
  • Upstream PR Checks and PR test LoC were sitting at action_required; both are approved and running against b80eb91 now.
  • Not exercised: Windows/Linux, SSH-hosted worktrees, and the conflict-review path (open-conflict-review.ts passes no pinnedGroupId, so it keeps the pre-existing unpinned behavior — covered by unit tests, not by this manual pass).

@nwparker

Copy link
Copy Markdown
Contributor

Readiness Checklist — Verdict: READY TO MERGE

Independent verification run against head b80eb91 (content-verified, see Note on rebase).

Gates

Gate Result
Rebase onto current origin/main Clean, 0 conflicts
pnpm typecheck Pass
pnpm lint (incl. localization catalog) Pass — 12,328 localization key refs verified
PR-added tests (7 files) 59/59 pass
Broad regression (store slices, right-sidebar, settings) 5,655/5,656 pass
Real Electron app validation Pass — see below
GitHub mergeability MERGEABLE / CLEAN, all checks green

The single broad-suite failure was ai-vault-session-worktree-map.test.tsx, a wall-clock perf assertion (306ms < 150ms) that failed only under parallel CPU load and passes standalone. That file is untouched by this PR — not a regression.

Electron proof (real app, CDP-attached to this branch)

Attached to the correct instance (pr-11866-ready @ worker/pr11866-ctx-bf7547da) and reproduced the exact #11839 layout: agent terminal in group A, diff preview parked in a right split (group B), driven through the real Source Control panel.

  1. The fix. With group A (terminal) focused, clicking bravo.ts in Source Control recycled the parked preview in group B (alpha.ts → bravo.ts). Tab count stayed at 2; no new diff tab stacked over the terminal. Cycled charlie.ts and delta.ts with a terminal re-focus before each click — tab count held at 2 every time. This is the pre-fix failure mode, gone.
  2. Regression guard. A pinned split-open into a new group C created a permanent charlie.ts diff tab there and did not evict group B's parked preview (3 groups / 3 tabs). Group scoping for caller-pinned opens is preserved.
  3. New opt-in setting. Defaults to false. Reachable from the Source Control overflow menu as "Open diffs in a side split". With it enabled, a row click from a single-group layout opened the diff straight into a newly created right split, recorded as the worktree's diff column.

Findings

  • P0: none.
  • P1: none.
  • P2 (non-blocking, no action required):
    • resolveReplaceablePreviewSlot uses .find over unifiedTabsByWorktree, so with two previews live in different groups the unpinned target is tab-insertion-order dependent rather than MRU. Pre-existing .find semantics, deliberately bounded by the active-group tests; not a regression.
    • 8 new settings-search keyword keys (git.search.diffSplit, sideSplit, …) have no en.json entries and fall through to their English literals. This matches existing entries (e.g. diffBase) and the localization catalog gate passes.

Residual risk

  • The modifier-click (Cmd/Alt) split path could not be driven through synthetic CDP clicks — the modifier is swallowed before reaching the row handler. Verified instead at the store layer via the equivalent pinned-targetGroupId open, plus unit coverage in SourceControl.preview-open.test.tsx and source-control-split-open.test.ts.
  • diffColumnGroupIdByWorktree is not persisted; a stale group id is defended by the caller's liveGroupIds liveness check, and cleanup is wired into worktree rename, removal, and purge.
  • Windows/Linux behavior not exercised locally; covered by CI (package (windows) green).

@nwparker

Copy link
Copy Markdown
Contributor

Visual proof — real Electron app, this branch

Captured via CDP against a dev build launched from this worktree (pr-11866-ready @ worker/pr11866-ctx-bf7547da), driven through the real Source Control panel. Layout is the one from #11839: agent terminal in the left group, diff preview parked in a right split.

1. Before the click — preview parked in the split, terminal focused

alpha.ts diff preview sits in the right split. The terminal group is what the user last touched.

parked preview

2. After clicking bravo.ts in Source Control — the fix

With the terminal group active, clicking bravo.ts recycles the parked preview in place: the split now shows bravo.ts (diff), and the terminal is untouched. Still exactly one editor tab — pre-fix this stacked a brand-new diff tab over the terminal and orphaned the preview. Cycling charlie.ts/delta.ts with a terminal re-focus before each click held the tab count at 2 every time.

source control recycled preview

3. Regression guard — a pinned split-open still cannot evict another group's preview

A caller-pinned open into a new group creates a permanent charlie.ts diff tab there while the parked alpha.ts preview survives in its own split. Three groups, three tabs.

pinned split guard

4. New opt-in setting, reachable from the panel overflow menu

overflow toggle

5. With "Open diffs in a side split" enabled

From a single-group layout, a Source Control row click opens the diff straight into a newly created right split — no manual move-tab ritual. That split is recorded as the worktree's diff column, so it stops following focus.

side split enabled

@dcieslak19973
dcieslak19973 force-pushed the dcieslak19973/bug-diff-preview-replacement-is-group-scoped-par branch from b80eb91 to e2978c8 Compare August 28, 2026 03:54
@dcieslak19973

Copy link
Copy Markdown
Contributor Author

Refreshed head e2978c8: rebased onto current main (was CONFLICTING/DIRTY, now MERGEABLE). Two conflicts, both additive:

  • src/shared/constants.ts / src/shared/default-global-settings.ts — main moved the settings defaults out of the getDefaultSettings call site into buildDefaultSettings, so the new sourceControlOpenDiffsInSideSplit: false default was placed there rather than re-inlining ~65 fields at the old call site.
  • src/renderer/src/i18n/locales/en.json — kept main's Create-PR strings and added the openDiffsInSideSplit key (used by header-overflow-menu.tsx); dropped an orphan createPrIntentEmptyGeneratedBody key that had no code references.

Verified locally: pnpm tc:web + pnpm tc:node pass; the PR's targeted suites (editor-parked-preview-reuse, open-diffs-in-side-split-search, header-overflow-menu) 10/10. Code is content-identical to the head you validated apart from those additive resolutions. PR description updated to match the squashed/re-homed layout.

@nwparker — since you'd already run the READY-TO-MERGE checklist at b80eb91, could you drop a formal approve on the refreshed head once CI settles?

@dcieslak19973
dcieslak19973 force-pushed the dcieslak19973/bug-diff-preview-replacement-is-group-scoped-par branch from e2978c8 to 6587ef7 Compare September 3, 2026 02:12
…in side-split diffs

Preview replacement was group-scoped, so a diff opened from Source Control while a
preview sat parked in another split was shadowed by a second preview in the resolved
group instead of recycling the parked one (stablyai#11839). Preview reuse is now
worktree-scoped: an unpinned open re-activates the entity's tab wherever it lives, and
a caller-pinned group keeps the old scoping so a split-open in group B never evicts
group A's preview.

`getReplaceablePreviewFileId` becomes `resolveReplaceablePreviewSlot`, returning the
`openFiles` index plus the group to retarget to, and `openWorkspaceEditorItem` takes an
options object so callers can distinguish a resolved target group from a pinned one.

Adds the opt-in "Open Diffs in a Side Split" setting, reachable from both Settings and
the Source Control overflow menu. The worktree records the diff column it settles on,
so the column stops moving with focus.

Squashed from eight commits and re-homed onto the post-split module layout
(`store/slices/editor/**`, `right-sidebar/source-control/**`), which landed after this
branch was cut:

  fix(editor): reuse a parked diff preview across tab groups (stablyai#11839)
  feat(source-control): add opt-in "Open Diffs in a Side Split" setting (stablyai#11839)
  fix(settings): match localized search aliases; share the editor-tab predicate
  docs(source-control): record why the two side-split heuristics differ
  feat(source-control): surface the side-split toggle in the panel overflow menu
  fix(source-control): track the diff column per worktree instead of inferring it
  refactor(source-control): unshadow the diff-placement group id and restore i18n test state
  fix(source-control): import Tab and GlobalSettings from their real modules

The re-home drops this branch's `src/shared/editor-tab-content-type.ts` and its
duplicate `source-control-split-open.ts` in favour of the equivalents main grew in the
meantime (`editor/tabs/editor-tab-content-type.ts`, `source-control/listing/split-open.ts`),
keeping only `resolveSideSplitDiffColumn`, which main lacks.
@nwparker

nwparker commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Thanks @dcieslak19973 — your parked-preview fix and optional side-split workflow form a useful, clean split. I extracted them into two focused PRs so the bug fix can be reviewed and merged separately from the new preference:

  1. fix(editor): reuse parked previews across tab groups #19181 — Reuse parked previews across tab groups. Contains the editor fix and its regression tests, targeting main.
  2. feat(source-control): optionally open diffs in a side split #19182 — Optionally open Source Control diffs in a side split. Contains the default-off setting, placement and lifecycle logic, UI, localization, and tests. Stacked on fix(editor): reuse parked previews across tab groups #19181; merge the fix first, then retarget the feature to main.

Credit for the original implementation belongs to Dan Cieslak (@dcieslak19973). Both extracted implementation commits retain your Git authorship, and both PR descriptions link back here and credit you explicitly.

The split is rebased onto current main. The only integration adjustment was adapting worktree-removal cleanup to the current implementation; I also completed missing setting/search translations across all six locale catalogs in a separate follow-up commit. The unrelated whitespace-only constants hunk was omitted.

Validation: the isolated fix passed 56 focused tests and web typecheck. The feature stack passed 61 focused tests, 46 additional cleanup/remote-editor tests, web/Node typechecks, targeted lint, and localization checks. Existing Electron proof from this PR is linked with its original provenance; it is not represented as a fresh UI run on the split heads. CI will cover the broader gates.

These two PRs are the proposed review/merge path for this work. Leaving this original PR open to preserve the discussion and review history.

@dcieslak19973

Copy link
Copy Markdown
Contributor Author

Superseded by #19181 (parked-preview reuse fix) and #19182 (opt-in side-split diffs), which @nwparker extracted from this PR — credited, rebased onto current main, and reviewed. Closing this in favor of that split to keep the queue clean; happy to reopen if anything there stalls. Thanks @nwparker for driving it.

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.

[Bug]: Diff preview replacement is group-scoped — parking a preview in a split breaks, and there's no way to open diffs in a split by default

4 participants