Skip to content

fix(editor): keep a pinned duplicate open on close and ignore setActiveFile for a missing file - #28120

Merged
nwparker merged 2 commits into
stablyai:mainfrom
BearMett:ym-pr/d1-editor-close-selection-guards
Oct 13, 2026
Merged

nwparker merged 2 commits into
stablyai:mainfrom
BearMett:ym-pr/d1-editor-close-selection-guards

Conversation

@BearMett

Copy link
Copy Markdown
Contributor

ELI5

Two small guards for editor tabs:

  • Closing a document also closes its clean duplicate copies. A duplicate that you pinned now stays open.
  • If something asks Orca to focus an editor file that is no longer open, Orca now ignores the request instead of making a missing file the active one.

What Changed

1. A pinned duplicate survives the close.

  • Before: closeFile (since main's c9f4cd7e27) also sweeps clean duplicate records for the same document and the same owner. It skipped dirty records and records with a draft, but not pinned ones. A pinned tab could vanish because you closed another tab for the same file.
  • After: the same-document sweep inside closeFile also skips a record whose tab in that workspace is pinned. That record and its tab stay open. Other clean, unpinned duplicates are still swept as before. This is the sibling sweep inside closeFile, not a bulk close command.

2. setActiveFile ignores an id with no open file.

  • Before: a stale tab or pane id could pass a file id that has no OpenFile record. setActiveFile still made it the global active file (activeFileId) when the call was scoped to the active workspace. The per-workspace entry (activeFileIdByWorktree) was already left alone, because no file supplied a workspace id.
  • After: setActiveFile returns without changing anything when no open file has that id. It does not log a warning.

Production change: 6 lines, in close-file-action.ts and open-file-mutations.ts.

Why

These are the two parts of #21124 that main does not already cover. The rest of #21124 is superseded by @nwparker's commits on main:

  • c9f4cd7e27 "close stale duplicate documents safely". It adapts fix(editor): close duplicate document siblings #23347's sibling sweep, with exact owner and captured-provenance checks.
  • 8bd567a015 "protect document backing files and complete close cleanup".
  • 31d85749b4 "retain placeholders for drafts during bulk close".
  • 14bae2e172 "route mirrored editor closes through their captured runtime owner".

Deliberately not carried over from #21124:

  • Merging same-document records when the session is written. Saving each record's id instead would keep same-path records distinguishable on disk; that is a separate change I have prepared locally; its publication is still under consideration.
  • Pruning open-file records that no tab references. A missing tab reference is not evidence that the user closed the file.

Linked Issue

Fixes #27985

Related to #21121. Replaces the remaining part of #21124.

Visual Proof

Hidden-Electron capture (ORCA_E2E_HEADLESS=1, ORCA_BACKGROUND_LAUNCH=1, CDP screenshot, temp profile, automated). src/index.ts is open; a second clean record for the same file and owner is injected through the store and shown in a pinned tab (the duplicate state from #21121 cannot be produced on purpose through the UI, so it is seeded). Then the first record is closed with closeFile.

Before, main (41fc9542b3): closing the first record removes both tabs. The pinned one is gone and the editor area is empty.

main after close: both tabs gone

After, this branch (e27353a12c): the pinned tab stays, still pinned, still showing the file.

this branch after close: pinned tab remains

main: tabs []                                  openFiles []
this: tabs [duplicate-tab (pinned): index.ts]  openFiles ['duplicate-record']

The setActiveFile guard has no visual surface; it is covered by editor-set-active-file-guard.test.ts.

Testing

Unit and integration tests, macOS, on e27353a12c:

  • editor-close-pinned-sibling.test.ts:
    • premise: the sibling tab is pinned and both records are open;
    • the pinned sibling's record stays open;
    • its tab stays open, and the closed record's tab is removed.
  • editor-set-active-file-guard.test.ts:
    • premise: the open document is active;
    • after the call with an unknown id, the in-memory active file is unchanged;
    • the per-workspace active file is unchanged. This last assertion also holds on main; it guards against a regression rather than proving the fix.
  • Suite results on e27353a12c (store/slices/editor/, the editor-* suites and active-selection-owner-scoping): 33 test files, 334 tests pass.
  • Local checks on e27353a12c: pnpm tc and pnpm run check:code-quality:changed (0 new findings across 4 files) pass; the layout-writer, focus-read and max-lines ratchets, check:reliability-gates and check:compat-boundary-imports passed on the previous head 5f06eff368, which differs only in a test file.

Not run: Linux, Windows, SSH. Electron was run only for the hidden-renderer capture above (macOS, temp profile, automated), not a manual session.

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

AI Disclosure

Written with Claude Code (Claude Opus 5.5) and Codex (gpt-6-astra).

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • SSH and remote: the pinned check reads only the workspace's own tabs. Which records count as the same document is unchanged: that is still main's isSameOwnedDocument.
  • Folder workspaces: both guards key on the workspace id, whether the workspace is a git worktree or a folder.
  • Wire: none.

Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • 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 path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred). Typecheck, changed-code quality and the related suites pass locally. Full lint, the full test suite and the build are left to CI.

…wner twin

Closing a document also closes clean same-owner duplicate records; a record
whose tab is pinned is now left open with its tab.
A stale tab or pane id could make a missing file active and persist it as the
workspace's active file.
@coderabbitai

coderabbitai Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8a5cea28-a401-413d-bb54-6d3c6377e248
📥 Commits

Reviewing files that changed from the base of the PR and between 5e83ca0 and e27353a.

📒 Files selected for processing (4)
  • src/renderer/src/store/slices/editor-close-pinned-sibling.test.ts
  • src/renderer/src/store/slices/editor-set-active-file-guard.test.ts
  • src/renderer/src/store/slices/editor/actions/close-file-action.ts
  • src/renderer/src/store/slices/editor/actions/open-file-mutations.ts

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

📝 Walkthrough

Walkthrough

The close action now excludes a pinned, same-owner clean sibling from cascading closure. setActiveFile now returns when the supplied ID has no open file. New tests cover both guards.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to e2735

The change keeps a pinned duplicate tab open when its sibling closes and ignores setActiveFile calls for unknown files. No actionable merge risk was identified.

Pre-merge checks · Passed 4 · Failed 1

Failed Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely summarizes both primary changes: preserving pinned duplicates during close and ignoring missing files in setActiveFile.
Description check Passed The description follows the required template and covers the user impact, implementation, rationale, linked issue, visual proof, testing, limitations, and checklist status. It clearly identifies tests…
Linked Issues check Passed The PR implements both coding requirements in #27985. close-file-action.ts excludes a same-owner, clean sibling when its workspace tab is pinned, while the explicit file remains closable. `open-file…
Out of Scope Changes check Passed The diff contains only the two requested guards and focused automated tests. The changes do not add duplicate-record creation, persistence merging, record pruning, or unrelated product behavior. The r…
  • Fix all pre-merge checks with AI
  • 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.

@nwparker
nwparker merged commit 52e88e4 into stablyai:main Oct 13, 2026
nwparker added a commit that referenced this pull request Oct 13, 2026
Samuel Vila (@SamuelAdigos) independently submitted both editor guards
and regression tests in #28063 before #28120 was opened. The narrower
implementation landed in #28120; this follow-up records credit for his
earlier contribution.

Co-authored-by: Samuel Vila <[email protected]>
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]: Closing an editor document also closes a pinned duplicate of it, and setActiveFile accepts an id with no open file

2 participants