Skip to content

fix: avoid false delete events during atomic saves#5

Merged
ptheofan merged 1 commit intoptheofan:mainfrom
woodrow:main
Mar 8, 2026
Merged

fix: avoid false delete events during atomic saves#5
ptheofan merged 1 commit intoptheofan:mainfrom
woodrow:main

Conversation

@woodrow
Copy link
Copy Markdown
Contributor

@woodrow woodrow commented Mar 6, 2026

Problem

Open Markdown can mis-handle editor save workflows that temporarily unlink a file (for example Vim-style atomic/truncate+rewrite saves). The app currently treats unlink as an immediate delete, clears the open document, and shows a deleted-file error even when the file is recreated moments later.

Solution

Treat delete events as pending and confirm them after a short grace period. If an add or change for the same path arrives before confirmation, cancel the pending delete and process the update normally.

What Changed

  • Added FILE_DELETE_CONFIRM_MS (750ms) in shared constants.
  • Updated FileWatcherService to:
    • track pending delete timers per file,
    • schedule deletion confirmation on unlink instead of immediate delete,
    • cancel pending delete on add and change,
    • confirm file is still missing before emitting delete,
    • keep watcher entries alive through transient unlink/recreate flows.
  • Expanded watcher unit tests to cover:
    • add handler registration,
    • delayed delete confirmation behavior,
    • transient unlink -> add and unlink -> change paths (no delete emitted),
    • recovery-path refresh assertions (change callback still fires),
    • updated multi-file delete test for delayed confirmation.

AI Disclosure

I used AI assistance (OpenAI Codex) to help draft and implement the code changes and tests, and to prepare this PR description. I personally reviewed and validated the final patch and test results, and tested the app works as expected with pnpm start, before opening this PR, though I am not a frontend expert by any means.

@ptheofan ptheofan merged commit c243b5c into ptheofan:main Mar 8, 2026
2 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.

2 participants