[GH-ISSUE #2470] [Issue]: Switching chats discards pending Card Evolution / Lorebook Keeper approval proposals #1212

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

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

Originally assigned to: @SpicyMarinara on GitHub.

Summary

Severity: Medium — data-loss (UX). Switching chats unconditionally resets the agent store, which discards any pending Card Evolution Auditor / Lorebook Keeper approval proposals that are waiting for the user to approve or reject. The proposals are not persisted anywhere, so they are unrecoverable.

Expected behavior

A pending card/lorebook approval should survive a chat switch (or at least not be silently destroyed), since generations for non-active chats are explicitly kept running in the background and these proposals are meant to "sit until the user approves or rejects."

Actual behavior

The chat-switch effect resets the whole agent store on any chat change, and reset() clears the pending-approval queues with no chat-scoping or condition:

// src/app/startup/chat-switch-effects.ts:13
useAgentStore.getState().reset();   // on any activeChatId change

// src/shared/stores/agent.store.ts:279-296 (reset)
pendingCardUpdates: [],        // 294
pendingLorebookUpdates: [],    // 295

Background generations do survive a chat switch (the chat store keeps per-chat abortControllers/streamBuffers), so a background chat's auditor can finish and enqueue a proposal — but if the user then switches away before approving, the proposal is wiped. The modals read only the live global array (CharacterCardUpdateModal.tsx, LorebookKeeperReviewModal.tsx), with no re-fetch path. The PendingCardUpdate docstring itself states these are sensitive and sit in the queue until the user acts.

Steps to reproduce

  1. Start a roleplay turn in chat A with the Card Evolution Auditor or Lorebook Keeper (review-required) enabled.
  2. When the approval modal opens, switch to any other chat before approving.
  3. The pending card/lorebook updates are gone and cannot be recovered.

Impact area

  • Roleplay mode
  • Shared mode UI
  • Runtime systems: generation, world-state, visuals, tracker, or haptics

Environment

  • Branch or commit: refactor @ 1fae2c42
  • Run mode: Tauri desktop / web shell
  • OS + version: found via static source audit (not runtime-reproduced)
  • Node + pnpm versions: n/a (static audit)
  • Rust version, if relevant: n/a (static audit)
  • Remote Runtime URL configured? not relevant
  • Provider, model, or integration, if relevant: n/a

Logs, screenshots, or video

Static trace: chat-switch-effects.ts:13, agent.store.ts:279-296 (clears at 294-295), modals CharacterCardUpdateModal.tsx / LorebookKeeperReviewModal.tsx.

Regression notes

Not a regression — main has equivalent behavior (chat.store.ts calls agentStore.reset() inside setActiveChatId, clearing pendingCardUpdates; pendingLorebookUpdates is a refactor-only addition with no main equivalent). Filing as a refactor bug to fix the data-loss UX, not as a main→refactor regression.

Additional context

The lost items are regenerable AI proposals (re-proposed next turn), not user-authored content — hence Medium. Fix: make pendingCardUpdates/pendingLorebookUpdates per-chat (they already carry the characterId/chatId) and only clear entries for chats that no longer exist, or preserve them in reset(). Mirror the durable pattern already in the repo (cyoaChoices is guarded by cyoaChoicesChatId; echo messages persist via chat metadata).

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 6, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2470 Originally assigned to: @SpicyMarinara on GitHub. ## Summary **Severity: Medium — data-loss (UX).** Switching chats unconditionally resets the agent store, which discards any pending Card Evolution Auditor / Lorebook Keeper approval proposals that are waiting for the user to approve or reject. The proposals are not persisted anywhere, so they are unrecoverable. ## Expected behavior A pending card/lorebook approval should survive a chat switch (or at least not be silently destroyed), since generations for non-active chats are explicitly kept running in the background and these proposals are meant to "sit until the user approves or rejects." ## Actual behavior The chat-switch effect resets the whole agent store on any chat change, and `reset()` clears the pending-approval queues with no chat-scoping or condition: ```ts // src/app/startup/chat-switch-effects.ts:13 useAgentStore.getState().reset(); // on any activeChatId change // src/shared/stores/agent.store.ts:279-296 (reset) pendingCardUpdates: [], // 294 pendingLorebookUpdates: [], // 295 ``` Background generations *do* survive a chat switch (the chat store keeps per-chat abortControllers/streamBuffers), so a background chat's auditor can finish and enqueue a proposal — but if the user then switches away before approving, the proposal is wiped. The modals read only the live global array (`CharacterCardUpdateModal.tsx`, `LorebookKeeperReviewModal.tsx`), with no re-fetch path. The `PendingCardUpdate` docstring itself states these are sensitive and sit in the queue until the user acts. ## Steps to reproduce 1. Start a roleplay turn in chat A with the Card Evolution Auditor or Lorebook Keeper (review-required) enabled. 2. When the approval modal opens, switch to any other chat before approving. 3. The pending card/lorebook updates are gone and cannot be recovered. ## Impact area - [x] Roleplay mode - [x] Shared mode UI - [x] Runtime systems: generation, world-state, visuals, tracker, or haptics ## Environment - Branch or commit: refactor @ 1fae2c42 - Run mode: Tauri desktop / web shell - OS + version: found via static source audit (not runtime-reproduced) - Node + pnpm versions: n/a (static audit) - Rust version, if relevant: n/a (static audit) - Remote Runtime URL configured? not relevant - Provider, model, or integration, if relevant: n/a ## Logs, screenshots, or video Static trace: `chat-switch-effects.ts:13`, `agent.store.ts:279-296` (clears at 294-295), modals `CharacterCardUpdateModal.tsx` / `LorebookKeeperReviewModal.tsx`. ## Regression notes Not a regression — main has equivalent behavior (`chat.store.ts` calls `agentStore.reset()` inside `setActiveChatId`, clearing `pendingCardUpdates`; `pendingLorebookUpdates` is a refactor-only addition with no main equivalent). Filing as a refactor `bug` to fix the data-loss UX, not as a main→refactor regression. ## Additional context The lost items are regenerable AI proposals (re-proposed next turn), not user-authored content — hence Medium. Fix: make `pendingCardUpdates`/`pendingLorebookUpdates` per-chat (they already carry the characterId/chatId) and only clear entries for chats that no longer exist, or preserve them in `reset()`. Mirror the durable pattern already in the repo (`cyoaChoices` is guarded by `cyoaChoicesChatId`; echo messages persist via chat metadata). ## 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:29:08 +07:00
Author
Owner

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

Fixed on refactor in 038b7220.

Switching chats no longer clears pending Card Evolution or Lorebook Keeper approval proposals; explicit clear paths remain available.

Verification: pnpm typecheck; pnpm build; pnpm check:architecture; cargo check --manifest-path src-tauri/Cargo.toml --workspace; focused Rust backup/profile tests; git diff --check; no .test.ts/.test.tsx files present.

<!-- gh-comment-id:4638720729 --> @SpicyMarinara commented on GitHub (Jun 6, 2026): Fixed on refactor in 038b7220. Switching chats no longer clears pending Card Evolution or Lorebook Keeper approval proposals; explicit clear paths remain available. Verification: pnpm typecheck; pnpm build; pnpm check:architecture; cargo check --manifest-path src-tauri/Cargo.toml --workspace; focused Rust backup/profile tests; git diff --check; no .test.ts/.test.tsx files present.
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#1212
No description provided.