[PR #5192] [CLOSED] [GUI] Hotfix: Fixed an issue where chats could be trimmed and not stored #5339

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

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/5192
Author: @MohSakhaei
Created: 11/4/2026
Status: ❌ Closed

Base: main ← Head: hotfix/chat-store


📝 Commits (1)

  • 27b1e14 Fixed an issue where chats could be trimmed and not stored

📊 Changes

3 files changed (+74 additions, -46 deletions)

View changed files

📝 apps/host/src/lib/session-persist.ts (+35 -39)
📝 apps/host/src/lib/store.ts (+1 -1)
📝 apps/host/tests/session-persist.test.mjs (+38 -6)

📄 Description

The title must start with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other], for example "[Engine] fix decode stop on long prompts" or "[GUI] keep the model list after a tab switch".

Problem and result

a chat with agent tool calls that grew past 1.5M of saved JSON silently lost its
oldest messages after each restart, and an older chat could disappear from the list altogether. Since the
saved list is the only place the app keeps chats (the load reads the same strata.sessions.v1 key back),
each restart trimmed the chat again: a three-question chat came back with one question and an answer whose
question was gone. Before this change serializeSession dropped the oldest messages in halves whenever a
chat passed MAX_SESSION_CHARS, and flush left whole chats out of the saved copy whenever the list passed
MAX_TOTAL_CHARS. 0.2.9 wrote the list whole (a quota failure kept the last good write; nothing was deleted),
so the loss is a 0.2.10 regression from the write-cap part of 1298a397 (#3604, #3603). The coalescing and
the write-per-second that fixed the renderer growth (#3604, #3603) are kept; only the deleting part is
replaced: oversized fields (mostly tool results) are clipped, and if the whole list still does not fit, the
oldest unpinned chats' fields are clipped harder (20k). Messages and chats are never removed, and a failed
write still leaves the last good copy.

none

Approach

The trimmed copy looked like a cache in the comments ("the saved list is a cache, not the source
of truth"), but there is no other copy to fall back on, so shortening it is permanent loss. The bytes that
matter to a person — questions and answers — are small; tool results are what grow. So the saved copy now
loses field length instead of entries: 200k per field as before, then a hard 20k per field for the oldest
unpinned chats, and only while the list is over budget; pinned and newest chats shrink last. The stored
format is unchanged (still a JSON array under strata.sessions.v1), so no migration is needed and older
builds still read it. Chats already trimmed by 0.2.10 cannot be restored by this change; the agent's own
session history under the data folder may still hold their text.

Validation

(Windows x64, Node v24.14.1, revision 27b1e14c; base ffa80d73 = v0.2.10):

Passed:

- `node --test tests/session-persist.test.mjs` — 6 pass, 0 fail.
- `npm test` (apps/host) — 1331 pass, 2 fail (below), Harness-dependent tests skipped (no STRATA_HARNESS_DIR).
- `npm run build` (apps/host) — built in ~5 s, no errors.
- The two new tests run against the base revision v0.2.10 in a temporary worktree: both fail there.
  The message test loses 35 of 40 messages and drops a whole chat; the reload test comes back with
  only the last two questions ("how much do we know about Mars' moons?", "and their shapes?") — the
  reported symptom. On this revision both pass.

Failed:

  • chat-shell.test.mjs "native file actions use explicit argument arrays and reject traversal and
    symlinks" and model-directory.test.mjs "existing flat and Strata-layout weights are found…" —
    EPERM: symlink; this Windows setup cannot create symlinks. Both fail identically on the base
    revision ffa80d73 without this change, so they are pre-existing and unrelated.

Not run:

  • Desktop (Tauri) end-to-end and a real app restart on a real WebView2 profile: not done; unverified
    is that a live 0.2.9-upgraded profile reads back correctly after the change (the format is unchanged).
    • A real three-question chat in the running app: reproduced at the store level by the new test, not
      by clicking through the app.

Limits

chats already trimmed by 0.2.10 stay trimmed — this change prevents further loss, it does not
recover past ones. In an over-budget list the oldest chats' tool results can show
"[shortened in the saved copy]" after a restart; their questions and answers stay whole. If the whole list
still cannot fit after everything shrinks, the storage write throws, the quota catch keeps the last good
copy, and only the newest unsaved turn is at risk — as in 0.2.9.


🔄 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/5192 **Author:** [@MohSakhaei](https://github.com/MohSakhaei) **Created:** 11/4/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `hotfix/chat-store` --- ### 📝 Commits (1) - [`27b1e14`](https://github.com/Niko1221/Strata/commit/27b1e14c7d3979c7558ac00080e91d813c0c597f) Fixed an issue where chats could be trimmed and not stored ### 📊 Changes **3 files changed** (+74 additions, -46 deletions) <details> <summary>View changed files</summary> 📝 `apps/host/src/lib/session-persist.ts` (+35 -39) 📝 `apps/host/src/lib/store.ts` (+1 -1) 📝 `apps/host/tests/session-persist.test.mjs` (+38 -6) </details> ### 📄 Description **The title must start with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other], for example "[Engine] fix decode stop on long prompts" or "[GUI] keep the model list after a tab switch".** <!-- Read CONTRIBUTING.md first. Lead with the problem and the result, not a file-by-file list. Placeholders below are not test results: replace them with what you observed, or write "none". --> ## Problem and result a chat with agent tool calls that grew past 1.5M of saved JSON silently lost its oldest messages after each restart, and an older chat could disappear from the list altogether. Since the saved list is the only place the app keeps chats (the load reads the same `strata.sessions.v1` key back), each restart trimmed the chat again: a three-question chat came back with one question and an answer whose question was gone. Before this change `serializeSession` dropped the oldest messages in halves whenever a chat passed `MAX_SESSION_CHARS`, and `flush` left whole chats out of the saved copy whenever the list passed `MAX_TOTAL_CHARS`. 0.2.9 wrote the list whole (a quota failure kept the last good write; nothing was deleted), so the loss is a 0.2.10 regression from the write-cap part of 1298a397 (#3604, #3603). The coalescing and the write-per-second that fixed the renderer growth (#3604, #3603) are kept; only the deleting part is replaced: oversized fields (mostly tool results) are clipped, and if the whole list still does not fit, the oldest unpinned chats' fields are clipped harder (20k). Messages and chats are never removed, and a failed write still leaves the last good copy. ## Related discussion none ## Approach The trimmed copy looked like a cache in the comments ("the saved list is a cache, not the source of truth"), but there is no other copy to fall back on, so shortening it is permanent loss. The bytes that matter to a person — questions and answers — are small; tool results are what grow. So the saved copy now loses field length instead of entries: 200k per field as before, then a hard 20k per field for the oldest unpinned chats, and only while the list is over budget; pinned and newest chats shrink last. The stored format is unchanged (still a JSON array under `strata.sessions.v1`), so no migration is needed and older builds still read it. Chats already trimmed by 0.2.10 cannot be restored by this change; the agent's own session history under the data folder may still hold their text. ## Validation (Windows x64, Node v24.14.1, revision 27b1e14c; base ffa80d73 = v0.2.10): **Passed:** - `node --test tests/session-persist.test.mjs` — 6 pass, 0 fail. - `npm test` (apps/host) — 1331 pass, 2 fail (below), Harness-dependent tests skipped (no STRATA_HARNESS_DIR). - `npm run build` (apps/host) — built in ~5 s, no errors. - The two new tests run against the base revision v0.2.10 in a temporary worktree: both fail there. The message test loses 35 of 40 messages and drops a whole chat; the reload test comes back with only the last two questions ("how much do we know about Mars' moons?", "and their shapes?") — the reported symptom. On this revision both pass. **Failed:** - `chat-shell.test.mjs` "native file actions use explicit argument arrays and reject traversal and symlinks" and `model-directory.test.mjs` "existing flat and Strata-layout weights are found…" — `EPERM: symlink`; this Windows setup cannot create symlinks. Both fail identically on the base revision ffa80d73 without this change, so they are pre-existing and unrelated. **Not run:** - Desktop (Tauri) end-to-end and a real app restart on a real WebView2 profile: not done; unverified is that a live 0.2.9-upgraded profile reads back correctly after the change (the format is unchanged). - A real three-question chat in the running app: reproduced at the store level by the new test, not by clicking through the app. ## Limits chats already trimmed by 0.2.10 stay trimmed — this change prevents further loss, it does not recover past ones. In an over-budget list the oldest chats' tool results can show "[shortened in the saved copy]" after a restart; their questions and answers stay whole. If the whole list still cannot fit after everything shrinks, the storage write throws, the quota catch keeps the last good copy, and only the newest unsaved turn is at risk — as in 0.2.9. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 16:34:28 +07:00
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#5339
No description provided.