[GH-ISSUE #2760] [Issue]: Game-mode AV cue alignment and minor playback/leak nits #1399

Closed
opened 2026-10-21 05:33:09 +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/2760

Originally assigned to: @SpicyMarinara on GitHub.

Summary

Game-mode AV cue alignment plus a few playback/leak nits. The notable one is that the scene-analyzer indexes narration 'beats' by raw source newlines, a different index space than the client's actual segmentation, so per-beat sfx/background/cinematic effects fire on the wrong (or no) narration segment.

Sub-bug 1: Beat-index mismatch mis-fires AV cues (#70) [primary]

  • How it breaks: scene-analyzer.ts:204 builds beats via narration.split(/\r?\n/).filter(...) and tells the model to key segmentEffects to those indices (261, 347). The client (parseNarrationSegments) and server mirror collapse consecutive prose lines into one fallback segment and can also expand dialogue, so the analyzer's line indices don't match the segment indices the client applies effects to (onSegmentEnter(sourceSegmentIndex), applied via raw equality in GameSurface with no remap). Late-beat effects are dropped or land on the wrong segment on most multi-line turns; failure is silent.
  • Repro: A multi-line plain-prose game turn with a sfx/background keyed to a later beat — it fires on segment 0 or not at all.

Sub-bug 2: Game-voice object-URL cache leak (#12)

  • How it breaks: gameVoiceCacheRef stores URL.createObjectURL blobs per message-identity key with no size cap and no per-turn eviction; the activeIndex/streaming effects never delete entries. Only unmount revokes. Keys are message-id-addressed so they grow monotonically over a long autoplay session.

Sub-bug 3: autoplay-block tag rollback desync (#13)

  • How it breaks: On play() rejection, the catch sets pendingMusic={newTag} but rolls currentMusicTag back to the previous tag (732) while the store already holds the new tag. A later playMusic(previousTag) hits the dedup early-return (649) without clearing pendingMusic, so the stale retry can fire the wrong track on the next gesture.

Sub-bug 4: scoreAmbient double-count (#71) [disputed]

  • How it breaks: Line 451 always pushes STATE_AMBIENT[state], duplicating it with line 449 — but only in the no-location branch (the if/else is mutually exclusive). Real one-line redundancy; the candidate's 'location vs state bias' framing is false. Low.

Sub-bug 5: Shared in-flight signal (#6) [disputed/timing]

  • How it breaks: A cached create() promise binds the first caller's AbortSignal; in theory a second caller awaiting the same alias could be poisoned by the first's abort. In practice the chat singleton serializes so the abort comes from the second caller's own stop(); a residual microtask race normally resolves safely. Decouple the shared generation from any single caller's signal.

Sub-bug 6: pause() retains element + URL (#9)

  • How it breaks: pause() retains this.audio + this.currentObjectUrl; cleanup() (the only revoker) only runs on stop/next-speak/onended/onerror, none of which fire for a paused-and-abandoned clip. Bounded to one element/URL (singleton). Call stop() on chat-view teardown.

Suggested Fix

  • Index scene-analyzer beats by the same segmentation the client uses to render narration (sentence/segment boundaries), or pass the canonical segment list to the analyzer so indices are stable.
  • Add an LRU cap to gameVoiceCacheRef and revoke object URLs on evicted/superseded entries.
  • Don't roll currentMusicTag back on autoplay-block (keep the requested tag, rely on pendingMusic), or clear pendingMusic when the dedup early-return hits.
  • Push STATE_AMBIENT once (drop the unconditional line 451 or dedupe the keyword array).
  • Have create() fetch without a per-caller signal; let consumers race their own signal against the shared promise.
  • Revoke on a hard reset (route/chat switch) by calling ttsService.stop() in a top-level unmount.

Verification checklist (all manual)

  • Manually verify per-beat sfx/background/cinematic cues fire on the correct narration segment for multi-line turns
  • Verify game-voice object URLs are bounded/revoked over a long autoplay session
  • Verify autoplay-blocked music retry plays the intended track and store state stays consistent
  • Verify ambient selection isn't skewed by the duplicated state keywords
  • Run pnpm check

Affected files

  • packages/server/src/services/sidecar/scene-analyzer.ts
  • packages/client/src/components/game/GameNarration.tsx
  • packages/client/src/lib/game-audio.ts
  • packages/client/src/lib/tts-service.ts
  • packages/shared/src/utils/music-score.ts

Audit provenance

Found by a multi-agent static audit of the TTS/voice + image-generation subsystems (Round 1 + round-2 gap sweep + completeness critic, each finding adversarially verified) against the merged staging tree. Severity: MEDIUM.

AI-drafted from a static read; validation/test-plan boxes 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/2760 Originally assigned to: @SpicyMarinara on GitHub. ## Summary Game-mode AV cue alignment plus a few playback/leak nits. The notable one is that the scene-analyzer indexes narration 'beats' by raw source newlines, a different index space than the client's actual segmentation, so per-beat sfx/background/cinematic effects fire on the wrong (or no) narration segment. ## Sub-bug 1: Beat-index mismatch mis-fires AV cues (#70) [primary] - **How it breaks:** `scene-analyzer.ts:204` builds beats via `narration.split(/\r?\n/).filter(...)` and tells the model to key segmentEffects to those indices (261, 347). The client (`parseNarrationSegments`) and server mirror collapse consecutive prose lines into one fallback segment and can also expand dialogue, so the analyzer's line indices don't match the segment indices the client applies effects to (`onSegmentEnter(sourceSegmentIndex)`, applied via raw equality in GameSurface with no remap). Late-beat effects are dropped or land on the wrong segment on most multi-line turns; failure is silent. - **Repro:** A multi-line plain-prose game turn with a sfx/background keyed to a later beat — it fires on segment 0 or not at all. ## Sub-bug 2: Game-voice object-URL cache leak (#12) - **How it breaks:** `gameVoiceCacheRef` stores `URL.createObjectURL` blobs per message-identity key with no size cap and no per-turn eviction; the activeIndex/streaming effects never delete entries. Only unmount revokes. Keys are message-id-addressed so they grow monotonically over a long autoplay session. ## Sub-bug 3: autoplay-block tag rollback desync (#13) - **How it breaks:** On play() rejection, the catch sets `pendingMusic={newTag}` but rolls `currentMusicTag` back to the previous tag (732) while the store already holds the new tag. A later `playMusic(previousTag)` hits the dedup early-return (649) without clearing pendingMusic, so the stale retry can fire the wrong track on the next gesture. ## Sub-bug 4: scoreAmbient double-count (#71) [disputed] - **How it breaks:** Line 451 always pushes `STATE_AMBIENT[state]`, duplicating it with line 449 — but only in the no-location branch (the if/else is mutually exclusive). Real one-line redundancy; the candidate's 'location vs state bias' framing is false. Low. ## Sub-bug 5: Shared in-flight signal (#6) [disputed/timing] - **How it breaks:** A cached create() promise binds the first caller's AbortSignal; in theory a second caller awaiting the same alias could be poisoned by the first's abort. In practice the chat singleton serializes so the abort comes from the second caller's own stop(); a residual microtask race normally resolves safely. Decouple the shared generation from any single caller's signal. ## Sub-bug 6: pause() retains element + URL (#9) - **How it breaks:** pause() retains `this.audio` + `this.currentObjectUrl`; cleanup() (the only revoker) only runs on stop/next-speak/onended/onerror, none of which fire for a paused-and-abandoned clip. Bounded to one element/URL (singleton). Call stop() on chat-view teardown. ## Suggested Fix - Index scene-analyzer beats by the same segmentation the client uses to render narration (sentence/segment boundaries), or pass the canonical segment list to the analyzer so indices are stable. - Add an LRU cap to gameVoiceCacheRef and revoke object URLs on evicted/superseded entries. - Don't roll `currentMusicTag` back on autoplay-block (keep the requested tag, rely on pendingMusic), or clear pendingMusic when the dedup early-return hits. - Push STATE_AMBIENT once (drop the unconditional line 451 or dedupe the keyword array). - Have create() fetch without a per-caller signal; let consumers race their own signal against the shared promise. - Revoke on a hard reset (route/chat switch) by calling ttsService.stop() in a top-level unmount. ## Verification checklist (all manual) - [ ] Manually verify per-beat sfx/background/cinematic cues fire on the correct narration segment for multi-line turns - [ ] Verify game-voice object URLs are bounded/revoked over a long autoplay session - [ ] Verify autoplay-blocked music retry plays the intended track and store state stays consistent - [ ] Verify ambient selection isn't skewed by the duplicated state keywords - [ ] Run `pnpm check` --- ### Affected files - `packages/server/src/services/sidecar/scene-analyzer.ts` - `packages/client/src/components/game/GameNarration.tsx` - `packages/client/src/lib/game-audio.ts` - `packages/client/src/lib/tts-service.ts` - `packages/shared/src/utils/music-score.ts` ### Audit provenance Found by a multi-agent static audit of the TTS/voice + image-generation subsystems (Round 1 + round-2 gap sweep + completeness critic, each finding adversarially verified) against the merged `staging` tree. Severity: **MEDIUM**. > AI-drafted from a static read; validation/test-plan boxes intentionally left UNCHECKED for a human to verify before close.
Author
Owner

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

Addressed on PR #2747. Fixed scene-analyzer beat indices by building canonical narration beats instead of raw non-empty lines, capped/revoked game voice cache entries, decoupled shared cached TTS creation from per-caller abort signals, kept autoplay-blocked music retry state aligned, removed duplicate ambient state keywords, and added a GameSurface TTS stop on chat/view teardown. Validation so far: git diff --check. Full pnpm checks are intentionally deferred until the issue sweep is complete.

<!-- gh-comment-id:4763358264 --> @SpicyMarinara commented on GitHub (Jun 21, 2026): Addressed on PR #2747. Fixed scene-analyzer beat indices by building canonical narration beats instead of raw non-empty lines, capped/revoked game voice cache entries, decoupled shared cached TTS creation from per-caller abort signals, kept autoplay-blocked music retry state aligned, removed duplicate ambient state keywords, and added a GameSurface TTS stop on chat/view teardown. Validation so far: git diff --check. Full pnpm checks are intentionally deferred 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#1399
No description provided.