mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2755] [Issue]: TTS audio cache — unbounded IndexedDB growth, write amplification, and fragile open path #1393
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#1393
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @kolacheee on GitHub (Jun 21, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2755
Originally assigned to: @SpicyMarinara on GitHub.
Summary
The persistent TTS audio cache (
tts-audio-cache.ts) has several storage-layer defects: it never evicts, it rewrites whole blobs on every read, it self-disables permanently on a transient open error, and its cross-message alias key is a collision-prone 32-bit hash.Sub-bug 1: Unbounded growth (#5) [primary]
putPersistentBlobwrites a row on every miss (and one per alias, 173-176) but nothing ever deletes persistent rows. ThelastUsedAtindex (60-62) is created and updated but never queried for pruning; only the 150-entry in-memory Map is bounded. The store is write-only-grows until quota exhaustion (then silently falls back to memory-only).Sub-bug 2: Write amplification (#44)
put({ ...record, lastUsedAt })(84-92) that re-serializes the FULL audio Blob just to bump a timestamp — and the timestamp is never consumed by any eviction.Sub-bug 3: Cache self-disables on transient open failure (#43)
dbPromiseis memoized and resolves to null ononerror/onblocked(66-67) but is never reset, soopenDb()returns the same resolved-null promise forever. The first line to hit a failing open (e.g. private-mode quota hiccup) poisons the persistent cache for the whole session.Sub-bug 4: 32-bit alias collision (#45)
chat-voice-line-text-v1:<hash>uses a 32-bit DJB-xor hash of (config+voice+speaker+tone+text). On a collision, an alias hit is treated as authoritative and copied to the primary key, so one line plays another's audio. Records store no plaintext to validate against. (Low probability — birthday-bound — but never-pruned population grows; the sibling game path prefixes a length discriminator, this one doesn't.)Suggested Fix
lastUsedAtindex) and revoke/delete evicted rows.lastUsedAtrewrite entirely until an eviction consumer exists.onerror/onblocked, resolve(null) AND resetdbPromise = nullso a later call retries; optionally retry once ononblocked.Verification checklist (all manual)
pnpm checkAffected files
packages/client/src/lib/tts-audio-cache.tspackages/client/src/lib/tts-dialogue.tsAudit 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
stagingtree. Severity: MEDIUM.@SpicyMarinara commented on GitHub (Jun 21, 2026):
Addressed on PR #2747. The TTS audio cache now uses DB v2 with a metadata store, metadata-only recency touches on cold reads, retryable IndexedDB open failures, throttled persistent pruning by entry/byte budget, and no blob-copy writes on alias hits or in-flight alias reuse. The TTS cache alias hash now includes a length discriminator and a widened two-lane hash instead of the old 32-bit key. Validated with git diff --check for the touched files; full pnpm validation is deferred until the end of the issue sweep per maintainer request.