[PR #1995] [MERGED] Fix startup bloat from prompt snapshots #5380

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/1995
Author: @cha1latte
Created: 6/3/2026
Status: ✅ Merged
Merged: 6/3/2026
Merged by: @cha1latte

Base: refactor ← Head: fix/refactor-startup-message-snapshot-bloat


📝 Commits (1)

  • 160c258 Fix startup message snapshot bloat

📊 Changes

7 files changed (+528 additions, -38 deletions)

View changed files

📝 src-tauri/src/commands/storage/chats.rs (+48 -12)
📝 src-tauri/src/commands/storage/contracts.rs (+1 -1)
📝 src-tauri/src/commands/storage/shared.rs (+239 -0)
📝 src-tauri/src/state.rs (+231 -2)
📝 src/engine/contracts/types/chat.ts (+1 -1)
📝 src/engine/generation/start-generation.ts (+1 -17)
📝 src/features/modes/shared/chat-ui/lib/prompt-snapshot.ts (+7 -5)

📄 Description

Linked issue

N/A - found during local refactor startup investigation.

Why this change

  • Refactor startup was slow because messages.json could grow huge when generated assistant messages persisted duplicate full prompt snapshots on the parent message and in per-swipe maps.

What changed

  • Keep swipe-scoped generation metadata canonical in swipes[].extra, including prompt snapshots, replay data, thinking, attachments, token info, and generation info.
  • Stop new generation writes from producing extra.generationPromptSnapshotsBySwipe.
  • Compact legacy parent prompt snapshots into swipe extras while preserving active-swipe prompt materialization on reads.
  • Add a one-time startup migration marker so message prompt snapshot compaction runs once, then later launches skip whole-file message migration.
  • Remove messages from unconditional startup JSON repair while preserving paged/projected message reads.

Refactor impact

Primary owner:

Rust storage / engine generation

Impact areas reviewed:

  • Message create/update defaults
  • Regenerate/add-swipe storage flow
  • Active swipe materialization
  • Legacy prompt snapshot fallback
  • Startup storage migration and marker behavior
  • Paged/projected message reads

Boundary notes:

  • Engine generation still writes through the storage API; canonical persistence is enforced in Rust storage normalization/compaction.
  • Feature UI keeps using the existing prompt snapshot resolver with legacy fallback.
  • No new public frontend API.

Pressure points touched:

  • Rust storage message normalization and chat swipe commands
  • App startup migration path
  • Shared chat UI prompt snapshot resolver

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

  • Codex ran node scratch\message-snapshot-bloat-proof.mjs: 500-message fixture compacted from 85,400,891 bytes to 28,520,891 bytes, saving 66.6%.
  • Codex ran cargo test --manifest-path src-tauri/Cargo.toml prompt_snapshot -- --nocapture: passed.
  • Codex ran cargo test --manifest-path src-tauri/Cargo.toml startup_skips_message_compaction_after_marker -- --nocapture: passed.
  • Codex ran pnpm typecheck: passed.
  • Codex ran pnpm check: passed.
  • Codex ran cargo test --manifest-path src-tauri/Cargo.toml --workspace: passed.
  • Bunny review passed locally on the current diff.
  • Human/manual app startup validation is still pending.

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:

  • N/A; this is internal storage compaction and startup performance recovery.

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

N/A - storage/startup performance fix with no visible UI change.


🔄 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/1995 **Author:** [@cha1latte](https://github.com/cha1latte) **Created:** 6/3/2026 **Status:** ✅ Merged **Merged:** 6/3/2026 **Merged by:** [@cha1latte](https://github.com/cha1latte) **Base:** `refactor` ← **Head:** `fix/refactor-startup-message-snapshot-bloat` --- ### 📝 Commits (1) - [`160c258`](https://github.com/Pasta-Devs/Marinara-Engine/commit/160c258d005e53eae4b1c7286f563ab8e0d600c5) Fix startup message snapshot bloat ### 📊 Changes **7 files changed** (+528 additions, -38 deletions) <details> <summary>View changed files</summary> 📝 `src-tauri/src/commands/storage/chats.rs` (+48 -12) 📝 `src-tauri/src/commands/storage/contracts.rs` (+1 -1) 📝 `src-tauri/src/commands/storage/shared.rs` (+239 -0) 📝 `src-tauri/src/state.rs` (+231 -2) 📝 `src/engine/contracts/types/chat.ts` (+1 -1) 📝 `src/engine/generation/start-generation.ts` (+1 -17) 📝 `src/features/modes/shared/chat-ui/lib/prompt-snapshot.ts` (+7 -5) </details> ### 📄 Description ## Linked issue N/A - found during local refactor startup investigation. ## Why this change - Refactor startup was slow because `messages.json` could grow huge when generated assistant messages persisted duplicate full prompt snapshots on the parent message and in per-swipe maps. ## What changed - Keep swipe-scoped generation metadata canonical in `swipes[].extra`, including prompt snapshots, replay data, thinking, attachments, token info, and generation info. - Stop new generation writes from producing `extra.generationPromptSnapshotsBySwipe`. - Compact legacy parent prompt snapshots into swipe extras while preserving active-swipe prompt materialization on reads. - Add a one-time startup migration marker so message prompt snapshot compaction runs once, then later launches skip whole-file message migration. - Remove `messages` from unconditional startup JSON repair while preserving paged/projected message reads. ## Refactor impact Primary owner: Rust storage / engine generation Impact areas reviewed: - Message create/update defaults - Regenerate/add-swipe storage flow - Active swipe materialization - Legacy prompt snapshot fallback - Startup storage migration and marker behavior - Paged/projected message reads Boundary notes: - Engine generation still writes through the storage API; canonical persistence is enforced in Rust storage normalization/compaction. - Feature UI keeps using the existing prompt snapshot resolver with legacy fallback. - No new public frontend API. Pressure points touched: - Rust storage message normalization and chat swipe commands - App startup migration path - Shared chat UI prompt snapshot resolver ## 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 - Codex ran `node scratch\message-snapshot-bloat-proof.mjs`: 500-message fixture compacted from 85,400,891 bytes to 28,520,891 bytes, saving 66.6%. - Codex ran `cargo test --manifest-path src-tauri/Cargo.toml prompt_snapshot -- --nocapture`: passed. - Codex ran `cargo test --manifest-path src-tauri/Cargo.toml startup_skips_message_compaction_after_marker -- --nocapture`: passed. - Codex ran `pnpm typecheck`: passed. - Codex ran `pnpm check`: passed. - Codex ran `cargo test --manifest-path src-tauri/Cargo.toml --workspace`: passed. - Bunny review passed locally on the current diff. - Human/manual app startup validation is still pending. ## 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: - N/A; this is internal storage compaction and startup performance recovery. ## 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 N/A - storage/startup performance fix with no visible UI change. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:15:46 +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#5380
No description provided.