Desktop app settings can be lost or reset: app_storage.json is rewritten without any locking

I use the Antigravity desktop app 2.26.0 on Windows 11. While checking why a setting I had changed was not taking effect, I looked at how the app saves its settings, and found a race that can lose settings or reset all of them.

The app keeps its settings in %APPDATA%\Antigravity\app_storage.json. On my machine that file is 100 KB with 190 keys. Besides settings such as autoCheckForUpdates, keepComputerAwake and runInBackground, it holds my comments (54 KB) and the layout of every conversation I have opened (172 keys, never cleaned up).

How the app writes it, from the app’s own dist/storage.js in resources\app.asar:

  • Every change reads the whole file, edits it in memory, and writes the whole file back in place.
  • Nothing orders two changes that happen at the same time, and the write is not done through a temporary file and a rename.
  • Changing the zoom with Ctrl and the mouse wheel starts one such write per wheel tick, without waiting for the previous one. The UI saves its own state through the same path.

I measured it two ways.

  1. While an agent was working, the app rewrote this 100 KB file 5 times in 90 seconds.
  2. I ran the app’s own read-edit-write logic against a test copy of the file, with 8 zoom changes and 1 UI change arriving together, 50 times:
Result Trials
At least one change lost 50 of 50
File left as invalid JSON 19 of 50
My paused-updates setting (autoCheckForUpdates: false) gone 21 of 50

The invalid JSON happens when a shorter write lands over a longer one and leaves the old tail behind. When the app next reads an invalid file, it treats it as empty, so every setting silently returns to its default. A crash or power loss in the middle of a write would do the same.

What I’d expect:

  • Write changes one at a time, in order.
  • Write to a temporary file and rename it over the old one, so the file is always either the old version or the new one.
  • Keep a copy in memory, so a zoom change does not reread 100 KB from disk.
  • Keep UI layout and comments apart from settings, and remove layout entries for conversations that no longer exist.

I have not seen my settings reset in normal use that I could tie to this. But I did change autoCheckForUpdates on purpose, and that is exactly the kind of setting this race can silently undo.

@Iamemily2050

I checked %APPDATA%\Antigravity\app_storage.json on my Windows 10 Pro box (2.26.0) after reading your post, and the payload grows much worse over time.

Mine is currently 676.4 KB (692,629 bytes) across 185 keys. Out of that:

  • comments alone is 628.5 KB (90.7% of the file) - a single stringified JSON blob holding files, artifacts, diffs, and drafts.
  • 160 keys (~24.3 KB) are old antigravity-multi-conversation-layout-v3-* window states from closed conversations.
  • Actual preferences (zoomLevel) take up 5 bytes.

Because StorageManager.updateItems() in dist/storage.js pretty-prints the entire object (JSON.stringify(currentItems, null, 2)) and flushes all 676 KB in place on every tick, the race window scales linearly with how many artefact comments and diffs you have accumulated.

Even worse, if an overlapping read in getRawItems() hits the file mid-flush, JSON.parse throws and drops into:

catch (e) {
    console.error('Error reading storage items:', e);
    return {};
}

updateItems() then merges the single incoming key (like a mousewheel zoom tick) onto that empty {} object and writes it back to disk, wiping not just your preferences, but hundreds of kilobytes of review comments in a single tick.

Hi @Iamemily2050,

Could you please few details:

  • The exact reproduction steps to reproduce this issue?
  • The Model you are using?

I’d include a two-window/process case in the regression tests, if those writers share this file. An in-process queue can still lose updates when a different process writes back a stale snapshot. The serialization needs to cover read, merge and replace together, or all writes need a single owner. Having each writer update a different key and checking that both survive would test lost updates separately from JSON validity; an atomic rename alone wouldn’t catch that case.