Skip to content

[#136] Vault → Write state.json atomically - #186

Merged
revett merged 1 commit into
mainfrom
revett/fix/136
Aug 2, 2026
Merged

revett merged 1 commit into
mainfrom
revett/fix/136

Conversation

@revett

@revett revett commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Resolves #136

Problem

state.json is written straight through the vault adapter, so a crash mid write can leave it torn; that file is the common ancestor every sync diffs against, and a torn read already falls back to an empty snapshot, which turns every remotely deleted file into a resurrection and every real divergence into a conflict copy

Why

  • State corruption here is silent, it only ever surfaces later as confusing sync behaviour, never as an error at write time
  • Reusing the existing install path means no new failure handling was invented, the same guarantee just gained a second caller

Greptile Summary

The PR makes persisted vault snapshots crash-safe by staging encoded state in a hidden sibling file and installing it through the existing replacement path.

  • Reuses the vault writer's staged rename behavior for state.json.
  • Adds adapter rename support to the store test fixture.
  • Verifies a failed installation preserves the previous snapshot.

Confidence Score: 5/5

The PR appears safe to merge, with snapshot writes now preserving the prior state when installation fails.

The changed store path writes the complete encoded snapshot to a sibling temporary file before invoking the existing replacement logic, while production synchronization serializes store writes and the tests verify prior-state preservation on failure.

Important Files Changed

Filename Overview
src/vault/obsidian.ts Replaces direct snapshot writes with deterministic temporary-file staging and the established replacement helper; no actionable defect was found.
src/vault/obsidian.test.ts Extends the fake adapter with rename behavior and verifies that an interrupted snapshot installation leaves the previous state intact.

Reviews (1): Last reviewed commit: "Write state.json atomically" | Re-trigger Greptile

Context used:

@revett
revett merged commit e589b8c into main Aug 2, 2026
10 checks passed
@revett
revett deleted the revett/fix/136 branch August 2, 2026 10:30
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.

Vault → state.json is not written atomically

1 participant