From 604a6058b82cc379c62c3825045d66989f4bc53c Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 17 Apr 2026 16:18:09 +0000 Subject: [PATCH] fix(storage): atomic task-file writes write_task used plain fs::write for the .md payload even though every other write path in this module (metadata files, sync state, offline queue, config) uses atomic_write. A crash mid-write left a truncated .md file whose malformed YAML frontmatter then failed list_tasks for the entire list. Route through atomic_write so a failed write either leaves the old file intact or produces the full new file. --- crates/onyx-core/src/storage.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/onyx-core/src/storage.rs b/crates/onyx-core/src/storage.rs index c966af0..fbf0a1b 100644 --- a/crates/onyx-core/src/storage.rs +++ b/crates/onyx-core/src/storage.rs @@ -381,7 +381,9 @@ impl Storage for FileSystemStorage { } let content = self.write_markdown_with_frontmatter(task)?; - fs::write(&task_path, content)?; + // Atomic write: a crash mid-write must not leave a truncated .md file + // that then fails YAML parsing on the next list_tasks/read_task. + atomic_write(&task_path, content.as_bytes())?; // Update list metadata to include this task in task_order if not already present let mut list_metadata = self.read_list_metadata(list_id)?;