super-productivity/packages/plugin-dev/sync-md/src/background/config.const.ts
Johannes Millan c73eeff75b fix(sync-md): prevent crash from sync oscillation when adding subtask to markdown file
When a user adds a subtask by editing the markdown file directly, the
MD→SP sync creates the task which triggers SP hooks, which trigger
SP→MD sync, which writes the file, which the file watcher detects,
creating a rapid sync oscillation loop that crashes the app.

Three-layer fix:
1. Stop file watcher for the entire MD→SP sync duration and cancel
   pending SP→MD debounce timers
2. Add a cooldown after MD→SP sync (set before and after in finally
   block) to suppress SP hooks that fire as side-effects
3. Simplify lazySetInterval with async/await and a stopped flag to
   prevent zombie rescheduling when cancelled during async callbacks

Also fixes a file watcher race condition where polling could start
before initial mtime was resolved.

Fixes #6021
2026-03-24 14:12:50 +01:00

8 lines
455 B
TypeScript

export const SYNC_DEBOUNCE_MS = 500;
export const SYNC_DEBOUNCE_MS_UNFOCUSED = 15000; // 15 seconds when SP is not focused
export const SYNC_DEBOUNCE_MS_MD_TO_SP = 10000; // 10 seconds for MD to SP sync
export const FILE_WATCH_POLL_INTERVAL_MS = 2000;
// Cooldown after MD→SP sync to suppress SP hooks that fire as side-effects
// of the batch update. Must be > SYNC_DEBOUNCE_MS to outlast the debounce window.
export const SP_HOOK_COOLDOWN_MS = 2000;