[GH-ISSUE #2728] [Issue]: Game-mode HUD widgets — stat_block update misrouting, lost manual saves, inventory_grid drops, off-screen recovery, timer restart #1372

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/2728

Originally assigned to: @SpicyMarinara on GitHub.

Summary

The game-mode HUD widget subsystem has multiple state/persistence defects. Model-driven stat_block updates are dropped or misrouted into a non-rendered value field when the block has no stats or the name doesn't match. Manual widget saves race two different persistence paths (a stale chat-metadata sync, and the debounced PUT) and get reverted. A configured inventory_grid widget is filtered out of the render path entirely. The inventory-grid contents editor wipes quantity/slot on any edit. A locked widget/map panel restored at a smaller viewport is never re-clamped and becomes unrecoverable. And a finished timer restarts on reload because completion is never persisted.


Bug 1 — applyWidgetUpdate drops/misroutes stat_block updates (medium)

How it breaks the pipeline: The stat_block branch is gated on changes.statName && w.type==='stat_block' && newConfig.stats. (a) When stats is undefined, control falls to the numeric else-branch which writes newConfig.value — a field StatBlockWidget never reads — so the stat write is lost and config is polluted. (b) Even with stats, the match is exact stat.name===targetName with no trim/case tolerance and no append fallback, so any drift drops the update.

Steps to replicate: Have a stat_block with no stats yet; the GM emits a [widget: id, stat="Str", value=5] tag. The stat never appears; a phantom config.value is set.

Code trace: game-mode.store.ts:337-350 (guard :337, else writes value :345-346); renderer reads only config.stats GameWidgetPanel.tsx:1068-1084; parser game-tag-parser.ts:921-924; sole apply path GameSurface.tsx:3873-3874. (Note: stats:[] is truthy so it takes the branch and silently drops; stats:undefined is the misroute case.)

Bug 2 — Manual widget save clobbered by stale chat-metadata sync (medium)

How it breaks the pipeline: The widget-persistence reconciliation guard (getPendingHudWidgetPersistenceSignature) is set only by the agent/debounced path; the manual saveWidget/useUpdateGameWidgets path never registers it. If chatMeta refetches with the old gameWidgetState while the PUT is in flight, useSyncGameState sees a signature mismatch with no pending guard and reverts the optimistic edit.

Steps to replicate: Edit a widget value during a game turn (when chatKeys.detail is invalidated by the streaming metadata patch); the value briefly reverts to the previous value.

Code trace: GameWidgetPanel.tsx:250-271 (saveWidget); use-game.ts:578-599 (useUpdateGameWidgets, no pending set); guard use-game.ts:727-736; signature set only by debouncedPersistWidgets/applyWidgetUpdate game-mode.store.ts:87-103,372-374; server PUT game.routes.ts:6044-6055; invalidation use-generate.ts:1703.

Bug 3 — Debounced widget PUT overwrites a concurrent manual save (low)

How it breaks the pipeline: applyWidgetUpdate's debounced timer captures a model-applied widget array and fires ~1s later; useUpdateGameWidgets's immediate PUT never cancels that timer. If a manual save lands between, the stale debounced PUT (full replace) overwrites the saved edit on the server, reverting it ~1s later.

Steps to replicate: Model emits a widget tag at turn end, user manually edits+saves within ~1s; the manual edit reverts after a beat.

Code trace: game-mode.store.ts:87-103 (debounce, only clearTimeout at :90), :328-379 (applyWidgetUpdate -> debouncedPersistWidgets :374); GameWidgetPanel.tsx:250-268; use-game.ts:578-600 (no timer cancel); server full replace game.routes.ts:6044-6055.

Bug 4 — Configured inventory_grid widget never renders (low)

How it breaks the pipeline: getVisibleWidgets filters w.type !== 'inventory_grid' before the MAX_WIDGETS slice, so an inventory_grid the user/model configured (and that counts toward the 4-widget budget, is persisted, and is kept updated by the server) never appears in the HUD rail despite a working renderer existing.

Code trace: GameWidgetPanel.tsx:84-86 (filter+slice); renderer exists :473-474,1107-1180; both panels use it GameSurface.tsx:8900-8901,9337-9345; selectable+counted GameWidgetSetupEditor.tsx:19,110-111,195,227; server maintains it scene-analyzer.ts:120-121,156-159.

Bug 5 — Inventory-grid contents editor resets quantity/slot on any edit (medium)

How it breaks the pipeline: The Contents textarea serializes only item.name and rebuilds the whole array as {name, quantity:1} on change, discarding existing quantity and slot (which drive the category tabs and count badges).

Steps to replicate: With a blueprint/imported inventory_grid containing {name:'Potion', quantity:5, slot:'consumable'}, edit the Contents textarea (add a line); Potion becomes {name:'Potion', quantity:1} and loses its slot.

Code trace: GameWidgetSetupEditor.tsx:534-546 (value :535, onChange rebuild :538-545); normalizeConfig keeps array as-is :158-163; lost fields used at GameWidgetPanel.tsx:1114,1167-1169; type game.ts:478.

Bug 6 — Locked-on-restore dragged panel never re-clamped, unrecoverable off-screen (medium)

How it breaks the pipeline: Panels default to locked; the unlock->drag->re-lock flow persists {locked:true, x, y}. On reload a locked panel has drag={false}, so framer-motion's drag feature (and its resize listener / ResizeObserver that would re-clamp) is never created; the stale wide-viewport offset applied via style={{x,y}} is never re-bounded at a smaller viewport, putting the header/lock toggle off-screen with no reset affordance. (Most exposed: the always-draggable GameMapPanel.)

Code trace: DraggablePanel.tsx:26-84 (seed from localStorage, no clamp/resize listener; writes only on dragEnd/toggleLocked); GameWidgetPanel.tsx:402-409/GameMap.tsx:546-554 (style={{x,y}}, drag={!locked}, no dragControls); constraints resize GameSurface.tsx:8734,9335. (Refined cause: locked-on-restore path, not framer-motion failing to re-bound in general.)

Bug 7 — Finished timer restarts on reload (low)

How it breaks the pipeline: The countdown lives only in local displaySeconds; on reaching 0 it never writes config.running=false/config.seconds=0, so persisted config keeps running:true and the old seconds. On reload the timer remounts and restarts.

Code trace: GameWidgetPanel.tsx:1182-1222 (local state :1185, reseed effect :1189-1194, completion clears interval but no write-back :1201-1209); rehydrate use-game.ts:719-733. (Only the reload path reproduces; in-session re-renders do not.)


Suggested Fix

  • For stat_block with statName, operate on (newConfig.stats ?? []), match trimmed/case-insensitively, and append {name, value} when no match — never fall through to the numeric value branch. (Bug 1.)
  • Register pendingWidgetPersistence (chatId+signature) in useUpdateGameWidgets/saveWidget before mutation and clear on settle so the sync respects in-flight manual edits. (Bug 2.)
  • Have useUpdateGameWidgets cancel any pending debounce (export clearPendingWidgetPersist() from the store, call in onMutate), or share one persistence path. (Bug 3.)
  • Render inventory_grid in the rail (drop the exclusion) or stop making it selectable/counted in the setup editor. (Bug 4.)
  • Preserve existing quantity/slot by matching incoming names against prior contents, or expose quantity/slot in the editor. (Bug 5.)
  • Clamp x/y into the constraints rect on mount and on a window/constraints ResizeObserver (for locked panels too), and add a reset-position affordance. (Bug 6.)
  • On reaching 0 (or pause), persist running:false/seconds:0 through applyWidgetUpdate/updateGameWidgets. (Bug 7.)

Template checklist

  • pnpm check passes (TypeScript + ESLint)
  • Manually verify a GM stat update on a stats-less stat_block creates/updates the named stat (no phantom value)
  • Manually verify a manual widget save during a game turn is not reverted by a metadata refetch
  • Manually verify a manual widget save is not overwritten by the debounced PUT ~1s later
  • Manually verify a configured inventory_grid widget renders in the HUD rail
  • Manually verify editing the inventory-grid Contents textarea preserves item quantity and slot
  • Manually verify a dragged+locked panel reloaded at a smaller window is reachable (or reset works)
  • Manually verify a timer that counted to 0 stays finished after reload

Affected files

  • packages/client/src/stores/game-mode.store.ts
  • packages/client/src/components/game/GameWidgetPanel.tsx
  • packages/client/src/components/game/GameWidgetSetupEditor.tsx
  • packages/client/src/components/game/DraggablePanel.tsx
  • packages/client/src/components/game/GameMap.tsx
  • packages/client/src/components/game/GameSurface.tsx
  • packages/client/src/hooks/use-game.ts

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: MEDIUM. 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/2728 Originally assigned to: @SpicyMarinara on GitHub. ## Summary The game-mode HUD widget subsystem has multiple state/persistence defects. Model-driven `stat_block` updates are dropped or misrouted into a non-rendered `value` field when the block has no stats or the name doesn't match. Manual widget saves race two different persistence paths (a stale chat-metadata sync, and the debounced PUT) and get reverted. A configured `inventory_grid` widget is filtered out of the render path entirely. The inventory-grid contents editor wipes quantity/slot on any edit. A locked widget/map panel restored at a smaller viewport is never re-clamped and becomes unrecoverable. And a finished timer restarts on reload because completion is never persisted. --- ### Bug 1 — applyWidgetUpdate drops/misroutes stat_block updates (medium) **How it breaks the pipeline:** The stat_block branch is gated on `changes.statName && w.type==='stat_block' && newConfig.stats`. (a) When `stats` is undefined, control falls to the numeric else-branch which writes `newConfig.value` — a field `StatBlockWidget` never reads — so the stat write is lost and config is polluted. (b) Even with stats, the match is exact `stat.name===targetName` with no trim/case tolerance and no append fallback, so any drift drops the update. **Steps to replicate:** Have a stat_block with no `stats` yet; the GM emits a `[widget: id, stat="Str", value=5]` tag. The stat never appears; a phantom `config.value` is set. **Code trace:** `game-mode.store.ts:337-350` (guard `:337`, else writes `value` `:345-346`); renderer reads only `config.stats` `GameWidgetPanel.tsx:1068-1084`; parser `game-tag-parser.ts:921-924`; sole apply path `GameSurface.tsx:3873-3874`. (Note: `stats:[]` is truthy so it takes the branch and silently drops; `stats:undefined` is the misroute case.) ### Bug 2 — Manual widget save clobbered by stale chat-metadata sync (medium) **How it breaks the pipeline:** The widget-persistence reconciliation guard (`getPendingHudWidgetPersistenceSignature`) is set only by the agent/debounced path; the manual `saveWidget`/`useUpdateGameWidgets` path never registers it. If `chatMeta` refetches with the old `gameWidgetState` while the PUT is in flight, `useSyncGameState` sees a signature mismatch with no pending guard and reverts the optimistic edit. **Steps to replicate:** Edit a widget value during a game turn (when `chatKeys.detail` is invalidated by the streaming metadata patch); the value briefly reverts to the previous value. **Code trace:** `GameWidgetPanel.tsx:250-271` (`saveWidget`); `use-game.ts:578-599` (`useUpdateGameWidgets`, no pending set); guard `use-game.ts:727-736`; signature set only by `debouncedPersistWidgets`/`applyWidgetUpdate` `game-mode.store.ts:87-103,372-374`; server PUT `game.routes.ts:6044-6055`; invalidation `use-generate.ts:1703`. ### Bug 3 — Debounced widget PUT overwrites a concurrent manual save (low) **How it breaks the pipeline:** `applyWidgetUpdate`'s debounced timer captures a model-applied widget array and fires ~1s later; `useUpdateGameWidgets`'s immediate PUT never cancels that timer. If a manual save lands between, the stale debounced PUT (full replace) overwrites the saved edit on the server, reverting it ~1s later. **Steps to replicate:** Model emits a widget tag at turn end, user manually edits+saves within ~1s; the manual edit reverts after a beat. **Code trace:** `game-mode.store.ts:87-103` (debounce, only `clearTimeout` at `:90`), `:328-379` (`applyWidgetUpdate` -> `debouncedPersistWidgets :374`); `GameWidgetPanel.tsx:250-268`; `use-game.ts:578-600` (no timer cancel); server full replace `game.routes.ts:6044-6055`. ### Bug 4 — Configured inventory_grid widget never renders (low) **How it breaks the pipeline:** `getVisibleWidgets` filters `w.type !== 'inventory_grid'` before the `MAX_WIDGETS` slice, so an `inventory_grid` the user/model configured (and that counts toward the 4-widget budget, is persisted, and is kept updated by the server) never appears in the HUD rail despite a working renderer existing. **Code trace:** `GameWidgetPanel.tsx:84-86` (filter+slice); renderer exists `:473-474,1107-1180`; both panels use it `GameSurface.tsx:8900-8901,9337-9345`; selectable+counted `GameWidgetSetupEditor.tsx:19,110-111,195,227`; server maintains it `scene-analyzer.ts:120-121,156-159`. ### Bug 5 — Inventory-grid contents editor resets quantity/slot on any edit (medium) **How it breaks the pipeline:** The Contents textarea serializes only `item.name` and rebuilds the whole array as `{name, quantity:1}` on change, discarding existing `quantity` and `slot` (which drive the category tabs and count badges). **Steps to replicate:** With a blueprint/imported inventory_grid containing `{name:'Potion', quantity:5, slot:'consumable'}`, edit the Contents textarea (add a line); Potion becomes `{name:'Potion', quantity:1}` and loses its slot. **Code trace:** `GameWidgetSetupEditor.tsx:534-546` (value `:535`, onChange rebuild `:538-545`); `normalizeConfig` keeps array as-is `:158-163`; lost fields used at `GameWidgetPanel.tsx:1114,1167-1169`; type `game.ts:478`. ### Bug 6 — Locked-on-restore dragged panel never re-clamped, unrecoverable off-screen (medium) **How it breaks the pipeline:** Panels default to locked; the unlock->drag->re-lock flow persists `{locked:true, x, y}`. On reload a locked panel has `drag={false}`, so framer-motion's drag feature (and its resize listener / ResizeObserver that would re-clamp) is never created; the stale wide-viewport offset applied via `style={{x,y}}` is never re-bounded at a smaller viewport, putting the header/lock toggle off-screen with no reset affordance. (Most exposed: the always-draggable `GameMapPanel`.) **Code trace:** `DraggablePanel.tsx:26-84` (seed from localStorage, no clamp/resize listener; writes only on dragEnd/toggleLocked); `GameWidgetPanel.tsx:402-409`/`GameMap.tsx:546-554` (`style={{x,y}}`, `drag={!locked}`, no dragControls); constraints resize `GameSurface.tsx:8734,9335`. (Refined cause: locked-on-restore path, not framer-motion failing to re-bound in general.) ### Bug 7 — Finished timer restarts on reload (low) **How it breaks the pipeline:** The countdown lives only in local `displaySeconds`; on reaching 0 it never writes `config.running=false`/`config.seconds=0`, so persisted config keeps `running:true` and the old seconds. On reload the timer remounts and restarts. **Code trace:** `GameWidgetPanel.tsx:1182-1222` (local state `:1185`, reseed effect `:1189-1194`, completion clears interval but no write-back `:1201-1209`); rehydrate `use-game.ts:719-733`. (Only the reload path reproduces; in-session re-renders do not.) --- ## Suggested Fix - For stat_block with `statName`, operate on `(newConfig.stats ?? [])`, match trimmed/case-insensitively, and append `{name, value}` when no match — never fall through to the numeric `value` branch. (Bug 1.) - Register `pendingWidgetPersistence` (chatId+signature) in `useUpdateGameWidgets`/`saveWidget` before mutation and clear on settle so the sync respects in-flight manual edits. (Bug 2.) - Have `useUpdateGameWidgets` cancel any pending debounce (export `clearPendingWidgetPersist()` from the store, call in `onMutate`), or share one persistence path. (Bug 3.) - Render `inventory_grid` in the rail (drop the exclusion) or stop making it selectable/counted in the setup editor. (Bug 4.) - Preserve existing `quantity`/`slot` by matching incoming names against prior contents, or expose quantity/slot in the editor. (Bug 5.) - Clamp `x/y` into the constraints rect on mount and on a window/constraints ResizeObserver (for locked panels too), and add a reset-position affordance. (Bug 6.) - On reaching 0 (or pause), persist `running:false`/`seconds:0` through `applyWidgetUpdate`/`updateGameWidgets`. (Bug 7.) --- ## Template checklist - [ ] `pnpm check` passes (TypeScript + ESLint) - [ ] Manually verify a GM stat update on a stats-less stat_block creates/updates the named stat (no phantom `value`) - [ ] Manually verify a manual widget save during a game turn is not reverted by a metadata refetch - [ ] Manually verify a manual widget save is not overwritten by the debounced PUT ~1s later - [ ] Manually verify a configured inventory_grid widget renders in the HUD rail - [ ] Manually verify editing the inventory-grid Contents textarea preserves item quantity and slot - [ ] Manually verify a dragged+locked panel reloaded at a smaller window is reachable (or reset works) - [ ] Manually verify a timer that counted to 0 stays finished after reload --- ### Affected files - `packages/client/src/stores/game-mode.store.ts` - `packages/client/src/components/game/GameWidgetPanel.tsx` - `packages/client/src/components/game/GameWidgetSetupEditor.tsx` - `packages/client/src/components/game/DraggablePanel.tsx` - `packages/client/src/components/game/GameMap.tsx` - `packages/client/src/components/game/GameSurface.tsx` - `packages/client/src/hooks/use-game.ts` ### 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: **MEDIUM**. 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 6e3ff066.\n\nCovered the HUD-widget failure cluster here:\n- routes stat_block model updates by stat name without falling through into the generic value path\n- keeps manual widget saves from being clobbered by stale metadata or pending debounced PUTs\n- restores inventory_grid widgets to the HUD and preserves item quantity/slot metadata when editing contents\n- clamps persisted map/widget panel positions back into the viewport and adds double-click reset on the lock button\n- persists completed timers as stopped at zero so they do not restart after reload\n\nPer maintainer request, deferred pnpm validation until the issue sweep is complete.

<!-- gh-comment-id:4761853849 --> @SpicyMarinara commented on GitHub (Jun 21, 2026): Fixed in 6e3ff066.\n\nCovered the HUD-widget failure cluster here:\n- routes stat_block model updates by stat name without falling through into the generic value path\n- keeps manual widget saves from being clobbered by stale metadata or pending debounced PUTs\n- restores inventory_grid widgets to the HUD and preserves item quantity/slot metadata when editing contents\n- clamps persisted map/widget panel positions back into the viewport and adds double-click reset on the lock button\n- persists completed timers as stopped at zero so they do not restart after reload\n\nPer maintainer request, deferred pnpm validation until the issue sweep is complete.
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#1372
No description provided.