Skip to content

fix(files): never overwrite upload_history.json on load failure#95

Open
Nic-dorman wants to merge 1 commit into
mainfrom
fix/upload-history-no-overwrite-on-load-fail
Open

fix(files): never overwrite upload_history.json on load failure#95
Nic-dorman wants to merge 1 commit into
mainfrom
fix/upload-history-no-overwrite-on-load-fail

Conversation

@Nic-dorman
Copy link
Copy Markdown
Contributor

Summary

Two customer reports after 0.7.0 of the app appearing to "delete or reset" the datamap storage dir — every prior datamap row vanishes from the Files table, even though the .datamap files themselves are still on disk in %APPDATA%\autonomi\ant-gui\.

Root cause: stores/files.ts::loadHistory swallowed any error from load_upload_history and left state.files = [] while still setting historyLoaded = true. The very next persistHistory() call (upload complete, row remove, or Clear history) rebuilt from the empty array and wrote {"entries": []} over the on-disk file, orphaning every prior datamap.

Fixes

  1. stores/files.ts — track historyLoadFailed. When set, persistHistory is a no-op and logs a warning. Fail-closed: if we can't read the file we never overwrite it.
  2. app.vueawait filesStore.loadHistory() on startup so no persistHistory can run against an unloaded store.
  3. src-tauri/src/config.rsUploadHistory::save writes to upload_history.json.tmp then atomic-renames over the target. A crash or partial write hitting the tempfile leaves the real history file intact.

Test plan

  • CI vitest run (local Win + Node 20.18 hits the known dev-env issue — CI is the source of truth)
  • Build app, simulate load failure by corrupting %APPDATA%\autonomi\ant-gui\upload_history.json to invalid JSON. Launch app → confirm the Files table is empty AND upload_history.json is not overwritten when a new upload completes.
  • With a valid history: launch, complete an upload, confirm new entry persisted and old entries preserved.
  • Confirm "Clear history" still works (load must succeed first, so the guard does not fire).

🤖 Generated with Claude Code

Two customer reports after 0.7.0 of the app "deleting/resetting the
datamap storage dir" — every prior datamap row vanishes from the Files
table, even though the `.datamap` files themselves are still on disk in
`%APPDATA%\autonomi\ant-gui\`.

Root cause: `stores/files.ts::loadHistory` swallowed any error from
`load_upload_history` and left `state.files = []` while setting
`historyLoaded = true`. The very next `persistHistory()` call (upload
complete, row remove, or Clear history) rebuilt from the empty array
and wrote `{"entries": []}` over the on-disk file, orphaning every
prior datamap.

Three defences:

1. `stores/files.ts` — track `historyLoadFailed`. When set,
   `persistHistory` is a no-op and logs a warning. Fail-closed: if we
   can't read the file we never overwrite it.

2. `app.vue` — await `filesStore.loadHistory()` on startup so no
   persistHistory can run before the load resolves.

3. `src-tauri/src/config.rs` — `UploadHistory::save` writes to a
   tempfile then atomic-renames over the target. A crash or partial
   write hitting the tempfile leaves the real history file intact.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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