[PR #2509] [CLOSED] Add chat swipe append fast path #5629

Closed
opened 2026-10-22 04:17:57 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/2509
Author: @Xelvanis
Created: 6/6/2026
Status: ❌ Closed

Base: refactor ← Head: perf/issue-2493-add-swipe-fast-path


📝 Commits (2)

  • c2c4b92 Add chat swipe append fast path
  • d4571a0 Harden swipe append transaction checks

📊 Changes

3 files changed (+993 additions, -7 deletions)

View changed files

📝 src-tauri/crates/storage/src/lib.rs (+643 -0)
📝 src-tauri/src/commands/storage/chats.rs (+204 -7)
📝 src-tauri/src/commands/storage/message_swipes.rs (+146 -0)

📄 Description

Linked issue

Part of #2493

Why this change

  • Regenerating assistant messages still paid the old full atomic rewrite cost for sidecar-backed swipes. Legacy execution only inserted the new swipe row and patched the parent message row, so this keeps the refactor storage path closer to that granular behavior while preserving fallback cleanup.

What changed

  • Added a storage primitive that stages append-only collection writes together with clean collection replacements, then commits or rolls back the whole set.
  • Updated chat_message_add_swipe to fast-path sidecar-backed messages by replacing the parent messages row, appending only new message-swipes rows, and applying chat memory invalidation in the same transaction when active content changes.
  • Kept the full replacement writer for embedded swipes, dirty cached collections, missing expected rows, and non-canonical legacy sidecars.
  • Added focused Rust coverage for canonical sidecar gating, trimmed legacy sidecar cleanup, active add-swipe memory pruning, cache fallback, rollback, and temp cleanup.

Refactor impact

Primary owner:

Rust storage and chat storage commands.

Impact areas reviewed:

  • FileStorage append/update transaction staging, rollback, and cache refresh.
  • Message swipe sidecar materialization and persistence shape.
  • chat_message_add_swipe active/inactive semantics and legacy silent compatibility.
  • Chat memory pruning when an active assistant message changes.
  • Legacy sidecar rows that match only after trimming and must fall back to full cleanup.

Boundary notes:

  • Changes stay in src-tauri Rust storage/command modules.
  • No React, TypeScript engine, shared API, command registration, or remote-runtime dispatch changes.
  • The new fast path returns None on unsafe storage shape so the existing full replacement path remains the correctness fallback.

Pressure points touched:

  • Rust storage command helpers only.
  • Did not touch ModeSurface, GameSurface, shared mode UI, src-tauri/src/lib.rs command registration, or import modules.

Validation

  • Matching validation command passes locally (for example pnpm typecheck, pnpm build, pnpm check:architecture, pnpm check:docs, or full pnpm check when warranted)
  • Full pnpm check passes before PR push/handoff
  • Human/manual validation completed by contributor or reviewer

Manual verification notes

Commands run locally:

  • cargo test --manifest-path src-tauri/Cargo.toml -p marinara-engine message_swipes_append_cleans_trimmed_legacy_sidecar_rows --lib
  • cargo test --manifest-path src-tauri/Cargo.toml -p marinara-engine message_swipes --lib
  • cargo test --manifest-path src-tauri/Cargo.toml -p marinara-storage append_many --lib
  • cargo check --manifest-path src-tauri/Cargo.toml --workspace
  • rustfmt --edition 2021 --check src-tauri/crates/storage/src/lib.rs src-tauri/src/commands/storage/chats.rs src-tauri/src/commands/storage/message_swipes.rs
  • git diff --check
  • pnpm check:architecture
  • pnpm check

Durable test rationale:

  • This changes a risky storage invariant: fast append must not preserve stale or malformed sidecar rows that the full replacement path would canonicalize.
  • Existing command output alone would not pin the fallback condition for legacy trimmed sidecar rows.
  • The added tests are narrow Rust owner tests around sidecar canonicality, append cleanup, and storage transaction behavior.

Native Tauri large-chat timing:

  • Rerun against the Phase 2 storage diff through the native Tauri/WebView2 QA path.
  • chat_message_add_swipe: 358.9ms -> 266.4ms on the 5k-message fixture.
  • Regenerate two-step total: 998.9ms -> 897.4ms.
  • The follow-up patchChatMessageExtra write still costs 631.0ms, so Phase 3 remains the clearest next latency win.
  • Broad refresh cost is effectively unchanged at about 190-201ms per scheduled refresh.

Remaining proof gap:

  • This timing pass did not run a live LM Studio generation stream.

Feature Discoverability

Check exactly one:

  • Updated src/features/shell/discovery/ because this PR adds or materially changes a user-discoverable feature, workflow, setting, mode, panel, import path, agent, media capability, or advanced tool.
  • N/A because this PR is only a bugfix, refactor, test, docs, internal wiring, visual polish, copy edit, or compatibility fix and does not add a new thing users need to find.

Reason:

  • Internal storage performance/correctness path only; no new user-discoverable feature or workflow.

Docs and release impact

  • No docs changes needed
  • Updated README.md
  • Updated CONTRIBUTING.md
  • Updated docs/developer/
  • Updated repo skills or AGENTS.md
  • Confirmed this PR does not restore old staging/package-workspace/release claims

UI evidence

No UI screenshots or recordings. This PR changes Rust storage behavior only.

Summary by CodeRabbit

  • Improvements
    • Optimized message swipe handling for faster append operations when certain conditions are met, avoiding full message replacement in common cases
    • Refined chat memory updates to invalidate only when visible content actually changes, improving performance
    • Added validation checks to ensure swipe data integrity during storage operations

🔄 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/Pasta-Devs/Marinara-Engine/pull/2509 **Author:** [@Xelvanis](https://github.com/Xelvanis) **Created:** 6/6/2026 **Status:** ❌ Closed **Base:** `refactor` ← **Head:** `perf/issue-2493-add-swipe-fast-path` --- ### 📝 Commits (2) - [`c2c4b92`](https://github.com/Pasta-Devs/Marinara-Engine/commit/c2c4b924f258149dd43a88cde10475b773a0daef) Add chat swipe append fast path - [`d4571a0`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d4571a0f18c6fcde9b7c7bc28184916eb7835837) Harden swipe append transaction checks ### 📊 Changes **3 files changed** (+993 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `src-tauri/crates/storage/src/lib.rs` (+643 -0) 📝 `src-tauri/src/commands/storage/chats.rs` (+204 -7) 📝 `src-tauri/src/commands/storage/message_swipes.rs` (+146 -0) </details> ### 📄 Description ## Linked issue Part of #2493 ## Why this change - Regenerating assistant messages still paid the old full atomic rewrite cost for sidecar-backed swipes. Legacy execution only inserted the new swipe row and patched the parent message row, so this keeps the refactor storage path closer to that granular behavior while preserving fallback cleanup. ## What changed - Added a storage primitive that stages append-only collection writes together with clean collection replacements, then commits or rolls back the whole set. - Updated `chat_message_add_swipe` to fast-path sidecar-backed messages by replacing the parent `messages` row, appending only new `message-swipes` rows, and applying chat memory invalidation in the same transaction when active content changes. - Kept the full replacement writer for embedded swipes, dirty cached collections, missing expected rows, and non-canonical legacy sidecars. - Added focused Rust coverage for canonical sidecar gating, trimmed legacy sidecar cleanup, active add-swipe memory pruning, cache fallback, rollback, and temp cleanup. ## Refactor impact Primary owner: Rust storage and chat storage commands. Impact areas reviewed: - `FileStorage` append/update transaction staging, rollback, and cache refresh. - Message swipe sidecar materialization and persistence shape. - `chat_message_add_swipe` active/inactive semantics and legacy `silent` compatibility. - Chat memory pruning when an active assistant message changes. - Legacy sidecar rows that match only after trimming and must fall back to full cleanup. Boundary notes: - Changes stay in `src-tauri` Rust storage/command modules. - No React, TypeScript engine, shared API, command registration, or remote-runtime dispatch changes. - The new fast path returns `None` on unsafe storage shape so the existing full replacement path remains the correctness fallback. Pressure points touched: - Rust storage command helpers only. - Did not touch `ModeSurface`, `GameSurface`, shared mode UI, `src-tauri/src/lib.rs` command registration, or import modules. ## Validation - [x] Matching validation command passes locally (for example `pnpm typecheck`, `pnpm build`, `pnpm check:architecture`, `pnpm check:docs`, or full `pnpm check` when warranted) - [x] Full `pnpm check` passes before PR push/handoff - [ ] Human/manual validation completed by contributor or reviewer ### Manual verification notes Commands run locally: - `cargo test --manifest-path src-tauri/Cargo.toml -p marinara-engine message_swipes_append_cleans_trimmed_legacy_sidecar_rows --lib` - `cargo test --manifest-path src-tauri/Cargo.toml -p marinara-engine message_swipes --lib` - `cargo test --manifest-path src-tauri/Cargo.toml -p marinara-storage append_many --lib` - `cargo check --manifest-path src-tauri/Cargo.toml --workspace` - `rustfmt --edition 2021 --check src-tauri/crates/storage/src/lib.rs src-tauri/src/commands/storage/chats.rs src-tauri/src/commands/storage/message_swipes.rs` - `git diff --check` - `pnpm check:architecture` - `pnpm check` Durable test rationale: - This changes a risky storage invariant: fast append must not preserve stale or malformed sidecar rows that the full replacement path would canonicalize. - Existing command output alone would not pin the fallback condition for legacy trimmed sidecar rows. - The added tests are narrow Rust owner tests around sidecar canonicality, append cleanup, and storage transaction behavior. Native Tauri large-chat timing: - Rerun against the Phase 2 storage diff through the native Tauri/WebView2 QA path. - `chat_message_add_swipe`: 358.9ms -> 266.4ms on the 5k-message fixture. - Regenerate two-step total: 998.9ms -> 897.4ms. - The follow-up `patchChatMessageExtra` write still costs 631.0ms, so Phase 3 remains the clearest next latency win. - Broad refresh cost is effectively unchanged at about 190-201ms per scheduled refresh. Remaining proof gap: - This timing pass did not run a live LM Studio generation stream. ## Feature Discoverability Check exactly one: - [ ] Updated `src/features/shell/discovery/` because this PR adds or materially changes a user-discoverable feature, workflow, setting, mode, panel, import path, agent, media capability, or advanced tool. - [x] N/A because this PR is only a bugfix, refactor, test, docs, internal wiring, visual polish, copy edit, or compatibility fix and does not add a new thing users need to find. Reason: - Internal storage performance/correctness path only; no new user-discoverable feature or workflow. ## Docs and release impact - [x] No docs changes needed - [ ] Updated `README.md` - [ ] Updated `CONTRIBUTING.md` - [ ] Updated `docs/developer/` - [ ] Updated repo skills or `AGENTS.md` - [x] Confirmed this PR does not restore old staging/package-workspace/release claims ## UI evidence No UI screenshots or recordings. This PR changes Rust storage behavior only. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Improvements** * Optimized message swipe handling for faster append operations when certain conditions are met, avoiding full message replacement in common cases * Refined chat memory updates to invalidate only when visible content actually changes, improving performance * Added validation checks to ensure swipe data integrity during storage operations <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:17:57 +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
Pasta-Devs/Marinara-Engine#5629
No description provided.