[PR #240] [MERGED] feat(chat): "Mari is thinking…" / "updating your stuff…" indicator #4525

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/240
Author: @LukaTheHero
Created: 4/26/2026
Status: ✅ Merged
Merged: 4/26/2026
Merged by: @LukaTheHero

Base: main ← Head: feat/mari-thinking-indicator-v2


📝 Commits (6)

  • fb8926e feat(chat): add "Mari is thinking…" indicator for command execution
  • ca899a0 fix(chat): address review comments on Mari thinking indicator
  • de189c9 fix(chat): hide Mari indicator immediately on chat switch
  • af7e356 chore(chat): skip idle hide timer when pill has no owner
  • 0bcad4c fix(chat): replace subscribeWithSelector transport, gate pill on token edge
  • c71b81d fix(chat): restore Mari pill on chat-switch-back mid-stream

📊 Changes

7 files changed (+268 additions, -0 deletions)

View changed files

📝 CHANGELOG.md (+6 -0)
📝 packages/client/src/components/chat/ChatInput.tsx (+4 -0)
📝 packages/client/src/components/chat/ConversationInput.tsx (+4 -0)
➕ packages/client/src/components/chat/MariThinkingIndicator.tsx (+166 -0)
📝 packages/client/src/hooks/use-generate.ts (+48 -0)
📝 packages/client/src/stores/chat.store.ts (+29 -0)
📝 packages/server/src/routes/generate.routes.ts (+11 -0)

📄 Description

Picks up @cha1latte's work in #222 and ships it with two correctness fixes and a small UX extension. His four commits are preserved with original authorship; my changes are the final commit on top.

What this does

A pill above the input bar tells you when Mari is doing background work, so you can tell the difference between "still thinking" and "stalled."

  • "Mari is thinking…" — appears the moment the typing indicator clears (first token of her reply), stays through the token stream.
  • "Mari is updating your stuff…" — replaces the thinking pill while her embedded commands (create_character, update_character, fetch, …) execute in the post-stream loop.
  • Clears on stream end / error / abort.

What's new vs #222

Bug fix: indicator never appeared in practice

The original used useChatStore.subscribe(selector, evaluate) to react to store changes. That's the same subscribeWithSelector + React 19 batching combination that GameSurface.tsx:2079-2081 already documents as unreliable for fast start/end transitions. The SSE events arrived (verified via Network → EventStream) but the subscription dropped them — pill never showed.

Switched the transport to window CustomEvents (marinara:mari-phase), matching the established pattern (marinara:generation-complete, marinara:generation-error) already used elsewhere in use-generate.ts. CustomEvents fire synchronously, outside React's batching, so every transition is observed.

UX extension: pill now covers the generation phase too

The original only showed the pill during the post-stream command window. But there's a similar dead-air window during token streaming — typing indicator hides on first token, then nothing visible until commands start (or completion). Extended the pill to cover that window too: "Mari is thinking…" fires on the first token (same edge that clears the typing indicator, so they never overlap), seamlessly transitions to "Mari is updating your stuff…" when commands start.

Cleanup

  • Fixes the lint warning from #222 (setCommandsExecuting missing from useCallback deps).
  • Extracts isMariParticipant as a pure function.
  • Splits the chat-switch hide logic into its own focused effect instead of tangling it inside evaluate().
  • Kept the Zustand commandsExecutingChatIds set + setCommandsExecuting action — still useful as a synchronous read source for any future consumer, costs nothing.

Why a new PR instead of pushing to #222

#222 is from @cha1latte's fork — I can't push to it. Cherry-picked his four commits onto this branch with original authorship preserved (you'll see his name on the first four commits in the history), then layered the fixes on top as one commit. Will close #222 with a comment explaining the situation and crediting his diagnosis.

Files

File Change
packages/client/src/components/chat/MariThinkingIndicator.tsx New component, two-phase pill, CustomEvent transport
packages/client/src/hooks/use-generate.ts Dispatch marinara:mari-phase on first token, on assistant_commands_start, and from termination cleanup
packages/client/src/stores/chat.store.ts Add commandsExecutingChatIds set + setCommandsExecuting action (preserved from #222)
packages/client/src/components/chat/ChatInput.tsx Mount <MariThinkingIndicator />
packages/client/src/components/chat/ConversationInput.tsx Mount <MariThinkingIndicator />
packages/server/src/routes/generate.routes.ts Emit assistant_commands_start / _end SSE events around the command loop (preserved from #222)
CHANGELOG.md Entry

Robustness

I walked every edge case I could think of:

  • Phase transitions within MIN_VISIBLE_MS: timer cleared on each new phase, no flash.
  • Duplicate idle fires (assistant_commands_end AND done both call cleanup): second short-circuits.
  • Background-chat events while user is in another chat: filtered.
  • Chat-switch while pill visible: dedicated effect hides immediately.
  • Stream error / abort / unexpected throw: finally block always dispatches idle. No stuck states.
  • Refresh mid-stream: clean (no events arrive, pill never shows).
  • Typing-indicator overlap (concern from testing): same-event-loop swap on first token. Atomic from user's perspective.
  • Dual-mount safety (ChatInput + ConversationInput both render it): only one mounts at a time; if both ever did, they'd both render the same correct pill — no state contention since each instance has its own refs.

Testing

  • pnpm check passes (no errors, no warnings).
  • Manually tested in conversation mode with Professor Mari:
    • Single-command prompt — pill fires, transitions thinking → updating → clears.
    • 30-command prompt — pill stays visible through the entire window.
    • Chat-switch mid-stream — pill clears immediately in the new chat.
    • Stop button mid-stream — pill clears.
    • Non-Mari chat — no pill ever.
    • Mari chat with no command-triggering prompt — only "Mari is thinking…" during streaming, then clears at done.

Test plan

  • Send Mari a prompt that runs commands — verify pill cycles thinking → updating → clears.
  • Watch typing indicator and pill don't overlap on first token.
  • Switch chats mid-stream — pill clears in the destination chat.
  • Trigger a stream error (kill network briefly) — pill clears.
  • Hit Stop mid-stream — pill clears.
  • Send a non-command message — pill shows during stream, hides at done.
  • Send a message in a non-Mari chat — pill never appears.
  • Mobile viewport — pill renders without escaping bounds.

Summary by CodeRabbit

  • New Features

    • Added a visible "Mari is thinking…" / working indicator above the chat composer that appears during Mari's processing phases (thinking/updating), with accessible status text and subtle animation.
    • Indicator stays visible for a minimum duration to avoid flicker for brief tasks.
  • Chore

    • Updated changelog with an Unreleased entry recording the new UI indicator.

🔄 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/240 **Author:** [@LukaTheHero](https://github.com/LukaTheHero) **Created:** 4/26/2026 **Status:** ✅ Merged **Merged:** 4/26/2026 **Merged by:** [@LukaTheHero](https://github.com/LukaTheHero) **Base:** `main` ← **Head:** `feat/mari-thinking-indicator-v2` --- ### 📝 Commits (6) - [`fb8926e`](https://github.com/Pasta-Devs/Marinara-Engine/commit/fb8926e2fcf4655d881a7e1cc4c7d3ca7e658746) feat(chat): add "Mari is thinking…" indicator for command execution - [`ca899a0`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ca899a00505c3d1fae367535d1bc43ec072cb229) fix(chat): address review comments on Mari thinking indicator - [`de189c9`](https://github.com/Pasta-Devs/Marinara-Engine/commit/de189c97e38a0e1180d5303a4540d7838881d1bb) fix(chat): hide Mari indicator immediately on chat switch - [`af7e356`](https://github.com/Pasta-Devs/Marinara-Engine/commit/af7e356d69c1956eebe8c90c4634622709d0996f) chore(chat): skip idle hide timer when pill has no owner - [`0bcad4c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/0bcad4ca468c76c820a9f310c25efdd6c6d426f7) fix(chat): replace subscribeWithSelector transport, gate pill on token edge - [`c71b81d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/c71b81dce884d238b0c7cc21bbf4f309765512cc) fix(chat): restore Mari pill on chat-switch-back mid-stream ### 📊 Changes **7 files changed** (+268 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+6 -0) 📝 `packages/client/src/components/chat/ChatInput.tsx` (+4 -0) 📝 `packages/client/src/components/chat/ConversationInput.tsx` (+4 -0) ➕ `packages/client/src/components/chat/MariThinkingIndicator.tsx` (+166 -0) 📝 `packages/client/src/hooks/use-generate.ts` (+48 -0) 📝 `packages/client/src/stores/chat.store.ts` (+29 -0) 📝 `packages/server/src/routes/generate.routes.ts` (+11 -0) </details> ### 📄 Description Picks up @cha1latte's work in #222 and ships it with two correctness fixes and a small UX extension. His four commits are preserved with original authorship; my changes are the final commit on top. ## What this does A pill above the input bar tells you when Mari is doing background work, so you can tell the difference between "still thinking" and "stalled." - **"Mari is thinking…"** — appears the moment the typing indicator clears (first token of her reply), stays through the token stream. - **"Mari is updating your stuff…"** — replaces the thinking pill while her embedded commands (`create_character`, `update_character`, `fetch`, …) execute in the post-stream loop. - Clears on stream end / error / abort. ## What's new vs #222 ### Bug fix: indicator never appeared in practice The original used `useChatStore.subscribe(selector, evaluate)` to react to store changes. That's the same `subscribeWithSelector` + React 19 batching combination that `GameSurface.tsx:2079-2081` already documents as unreliable for fast start/end transitions. The SSE events arrived (verified via Network → EventStream) but the subscription dropped them — pill never showed. Switched the transport to window `CustomEvent`s (`marinara:mari-phase`), matching the established pattern (`marinara:generation-complete`, `marinara:generation-error`) already used elsewhere in `use-generate.ts`. CustomEvents fire synchronously, outside React's batching, so every transition is observed. ### UX extension: pill now covers the generation phase too The original only showed the pill during the post-stream command window. But there's a similar dead-air window during token streaming — typing indicator hides on first token, then nothing visible until commands start (or completion). Extended the pill to cover that window too: **"Mari is thinking…"** fires on the first token (same edge that clears the typing indicator, so they never overlap), seamlessly transitions to **"Mari is updating your stuff…"** when commands start. ### Cleanup - Fixes the lint warning from #222 (`setCommandsExecuting` missing from `useCallback` deps). - Extracts `isMariParticipant` as a pure function. - Splits the chat-switch hide logic into its own focused effect instead of tangling it inside `evaluate()`. - Kept the Zustand `commandsExecutingChatIds` set + `setCommandsExecuting` action — still useful as a synchronous read source for any future consumer, costs nothing. ## Why a new PR instead of pushing to #222 #222 is from @cha1latte's fork — I can't push to it. Cherry-picked his four commits onto this branch with original authorship preserved (you'll see his name on the first four commits in the history), then layered the fixes on top as one commit. Will close #222 with a comment explaining the situation and crediting his diagnosis. ## Files | File | Change | |---|---| | `packages/client/src/components/chat/MariThinkingIndicator.tsx` | New component, two-phase pill, CustomEvent transport | | `packages/client/src/hooks/use-generate.ts` | Dispatch `marinara:mari-phase` on first token, on `assistant_commands_start`, and from termination cleanup | | `packages/client/src/stores/chat.store.ts` | Add `commandsExecutingChatIds` set + `setCommandsExecuting` action (preserved from #222) | | `packages/client/src/components/chat/ChatInput.tsx` | Mount `<MariThinkingIndicator />` | | `packages/client/src/components/chat/ConversationInput.tsx` | Mount `<MariThinkingIndicator />` | | `packages/server/src/routes/generate.routes.ts` | Emit `assistant_commands_start` / `_end` SSE events around the command loop (preserved from #222) | | `CHANGELOG.md` | Entry | ## Robustness I walked every edge case I could think of: - **Phase transitions within MIN_VISIBLE_MS**: timer cleared on each new phase, no flash. - **Duplicate idle fires** (`assistant_commands_end` AND `done` both call cleanup): second short-circuits. - **Background-chat events while user is in another chat**: filtered. - **Chat-switch while pill visible**: dedicated effect hides immediately. - **Stream error / abort / unexpected throw**: `finally` block always dispatches `idle`. No stuck states. - **Refresh mid-stream**: clean (no events arrive, pill never shows). - **Typing-indicator overlap (concern from testing)**: same-event-loop swap on first token. Atomic from user's perspective. - **Dual-mount safety** (`ChatInput` + `ConversationInput` both render it): only one mounts at a time; if both ever did, they'd both render the same correct pill — no state contention since each instance has its own refs. ## Testing - `pnpm check` passes (no errors, no warnings). - Manually tested in conversation mode with Professor Mari: - Single-command prompt — pill fires, transitions thinking → updating → clears. - 30-command prompt — pill stays visible through the entire window. - Chat-switch mid-stream — pill clears immediately in the new chat. - Stop button mid-stream — pill clears. - Non-Mari chat — no pill ever. - Mari chat with no command-triggering prompt — only "Mari is thinking…" during streaming, then clears at done. ## Test plan - [x] Send Mari a prompt that runs commands — verify pill cycles thinking → updating → clears. - [x] Watch typing indicator and pill don't overlap on first token. - [x] Switch chats mid-stream — pill clears in the destination chat. - [x] Trigger a stream error (kill network briefly) — pill clears. - [x] Hit Stop mid-stream — pill clears. - [x] Send a non-command message — pill shows during stream, hides at done. - [x] Send a message in a non-Mari chat — pill never appears. - [x] Mobile viewport — pill renders without escaping bounds. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added a visible "Mari is thinking…" / working indicator above the chat composer that appears during Mari's processing phases (thinking/updating), with accessible status text and subtle animation. * Indicator stays visible for a minimum duration to avoid flicker for brief tasks. * **Chore** * Updated changelog with an Unreleased entry recording the new UI indicator. <!-- 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:08:24 +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#4525
No description provided.