Skip to content

Incompatible operational state deletes every conversation without warning or backup #2357

Closed

Description

@Astro-Han

What happens

resetIncompatibleOperationalStateDatabase (packages/storage/src/operational-state-store.ts:67, added in #2122) deletes runtime.sqlite and its WAL/SHM sidecars whenever any of the eight tracked schema versions differs from the running build. It runs at apps/desktop/src/main/boot.ts:228, before any store opens, and reports the deletion as a single console.warn.

session_metadata lives in that database. Deleting it removes every conversation from the UI.

I hit this on a real profile: a production install at runtime schema 10, opened by a build at schema 11. All 40 sessions disappeared from the sidebar; the database dropped from 254 MB to 896 KB.

Why this is broader than "operational state"

The trigger is routine, not exceptional. hasCurrentOperationalSchema requires all eight schema versions to match exactly, in both directions — an upgrade and a downgrade are equally fatal. runtime alone was bumped 8 times in the last three months (4 of them between 2026-08-02 and 2026-08-06); session_metadata was bumped 15 times in six months. Any one of those bumps wipes the profile. For anyone tracking main or nightly builds, this is closer to "every update" than to "rare incompatible version".

The conversation text is not actually lost. sessions/<id>/session.jsonl survives untouched — I recovered full assistant messages from it after the reset. session_metadata is a projection over data that is still on disk. The truth is "the index can be rebuilt"; the code is written as "the data is disposable".

The same boot path holds two different standards. Twelve lines earlier, resolveDesktopStorageRoot gates a repair behind a confirmation dialog (confirmDesktopStorageRootRepair, boot.ts:216). The more destructive action — rmSync(..., { force: true }) with no backup, no prompt, no undo — runs silently right after it.

Suggested directions, cheapest first

  1. Rename instead of delete. Move the file to runtime.sqlite.incompatible-v<n> rather than rmSync. The no-migration policy is unchanged; the outcome becomes recoverable, and support can ask the user to hand the file back. This is a few lines.
  2. Reuse the gate that already exists. Route the reset through the same confirmation seam as the storage-root repair, so the user learns their history is about to be cleared before it happens.
  3. Rebuild the index. Repopulate session_metadata from sessions/*.jsonl, which is already the authority for message content. This removes the data-loss question rather than softening it.

Notes

#2122 describes this as "the requested no-migration policy", but the PR has no linked issue, review, or discussion, so the original requirement isn't recorded anywhere I can find. If the intent was specifically "conversations are expendable across versions", it would be worth writing that down — the current behaviour reads as an accident to anyone who loses a profile to it.

Activity

  1. Astro-Han commented on Aug 6, 2026

    @Astro-Han
    ContributorAuthor

    Claiming this.

    I confirmed the root cause: Desktop deletes the shared runtime.sqlite before the existing forward migrators can run. The database contains durable session and message state, so schema mismatch must never be handled by deleting the file.

    I’ll address this in two stages:

    1. Fix Incompatible operational state deletes every conversation without warning or backup #2357 with the smallest complete change:
      • remove the destructive reset path;
      • preflight all schema authorities in the storage owner before any migration runs;
      • allow older/equal schemas through the existing transactional forward migrations;
      • preserve the database and abort with an actionable error when any schema is newer or unknown;
      • replace the deletion contract test with data-preservation, mixed-version, and fail-closed coverage.
    2. Follow up separately with a downgrade-compatibility contract from a new safe baseline, using an explicit minimum-reader version and expand/contract schema evolution. This will not attempt reverse migrations or claim compatibility with already-released binaries that contain the destructive reset.

    The first PR will stay focused on stopping data loss and restoring normal upgrades; no database split, per-table reset, or automatic migration backup.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions