Skip to content

Discard pauses autosave of the file in every workspace; read-only Markdown/CSV tabs can't overwrite unsaved edits (phase 1b-3) - #31413

Merged
nwparker merged 3 commits into
mainfrom
nwparker/editor-buffer-phase-1b-3
Oct 21, 2026
Merged

nwparker merged 3 commits into
mainfrom
nwparker/editor-buffer-phase-1b-3

Conversation

@nwparker

@nwparker nwparker commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​341 $\color{#cf222e}{\Huge{\mathbf{−}}}$​5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​336
Prod 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​309 $\color{#cf222e}{\Huge{\mathbf{−}}}$​55 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​254

ELI5

Two ways an editor could write the wrong text into a file are closed. (1) Discarding a file's changes in Source Control now stops autosave of that file in every workspace until git has finished, so another workspace's tab can't save its old edits back over the restored file. (2) A read-only Markdown or CSV tab can no longer push the file's disk text over a writable tab's unsaved edits on the same file.

What Changed

  • Discard pauses autosave everywhere. Source Control Discard (single and bulk) takes a pause on the physical file (host + path) covering every editable view of it — edit tabs and unstaged diff tabs — in every workspace, including when the discarding workspace has no tab of the file open. In-flight saves are waited for first. The pause is released in a finally when git finishes or fails. If quiescing fails (e.g. an unresolved CSV cell), the pause is released and the discard reports the error. A 120 s backstop only shows the existing changed-on-disk banner on dirty tabs; it never resumes autosave while git might still be running. Manual, quit and restart saves are not paused.
  • Read-only Markdown/CSV tabs render plain source on the shared text model, so they now count as code views of that model. A clean read-only tab can no longer push disk text into the model over a writable tab's unsaved edits.
  • The pause key reuses the path rules from Add the rules that decide which editor tabs are the same file (phase 1b-1, unused) #31272 (POSIX backslashes are kept; Windows separators/drive case folded only for proven Windows paths), so a Windows client connected to a Linux host never pauses an unrelated file.

Why

Both were real on main (reproduced with failing tests, now regression tests). The discard race was refused by the guarded write on current hosts but could overwrite git's restore on older hosts that compare-then-write; the read-only push could lose a writable tab's edits.

A broader change — one autosave timer shared by all tabs of a file — was prototyped here and dropped: until tabs share one record of unsaved text (the next step), a shared timer can save an outdated copy held by a hidden tab. Reviews found several such cases; they are kept as test scenarios for that step. This PR only removes or delays writes.

Linked Issue

Follow-up to #31313.

Visual Proof

N/A: no new UI. The only visible effect is the existing changed-on-disk banner on a dirty tab when a Discard takes longer than 120 s.

Testing

  • Regression tests: cross-workspace discard (with and without a tab open in the discarding workspace), slow git restore, watcher notice alone doesn't release, failed discard and failed quiesce resume autosave, discard slower than the backstop (banner, no write, banner returns if dismissed), unstaged diff tab in another workspace, POSIX backslash path vs slash path from a Windows client, read-only .md/.csv (and a .jsonl control).

  • Editor, store, hooks, runtime and right-sidebar suites pass; pnpm tc, check:e2e-typecheck-ratchet, check:code-quality:changed, oxfmt --check pass.

  • Reviewed by GPT and Opus over several rounds.

  • 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. A save hung in another workspace (e.g. a stuck SSH write) now delays a Discard here until it settles.

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 3 commits October 20, 2026 19:31
…ead-only markdown/CSV never pushes over edits (phase 1b-3)

- A Source Control discard holds autosave (and waits for in-flight saves) for every tab of that
  file in every workspace, keyed by its model save key, until the discard finishes or fails; the
  quiesce now returns the release, called in a finally. Watcher notices don't release it. A 120 s
  backstop only shows the changed-on-disk banner on dirty tabs and never reopens autosave. This
  closes the race where the compare fallback on older hosts reads disk just before git restores it.
- A read-only tab renders raw Monaco source whatever its type, so it counts as a code view: a clean
  read-only .md/.csv tab can no longer push disk text over a writable tab's unsaved edits.

Only removes or delays writes. One autosave timer per model moves to 1b-4.

Co-Authored-By: Claude <[email protected]>
…ed diffs, re-show an overdue banner (phase 1b-3)

- A quiesce that throws (e.g. an unresolved CSV cell) releases its hold and rejects, so the discard
  reports the error instead of hanging with autosave off; a bulk discard frees the holds the other
  paths took.
- Holds key on the physical file (host + path), so an unstaged diff tab of the file in another
  workspace is paused and drained too; save-queue keys are unchanged.
- Past the backstop, a dirty held tab whose banner was dismissed gets it back, so the pause is
  never silent. Taking a hold no longer re-syncs; the save-time check already refuses.

Co-Authored-By: Claude <[email protected]>
…not the client's URI rules (phase 1b-3)

The hold key went through the Monaco model URI, which normalizes paths by the client platform, so
on a Windows client `/repo/a\b.ts` and `/repo/a/b.ts` on a POSIX host shared a key. It now uses
the owner key plus `editorBufferOwnerPathKey` (new, in editor-buffer-identity), which applies the
1b-1 rules: POSIX backslashes kept, separators folded only for proven-Windows paths, UNC server
case, and WSL aliases on the local Windows client. Same on the tab and the discard-path side.

Co-Authored-By: Claude <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 7 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 613620ec-18f0-41c7-8385-e5cec4f82c53
📥 Commits

Reviewing files that changed from the base of the PR and between 01562f8 and 66f799f.

📒 Files selected for processing: 13
  • src/renderer/src/components/editor/editor-autosave-controller.ts
  • src/renderer/src/components/editor/editor-autosave-holds.test.ts
  • src/renderer/src/components/editor/editor-autosave-holds.ts
  • src/renderer/src/components/editor/editor-autosave.test.ts
  • src/renderer/src/components/editor/editor-autosave.ts
  • src/renderer/src/components/editor/editor-git-discard-other-workspace.test.ts
  • src/renderer/src/components/editor/editor-model-owner.ts
  • src/renderer/src/components/editor/editor-readonly-markdown-push.test.ts
  • src/renderer/src/components/editor/editor-save-disk-precondition.ts
  • src/renderer/src/components/editor/editor-save-queue.ts
  • src/renderer/src/components/right-sidebar/source-control/commit/source-control-discard-editor-owner.test.tsx
  • src/renderer/src/components/right-sidebar/source-control/commit/use-entry-mutations.ts
  • src/renderer/src/store/slices/editor/buffers/editor-buffer-identity.ts
  • 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 546304f into main Oct 21, 2026
54 of 56 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