fix(files): never overwrite upload_history.json on load failure#95
Open
Nic-dorman wants to merge 1 commit into
Open
fix(files): never overwrite upload_history.json on load failure#95Nic-dorman wants to merge 1 commit into
Nic-dorman wants to merge 1 commit into
Conversation
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>
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
.datamapfiles themselves are still on disk in%APPDATA%\autonomi\ant-gui\.Root cause:
stores/files.ts::loadHistoryswallowed any error fromload_upload_historyand leftstate.files = []while still settinghistoryLoaded = true. The very nextpersistHistory()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
stores/files.ts— trackhistoryLoadFailed. When set,persistHistoryis a no-op and logs a warning. Fail-closed: if we can't read the file we never overwrite it.app.vue—await filesStore.loadHistory()on startup so nopersistHistorycan run against an unloaded store.src-tauri/src/config.rs—UploadHistory::savewrites toupload_history.json.tmpthen atomic-renames over the target. A crash or partial write hitting the tempfile leaves the real history file intact.Test plan
%APPDATA%\autonomi\ant-gui\upload_history.jsonto invalid JSON. Launch app → confirm the Files table is empty ANDupload_history.jsonis not overwritten when a new upload completes.🤖 Generated with Claude Code