[PR #1198] [MERGED] Fix scene memory cleanup on chat delete #4972

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/1198
Author: @cha1latte
Created: 5/25/2026
Status: ✅ Merged
Merged: 5/25/2026
Merged by: @cha1latte

Base: refactor ← Head: fix/refactor-issue-1182-scene-memory-delete


📝 Commits (2)

  • 7d449d3 Fix scene memory cleanup on chat delete
  • 232b711 Tighten scene delete cleanup boundaries

📊 Changes

3 files changed (+483 additions, -6 deletions)

View changed files

📝 src-tauri/src/commands/storage/chats.rs (+468 -5)
📝 src-tauri/src/commands/storage/commands/entities.rs (+8 -1)
📝 src-tauri/src/http_dispatch.rs (+7 -0)

📄 Description

What?

Fixes #1182.

Deleting a chat now uses the chat-aware cleanup path instead of the raw storage delete path. When the deleted chat owns roleplay scenes, Marinara removes the owned scene child chats, their messages, tracker snapshots, and the matching character-level scene memories.

Why?

Concluded roleplay scenes write continuity into both the origin chat metadata and each character's extensions.characterMemories. Deleting the origin conversation previously removed only the origin chat row, leaving scene chats and character memories available for later conversations with the same character.

How?

  • Routes storage_delete(entity = "chats") through delete_chat_with_messages for both Tauri and HTTP runtime entrypoints.
  • Extends delete_chat_with_messages to discover scene IDs from owned scene rows and origin metadata, then clean up scene chat rows/messages and matching character memories.
  • Keeps the destructive boundary narrow: non-scene linked chats are not deleted, and unrelated character memories are preserved.

Testing?

Machine verification:

  • cargo test --manifest-path src-tauri\Cargo.toml storage_commands::chats::tests
    • Before fix: failed because scene-chat still existed after deleting origin-chat.
    • After fix: passed; the owned scene chat/messages were deleted, matching character memories were removed, unrelated memories stayed, stringified scene-memory records were parsed, direct scene deletion pruned origin scene state, and a linked non-scene chat stayed.
  • pnpm check
    • Passed architecture checks, frontend typecheck, Rust check, and docs validation.
  • node C:\Users\celia\.codex\tools\marinara-proof-gate.mjs scratch\bugfix-verification.json
    • Passed.
  • Bunny review
    • Passed after tightening the helper to no-op when the target chat row is already missing.
  • CodeRabbit follow-up
    • Addressed current-head comments by limiting cleanup to validated owned scene IDs, parsing stringified history/memory entries, refreshing lastRoleplaySceneSummary after pruning, clearing sceneBusyCharIds, and preserving unrelated connectedChatId links.

Manual verification:

  • None required for the core claim. If manually testing destructive chat deletion against real app data, first back up <Marinara app data>/data/collections/chats.json, messages.json, characters.json, and game-state-snapshots.json when present to a separate folder outside the app data directory.

Screenshots

N/A. This is a storage cleanup bug verified by a targeted Rust harness and pnpm check.

Anything Else?

Base branch: refactor.

Out of scope: changing scene conclusion behavior, memory recall ranking, prompt assembly, or ordinary linked-chat deletion.

Summary by CodeRabbit

  • Bug Fixes
    • Improved chat deletion to properly handle scene-related chats and associated data. When deleting a chat that's part of a roleplay scene, the system now correctly cleans up linked scene chats, character memories, and scene references, preventing orphaned data and broken connections.

Review Change Stack


🔄 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/1198 **Author:** [@cha1latte](https://github.com/cha1latte) **Created:** 5/25/2026 **Status:** ✅ Merged **Merged:** 5/25/2026 **Merged by:** [@cha1latte](https://github.com/cha1latte) **Base:** `refactor` ← **Head:** `fix/refactor-issue-1182-scene-memory-delete` --- ### 📝 Commits (2) - [`7d449d3`](https://github.com/Pasta-Devs/Marinara-Engine/commit/7d449d3b7e063410aff2eca7474a684e4edbed2e) Fix scene memory cleanup on chat delete - [`232b711`](https://github.com/Pasta-Devs/Marinara-Engine/commit/232b711eb6a88630cd472080317803d0cc0084c1) Tighten scene delete cleanup boundaries ### 📊 Changes **3 files changed** (+483 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `src-tauri/src/commands/storage/chats.rs` (+468 -5) 📝 `src-tauri/src/commands/storage/commands/entities.rs` (+8 -1) 📝 `src-tauri/src/http_dispatch.rs` (+7 -0) </details> ### 📄 Description ## What? Fixes #1182. Deleting a chat now uses the chat-aware cleanup path instead of the raw storage delete path. When the deleted chat owns roleplay scenes, Marinara removes the owned scene child chats, their messages, tracker snapshots, and the matching character-level scene memories. ## Why? Concluded roleplay scenes write continuity into both the origin chat metadata and each character's `extensions.characterMemories`. Deleting the origin conversation previously removed only the origin chat row, leaving scene chats and character memories available for later conversations with the same character. ## How? - Routes `storage_delete(entity = "chats")` through `delete_chat_with_messages` for both Tauri and HTTP runtime entrypoints. - Extends `delete_chat_with_messages` to discover scene IDs from owned scene rows and origin metadata, then clean up scene chat rows/messages and matching character memories. - Keeps the destructive boundary narrow: non-scene linked chats are not deleted, and unrelated character memories are preserved. ## Testing? Machine verification: - `cargo test --manifest-path src-tauri\Cargo.toml storage_commands::chats::tests` - Before fix: failed because `scene-chat` still existed after deleting `origin-chat`. - After fix: passed; the owned scene chat/messages were deleted, matching character memories were removed, unrelated memories stayed, stringified scene-memory records were parsed, direct scene deletion pruned origin scene state, and a linked non-scene chat stayed. - `pnpm check` - Passed architecture checks, frontend typecheck, Rust check, and docs validation. - `node C:\Users\celia\.codex\tools\marinara-proof-gate.mjs scratch\bugfix-verification.json` - Passed. - Bunny review - Passed after tightening the helper to no-op when the target chat row is already missing. - CodeRabbit follow-up - Addressed current-head comments by limiting cleanup to validated owned scene IDs, parsing stringified history/memory entries, refreshing `lastRoleplaySceneSummary` after pruning, clearing `sceneBusyCharIds`, and preserving unrelated `connectedChatId` links. Manual verification: - None required for the core claim. If manually testing destructive chat deletion against real app data, first back up `<Marinara app data>/data/collections/chats.json`, `messages.json`, `characters.json`, and `game-state-snapshots.json` when present to a separate folder outside the app data directory. ## Screenshots N/A. This is a storage cleanup bug verified by a targeted Rust harness and `pnpm check`. ## Anything Else? Base branch: `refactor`. Out of scope: changing scene conclusion behavior, memory recall ranking, prompt assembly, or ordinary linked-chat deletion. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved chat deletion to properly handle scene-related chats and associated data. When deleting a chat that's part of a roleplay scene, the system now correctly cleans up linked scene chats, character memories, and scene references, preventing orphaned data and broken connections. <!-- review_stack_entry_start --> [![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/Pasta-Devs/Marinara-Engine/pull/1198?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack) <!-- review_stack_entry_end --> <!-- 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:12:08 +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#4972
No description provided.