Skip to content

Harden data safety: awaited saves, atomic writes, corruption recovery, rolling backups - #144

Open
tahabasri wants to merge 1 commit into
mainfrom
feature/data-safety
Open

Harden data safety: awaited saves, atomic writes, corruption recovery, rolling backups#144
tahabasri wants to merge 1 commit into
mainfrom
feature/data-safety

Conversation

@tahabasri

Copy link
Copy Markdown
Owner

What

The extension's most serious recurring bug class is silent data loss (#31, #33, #66, #101, #119, #129). This PR hardens the whole persistence path:

  • Fix handleCommand: new Promise(callback) treated command bodies as executors whose resolve/reject were never called — the promise never settled and async command errors bypassed the handler entirely. Now chains through Promise.resolve().then(callback) so rejections are surfaced to the user and logged with a stack.
  • Awaited saves end-to-end: memento.update() was fire-and-forget, so save failures were silently swallowed and the tree refreshed from a state that never committed. DataAccess.save is now async and SnippetsProvider.sync() awaits it; all provider mutations propagate the save promise.
  • Atomic file writes: FileDataAccess writes to a temp file then renames, so a crash mid-write can never truncate .vscode/snippets.json.
  • Corruption recovery: an unparseable snippets file no longer kills activation — the persistent workspace backend preserves it as *.corrupt-<timestamp>, reseeds an empty root and notifies the user. Transient import instances keep throwing so a bad import source is never overwritten.
  • Rolling automatic backups (new BackupManager): timestamped snapshots (10 kept per view) in global storage before destructive operations (import, troubleshoot, folder deletion) plus at most one automatic snapshot per day. New Snippets: Open Backups Folder command makes them discoverable.

Tests

  • New suites for atomic saves, corruption recovery (both modes) and backup rotation/pruning; existing suites updated for the async signatures. 49 tests passing locally.
  • @vscode/test-electron bumped 2.3.4 → 2.5.2 (the old version cannot launch current VS Code stable builds).

🤖 Generated with Claude Code

…, rolling backups

- Fix handleCommand: 'new Promise(callback)' treated command bodies as
  executors whose resolve/reject were never called, so the promise never
  settled and async command errors bypassed the handler entirely. Chain
  through Promise.resolve().then(callback) so rejections are caught,
  shown to the user, and logged with a stack.
- Make DataAccess.save async end-to-end and await it in
  SnippetsProvider.sync(): memento.update was fire-and-forget, so save
  failures were silently swallowed and the tree refreshed from a state
  that never committed. All provider mutations now propagate the save
  promise to their callers.
- FileDataAccess: atomic writes (write temp file, then rename) so a
  crash mid-write can never truncate snippets.json; on unparseable
  JSON the persistent workspace backend now preserves the file as
  *.corrupt-<timestamp>, reseeds an empty root and notifies the user
  instead of dying during activation. Transient import instances keep
  throwing so a bad import source is never overwritten.
- New BackupManager: rolling timestamped backups (10 kept per view) in
  globalStorage before destructive operations (import, troubleshoot,
  folder deletion) and at most one automatic snapshot per day.
- New 'Snippets: Open Backups Folder' command to make backups
  discoverable (command palette + view overflow menu).
- Tests for atomic saves, corruption recovery and backup rotation;
  bump @vscode/test-electron 2.3.4 -> 2.5.2 (old version cannot launch
  current VS Code stable).
tahabasri added a commit that referenced this pull request Jul 11, 2026
Pre-resolves the extension.ts conflict between the two 4.3.0 PRs so they
merge cleanly in order (#144 then #145). Quick Edit saves now also go
through the awaited sync path introduced by the data-safety work.
@tahabasri tahabasri mentioned this pull request Jul 11, 2026
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