Skip to content

[BUG] Background AI model sync can overwrite externally updated QuickAdd settings #1749

Closed

Description

@hollowhemlock

[BUG] Background AI model sync can overwrite externally updated QuickAdd settings

Describe the bug

QuickAdd 2.24.2 retains the complete contents of data.json in memory. A successful background AI model sync updates the in-memory provider models and ai.lastModelAutoSyncAt, then the settings-store subscriber serializes the complete settings object back to data.json.

If a sync service or another process updates data.json after QuickAdd loads but before that save completes, the background save can silently replace the external changes with QuickAdd's stale in-memory values.

I reproduced this in an isolated Obsidian vault by changing a marker directly on disk after QuickAdd loaded. The subsequent automatic model sync reverted the marker while adding the discovered model and sync timestamp. No error or warning was produced.

To Reproduce

I used a disposable local OpenAI-compatible endpoint so no real provider or API key was involved.

  1. Start Obsidian with QuickAdd 2.24.2 enabled.

  2. Configure QuickAdd with:

    • Disable AI & online features: off
    • One provider with Auto-sync models: on
    • Provider endpoint: http://127.0.0.1:43179
    • Model source: provider API
    • Existing model: mock-model-v1
    • No ai.lastModelAutoSyncAt value
  3. Have the endpoint return the following from /v1/models:

    {"object":"list","data":[{"id":"mock-model-v2","context_length":32768}]}
  4. Add a recognizable value to the saved settings, such as:

    "globalVariables": {
      "syncMarker": "device-b-stale"
    }
  5. Reload QuickAdd so it loads that value into memory and schedules its startup model sync.

  6. Before the model sync completes, externally edit data.json without reloading QuickAdd:

    "globalVariables": {
      "syncMarker": "device-a-newer"
    }
  7. Wait for the automatic model sync and its debounced settings save.

  8. Read data.json again.

For deterministic test timing, run this through Obsidian's eval command before reloading QuickAdd:

(() => {
  window.__quickAddOriginalSetTimeout = window.setTimeout;
  window.setTimeout = (callback, delay, ...args) =>
    window.__quickAddOriginalSetTimeout(
      callback,
      delay === 5000 ? 30000 : delay,
      ...args,
    );
  return true;
})()

Reload QuickAdd, then immediately restore the original function:

(() => {
  window.setTimeout = window.__quickAddOriginalSetTimeout;
  delete window.__quickAddOriginalSetTimeout;
  return true;
})()

This changes only the startup delay from 5 seconds to 30 seconds. No QuickAdd source, model-sync logic, or save logic is modified. A slow provider response or appropriately timed external sync creates the same interval in normal operation.

Observed result

Phase syncMarker Models lastModelAutoSyncAt SHA-256
QuickAdd's loaded baseline device-b-stale mock-model-v1 absent 7FA469D9E3DB4C48115D4738D733E2D653A1D96B8EF235973102B57D9A57DD20
External edit on disk device-a-newer mock-model-v1 absent 0EF2C257DC49CD2B966AA9D6BC13BB18590A19095409A4AC67CE460ED4FF07D2
After automatic model sync device-b-stale mock-model-v1, mock-model-v2 1788982813069 7FA87167F65EC0DE44A6457F02011AF10C0E6F0F7E6B0C2F21BBF1E9A8DB044D

The model and timestamp changes confirm that automatic model sync caused the final save. The externally written device-a-newer value was silently replaced by the stale device-b-stale value held in memory. dev:errors reported no errors.

Expected behavior

A background metadata or model-discovery update should not silently overwrite settings that changed externally after QuickAdd loaded.

QuickAdd could detect that data.json changed before a whole-file save and preserve or report the conflict. Another option would be to avoid storing frequently changing operational metadata in the same synchronized object as user-authored choices and settings.

Obsidian Debug Info

