Skip to content

Sync → Flush open editors before reading the vault - #178

Merged
revett merged 1 commit into
mainfrom
revett/fix-editor-flush-before-sync
Jul 31, 2026
Merged

revett merged 1 commit into
mainfrom
revett/fix-editor-flush-before-sync

Conversation

@revett

@revett revett commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Problem

  • checkLocalDrift reads through the Vault API, which only reflects bytes Obsidian has already written to disk
  • Obsidian's own editor autosave debounces roughly two seconds behind the last keystroke, so a file mid edit can hold unsaved bytes the drift check never sees
  • A pull landing in that window overwrites the file, and the pending autosave then reintroduces the stale buffer on top of it, silently discarding the pulled content
  • The same blind spot lets a conflict rename preserve stale, pre edit bytes as the local side rather than what the editor actually holds

Why

  • Closes a silent data loss path ahead of automatic sync landing, where the exposure window turns from an occasional manual click into a routine background pass
  • Relies on the existing drift check machinery rather than adding a parallel safety mechanism, keeping the fix small and the guarantee it depends on unchanged

Greptile Summary

This PR flushes pending content from open Markdown editors before sync reads the vault.

  • Adds flushOpenEditors, which awaits every save-capable Markdown view and propagates save failures.
  • Calls the flush immediately before reading sync state and running syncOnce.
  • Adds unit coverage for multiple leaves, unsupported views, empty workspaces, and failed saves.

Confidence Score: 5/5

The PR appears safe to merge, with no concrete correctness or security failures identified.

The new flush is awaited before sync begins reading vault content, skips incompatible views, and aborts the sync through its existing error handling if persistence fails.

Important Files Changed

Filename Overview
src/main.ts Integrates the editor flush into the guarded sync lifecycle immediately before vault reads.
src/vault/obsidian.ts Adds a focused helper that awaits save-capable Markdown views and correctly propagates failures.
src/vault/obsidian.test.ts Covers successful, unsupported, empty, and rejected editor-save cases.

Reviews (1): Last reviewed commit: "Fix editor race" | Re-trigger Greptile

Context used:

@revett
revett merged commit 47d474a into main Jul 31, 2026
10 checks passed
@revett
revett deleted the revett/fix-editor-flush-before-sync branch July 31, 2026 21:50
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