Skip to content

fix(session): deduplicate editor records during restore - #17370

Merged
nwparker merged 4 commits into
stablyai:mainfrom
nwparker:fix-17185-editor-session-dedupe-v2
Aug 30, 2026
Merged

nwparker merged 4 commits into
stablyai:mainfrom
nwparker:fix-17185-editor-session-dedupe-v2

Conversation

@nwparker

Copy link
Copy Markdown
Contributor

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

  • Dedupe same-owner OpenFile records while hydrating an editor session.
  • Dedupe repeated editor tabs for the same entity within a tab group while preserving the first
    (stable) row.
  • Rewrite tabOrder, active-tab, and MRU references through the survivor alias before validating
    the hydrated groups.
  • Keep the same editor entity in separate split groups; only duplicate rows in one group are
    collapsed.
  • Add regression coverage for corrupted persisted sessions, close/restart behavior, and an
    SSH-hosted folder workspace.

Why

I reproduced #17185 from the reported persisted state: duplicate openFilesByWorktree entries,
duplicate unifiedTabs rows, and group/active references to stale editor IDs caused a closed PNG
tab 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

  • I manually reproduced the persisted duplicate-record state before changing the code
  • Automated tests added/updated

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 tc and the changed-code quality
gate 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

  • Not applicable.

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

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • 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 compatibility impact considered (or N/A)
  • pnpm typecheck/focused tests pass; CI will run the full build and lint gates

Deduplicate editor records during session restore (stablyai#17185)
@greptile-apps

greptile-apps Bot commented Aug 30, 2026 •

Copy link
Copy Markdown

Greptile Summary

The PR repairs corrupted editor-session hydration by deduplicating editor records and consistently rebuilding tab-group references.

  • Deduplicates same-owner open files and same-entity editor tabs within each group.
  • Uses group-scoped aliases when repairing tab order, active-tab, and recent-tab references.
  • Resolves retained tab ownership before validating groups and restores omitted tabs to surviving declared owners.
  • Adds coverage for close/restart restoration, split groups, duplicate IDs, and SSH folder workspaces.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

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]
Loading

Reviews (4): Last reviewed commit: "fix(tabs): honor surviving tab group own..." | Re-trigger Greptile

@coderabbitai

coderabbitai Bot commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

Next included review available in 13 minutes.

View limit details

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

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 017602a6-b2ad-41f5-a155-0ddeab42e097

📥 Commits

Reviewing files that changed from the base of the PR and between 1bbeea7 and a0c32be.

📒 Files selected for processing (3)
  • src/renderer/src/store/slices/editor-session-duplicate-restore.test.ts
  • src/renderer/src/store/slices/tab-group-reference-repair.ts
  • src/renderer/src/store/slices/tabs-hydration.ts

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d4fdf67c-545d-4d4c-baf2-ff257e9af248

📥 Commits

Reviewing files that changed from the base of the PR and between 2ec5dd4 and 1bbeea7.

📒 Files selected for processing (4)
  • src/renderer/src/store/slices/editor-session-duplicate-restore.test.ts
  • src/renderer/src/store/slices/tab-group-reference-repair.ts
  • src/renderer/src/store/slices/tab-group-state.ts
  • src/renderer/src/store/slices/tabs-hydration.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

The 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 1bbee

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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the primary change: deduplicating editor records during session restore.
Description check ✅ Passed The description is complete and follows the repository template. It explains the problem, changes, rationale, linked issue, testing, visual-proof status, compatibility considerations, and scope.
Linked Issues check ✅ Passed The implementation satisfies issue #17185 by deduplicating same-owner editor records, collapsing duplicate editor tabs within each group, repairing stale references, preserving separate split groups, …
Out of Scope Changes check ✅ Passed 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 cha…
Full details: Linked Issues check

Explanation

The implementation satisfies issue #17185 by deduplicating same-owner editor records, collapsing duplicate editor tabs within each group, repairing stale references, preserving separate split groups, and adding regression coverage for restart and SSH workspace cases.

Full details: Out of Scope Changes check

Explanation

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nwparker

Copy link
Copy Markdown
Contributor Author

