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

Open
opened 2026-11-07 16:34:57 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/5359
Author: @zapabob
Created: 11/5/2026
Status: 🔄 Open

Base: main ← Head: codex/fix-chat-revision-recovery


📝 Commits (1)

  • 85e899f fix(gui): recover chat revisions from committed files

📊 Changes

2 files changed (+53 additions, -7 deletions)

View changed files

📝 apps/host/server/chat-store.mjs (+4 -7)
📝 apps/host/tests/chat-store.test.mjs (+49 -0)

📄 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 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.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/5359 **Author:** [@zapabob](https://github.com/zapabob) **Created:** 11/5/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `codex/fix-chat-revision-recovery` --- ### 📝 Commits (1) - [`85e899f`](https://github.com/Niko1221/Strata/commit/85e899f9a71c18f9194c3b0cba733d938b760f21) fix(gui): recover chat revisions from committed files ### 📊 Changes **2 files changed** (+53 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `apps/host/server/chat-store.mjs` (+4 -7) 📝 `apps/host/tests/chat-store.test.mjs` (+49 -0) </details> ### 📄 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#5402
No description provided.