Repository navigation
fix(session): deduplicate editor records during restore - #17370
Conversation
Deduplicate editor records during session restore (stablyai#17185)
Greptile SummaryThe PR repairs corrupted editor-session hydration by deduplicating editor records and consistently rebuilding tab-group references.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| src/renderer/src/store/slices/editor/actions/hydrate-editor-session.ts | Deduplicates persisted open-file records by editor owner and file path before legacy ID migration. |
| src/renderer/src/store/slices/tab-group-state.ts | Deduplicates editor entities within each group and records group-scoped aliases for removed rows. |
| src/renderer/src/store/slices/tab-group-reference-repair.ts | Resolves each retained tab to one surviving group and restores omitted declared-owner references. |
| src/renderer/src/store/slices/tabs-hydration.ts | Integrates deduplication, alias rewriting, ownership filtering, and group validation into unified-session hydration. |
| src/renderer/src/store/slices/editor-session-duplicate-restore.test.ts | Covers corrupted editor records, restart behavior, split ownership, duplicate IDs, and SSH folder restoration. |
| src/renderer/src/store/slices/tabs-hydration.test.ts | Updates duplicate-ID hydration coverage to distinguish the surviving editor entity. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart LR
P[Persisted session] --> O[Deduplicate same-owner open files]
P --> T[Sort and deduplicate tab rows]
T --> A[Build group-scoped ID aliases]
A --> R[Resolve surviving tab owners]
R --> G[Repair tab order, active tab, and MRU]
G --> H[Re-stamp or adopt tabs when needed]
H --> S[Hydrated editor and split-group state]
Reviews (4): Last reviewed commit: "fix(tabs): honor surviving tab group own..." | Re-trigger Greptile
|
Warning Review limit reachedNext included review available in 13 minutes. View limit detailsLimit details: You’ve used all 10 included reviews currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
Included review availability: Your plan provides up to 10 included reviews per hour; 1 remains after this review. 📝 WalkthroughWalkthroughThe change hardens editor session restoration against corrupted duplicate records. Editor file hydration skips repeated files with the same path and editor owner. Tab hydration removes duplicate editor tabs within groups and maps discarded tab IDs to surviving IDs. Group order, active-tab, and recent-tab references use these aliases before validation. Tests cover local and SSH workspaces, restart restoration, split groups, and duplicate tab ordering. Merge Risk: ⚪ Minimal · up to The change narrowly repairs duplicate editor-session records and their tab references during restore, with focused regression coverage and no identified merge-blocking risk remaining after normal checks and review. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Linked Issues checkExplanation The implementation satisfies issue Full details: Out of Scope Changes checkExplanation The changes remain within session hydration and reference repair. The added tests directly cover the reported corruption scenarios. No unrelated product, dependency, protocol, or platform-specific changes are included. 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. Comment |
|
Addressed Greptile's cross-group alias finding in Repro before the fix (
The fix stores aliases per worktree and owning tab group. Group A can still repair its duplicate references, while Group B leaves the foreign stale ID untouched so normal valid-ID filtering drops it. The regression now restores Group A as Validation:
Missing-on-disk file pruning remains intentionally out of scope. This PR repairs persisted structural duplication during synchronous renderer hydration. File existence is owned by the applicable native, WSL, SSH, or runtime host; when that host cannot be contacted the file is unverifiable, so treating a failed probe as absence could discard a restorable remote session. |
There was a problem hiding this comment.
ℹ️ No critical issues — one test-coverage suggestion inline.
Reviewed changes
- OpenFile record dedupe —
hydrateEditorSessionnow skips a persisted file once a same-path, same-owner record has already been hydrated, so a duplicate can no longer mint a secondOpenFileunder a re-ided owned id. - Editor tab dedupe within groups —
dedupeEditorTabsWithinGroupscollapses duplicate editor tabs sharing(groupId, entityId), keeping the first row and recording id aliases for the removed ones; split groups are preserved. - Group reference repair — hydration rewrites
tabOrder,activeTabId, andrecentTabIdsthrough the alias map before validating groups, so references to a dropped duplicate resolve to the survivor. - Regression coverage — close/restart tests for corrupted sessions, plus folder-workspace and split-group cases.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
| it('cleans the same corruption for an SSH-hosted folder workspace', () => { | ||
| const restarted = closeAndRestart( | ||
| prepareSshFolderStore, | ||
| corruptSession(SSH_FOLDER_KEY, SSH_FILE_PATH), |
There was a problem hiding this comment.
This fixture hydrates SSH-folder files with no runtimeEnvironmentId, so it exercises folder-workspace-key scoping but not the runtime-owner branch of isSameEditorOwner that this dedupe depends on — and no test pins that same-path, different-owner records are preserved. Consider a case where two records share filePath/worktreeId but differ by runtimeEnvironmentId, asserting both survive hydration.
There was a problem hiding this comment.
The runtime-owner branch is already covered by the existing store-session-editor-hydration.test.ts case “keeps same-path local and runtime legacy references on their original owners” (lines 268-380). It hydrates the same path for a local owner and runtime-1, asserts both OpenFile IDs and owners plus both tab references, and passes in the focused hydration suite (77/77).
There was a problem hiding this comment.
ℹ️ No new issues in this delta — one prior suggestion remains open.
Reviewed changes (delta since the prior pullfrog review)
- Group-scoped alias maps —
dedupeEditorTabsWithinGroupsnow keys aliases bygroupId, andhydrateUnifiedFormatresolvescanonicalTabIdper group, so a stale tab reference in one group is dropped instead of being rewritten to a survivor tab that lives in another group. - Regression test — a new case pins that a stale alias reference in
group-bis filtered out rather than redirected intogroup-a's surviving tab.
The test-coverage suggestion from the prior review remains open: the SSH folder fixture still sets no runtimeEnvironmentId, so no test exercises the isSameEditorOwner runtime-owner branch (same path, different owner must both survive hydration).
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
ℹ️ No new issues in this delta — the prior test-coverage suggestion remains open.
Reviewed changes — delta since the prior pullfrog review (00f89d7).
- Tab ownership resolution —
resolveTabGroupOwnerscomputes each surviving tab's owning group from its persistedgroupId, so a tab id that was deduped across groups stays in exactly one group. - Owner-filtered hydration —
hydrateUnifiedFormatnow filterstabOrderandactiveTabIdby the owning group, so a stale cross-group reference is dropped rather than rehydrating the survivor into a second group. - Regression coverage — a new test pins that a globally duplicated id hydrates into its owning group only, and the legacy-format collision test now gives the unique tab a distinct
entityId.
The suggestion from the prior review is still open: the SSH folder fixture in editor-session-duplicate-restore.test.ts sets no runtimeEnvironmentId, so no test exercises the isSameEditorOwner runtime-owner branch (same path, different owner must both survive hydration). This delta does not touch that path.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
ℹ️ No new issues in this delta — the prior test-coverage suggestion remains open.
Reviewed changes — delta since the prior pullfrog review (1bbeea7).
- Declared-owner seeding —
resolveTabGroupOwnersnow seeds ownership from each surviving tab's declaredgroupId(when that group survives) before letting the first referencing group claim tabs whose declared group is gone. - Owned-tab reinsertion —
appendOwnedTabIdsToGroupsre-adds tabs omitted from their declared group's persistedtabOrder, so a surviving declared owner is not dropped just because a stale cross-group reference claimed it first. - Regression coverage — a new test pins that a tab whose declared group survives stays in that group even when another group's
tabOrderandactiveTabIdreferenced it.
The prior suggestion is still open: no test exercises the isSameEditorOwner runtime-owner branch (same path, different runtimeEnvironmentId must both survive hydration).
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
|
Readiness review on current head a0c32be:
Validation: pnpm tc; changed-code quality (0 findings across 6 files); git diff --check; 11 focused hydration files, 77/77 tests. Competing-PR check found no open PR implementing the same #17185 fix. #16480 addresses the separate #16205 close-handler bug and should remain independent; #9200 addresses orphaned repo/session ownership in main persistence and is not a duplicate. No code was copied from those contributors. |
Deduplicate persisted editor records and repair tab-group references during session hydration. Closes stablyai#17185.
orca-data.json grew without bound (79 persisted rows for 5 real files) because an open file's identity is the raw path string x runtime env id: hydration recasts every persisted row to an owned id (editor:<wt>:<env>:<encoded path>), so the session mirror's lookup by raw path always misses and re-appends a (path, worktree, runtime) row on each launch, while rows from older environments are never re-keyed or culled. Stop the bleeding on the persist side: buildEditorSessionData now keeps only the first row per (filePath, worktreeId, runtimeOwnerKey) tuple. This is lossless for restore - hydrateEditorSession already treats repeated records for the same owner as corruption and keeps the first (stablyai#17370) - so restore output is unchanged, new duplicate rows stop being written, and existing ones are cleaned up on the next save. Rows owned by a different runtime environment stay distinct; converging identity across environment changes plus path-separator normalization is a separate follow-up that needs a maintainer decision. Refs stablyai#23967 Generated-by: GLM-5.3-Flash (ZCode)
orca-data.json grew without bound (79 persisted rows for 5 real files) because an open file's identity is the raw path string x runtime env id: hydration recasts every persisted row to an owned id (editor:<wt>:<env>:<encoded path>), so the session mirror's lookup by raw path always misses and re-appends a (path, worktree, runtime) row on each launch, while rows from older environments are never re-keyed or culled. Stop the bleeding on the persist side: buildEditorSessionData now keeps only the first row per (filePath, worktreeId, runtimeOwnerKey) tuple. This is lossless for restore - hydrateEditorSession already treats repeated records for the same owner as corruption and keeps the first (stablyai#17370) - so restore output is unchanged, new duplicate rows stop being written, and existing ones are cleaned up on the next save. Rows owned by a different runtime environment stay distinct; converging identity across environment changes plus path-separator normalization is a separate follow-up that needs a maintainer decision. Refs stablyai#23967 Generated-by: GLM-5.3-Flash (ZCode)

ELI5
Session restore could keep several records for the same editor file. Closing the visible tab
removed only one record, so the stale ones recreated the tab on the next restart. Restore now
keeps one record for each editor owner/file and repairs every tab reference to that survivor.
What Changed
OpenFilerecords while hydrating an editor session.(stable) row.
tabOrder, active-tab, and MRU references through the survivor alias before validatingthe hydrated groups.
collapsed.
SSH-hosted folder workspace.
Why
I reproduced #17185 from the reported persisted state: duplicate
openFilesByWorktreeentries,duplicate
unifiedTabsrows, and group/active references to stale editor IDs caused a closed PNGtab to resurrect after restart. The old hydration path only removed duplicate tab IDs, not the
same-file/same-owner records that minted the ghost tab.
Linked Issue
Fixes #17185
Visual Proof
N/A — this is persisted-session hydration and reference repair; there is no new visual surface.
Testing
The focused restore/hydration run passes (157 tests across the issue-focused files), including the
new close/restart regression and SSH/folder-workspace case.
pnpm tcand the changed-code qualitygate pass. The tests assert that a closed editor stays closed after a second hydration and that
split groups sharing an entity remain intact.
Review
The repair is bounded to hydration: it does not rewrite persisted data in place, and it aliases
only IDs that were actually removed. Existing terminal/browser tabs and separate split groups are
left unchanged. Folder workspaces and SSH-scoped session keys use the same ownership check.
Agent skill upstream boundary
Notes
No RPC, wire field, dependency, or platform-specific process behavior changes. The logic runs on
local, folder, SSH, and mixed-version session payloads using the existing optional fields.
Checklist
N/Awith reasonpnpm typecheck/focused tests pass; CI will run the full build and lint gates