Addressed Greptile's cross-group alias finding in 00f89d72c7212ca5a8075817d4d49135cb4efd5f.

Repro before the fix (2ec5dd41):

  • Group A contained survivor editor-a plus duplicate editor-b, so hydration created editor-b -> editor-a.
  • A malformed Group B order still referenced editor-b before its own editor-c.
  • The worktree-wide alias map rewrote Group B to [editor-a, editor-c], inserting Group A's survivor into the wrong split. The targeted regression failed with that exact received order.

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 [editor-a] and Group B as [editor-c].

Validation:

  • Focused restore/hydration regression: 2 files, 15 tests passed.
  • Broader editor/tab hydration regression: 11 files, 157 tests passed.
  • pnpm run tc:web passed.
  • Changed-code quality passed with zero code-quality, type-aware, or React Doctor findings.
  • Pre-commit Oxlint/React Doctor/format hooks and git diff --check passed.

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.

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

ℹ️ No critical issues — one test-coverage suggestion inline.

Reviewed changes

  • OpenFile record dedupe — hydrateEditorSession now skips a persisted file once a same-path, same-owner record has already been hydrated, so a duplicate can no longer mint a second OpenFile under a re-ided owned id.
  • Editor tab dedupe within groups — dedupeEditorTabsWithinGroups collapses 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, and recentTabIds through 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.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using 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),

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.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

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

ℹ️ No new issues in this delta — one prior suggestion remains open.

Reviewed changes (delta since the prior pullfrog review)

  • Group-scoped alias maps — dedupeEditorTabsWithinGroups now keys aliases by groupId, and hydrateUnifiedFormat resolves canonicalTabId per 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-b is filtered out rather than redirected into group-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).

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

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

ℹ️ 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 — resolveTabGroupOwners computes each surviving tab's owning group from its persisted groupId, so a tab id that was deduped across groups stays in exactly one group.
  • Owner-filtered hydration — hydrateUnifiedFormat now filters tabOrder and activeTabId by 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.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

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

ℹ️ 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 — resolveTabGroupOwners now seeds ownership from each surviving tab's declared groupId (when that group survives) before letting the first referencing group claim tabs whose declared group is gone.
  • Owned-tab reinsertion — appendOwnedTabIdsToGroups re-adds tabs omitted from their declared group's persisted tabOrder, 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 tabOrder and activeTabId referenced it.

The prior suggestion is still open: no test exercises the isSameEditorOwner runtime-owner branch (same path, different runtimeEnvironmentId must both survive hydration).

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@nwparker

Copy link
Copy Markdown
Contributor Author

Readiness review on current head a0c32be:

  • Verdict: PASS. No proven P0/P1/P2 findings remain; findings-severity counsel was skipped per checklist because the candidate list is empty.
  • SSH/remote: no transport or RPC changes; SSH folder hydration is covered, and owner scoping remains runtime-aware.
  • Crash/retry/growth: hydration-only bounded Set/Map work; no timers, listeners, retries, subprocesses, or unbounded retained state added.
  • Security/supply chain: no dependencies, commands, network sinks, secrets, or persisted-schema changes.
  • Performance: one-time restore path; focused restore/hydration suite is 77/77 and no hot-path polling/fanout was added.
  • Backcompat/mobile: no mobile-facing surface, wire field, route, pairing state, or persisted key changed.
  • Cross-platform: path/owner comparisons are platform-neutral; local, folder, and SSH-scoped fixtures pass.
  • Organization: changes stay in the existing editor/tab hydration modules with no vague modules or lint disables.

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.

@nwparker
nwparker merged commit 16e6b10 into stablyai:main Aug 30, 2026
50 of 52 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
Deduplicate persisted editor records and repair tab-group references during session hydration. Closes stablyai#17185.
ggbdpq added a commit to ggbdpq/orca that referenced this pull request Oct 25, 2026
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)
ggbdpq added a commit to ggbdpq/orca that referenced this pull request Nov 5, 2026
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)
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]: Session restore duplicates editor tab records in orca-data.json — closed editor tab resurrects on every restart

1 participant