[GH-ISSUE #1933] [Feature]: add warm storage cache and debounced flush parity for Tauri storage #948

Closed
opened 2026-10-21 05:23:58 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @Xelvanis on GitHub (Jun 2, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/1933

Originally assigned to: @SpicyMarinara on GitHub.

What problem does this solve?

The refactor storage path still differs from legacy in a way that can explain broad lag or slow responsiveness even after narrow projection fixes.

Legacy 1.6.1 file-native storage keeps table snapshots warm in memory and persists dirty tables on a debounce. Refactor FileStorage mostly reads/parses collection files per operation and writes pretty JSON immediately for patch/update/delete. That leaves repeated UI reads, metadata patches, tracker updates, imports, deletes, and post-generation writes exposed to disk and JSON parse/write cost.

Proposed behavior

Add a storage-level performance path that restores the important legacy behavior without breaking the Tauri/refactor storage contract:

  • keep hot collection rows or indexes warm in Rust storage after startup/read;
  • serve repeated list, get, filtered list, projected get/list, message page/count/id reads from the cache or an equivalent index when safe;
  • mark collections dirty on writes and flush them with bounded debounce/safety timing;
  • keep atomic write, backup recovery, corrupt-file preservation, and explicit collection validation;
  • keep embedded Tauri and remote /api/invoke behavior identical;
  • add timing proof before and after for cold/warm reads and write-heavy paths.

This can start as a timing harness and design issue before changing persistence semantics.

Evidence

Legacy static evidence:

  • packages/server/src/db/file-backed-store.ts:148-:150 defines SAVE_DEBOUNCE_MS = 750 and SAFETY_SAVE_MS = 10_000.
  • packages/server/src/db/file-backed-store.ts:783 keeps tables in Map<string, Row[]>.
  • packages/server/src/db/file-backed-store.ts:980-:988 marks dirty tables and schedules debounced flush.
  • packages/server/src/db/file-backed-store.ts:1217-:1226 writes only dirty table snapshots during save.
  • packages/server/src/db/file-backed-store.ts:1243-:1251 installs safety/before-exit flushes.

Refactor static evidence:

  • src-tauri/crates/storage/src/lib.rs:16-:29 stores only root path plus lock; no warm table cache or durable id index is visible.
  • src-tauri/crates/storage/src/lib.rs:469-:516 reads collection files from disk for full/filtered reads.
  • src-tauri/crates/storage/src/lib.rs:923-:930 writes full pretty JSON collections atomically.
  • src-tauri/crates/storage/src/lib.rs:205-:245 patch/update paths read the collection, mutate, then write the collection immediately.
  • src-tauri/crates/storage/src/lib.rs:933-:1000 has an append optimization for new chats/messages, but patch/update/delete still rewrite collections.

Refactor has important targeted optimizations already, including projected gets, projected lists, message id/count/page readers, and remote/embedded storage helper parity. This issue is about the remaining broad storage backend shape.

Expected owner or impact area

  • App shell, navigation, startup, or providers
  • Catalog resources: chats, characters, personas, lorebooks, presets, connections, agents, gallery, or knowledge
  • Chat mode
  • Roleplay mode
  • Game mode
  • Shared mode UI
  • Runtime systems: generation, world-state, visuals, tracker, or haptics
  • Professor Mari or shell tools
  • React-free engine behavior, contracts, agents, or capability ports
  • Shared API wrapper or remote runtime routing
  • Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime
  • Docs, contributor workflow, or templates

Refactor branch considerations

This is user-data and persistence-sensitive work. Required proof should include:

  • cold and warm timing harness for storage_list, projected storage_get, paged message reads, writes, deletes, and metadata patches;
  • crash/restart behavior with dirty data and safety flush timing;
  • corrupt primary and backup recovery;
  • remote /api/invoke parity;
  • import/export and profile migration compatibility;
  • negative controls for unsupported collection names and malformed rows;
  • native Tauri proof, not only standalone Vite proof.

Alternatives considered

Continue adding narrow streaming/projection fast paths. Those help specific commands and should continue where they are small, but they do not restore legacy warm-read/debounced-write behavior across the whole storage surface.

Move directly to a physical schema split for messages/swipes. That may still be valuable for large swipe histories, but it is a larger storage migration and does not address repeated full-file reads/writes for other collections.

Additional context

Related but not duplicate:

  • #1885, #1887, #1888, and #1919 are closed narrow storage read fixes.
  • #1932 tracks paged message reads parsing full rows before projection.
  • #1923 discusses splitting message swipe storage, which is a narrower physical layout decision.

Template check

Please uncheck the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @Xelvanis on GitHub (Jun 2, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/1933 Originally assigned to: @SpicyMarinara on GitHub. ## What problem does this solve? The refactor storage path still differs from legacy in a way that can explain broad lag or slow responsiveness even after narrow projection fixes. Legacy 1.6.1 file-native storage keeps table snapshots warm in memory and persists dirty tables on a debounce. Refactor `FileStorage` mostly reads/parses collection files per operation and writes pretty JSON immediately for patch/update/delete. That leaves repeated UI reads, metadata patches, tracker updates, imports, deletes, and post-generation writes exposed to disk and JSON parse/write cost. ## Proposed behavior Add a storage-level performance path that restores the important legacy behavior without breaking the Tauri/refactor storage contract: - keep hot collection rows or indexes warm in Rust storage after startup/read; - serve repeated `list`, `get`, filtered list, projected get/list, message page/count/id reads from the cache or an equivalent index when safe; - mark collections dirty on writes and flush them with bounded debounce/safety timing; - keep atomic write, backup recovery, corrupt-file preservation, and explicit collection validation; - keep embedded Tauri and remote `/api/invoke` behavior identical; - add timing proof before and after for cold/warm reads and write-heavy paths. This can start as a timing harness and design issue before changing persistence semantics. ## Evidence Legacy static evidence: - `packages/server/src/db/file-backed-store.ts:148`-`:150` defines `SAVE_DEBOUNCE_MS = 750` and `SAFETY_SAVE_MS = 10_000`. - `packages/server/src/db/file-backed-store.ts:783` keeps tables in `Map<string, Row[]>`. - `packages/server/src/db/file-backed-store.ts:980`-`:988` marks dirty tables and schedules debounced flush. - `packages/server/src/db/file-backed-store.ts:1217`-`:1226` writes only dirty table snapshots during save. - `packages/server/src/db/file-backed-store.ts:1243`-`:1251` installs safety/before-exit flushes. Refactor static evidence: - `src-tauri/crates/storage/src/lib.rs:16`-`:29` stores only root path plus lock; no warm table cache or durable id index is visible. - `src-tauri/crates/storage/src/lib.rs:469`-`:516` reads collection files from disk for full/filtered reads. - `src-tauri/crates/storage/src/lib.rs:923`-`:930` writes full pretty JSON collections atomically. - `src-tauri/crates/storage/src/lib.rs:205`-`:245` patch/update paths read the collection, mutate, then write the collection immediately. - `src-tauri/crates/storage/src/lib.rs:933`-`:1000` has an append optimization for new chats/messages, but patch/update/delete still rewrite collections. Refactor has important targeted optimizations already, including projected gets, projected lists, message id/count/page readers, and remote/embedded storage helper parity. This issue is about the remaining broad storage backend shape. ## Expected owner or impact area - [ ] App shell, navigation, startup, or providers - [x] Catalog resources: chats, characters, personas, lorebooks, presets, connections, agents, gallery, or knowledge - [x] Chat mode - [x] Roleplay mode - [x] Game mode - [x] Shared mode UI - [x] Runtime systems: generation, world-state, visuals, tracker, or haptics - [ ] Professor Mari or shell tools - [ ] React-free engine behavior, contracts, agents, or capability ports - [x] Shared API wrapper or remote runtime routing - [x] Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime - [ ] Docs, contributor workflow, or templates ## Refactor branch considerations This is user-data and persistence-sensitive work. Required proof should include: - cold and warm timing harness for `storage_list`, projected `storage_get`, paged message reads, writes, deletes, and metadata patches; - crash/restart behavior with dirty data and safety flush timing; - corrupt primary and backup recovery; - remote `/api/invoke` parity; - import/export and profile migration compatibility; - negative controls for unsupported collection names and malformed rows; - native Tauri proof, not only standalone Vite proof. ## Alternatives considered Continue adding narrow streaming/projection fast paths. Those help specific commands and should continue where they are small, but they do not restore legacy warm-read/debounced-write behavior across the whole storage surface. Move directly to a physical schema split for messages/swipes. That may still be valuable for large swipe histories, but it is a larger storage migration and does not address repeated full-file reads/writes for other collections. ## Additional context Related but not duplicate: - #1885, #1887, #1888, and #1919 are closed narrow storage read fixes. - #1932 tracks paged message reads parsing full rows before projection. - #1923 discusses splitting message swipe storage, which is a narrower physical layout decision. ## Template check Please uncheck the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
Author
Owner

@SpicyMarinara commented on GitHub (Jun 2, 2026):

Implemented the first storage-shape fix on refactor in commit 0a6fc394 (Add warm storage cache and debounced flush).

What changed:

  • Added an in-process warm collection cache to FileStorage.
  • Full collection reads now populate the cache; hot projected reads, get, message counts, message IDs, and paged message reads can serve from cached rows once warm.
  • Row-level mutations now update cached rows and mark collections dirty instead of synchronously rewriting the full pretty JSON collection every time.
  • Dirty collections flush through the existing atomic write/backup path after a bounded debounce.
  • Immediate durability is preserved for recovery and profile/import replacement paths.
  • Managed backup/profile ZIP creation explicitly flushes pending dirty storage before copying files.

Verification run locally:

  • git diff --check
  • cargo check --manifest-path src-tauri/Cargo.toml
  • pnpm typecheck
  • pnpm check:architecture
  • pnpm check:unused
  • pnpm build

Leaving this open for now because the issue also asks for timing proof and broader cold/warm native measurements.

<!-- gh-comment-id:4602293074 --> @SpicyMarinara commented on GitHub (Jun 2, 2026): Implemented the first storage-shape fix on `refactor` in commit `0a6fc394` (`Add warm storage cache and debounced flush`). What changed: - Added an in-process warm collection cache to `FileStorage`. - Full collection reads now populate the cache; hot projected reads, `get`, message counts, message IDs, and paged message reads can serve from cached rows once warm. - Row-level mutations now update cached rows and mark collections dirty instead of synchronously rewriting the full pretty JSON collection every time. - Dirty collections flush through the existing atomic write/backup path after a bounded debounce. - Immediate durability is preserved for recovery and profile/import replacement paths. - Managed backup/profile ZIP creation explicitly flushes pending dirty storage before copying files. Verification run locally: - `git diff --check` - `cargo check --manifest-path src-tauri/Cargo.toml` - `pnpm typecheck` - `pnpm check:architecture` - `pnpm check:unused` - `pnpm build` Leaving this open for now because the issue also asks for timing proof and broader cold/warm native measurements.
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
Pasta-Devs/Marinara-Engine#948
No description provided.