#5359 [GUI] recover chat revisions after an index write failure

closed · @zapabob · 0 comments · View on GitHub

BenchmarksMulti-GPUSecurityWindowsLinux

Description

## Problem and result

If a chat file is committed but the following index write fails, the save succeeds and the existing index remains valid JSON with the previous revision. On restart, the host trusts that stale entry for an already indexed chat. A second window saving with the old base revision can then overwrite the newer chat without preserving it as a conflict.

Recover the revision and list metadata from every committed chat envelope at startup. The same recovery also reports an indexed file that has become unreadable, without modifying its bytes.

## Related discussion

Related chat-persistence history: #5192. Searched open and closed issues and pull requests for chat-store revision and index recovery; no matching fix found. This is a focused persistence bug fix, with no new feature, dependency or storage-format change.

## Approach

Treat the individual chat files as authoritative and rebuild the in-memory index from them. Reuse the existing envelope validation, metadata extraction and damaged-file reporting. Atomic writes, conflict retention and the on-disk format remain unchanged.

Two regression tests cover an injected ENOSPC affecting only the index write after a successful chat commit, and corruption of a file already present in a valid index. The first also checks that restart recovers revision 2 and that an old window's subsequent save becomes revision 3 while preserving revision 2 in conflicts.

## Validation

Windows x64, Node v24.22.2. Upstream base: `9f7d977d220e9fdf2ec53cf2620cdadac1cfb24e`. Submitted code: `85e899f9a71c18f9194c3b0cba733d938b760f21`.

**Passed:**

- `node --test apps/host/tests/chat-store.test.mjs`: 13 passed, 0 failed after the fix. Includes the existing greater-than-10-MB restart fixture.
- `node --test --test-timeout=90000 apps/host/tests/chat-store-api.test.mjs`: 3 passed, 0 failed. Starts the real host with temporary profiles; covers a 12-MB chat across host restart, chat routes, and events between windows.
- `node --check apps/host/server/chat-store.mjs`, `node --check apps/host/tests/chat-store.test.mjs`, and `git diff --check`: passed.

**Failed:**

- Expected reproduction on the unchanged upstream implementation with the two new tests: 11 passed, 2 failed. The recovered revision was 1 instead of 2; a damaged indexed chat remained in the list. No failures observed after the fix in the checks above.

**Not run:**

- The complete host suite and interactive Tauri/WebView2 end-to-end checks.
- A large-history startup performance benchmark and macOS/Linux execution.
- Engine/backend builds: no engine or backend source is changed.

## Limits

Startup now reads and parses each chat file, so its cost grows with the total saved chat history. The existing large-chat tests exercise correctness but are not a startup performance benchmark. This prevents future revision recovery failures; it cannot recover a chat that was already overwritten without a retained conflict copy.

Related on this site

Quick links to related pages.