[GH-ISSUE #2296] [Issue]: Deleting a chat orphans its agent-runs and agent-memory rows (storage bloat; main cleaned them on delete) #1132

Closed
opened 2026-10-21 05:27:35 +07:00 by bsakaguchi · 0 comments
Owner

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

Originally assigned to: @Xelvanis on GitHub.

Summary

Deleting a chat cascades messages, swipes, tracker snapshots, gallery, and scene memories, but never clears that chat's agent-runs / agent-memory rows. Those live in a separate chatId-keyed store, so they are orphaned and accumulate per deleted chat. Main deleted them on chat remove.

Expected behavior

Deleting a chat (or chat group) should also remove that chat's agent-runs and agent-memory rows, so no per-chat agent bookkeeping is left behind.

Actual behavior

Agent-runs and agent-memory rows keyed by the deleted chat's id survive deletion and are never garbage-collected, growing monotonically as storage bloat. Active chats are unaffected (orphans are inert), so the impact is storage growth that scales with how many chats a user deletes and how active their agents were.

Steps to reproduce

  1. Use a chat with tracker / world-state / echo agents so agent-runs and agent-memory rows accumulate for it.
  2. Delete the chat (or its chat group).
  3. Inspect storage: the agent-runs and agent-memory entries keyed by that chat id remain.

Impact area

  • App shell, navigation, startup, or providers
  • Catalog resources
  • 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

Environment

  • Branch or commit: refactor @ f56a3774 (compared against main @ b4ab97fb)
  • Run mode: Tauri desktop
  • OS + version: Windows 11
  • Node + pnpm versions: n/a (static source audit)
  • Rust version, if relevant: n/a (static source audit)
  • Remote Runtime URL configured? not relevant
  • Provider, model, or integration, if relevant: not relevant

Logs, screenshots, or video

n/a (static source comparison of main vs refactor)

Regression notes

Worked in main. Main packages/server/src/services/storage/chats.storage.ts:411-412 (in remove()) deletes agentRuns and agentMemory by chatId (and again at :427-428 in removeGroup). Refactor src-tauri/src/commands/storage/chats.rs:1120-1147 (delete_chat_with_messages) cascades tracker snapshots (:1138), gallery (:1140), message rows + swipes (:1141), and scene memories/refs (:1130-1131), then deletes the chat row (:1144), but never calls clear_agent_runs_and_memory_for_chat (src-tauri/src/commands/storage/agents.rs:329-368). That cleanup is reachable only via the standalone agent_runs_clear_for_chat command, which the TS side calls only from the roleplay "reset world state" button (RoleplayHUD.tsx:205), never from deletion. Agent-runs/agent-memory are stored in separate agent-runs / agent-memory collections keyed by chat id (agents.rs:350-356), so they survive the chat-row delete. The chat-delete flow is useDeleteChat -> storageApi.delete("chats", id) -> Rust storage_delete (entities.rs:730) -> delete_chat_with_messages.

Additional context

Call clear_agent_runs_and_memory_for_chat from delete_chat_with_messages (and the group-delete path) so agent bookkeeping is cleaned alongside the other cascaded dependents.

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 @Romuromylus on GitHub (Jun 5, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2296 Originally assigned to: @Xelvanis on GitHub. ## Summary Deleting a chat cascades messages, swipes, tracker snapshots, gallery, and scene memories, but never clears that chat's agent-runs / agent-memory rows. Those live in a separate chatId-keyed store, so they are orphaned and accumulate per deleted chat. Main deleted them on chat remove. ## Expected behavior Deleting a chat (or chat group) should also remove that chat's agent-runs and agent-memory rows, so no per-chat agent bookkeeping is left behind. ## Actual behavior Agent-runs and agent-memory rows keyed by the deleted chat's id survive deletion and are never garbage-collected, growing monotonically as storage bloat. Active chats are unaffected (orphans are inert), so the impact is storage growth that scales with how many chats a user deletes and how active their agents were. ## Steps to reproduce 1. Use a chat with tracker / world-state / echo agents so agent-runs and agent-memory rows accumulate for it. 2. Delete the chat (or its chat group). 3. Inspect storage: the `agent-runs` and `agent-memory` entries keyed by that chat id remain. ## Impact area - [ ] App shell, navigation, startup, or providers - [ ] Catalog resources - [ ] Chat mode - [ ] Roleplay mode - [ ] Game mode - [ ] 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 - [ ] Shared API wrapper or remote runtime routing - [x] Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime - [ ] Docs, contributor workflow, or templates ## Environment - Branch or commit: refactor @ f56a3774 (compared against main @ b4ab97fb) - Run mode: Tauri desktop - OS + version: Windows 11 - Node + pnpm versions: n/a (static source audit) - Rust version, if relevant: n/a (static source audit) - Remote Runtime URL configured? not relevant - Provider, model, or integration, if relevant: not relevant ## Logs, screenshots, or video n/a (static source comparison of main vs refactor) ## Regression notes Worked in main. Main `packages/server/src/services/storage/chats.storage.ts:411-412` (in `remove()`) deletes `agentRuns` and `agentMemory` by `chatId` (and again at `:427-428` in `removeGroup`). Refactor `src-tauri/src/commands/storage/chats.rs:1120-1147` (`delete_chat_with_messages`) cascades tracker snapshots (`:1138`), gallery (`:1140`), message rows + swipes (`:1141`), and scene memories/refs (`:1130-1131`), then deletes the chat row (`:1144`), but never calls `clear_agent_runs_and_memory_for_chat` (`src-tauri/src/commands/storage/agents.rs:329-368`). That cleanup is reachable only via the standalone `agent_runs_clear_for_chat` command, which the TS side calls only from the roleplay "reset world state" button (`RoleplayHUD.tsx:205`), never from deletion. Agent-runs/agent-memory are stored in separate `agent-runs` / `agent-memory` collections keyed by chat id (`agents.rs:350-356`), so they survive the chat-row delete. The chat-delete flow is `useDeleteChat` -> `storageApi.delete("chats", id)` -> Rust `storage_delete` (`entities.rs:730`) -> `delete_chat_with_messages`. ## Additional context Call `clear_agent_runs_and_memory_for_chat` from `delete_chat_with_messages` (and the group-delete path) so agent bookkeeping is cleaned alongside the other cascaded dependents. ## 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.
bsakaguchi 2026-10-21 05:27:35 +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#1132
No description provided.