[GH-ISSUE #2727] [Issue]: Tracker panel rendering crashes and numeric/string coercion bugs in stat bars (non-array stats crash the whole panel) #1371

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

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

Originally assigned to: @SpicyMarinara on GitHub.

Summary

The tracker types assert stats: CharacterStat[], value: number, customFields: Record<string,string>, etc., but nothing coerces or validates the LLM's free-form JSON at the agent-merge boundary, and the renderers trust the declared types. A misbehaving tracker model that emits a non-array stats, a numeric string, or an off-type value either CRASHES the whole tracker panel (no error boundary anywhere in the subtree) or silently renders empty/garbled bars. Separately, the Fahrenheit-conversion regex matches a bare 'f' anywhere in the temperature string, mis-converting common Celsius+condition strings. These map directly to "tracker panel blanks out" and "stat bar not updating / shows wrong value" reports.


Bug 1 — Non-array character.stats crashes the entire tracker panel (high)

How it breaks the pipeline: getCharacterAmbienceStyle runs unconditionally for every character card and does character.stats?.find(...). Optional chaining guards only null/undefined; a truthy non-array ({}, string) makes .find not a function -> synchronous TypeError in render. There is NO error boundary in the tracker subtree, so the throw unmounts the React tree and blanks the app.

Steps to replicate: Have the character-tracker emit a character with "stats": {} (or "none"). The whole tracker panel white-screens.

Code trace: tracker-profile-style.ts:330 getSolidCssColor(character.stats?.find(s=>s.color)?.color); called CharacterTrackerCard.tsx:228, FeaturedCharacterTrackerCard.tsx:211 (pass raw character, so the local ?? [] guards don't help). Server persists verbatim (generate.routes.ts:7661,7872), lock-merge only touches stats if(Array.isArray(next.stats)) (tracker-field-locks.ts:569), client normalizeGameState coerces only text fields (game-state.store.ts:30). No error boundary under tracker-panel (repo grep finds only EncounterModal.tsx).

Bug 2 — Non-array personaStats / customTrackerFields crash the panel (low)

How it breaks the pipeline: TrackerSectionList guards only null (?? []); a non-array object reaches PersonaTrackerPanel/StatList/CustomFieldList where .length/.map/.some throw.

Code trace: TrackerSectionList.tsx:94,98; crash sites PersonaTrackerPanel.tsx:225-230, StatList.tsx:330,389, CustomTrackerPanel.tsx:46,73. (Reachable via the unvalidated PATCH endpoint chats.routes.ts:1482-1483 or a pre-existing bad row; normal agent paths normalize to arrays, so this is an API-boundary robustness gap.)

Bug 3 — String-typed stat max collapses the bar to 0% (medium)

How it breaks the pipeline: getStatPercent guards max with Number.isFinite (the static, non-coercing form): Number.isFinite('100')===false, so a numeric-string max returns 0% even though the numbers next to the bar read correctly. Bar empty in both edit and read-only mode.

Steps to replicate: Tracker emits {value:75, max:'100'}; the bar is empty, label reads '75 / 100'.

Code trace: tracker-stat-layout.ts:51-54; consumed StatList.tsx:100,289. No numeric coercion on the AI write path (agent-executor.ts:1929-1937 raw parse; generate-route-utils.ts:136 verbatim; tracker-field-locks.ts:417-421 spread; client coerces only text fields).

Bug 4 — String-typed stat value shows 0 in edit mode while the bar shows the real percentage (medium)

How it breaks the pipeline: InlineNumber uses Number.isFinite(value) ? value : 0, so a string value renders 0 in the editor while the bar computes the real percent via JS arithmetic coercion — a confusing mismatch, and saving overwrites the real value with 0.

Steps to replicate: Tracker emits {value:'50', max:100}; bar shows 50%, editor shows 0, static display shows '50'.

Code trace: InlineControls.tsx:344-348; bar StatList.tsx:289 via tracker-stat-layout.ts:51-54; static StatList.tsx:266-270.

Bug 5 — Non-numeric stat value -> invalid 'NaN%' width (low)

How it breaks the pipeline: getStatPercent does not guard/coerce stat.value; 'high'/100*100=NaN propagates through Math.min/max to width:'NaN%', an invalid CSS length the browser ignores, so the fill never reflects the value.

Code trace: tracker-stat-layout.ts:51-54; StatList.tsx:100,289. (Same applies in the HUD RoleplayHUDPanels.tsx:1730,1792.)

Bug 6 — Temperature with any 'f' mis-converted from Fahrenheit (medium)

How it breaks the pipeline: parseTemperatureValue tests /°?\s*f/i with both the degree and whitespace optional, so a bare 'f' anywhere (e.g. '5°C, foggy') triggers Fahrenheit conversion, corrupting the gauge label, color, and percent.

Steps to replicate: Set/emit temperature '5°C, foggy' (or '12C, frosty', '-3°C, frigid'); the panel shows a far-colder converted value (e.g. -15°C).

Code trace: world-state-display.ts:231-237 (test :235), consumed :256,269,287; rendered via WorldStatePanel.tsx:81 -> WorldForecastTile.tsx:32,105,108,117. (Requires both a digit and a stray 'f' in the same string; bare condition words alone return null.)


Suggested Fix

  • Add an error boundary around TrackerSectionList so one bad field can't blank the panel; coerce defensively in getCharacterAmbienceStyle (const stats = Array.isArray(character.stats) ? character.stats : []). (Bug 1.)
  • Use Array.isArray(...) ? ... : [] guards for personaStats/customFields/inventory/quests in TrackerSectionList, or normalize all GameState array fields in normalizeGameState. (Bug 2.)
  • In getStatPercent, coerce both operands with Number(...) and guard with Number.isFinite before dividing; ideally coerce stat.value/stat.max to finite numbers when normalizing the snapshot so the bar, editor (InlineNumber), and static display all agree. (Bugs 3-5.)
  • Also coerce in InlineNumber (typeof value==='number' ? value : Number(value)). (Bug 4.) Mirror the value-coercion fix in RoleplayHUDPanels stat bars. (Bug 5.)
  • Require the F to be a unit: anchor the regex to a degree/digit boundary (e.g. /(?:\d|°)\s*°?\s*f(?:ahrenheit)?\b/i) so 'foggy'/'frosty' don't trigger conversion. (Bug 6.)

Template checklist

  • pnpm check passes (TypeScript + ESLint)
  • Manually verify a character with non-array stats does not crash the tracker panel
  • Manually verify non-array personaStats/customTrackerFields do not crash the panel
  • Manually verify a stat with a numeric-string max renders the correct bar fill
  • Manually verify a stat with a numeric-string value shows the same number in the bar, editor, and static display
  • Manually verify a non-numeric stat value yields an empty (0%) bar, not NaN%
  • Manually verify '5°C, foggy' renders ~5°C, not a Fahrenheit-converted value

Affected files

  • packages/client/src/features/tracker-panel/lib/tracker-profile-style.ts
  • packages/client/src/features/tracker-panel/components/TrackerSectionList.tsx
  • packages/client/src/features/tracker-panel/lib/tracker-stat-layout.ts
  • packages/client/src/features/tracker-panel/components/controls/InlineControls.tsx
  • packages/client/src/features/tracker-panel/components/controls/StatList.tsx
  • packages/client/src/features/tracker-panel/lib/world-state-display.ts
  • packages/client/src/components/game/RoleplayHUDPanels.tsx

Audit provenance

Found by a multi-agent static audit of the trackers/widgets subsystem (Round 1 + round-2 gap sweep + completeness critic, each finding adversarially verified). Severity: HIGH. Line numbers are against the staging working tree.

Note: this issue was AI-drafted from a static read of the code; the validation/test-plan boxes are intentionally left UNCHECKED for a human to verify before close.

Originally created by @kolacheee on GitHub (Jun 21, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2727 Originally assigned to: @SpicyMarinara on GitHub. ## Summary The tracker types assert `stats: CharacterStat[]`, `value: number`, `customFields: Record<string,string>`, etc., but nothing coerces or validates the LLM's free-form JSON at the agent-merge boundary, and the renderers trust the declared types. A misbehaving tracker model that emits a non-array `stats`, a numeric string, or an off-type value either CRASHES the whole tracker panel (no error boundary anywhere in the subtree) or silently renders empty/garbled bars. Separately, the Fahrenheit-conversion regex matches a bare 'f' anywhere in the temperature string, mis-converting common Celsius+condition strings. These map directly to "tracker panel blanks out" and "stat bar not updating / shows wrong value" reports. --- ### Bug 1 — Non-array character.stats crashes the entire tracker panel (high) **How it breaks the pipeline:** `getCharacterAmbienceStyle` runs unconditionally for every character card and does `character.stats?.find(...)`. Optional chaining guards only null/undefined; a truthy non-array (`{}`, string) makes `.find` not a function -> synchronous TypeError in render. There is NO error boundary in the tracker subtree, so the throw unmounts the React tree and blanks the app. **Steps to replicate:** Have the character-tracker emit a character with `"stats": {}` (or `"none"`). The whole tracker panel white-screens. **Code trace:** `tracker-profile-style.ts:330` `getSolidCssColor(character.stats?.find(s=>s.color)?.color)`; called `CharacterTrackerCard.tsx:228`, `FeaturedCharacterTrackerCard.tsx:211` (pass raw `character`, so the local `?? []` guards don't help). Server persists verbatim (`generate.routes.ts:7661,7872`), lock-merge only touches stats `if(Array.isArray(next.stats))` (`tracker-field-locks.ts:569`), client `normalizeGameState` coerces only text fields (`game-state.store.ts:30`). No error boundary under tracker-panel (repo grep finds only `EncounterModal.tsx`). ### Bug 2 — Non-array personaStats / customTrackerFields crash the panel (low) **How it breaks the pipeline:** `TrackerSectionList` guards only null (`?? []`); a non-array object reaches `PersonaTrackerPanel`/`StatList`/`CustomFieldList` where `.length`/`.map`/`.some` throw. **Code trace:** `TrackerSectionList.tsx:94,98`; crash sites `PersonaTrackerPanel.tsx:225-230`, `StatList.tsx:330,389`, `CustomTrackerPanel.tsx:46,73`. (Reachable via the unvalidated PATCH endpoint `chats.routes.ts:1482-1483` or a pre-existing bad row; normal agent paths normalize to arrays, so this is an API-boundary robustness gap.) ### Bug 3 — String-typed stat max collapses the bar to 0% (medium) **How it breaks the pipeline:** `getStatPercent` guards max with `Number.isFinite` (the static, non-coercing form): `Number.isFinite('100')===false`, so a numeric-string max returns 0% even though the numbers next to the bar read correctly. Bar empty in both edit and read-only mode. **Steps to replicate:** Tracker emits `{value:75, max:'100'}`; the bar is empty, label reads '75 / 100'. **Code trace:** `tracker-stat-layout.ts:51-54`; consumed `StatList.tsx:100,289`. No numeric coercion on the AI write path (`agent-executor.ts:1929-1937` raw parse; `generate-route-utils.ts:136` verbatim; `tracker-field-locks.ts:417-421` spread; client coerces only text fields). ### Bug 4 — String-typed stat value shows 0 in edit mode while the bar shows the real percentage (medium) **How it breaks the pipeline:** `InlineNumber` uses `Number.isFinite(value) ? value : 0`, so a string value renders 0 in the editor while the bar computes the real percent via JS arithmetic coercion — a confusing mismatch, and saving overwrites the real value with 0. **Steps to replicate:** Tracker emits `{value:'50', max:100}`; bar shows 50%, editor shows 0, static display shows '50'. **Code trace:** `InlineControls.tsx:344-348`; bar `StatList.tsx:289` via `tracker-stat-layout.ts:51-54`; static `StatList.tsx:266-270`. ### Bug 5 — Non-numeric stat value -> invalid 'NaN%' width (low) **How it breaks the pipeline:** `getStatPercent` does not guard/coerce `stat.value`; `'high'/100*100`=NaN propagates through Math.min/max to `width:'NaN%'`, an invalid CSS length the browser ignores, so the fill never reflects the value. **Code trace:** `tracker-stat-layout.ts:51-54`; `StatList.tsx:100,289`. (Same applies in the HUD `RoleplayHUDPanels.tsx:1730,1792`.) ### Bug 6 — Temperature with any 'f' mis-converted from Fahrenheit (medium) **How it breaks the pipeline:** `parseTemperatureValue` tests `/°?\s*f/i` with both the degree and whitespace optional, so a bare 'f' anywhere (e.g. '5°C, foggy') triggers Fahrenheit conversion, corrupting the gauge label, color, and percent. **Steps to replicate:** Set/emit temperature '5°C, foggy' (or '12C, frosty', '-3°C, frigid'); the panel shows a far-colder converted value (e.g. -15°C). **Code trace:** `world-state-display.ts:231-237` (test `:235`), consumed `:256,269,287`; rendered via `WorldStatePanel.tsx:81` -> `WorldForecastTile.tsx:32,105,108,117`. (Requires both a digit and a stray 'f' in the same string; bare condition words alone return null.) --- ## Suggested Fix - Add an error boundary around `TrackerSectionList` so one bad field can't blank the panel; coerce defensively in `getCharacterAmbienceStyle` (`const stats = Array.isArray(character.stats) ? character.stats : []`). (Bug 1.) - Use `Array.isArray(...) ? ... : []` guards for personaStats/customFields/inventory/quests in `TrackerSectionList`, or normalize all GameState array fields in `normalizeGameState`. (Bug 2.) - In `getStatPercent`, coerce both operands with `Number(...)` and guard with `Number.isFinite` before dividing; ideally coerce `stat.value`/`stat.max` to finite numbers when normalizing the snapshot so the bar, editor (`InlineNumber`), and static display all agree. (Bugs 3-5.) - Also coerce in `InlineNumber` (`typeof value==='number' ? value : Number(value)`). (Bug 4.) Mirror the value-coercion fix in `RoleplayHUDPanels` stat bars. (Bug 5.) - Require the F to be a unit: anchor the regex to a degree/digit boundary (e.g. `/(?:\d|°)\s*°?\s*f(?:ahrenheit)?\b/i`) so 'foggy'/'frosty' don't trigger conversion. (Bug 6.) --- ## Template checklist - [ ] `pnpm check` passes (TypeScript + ESLint) - [ ] Manually verify a character with non-array `stats` does not crash the tracker panel - [ ] Manually verify non-array personaStats/customTrackerFields do not crash the panel - [ ] Manually verify a stat with a numeric-string max renders the correct bar fill - [ ] Manually verify a stat with a numeric-string value shows the same number in the bar, editor, and static display - [ ] Manually verify a non-numeric stat value yields an empty (0%) bar, not NaN% - [ ] Manually verify '5°C, foggy' renders ~5°C, not a Fahrenheit-converted value --- ### Affected files - `packages/client/src/features/tracker-panel/lib/tracker-profile-style.ts` - `packages/client/src/features/tracker-panel/components/TrackerSectionList.tsx` - `packages/client/src/features/tracker-panel/lib/tracker-stat-layout.ts` - `packages/client/src/features/tracker-panel/components/controls/InlineControls.tsx` - `packages/client/src/features/tracker-panel/components/controls/StatList.tsx` - `packages/client/src/features/tracker-panel/lib/world-state-display.ts` - `packages/client/src/components/game/RoleplayHUDPanels.tsx` ### Audit provenance Found by a multi-agent static audit of the trackers/widgets subsystem (Round 1 + round-2 gap sweep + completeness critic, each finding adversarially verified). Severity: **HIGH**. Line numbers are against the `staging` working tree. > Note: this issue was AI-drafted from a static read of the code; the validation/test-plan boxes are intentionally left UNCHECKED for a human to verify before close.
Author
Owner

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

Fixed in eccb5e20. Tracker character cards and section lists now guard malformed non-array stats/persona/custom arrays, the tracker panel has a local error boundary fallback, stat percentage/edit controls coerce numeric strings and clamp invalid values, the compact roleplay HUD uses the same stat coercion, and Fahrenheit parsing now requires the unit next to the numeric temperature so strings like '5°C, foggy' stay Celsius.

<!-- gh-comment-id:4761830051 --> @SpicyMarinara commented on GitHub (Jun 21, 2026): Fixed in eccb5e20. Tracker character cards and section lists now guard malformed non-array stats/persona/custom arrays, the tracker panel has a local error boundary fallback, stat percentage/edit controls coerce numeric strings and clamp invalid values, the compact roleplay HUD uses the same stat coercion, and Fahrenheit parsing now requires the unit next to the numeric temperature so strings like '5°C, foggy' stay Celsius.
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#1371
No description provided.