SYSTEM INFO:
	Obsidian version: 1.13.7
	Installer version: 1.13.7
	Operating system: Windows 11 Pro 10.0.26200
	Login status: logged in
	Language: en
	Catalyst license: insider
	Insider build toggle: off
	Live preview: on
	Base theme: adapt to system
	Community theme: none
	Snippets enabled: 0
	Restricted mode: off
	Plugins installed: 1
	Plugins enabled: 1
		1: QuickAdd v2.24.2

Screenshots

Not applicable. The before-and-after values and hashes above capture the behavior.

Environment

  • Obsidian version: 1.13.7 (installer 1.13.7)
  • QuickAdd version: 2.24.2
  • Operating system: Windows 11 Pro 10.0.26200
  • Other plugins enabled: none
  • Theme: default/adapt to system
  • Sync service: not involved in the isolated reproduction

Console Logs

No console or runtime error was captured. The operation completed successfully but persisted stale settings.

Mobile

Not tested.

Additional context

Related: #292 discusses settings not reloading after sync and was closed as an expected limitation. This report provides a reproduction of a background model-sync save overwriting newer on-disk settings, even without a user editing QuickAdd settings on the stale instance. Restarting after the overwrite does not recover the overwritten value.

2.25.0 source verification: Compared the fetched release tag 2.25.0 (30b8a001) with 2.24.2. src/main.ts, src/settingsStore.ts, and src/ai/modelSyncService.ts are byte-for-byte unchanged, so the affected save path remains present in 2.25.0. This is source-level verification only; the runtime reproduction, debug information, and hashes above were captured on 2.24.2, and the reproduction has not been rerun on 2.25.0.

The local reproduction isolates QuickAdd's behavior from sync-provider conflict resolution. In a multi-device vault, the external edit corresponds to a newer data.json arriving from another device while QuickAdd remains loaded. Whether a particular sync provider preserves a conflict copy or propagates the overwritten file is provider- and timing-dependent.

Relevant implementation details in 2.24.2:

  • src/main.ts loads settings once and stores the complete object in memory.
  • Store changes schedule a debounced saveData(this.settings), which rewrites the complete file.
  • src/ai/modelSyncService.ts merges discovered models into the in-memory store and updates lastModelAutoSyncAt after any successful provider refresh.
  • No external data.json change listener, disk revision comparison, or conflict-aware save was found.

Recent settings history in the affected real vault also showed frequent writes caused only by operational metadata: eight of the ten most recent data.json versions changed only ai.lastModelAutoSyncAt; another changed the model list and timestamp; and a plugin update changed version.

AI assistance was used for source inspection, reproduction design, and drafting; I reviewed the report and the behavior was reproduced in Obsidian as documented above.

Activity

  1. chhoumann commented on Sep 12, 2026

    @chhoumann
    Owner

    Thanks for the careful repro and the before/after hashes. Background model auto-sync was updating settings in memory, and a full-file save could overwrite a newer on-disk data.json with that stale snapshot.

    Fixed in #1750 (d418f01f). Before saving, QuickAdd re-reads data.json and three-way-merges local changes onto disk when the file has moved. Provider and model lists merge by identity, so concurrent edits on those lists are less likely to clobber each other.

    Obsidian's plugin loadData / saveData API has no compare-and-swap, so writers can still interleave in a very narrow window. Irreducible leaf conflicts still prefer the in-memory side.

    This will ship in the next release after 2.25.0.

  2. chhoumann commented on Sep 19, 2026

    @chhoumann
    Owner

    The fix from #1750 is in QuickAdd 2.26.0, released today. QuickAdd now re-reads data.json before each save and merges local changes into it when the file has changed. Thanks again for the repro.

  3. hollowhemlock commented on Sep 20, 2026

    @hollowhemlock
    Author

    Happy to help. Thanks for the feedback. I started with a hunch from one setting reversion tracked in git. LLMs certainly made it more digestible to reproduce. Really makes complicated things fixable on the fly instead of something to be tabled for later.

  4. chhoumann commented on Sep 21, 2026

    @chhoumann
    Owner

    For sure!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions