[GH-ISSUE #3104] [Issue]: Severe client freeze (multi-second main-thread blocks, GPU spikes) on chats using the world-state / character-tracker agents #1664

Closed
opened 2026-10-21 05:41:29 +07:00 by bsakaguchi · 7 comments
Owner

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

Originally assigned to: @SpicyMarinara, @kolacheee on GitHub.

What's wrong

Opening a chat that uses the world-state and/or character-tracker agents puts the client into a severe main-thread freeze: interactions take tens of seconds, the GPU spikes, and the tab is effectively unresponsive ("memory-leak vibes"). It is reported in all chat modes (Conversation, Roleplay, and Game), only on chats that ran these agents, and it stops the moment you navigate to home, a new chat, or a chat that did not use those agents. It is worst on older chats (created/used on earlier versions) that have accumulated a lot of tracked-character / world-state data.

This is a client-side problem (the browser main thread is blocked), not slow generation — it happens while the chat just sits open, and clears when you leave the chat.

How to reproduce (try it yourself)

  1. Open a chat that has the character-tracker and/or world-state agent enabled and that has been used for many turns (so the tracker has accumulated several present characters / world-state), ideally on an install with a large character/persona library.
  2. Let the chat open, then try to interact (click a message, scroll, delete a message, type a reply).

You'll see: each interaction takes many seconds to tens of seconds; the GPU revs; deleting/replying causes a heavy momentary freeze. Navigating to the home page or a non-agent chat makes it instantly responsive again.

Evidence captured from affected users (DevTools)

  • Web Vitals INP = 188,848 ms. Two recorded pointer interactions: one 115,472 ms (input delay 69,013 ms, processing 46,411 ms), one 188,848 ms (input delay 49,009 ms, processing 46,607 ms, presentation 93,233 ms). The ~46 s processing + ~49–69 s input delay mean the main thread is doing ~46 s synchronous chunks of work back-to-back.
  • Network requests left pending >50 s (fetch callbacks starved behind the blocked main thread).
  • Opening an affected Roleplay chat lazy-loads exactly these chunks: TrackerDataSidebar (~175 kB), RoleplayHUD (~29 kB), world-state-display (~12 kB), TrackerSizeTierIcon — i.e. the tracker-panel / world-state UI.
  • One user: "it's loading every persona and character in my app, even ones not in this chat."

Where it is (localized — see confidence note below)

The hotspot is the tracker-panel feature that renders the world-state / character-tracker agent output. It mounts only when those agents are active (which is why the lag tracks "chats with agents" across all modes, and clears on chats without them):

  • packages/client/src/features/tracker-panel/components/TrackerDataSidebar.tsx, TrackerSectionList.tsx, components/sections/WorldStatePanel.tsx, components/character-card/CharacterTrackerCard.tsx, and packages/client/src/components/chat/RoleplayHUD.tsx — the components in the lazy chunks above.
  • Whole-library over-fetch + parse (matches "loading every character/persona"): packages/client/src/features/tracker-panel/hooks/use-tracker-sprite-lookup.ts:16-49 calls useCharacters() (the entire library) and then maps parseCharacterDisplayData(character) over every character row to build a name→id lookup — even though only the chat's tracked characters are rendered. packages/client/src/features/tracker-panel/hooks/use-tracker-panel-model.ts:70 likewise loads all personas. For a library of hundreds of cards, building that lookup is an O(library) JSON-parse pass that re-runs whenever the character-list reference changes.
  • The per-tracked-character render: components/sections/CharacterTrackerPanel.tsx:76 maps a CharacterTrackerCard per present character; old chats accumulate many present characters.

What's happening (leading mechanism)

A chat with the world-state/character-tracker agents mounts the tracker panel, which (a) loads and parses the entire character + persona library to build sprite/name lookups it only needs the chat's characters for, and (b) renders a card per accumulated tracked character. The cost scales with library size × tracked-character count, both of which are large for long-lived older chats on big installs — producing the ~46 s synchronous main-thread blocks. Because the panel re-renders on every gameState/agent update and on edits, the freeze recurs continuously while the chat is open.

Ruled out (investigated and excluded, so reviewers don't re-chase them):

  • Macro corruption / re-expansion of stored agent macros — the engine deliberately prevents this ({{agent::TYPE}} is a terminal flat substitution placed after all macro passes); stored tracker text is never re-run through resolveMacros.
  • Server generation cost / tracker-context assembly — those are per-send, can't cause a freeze while the chat sits idle.
  • The game-session auto-switch effect (resolveCurrentGameSessionChatId) — it early-returns for non-game chats, so it cannot affect Conversation/Roleplay.
  • The macro engine itself — benchmarked on the compiled build; ~336 ms worst case for a 200 KB prompt, guarded by MAX_MACRO_EXPANSIONS.

Suggested direction

  1. Pin the exact hot frame with a Performance → Bottom-Up (self-time) profile recorded while an affected chat is open — it will name the precise function inside features/tracker-panel/**.
  2. Likely fixes once confirmed: scope use-tracker-sprite-lookup to the chat's characters instead of parsing the whole library; memoize/virtualize the tracked-character card list; avoid re-parsing character cards on every list-reference change; and bound work to the number of present characters actually rendered.

Confidence note

This is a localization, not a pinned root-cause line. The evidence (the loaded tracker chunks, the INP breakdown, the whole-library parse in use-tracker-sprite-lookup, and the symptom matrix) strongly points at the tracker-panel render, but the single exact O(n) frame should be confirmed with a Bottom-Up profile or a local repro (a chat with the character-tracker/world-state agents and many accumulated present characters on a large-library install) before fixing.


AI-investigated against v2.0.8 (main). Symptom data from affected users' DevTools (INP/Network); code paths read and cited. The exact hot function is not yet pinned — please capture a Bottom-Up profile or reproduce locally to confirm before fixing.

Originally created by @kolacheee on GitHub (Jun 30, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3104 Originally assigned to: @SpicyMarinara, @kolacheee on GitHub. **What's wrong** Opening a chat that uses the **world-state** and/or **character-tracker** agents puts the client into a severe main-thread freeze: interactions take tens of seconds, the GPU spikes, and the tab is effectively unresponsive ("memory-leak vibes"). It is reported in **all chat modes** (Conversation, Roleplay, and Game), only on chats that ran these agents, and it **stops the moment you navigate to home, a new chat, or a chat that did not use those agents**. It is worst on **older chats** (created/used on earlier versions) that have accumulated a lot of tracked-character / world-state data. This is a **client-side** problem (the browser main thread is blocked), not slow generation — it happens while the chat just sits open, and clears when you leave the chat. **How to reproduce (try it yourself)** 1. Open a chat that has the **character-tracker** and/or **world-state** agent enabled and that has been used for many turns (so the tracker has accumulated several present characters / world-state), ideally on an install with a large character/persona library. 2. Let the chat open, then try to interact (click a message, scroll, delete a message, type a reply). You'll see: each interaction takes many seconds to tens of seconds; the GPU revs; deleting/replying causes a heavy momentary freeze. Navigating to the home page or a non-agent chat makes it instantly responsive again. **Evidence captured from affected users (DevTools)** - **Web Vitals INP = 188,848 ms.** Two recorded `pointer` interactions: one `115,472 ms` (input delay **69,013 ms**, processing **46,411 ms**), one `188,848 ms` (input delay **49,009 ms**, processing **46,607 ms**, presentation **93,233 ms**). The ~46 s *processing* + ~49–69 s *input delay* mean the main thread is doing ~46 s synchronous chunks of work back-to-back. - Network requests left **pending >50 s** (fetch callbacks starved behind the blocked main thread). - Opening an affected Roleplay chat lazy-loads exactly these chunks: **`TrackerDataSidebar` (~175 kB)**, `RoleplayHUD` (~29 kB), `world-state-display` (~12 kB), `TrackerSizeTierIcon` — i.e. the tracker-panel / world-state UI. - One user: *"it's loading every persona and character in my app, even ones not in this chat."* **Where it is (localized — see confidence note below)** The hotspot is the **tracker-panel feature** that renders the world-state / character-tracker agent output. It mounts only when those agents are active (which is why the lag tracks "chats with agents" across all modes, and clears on chats without them): - `packages/client/src/features/tracker-panel/components/TrackerDataSidebar.tsx`, `TrackerSectionList.tsx`, `components/sections/WorldStatePanel.tsx`, `components/character-card/CharacterTrackerCard.tsx`, and `packages/client/src/components/chat/RoleplayHUD.tsx` — the components in the lazy chunks above. - **Whole-library over-fetch + parse** (matches "loading every character/persona"): `packages/client/src/features/tracker-panel/hooks/use-tracker-sprite-lookup.ts:16-49` calls `useCharacters()` (the entire library) and then maps `parseCharacterDisplayData(character)` over **every** character row to build a name→id lookup — even though only the chat's tracked characters are rendered. `packages/client/src/features/tracker-panel/hooks/use-tracker-panel-model.ts:70` likewise loads **all** personas. For a library of hundreds of cards, building that lookup is an O(library) JSON-parse pass that re-runs whenever the character-list reference changes. - The per-tracked-character render: `components/sections/CharacterTrackerPanel.tsx:76` maps a `CharacterTrackerCard` per present character; old chats accumulate many present characters. **What's happening (leading mechanism)** A chat with the world-state/character-tracker agents mounts the tracker panel, which (a) loads and **parses the entire character + persona library** to build sprite/name lookups it only needs the chat's characters for, and (b) renders a card per accumulated tracked character. The cost scales with **library size × tracked-character count**, both of which are large for long-lived older chats on big installs — producing the ~46 s synchronous main-thread blocks. Because the panel re-renders on every gameState/agent update and on edits, the freeze recurs continuously while the chat is open. **Ruled out** (investigated and excluded, so reviewers don't re-chase them): - Macro corruption / re-expansion of stored agent macros — the engine deliberately prevents this (`{{agent::TYPE}}` is a terminal flat substitution placed after all macro passes); stored tracker text is never re-run through `resolveMacros`. - Server generation cost / tracker-context assembly — those are per-send, can't cause a freeze while the chat sits idle. - The game-session auto-switch effect (`resolveCurrentGameSessionChatId`) — it early-returns for non-game chats, so it cannot affect Conversation/Roleplay. - The macro engine itself — benchmarked on the compiled build; ~336 ms worst case for a 200 KB prompt, guarded by `MAX_MACRO_EXPANSIONS`. **Suggested direction** 1. Pin the exact hot frame with a **Performance → Bottom-Up (self-time)** profile recorded while an affected chat is open — it will name the precise function inside `features/tracker-panel/**`. 2. Likely fixes once confirmed: scope `use-tracker-sprite-lookup` to the **chat's** characters instead of parsing the whole library; memoize/virtualize the tracked-character card list; avoid re-parsing character cards on every list-reference change; and bound work to the number of present characters actually rendered. **Confidence note** This is a **localization**, not a pinned root-cause line. The evidence (the loaded tracker chunks, the INP breakdown, the whole-library parse in `use-tracker-sprite-lookup`, and the symptom matrix) strongly points at the tracker-panel render, but the single exact O(n) frame should be confirmed with a Bottom-Up profile or a local repro (a chat with the character-tracker/world-state agents and many accumulated present characters on a large-library install) before fixing. --- *AI-investigated against v2.0.8 (`main`). Symptom data from affected users' DevTools (INP/Network); code paths read and cited. The exact hot function is not yet pinned — please capture a Bottom-Up profile or reproduce locally to confirm before fixing.*
bsakaguchi 2026-10-21 05:41:29 +07:00
Author
Owner

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

Is this still happening on staging?

<!-- gh-comment-id:4845254017 --> @SpicyMarinara commented on GitHub (Jun 30, 2026): Is this still happening on staging?
Author
Owner

@kolacheee commented on GitHub (Jun 30, 2026):

I hadn't checked yet personally but good to keep this up in case users still report the issue in staging

<!-- gh-comment-id:4845285699 --> @kolacheee commented on GitHub (Jun 30, 2026): I hadn't checked yet personally but good to keep this up in case users still report the issue in staging
Author
Owner

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

Still happening on staging.

<!-- gh-comment-id:4845403532 --> @SpicyMarinara commented on GitHub (Jun 30, 2026): Still happening on staging.
Author
Owner

@kolacheee commented on GitHub (Jun 30, 2026):

Opened a draft diagnostic PR toward this: #3111.

It adds self-gating render-timing + long-task warnings (silent in normal use) so an affected user can pin the exact slow subtree by just opening the laggy chat and reporting the [mari-perf] console line (e.g. [mari-perf] tracker-panel render+commit took 46180ms). That names the fix target so the follow-up PR is the real fix rather than a guess. Targets staging; meant to be reverted once the frame is identified.

<!-- gh-comment-id:4846207265 --> @kolacheee commented on GitHub (Jun 30, 2026): Opened a draft diagnostic PR toward this: #3111. It adds **self-gating** render-timing + long-task warnings (silent in normal use) so an affected user can pin the exact slow subtree by just opening the laggy chat and reporting the `[mari-perf]` console line (e.g. `[mari-perf] tracker-panel render+commit took 46180ms`). That names the fix target so the follow-up PR is the real fix rather than a guess. Targets `staging`; meant to be reverted once the frame is identified.
Author
Owner

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

Codex is taking this now on branch codex/3104-tracker-panel-freeze. Draft PR will track the fix while I narrow the tracker-panel hot path and keep the patch scoped.

<!-- gh-comment-id:4846826026 --> @SpicyMarinara commented on GitHub (Jun 30, 2026): Codex is taking this now on branch codex/3104-tracker-panel-freeze. Draft PR will track the fix while I narrow the tracker-panel hot path and keep the patch scoped.
Author
Owner

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

Addressed, but not closing yet, until getting confirmation the issue was fixed.

<!-- gh-comment-id:4847012290 --> @SpicyMarinara commented on GitHub (Jun 30, 2026): Addressed, but not closing yet, until getting confirmation the issue was fixed.
Author
Owner

@SpicyMarinara commented on GitHub (Jul 2, 2026):

Closing now that the staged perf work has landed across the tracker/render-scope/macro follow-ups, including PRs #3111, #3112, #3113, #3115, and #3118.

<!-- gh-comment-id:4864503717 --> @SpicyMarinara commented on GitHub (Jul 2, 2026): Closing now that the staged perf work has landed across the tracker/render-scope/macro follow-ups, including PRs #3111, #3112, #3113, #3115, and #3118.
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#1664
No description provided.