[PR #2428] [MERGED] Scope regenerate and streaming character ids per chat #5602

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

📋 Pull Request Information

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

Base: refactor ← Head: fix/per-chat-regenerate-streaming-ids


📝 Commits (1)

  • db8e811 Scope regenerate and streaming character ids per chat

📊 Changes

2 files changed (+55 additions, -12 deletions)

View changed files

📝 src/features/runtime/generation/hooks/use-generate.ts (+8 -7)
📝 src/shared/stores/chat.store.ts (+47 -5)

📄 Description

Linked issue

Closes #2321

Why this change

  • regenerateMessageId and streamingCharacterId were the last two generation-UI fields left as global scalars in chat.store, while their siblings (streamBuffers / thinkingBuffers / abortControllers) are already per-chat Maps. During concurrent generation across chats, chat A's regenerate/streaming-character id leaked into chat B's foreground view (typing routed to the wrong bubble, wrong streaming card/voice).

What changed

  • src/shared/stores/chat.store.ts: added regenerateMessageIdByChatId / streamingCharacterIdByChatId Maps next to the existing per-chat maps. The setters take an optional chatId, write the per-chat entry, and mirror to the global scalar only when that chat is active — byte-for-byte the same shape as setStreamBuffer. setActiveChatId restores both globals from the maps on switch (and nulls them on no-chat); reset() clears the maps.
  • src/features/runtime/generation/hooks/use-generate.ts: set/clear both ids with the explicit chatId. releaseForegroundGenerationUi now clears the completing chat's own ids regardless of foreground (they self-scope by chatId), so a background chat's completion can't leave stale per-chat entries.

Refactor impact

Primary owner: shared API / chat store

Impact areas reviewed:

  • src/shared/stores/chat.store.ts (per-chat maps + global mirror)
  • src/features/runtime/generation/hooks/use-generate.ts (explicit chatId at set/clear sites)

Boundary notes:

  • None. The new chatId arg is optional and falls back to the active chat (only callers are in use-generate.ts, now all explicit). Existing consumers (ConversationView, ChatRoleplaySurface) read the global mirror unchanged. No persistence/IPC/Rust change.

Pressure points touched:

  • Shared mode UI (chat store), runtime generation.

Validation

  • Matching validation command passes locally
  • Full pnpm check passes before PR push/handoff
  • Human/manual validation completed by contributor or reviewer

Manual verification notes

  • pnpm vitest run src/features/runtime/generation src/engine/generation — 67 passed. A local-only store test confirmed cross-chat isolation: chat A's regenerate/streaming ids do not bleed into B on switch, A's values restore on switch back, a background chat's completion clears its own ids without touching the foreground, and switching to no-chat clears both globals.
  • pnpm exec tsc -b — clean.

Feature Discoverability

  • Updated src/features/shell/discovery/
  • N/A because this PR is a state-isolation bugfix.

Reason:

  • No new discoverable surface.

Docs and release impact

  • No docs changes needed

🔄 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/2428 **Author:** [@Romuromylus](https://github.com/Romuromylus) **Created:** 6/6/2026 **Status:** ✅ Merged **Merged:** 6/6/2026 **Merged by:** [@Romuromylus](https://github.com/Romuromylus) **Base:** `refactor` ← **Head:** `fix/per-chat-regenerate-streaming-ids` --- ### 📝 Commits (1) - [`db8e811`](https://github.com/Pasta-Devs/Marinara-Engine/commit/db8e811ddffb91f40ff133ef01211f7737883cb9) Scope regenerate and streaming character ids per chat ### 📊 Changes **2 files changed** (+55 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `src/features/runtime/generation/hooks/use-generate.ts` (+8 -7) 📝 `src/shared/stores/chat.store.ts` (+47 -5) </details> ### 📄 Description ## Linked issue Closes #2321 ## Why this change - `regenerateMessageId` and `streamingCharacterId` were the last two generation-UI fields left as global scalars in `chat.store`, while their siblings (`streamBuffers` / `thinkingBuffers` / `abortControllers`) are already per-chat Maps. During concurrent generation across chats, chat A's regenerate/streaming-character id leaked into chat B's foreground view (typing routed to the wrong bubble, wrong streaming card/voice). ## What changed - `src/shared/stores/chat.store.ts`: added `regenerateMessageIdByChatId` / `streamingCharacterIdByChatId` Maps next to the existing per-chat maps. The setters take an optional `chatId`, write the per-chat entry, and mirror to the global scalar only when that chat is active — byte-for-byte the same shape as `setStreamBuffer`. `setActiveChatId` restores both globals from the maps on switch (and nulls them on no-chat); `reset()` clears the maps. - `src/features/runtime/generation/hooks/use-generate.ts`: set/clear both ids with the explicit `chatId`. `releaseForegroundGenerationUi` now clears the completing chat's own ids regardless of foreground (they self-scope by chatId), so a background chat's completion can't leave stale per-chat entries. ## Refactor impact Primary owner: shared API / chat store Impact areas reviewed: - `src/shared/stores/chat.store.ts` (per-chat maps + global mirror) - `src/features/runtime/generation/hooks/use-generate.ts` (explicit chatId at set/clear sites) Boundary notes: - None. The new `chatId` arg is optional and falls back to the active chat (only callers are in use-generate.ts, now all explicit). Existing consumers (`ConversationView`, `ChatRoleplaySurface`) read the global mirror unchanged. No persistence/IPC/Rust change. Pressure points touched: - Shared mode UI (chat store), runtime generation. ## Validation - [x] Matching validation command passes locally - [ ] Full `pnpm check` passes before PR push/handoff - [ ] Human/manual validation completed by contributor or reviewer ### Manual verification notes - `pnpm vitest run src/features/runtime/generation src/engine/generation` — 67 passed. A local-only store test confirmed cross-chat isolation: chat A's regenerate/streaming ids do not bleed into B on switch, A's values restore on switch back, a background chat's completion clears its own ids without touching the foreground, and switching to no-chat clears both globals. - `pnpm exec tsc -b` — clean. ## Feature Discoverability - [ ] Updated `src/features/shell/discovery/` - [x] N/A because this PR is a state-isolation bugfix. Reason: - No new discoverable surface. ## Docs and release impact - [x] No docs changes needed --- <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:44 +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#5602
No description provided.