Skip to content

Fix Files v2 workbench overwriting disk after external edits#450

Draft
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-correctness-bugs-9c1a
Draft

Fix Files v2 workbench overwriting disk after external edits#450
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-correctness-bugs-9c1a

Conversation

@cursor
Copy link
Copy Markdown
Contributor

@cursor cursor Bot commented May 31, 2026

Bug and impact

With the Files tab v2 workbench enabled (ade.files.workbenchV2), opening a file and then having another process modify it on disk (agent edit, git checkout, terminal write) left the Monaco buffer stale. The watcher only invalidated the read cache and refreshed the tree; open editors never reloaded.

Trigger: User opens foo.ts in Files v2, an agent edits foo.ts on disk, user saves (or saves without noticing stale content). The save writes the old buffer and overwrites the newer on-disk file — data loss.

Root cause

FilesWorkbench called invalidateFileContent on ade.files.change but did not mirror v1 FilesPage behavior: no syncCleanTabFromDisk, no reload token for useFileContent, and monacoModelRegistry.getOrCreate returned cached models without applying fresh disk text for clean tabs.

Fix

  • Reload clean open tabs from disk on watcher events (debounced), bumping per-path reload tokens so ViewerHost refetches.
  • Update Monaco models when revisiting a path if the tab is clean and disk content changed.
  • Track dirty tabs with disk changes separately: amber tab indicator + banner with explicit reload (discards local edits).
  • Close tabs when watched paths are deleted.

Validation

  • npx vitest run src/renderer/components/files/monacoModelRegistry.test.ts src/renderer/components/files/v2/editorGroupsStore.test.ts (24 tests passed)
  • Desktop typecheck: no errors in touched files
Open in Web View Automation 

Files tab v2 invalidated the read cache on watcher events but never
reloaded open editors. Monaco models kept stale buffers, so a save after
an agent or git edit could overwrite newer on-disk content.

Reload clean tabs from disk, surface a disk-changed banner on dirty
tabs, and update cached Monaco models when revisiting a clean path.

Co-authored-by: Arul Sharma <arul28@users.noreply.github.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 31, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
ade Ignored Ignored Preview May 31, 2026 2:07am

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