Skip to content

Editor buffers ready for sharing: autosave per record, separate models for detached tabs (no behaviour change) - #31970

Merged
nwparker merged 9 commits into
mainfrom
nwparker/editor-buffer-switch-g1
Oct 22, 2026
Merged

nwparker merged 9 commits into
mainfrom
nwparker/editor-buffer-switch-g1

Conversation

@nwparker

@nwparker nwparker commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​423 $\color{#cf222e}{\Huge{\mathbf{−}}}$​11 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​412
Prod 9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​206 $\color{#cf222e}{\Huge{\mathbf{−}}}$​60 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​146

ELI5

Groundwork for letting every tab that shows the same file share one record of unsaved edits. Nothing changes for users yet: today every tab still has its own record. This makes autosave, the editor model and the join rules ready for sharing, and fixes two autosave problems that would only appear once records are shared.

What Changed

  • Autosave is scheduled per record, not per tab: the record's first view that is allowed to autosave decides the timer, so a read-only view can't cancel it and closing the tab that started the timer doesn't drop it. The writer view is chosen with the same rules.
  • Tabs kept apart get their own editor model (detached: record ids), so their text never mixes with the file's other record.
  • Join and rejoin rules as standalone functions (not used yet): first join re-keys, clean+clean attaches, unsaved wins, identical unsaved merges, different unsaved (or a pending conflict/migration on one side) stays apart; rejoin only once one side is clean.
  • Tabs mirrored from a paired host: a record's unsaved flag is the OR of its host tabs, because older hosts publish it per tab; the dev check tolerates exactly that case.

Why

First of the stacked PRs that switch Orca to one editor buffer per file. This part is safe to ship alone because every record still has one view; the next PR (views share one record, plus rich/notebook/CSV writing through the record) lands as one unit.

Linked Issue

Follow-up to #31768.

Visual Proof

N/A: no visible change.

Testing

  • Per-record autosave (read-only view first, timer surviving the scheduling tab closing), detached model owner keys, join/rejoin rules incl. pending conflicts and drafts not yet serialized, mirrored dirty OR.

  • pnpm tc, check:code-quality:changed, oxfmt, oxlint pass; editor/store/runtime/hooks/sidebar suites pass.

  • Reviewed by Opus; its findings are applied.

  • I manually tested these changes locally

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

AI Disclosure

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

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

No wire or persisted-state change.

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)

nwparker and others added 9 commits October 21, 2026 14:42
…oved tabs

Delete the pendingDiskBaselineVerification and pendingLiveDiskVerification
pause flags. Every editor save is already a guarded write; a refusal raises
the changed-on-disk banner, which is what stops autosave until an explicit
save.

A guarded write now succeeds when disk changed but already holds exactly the
text being saved (local/host compare is byte-exact; client-side fallbacks
compare decoded text and refuse when it holds U+FFFD), so a restored draft
that matches disk goes clean instead of showing a banner.

The restore scan only raises the banner early for tabs that arrive dirty; a
watch resync no longer re-checks dirty tabs.

Co-Authored-By: Claude <[email protected]>
Return a compatible optional no-op result from hosts and client fallbacks, clean the tab, and clear its provisional self-write stamp without rewriting identical bytes.

Co-Authored-By: Claude <[email protected]>
…er hosts, flag dirty tabs on resync

- Autosave and pre-restart saves refuse when disk text can't be decoded losslessly, so a
  baseline that decoded to U+FFFD can't authorize overwriting different bytes.
- New files.write.identical-noop.v1 capability; for hosts with only the v1 guarded write the
  client compares first, skips identical saves, then delegates to the host's guarded write.
- Watch resync compares dirty tabs against disk and shows the changed-on-disk banner.
- Local guarded writes check for identical content before the write-only regular-file probe.

Co-Authored-By: Claude <[email protected]>
…false resync banners

- Local guarded writes judge losslessness by bytes, so a valid UTF-8 file containing U+FFFD
  autosaves again. A file that really isn't UTF-8 is refused with its own reason, 'not-utf8'
  (older clients read it as 'changed'), which pauses autosave for that file with one notice
  until an explicit save converts it.
- A watch resync whose disk read fails leaves dirty tabs alone; the guarded save still catches
  a real conflict.
- Resync and restored-tab checks treat disk holding the tab's own just-written save as an echo.
- On hosts with only the v1 guarded write, only automatic saves read the file first; explicit
  saves go straight to the host's guard.

Co-Authored-By: Claude <[email protected]>
…d report disk changes first

- The pause is released once no dirty tab of the file remains (close, reload from disk,
  discard), so a reopened or reloaded file's next autosave asks the host again and notifies.
- Client-side precondition checks compare the signature before looking for U+FFFD, so an
  external rewrite shows the changed-on-disk banner rather than the non-UTF-8 notice.

Co-Authored-By: Claude <[email protected]>
…e sharing switch uses

First of the stacked sharing-switch PRs (G1). Inert while every record has
one view, which is all main produces today; tests drive the shared shape
through hand-built view indexes.

- Autosave timers are decided per record by its first view that may
  autosave, so a read-only or preview view of a record no longer cancels
  the record's timer, and a timer survives the view that scheduled it
  closing (it resolves a live view of the record when it fires).
- A view of a detached record gets its own model owner key, so divergent
  dirty drafts never share text with the file's other record.
- Pure join and rejoin rules: rekey / attach / adopt (dirty wins) / merge
  (identical dirty) / detach (divergent dirty); a detached pair rejoins
  only once one side is clean.
- Mirrored host tabs: a record's dirty flag is the OR of its host-owned
  views, since an older host publishes it per tab; the dev invariant
  tolerates exactly that disagreement.

Co-Authored-By: Claude <[email protected]>
…e view for autosave

- A merge needs equal drafts, baselines, conflict and owner-migration state;
  anything else detaches, so a paused record never resumes autosave by joining.
  A side whose text is still pending (no draft) never counts as identical.
- A clean-flagged view that still holds a draft counts as dirty in joins.
- The invariant tolerates a clean host-owned view on a dirty record only when
  another host-owned view of that record reads dirty.
- Autosave and restart skip CSV-preview and read-only views when picking the
  view a record writes through.

Co-Authored-By: Claude <[email protected]>
…r-switch-g1-fixes

# Conflicts:
#	src/renderer/src/components/editor/editor-save-queue.ts
@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

The PR adds detached editor-buffer identity and model ownership, buffer join and rejoin decisions, and mirrored dirty-state reconciliation. It also centralizes autosave eligibility, adjusts save-writer selection, and updates autosave scheduling for records shared across views.

Priority: ➖ Normal

Merge Risk: 🔵 Low · up to 48385

The new join rules need two state-preservation fixes before they are used for shared records. They are not currently connected to the editor workflow, so the present merge risk is bounded.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 62.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 24 functions across 15 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 the main changes: per-record autosave and separate models for detached tabs. It also states that user behavior does not change.
Description check Passed The description is complete and aligned with the template. It explains the user impact, implementation, rationale, linked issue, visual proof, testing, compatibility considerations, and checklist stat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description is complete and aligned with the template. It explains the user impact, implementation, rationale, linked issue, visual proof, testing, compatibility considerations, and checklist status. Automated validation is documented, while broader commands are explicitly left for CI.

✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • 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.

@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: 2


ℹ️ Review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 85a3105a-c003-49ba-a660-958103382d67
📥 Commits

Reviewing files that changed from the base of the PR and between 0b4f2d9 and 48385f7.

📒 Files selected for processing: 16
  • src/renderer/src/components/editor/editor-autosave-controller.test.ts
  • src/renderer/src/components/editor/editor-autosave-due-records.ts
  • src/renderer/src/components/editor/editor-model-owner.test.ts
  • src/renderer/src/components/editor/editor-model-owner.ts
  • src/renderer/src/components/editor/editor-save-queue-records.test.ts
  • src/renderer/src/components/editor/editor-save-queue.ts
  • src/renderer/src/components/editor/editor-save-writer-view.test.ts
  • src/renderer/src/components/editor/editor-save-writer-view.ts
  • src/renderer/src/store/editor-buffer-record-lifecycle.ts
  • src/renderer/src/store/slices/editor/buffers/editor-buffer-identity.test.ts
  • src/renderer/src/store/slices/editor/buffers/editor-buffer-identity.ts
  • src/renderer/src/store/slices/editor/buffers/editor-buffer-join.test.ts
  • src/renderer/src/store/slices/editor/buffers/editor-buffer-join.ts
  • src/renderer/src/store/slices/editor/buffers/editor-buffer-mirrored-dirty.test.ts
  • src/renderer/src/store/slices/editor/buffers/editor-buffer-record.ts
  • src/renderer/src/store/slices/editor/buffers/editor-buffer-views.ts
💤 Files with no reviewable changes: 1
  • src/renderer/src/store/slices/editor/buffers/editor-buffer-identity.ts

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

Comment on lines +27 to +31
if (!isDirtySide(joining)) {
return 'attach'
}
if (!isDirtySide(target)) {
return 'adopt'

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.

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Preserve pauses when a clean side joins.

A side with isDirty: false, no draft, and pendingOwnerMigration: true takes the clean-side branch. attach or adopt can then discard that side’s migration pause. The same branches can discard externalMutation. Defer the join or retain the relevant state until the pause or conflict is resolved.

Comment on lines +72 to +73
case 'merge':
return target

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.

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Keep the dirty flag when identical drafts merge.

If the target holds a draft with record.isDirty: false and the joining side holds the same draft with record.isDirty: true, joinOnto selects merge. joinedEditorBuffer returns the clean-flagged target and drops the joining side’s dirty flag. OR the flags in the merged record, or reject this merge until the flags agree.

@nwparker
nwparker merged commit 54acda1 into main Oct 22, 2026
33 checks passed
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.

1 participant