Skip to content

fix(editor): keep a pinned duplicate open and ignore unknown ids in setActiveFile - #28063

Closed
SamuelAdigos wants to merge 1 commit into
stablyai:mainfrom
SamuelAdigos:fix/editor-close-pinned-duplicate
Closed

SamuelAdigos wants to merge 1 commit into
stablyai:mainfrom
SamuelAdigos:fix/editor-close-pinned-duplicate

Conversation

@SamuelAdigos

Copy link
Copy Markdown
Contributor

ELI5

Two small editor fixes. Closing a tab no longer also closes a pinned tab for the same file, and asking the editor to select a file that isn't open no longer leaves the selection pointing at nothing.

What Changed

Before:

After:

  • The duplicate sweep in closeFile skips records whose editor tab is pinned, next to the existing dirty and draft exclusions.
  • setActiveFile returns without changes when no open file has the id. Because the file is now always known, its fallbacks to the active workspace are gone.

Why

Pinning a tab is an explicit "keep this open", so a cleanup sweep should respect it the same way it respects unsaved work. A selection that points at no open file is what lets stale tab and pane ids (recent-tab cycling → activateCyclableTab → setActiveFile) leak into the global state. Every caller passes the entity id of an editor-family tab, and all of those are backed by an OpenFile, so the guard blocks no real selection.

Linked Issue

Fixes #27985

Visual Proof

N/A: store-level fix. Reproducing it needs duplicate records from older builds, and the new store tests cover that state.

Testing

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • editor-close-document-siblings.test.ts: a pinned clean duplicate and its tab survive closing the other record.

  • active-selection-owner-scoping.test.ts: setActiveFile('stale-file-id') leaves activeFileId and activeFileIdByWorktree unchanged.

  • Both fail before the fix. pnpm test src/renderer passes (4730 files), as do pnpm tc:web, pnpm run check:code-quality:changed, and oxlint and oxfmt on the changed files. macOS only.

AI Disclosure

Claude Code helped investigate and write the change; I reviewed and tested it.

Review

Duplicate records themselves stay out of scope, as the issue asks (#21121).

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

Renderer store only: no IPC, wire, SSH, mobile or platform impact.

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)

…etActiveFile

closeFile's duplicate sweep closed clean same-owner records even when
their tab was pinned; skip those like dirty and drafted records.
setActiveFile made an id with no open file the global active file;
return without changes instead.
@coderabbitai

coderabbitai Bot commented Oct 12, 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: 7210be98-65c2-4a2e-a230-e51c318d9294

📥 Commits

Reviewing files that changed from the base of the PR and between 0ec645f and 6e99a07.


📒 Files selected for processing (4)
  • src/renderer/src/store/slices/active-selection-owner-scoping.test.ts
  • src/renderer/src/store/slices/editor-close-document-siblings.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; 8 remain after this review.



📝 Walkthrough

Walkthrough

The changes prevent setActiveFile from changing selection when the requested file has no open record. They also prevent closeFile from closing pinned duplicate editor tabs during same-owner clean-file cleanup.


Priority: ⬇️ Low

Severity of issue fixed: Low

Merge Risk: ⚪ Minimal · up to 6e99a

The reviewed selection and pinned-tab guards have no remaining actionable risk identified in the inspected call paths.

Pre-merge checks · Passed 4 · Failed 1

Failed Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 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 identifies both primary fixes: preserving pinned duplicate tabs and ignoring unknown IDs in setActiveFile.
Description check Passed The description covers the required sections, explains the before and after behavior, links issue #27985, documents testing, and explains the N/A visual proof. It also states that manual testing was n…
Linked Issues check Passed Issue #27985 requires two guards. closeFile now excludes pinned editor-tab entity IDs from the same-owner clean-duplicate sweep, while the requested file remains closable. setActiveFile now return…
Out of Scope Changes check Passed The changes stay within issue #27985. The production changes implement the two requested guards. The two added tests directly verify those guards. The duplicate records exist only as test setup; the P…

  • 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 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]>
@nwparker

Copy link
Copy Markdown
Contributor

Thanks, @SamuelAdigos, for the earlier implementation and regression tests. Your PR was opened before #28120 and independently covered both guards.

Both fixes have now landed through #28120. We selected that smaller patch after reproducing the regressions, exercising the editor close flow in hidden Electron, and passing 693 related tests.

I've added you as a co-author in a follow-up attribution commit: f118137. This explicitly records credit for your earlier contribution; the original merged commit is unchanged.

Closing this PR as superseded. Thank you for the investigation and regression coverage.

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