mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #5889] Safari TTS: infinite zero-delay play() retry loop freezes the tab (reported as "TTS freezes my instance") #3249
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#3249
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 (Sep 6, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/5889
Originally assigned to: @kolacheee on GitHub.
In one sentence: starting TTS in Safari can spin the client into an infinite zero-delay
audio.play()retry loop that freezes the tab and balloons memory until WebKit kills it — reported in the field as "TTS freezes my whole Marinara instance," and reproducible in principle on any Safari with autoplay restrictions (iOS and macOS both).Field report
Docker/Linux server, Safari on macOS + iOS. Starting xAI TTS (any voice, autoplay or manual) freezes the triggering client; Safari memory "shoots way up"; disabling TTS prevents it entirely; server console shows nothing unusual. Build
2.4.4+e390e36194a0— but there are zero TTS changes between that commit and current staging, so this is live for everyone.Mechanism (confirmed from source)
playWhenAvailableinpackages/client/src/lib/tts-service.ts(~141-160) iswhile (true) { await audio.play() }. Its retry gate treatsNotAllowedErroras "wait until the document is visible and focused, then try again" — but Safari throwsNotAllowedErrorfor a policy reason (no live user activation), not a visibility reason. When the tab is already visible and focused — exactly the autoplay case — the wait resolves immediately and the loop retriesplay()with zero backoff, no cap, and no way to succeed, allocating a promise + DOMException per iteration on the main thread until the tab freezes.Both entry points are affected:
NotAllowedError→ spin./api/tts/speakfetch before callingplay(), which lands outside Safari's synchronous gesture window → same rejection on restrictive settings ("Never Auto-Play" / Stop Media with Sound) → same spin.Two compounding findings:
tts-audio-cache.ts) is capped at 150 entries with no byte cap (the persistent IndexedDB tier is deliberately disabled on iOS WebKit), so long sessions accumulate up to 150 live audio blobs — the slow memory balloon the reporter describes, additive to the fast one from the spin.What is proven NOT the cause
The server
/speakpath was audited at the reporter's commit and exonerated: it is a stateless binary proxy (zod-capped input, rawBufferout; audio is never base64-encoded, never JSON-embedded, never written to the chat store; no shared locks; single-digit-millisecond synchronous cost for a 5 MB clip). The audio also never enters chat payloads, caches, or anything a second client would receive.That honesty leaves one open remainder: the reporter says their desktop client seized at the same time and reloads gave a blank page — and neither confirmed mechanism explains that half (the desktop provably runs no TTS code for a mobile-triggered generation). Discriminator for the reporter, next episode:
from any other machine during the freeze. Fast = server healthy, desktop symptom is its own tab (tell us what it was doing); slow = a server stall we have not found, and that timing is the lead.
Fix (PR incoming)
NotAllowedErrorin a visible, focused document becomes terminal for automatic retries: surface a blocked/tap-to-play state and re-arm playback from a real one-shot user-gesture listener instead of spinning.playWhenAvailableregardless of error type.play()synchronously inside the click gesture on a pre-created element, then swaps in the fetched source, so Safari's gesture unlock applies.