[GH-ISSUE #2949] [Issue]: TTS speakSequence uses Promise.all — single chunk failure discards all audio, and nothing plays until the entire batch is fetched #1526

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

Originally created by @kevin-ho on GitHub (Jun 28, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2949

Originally assigned to: @SpicyMarinara on GitHub.

Summary

The client-side TTS speakSequence method fetches all audio chunks for a message in parallel using Promise.all, then plays them sequentially. When used with self-hosted TTS backends that process requests sequentially (single GPU, no batching), concurrent requests queue up and later ones can exceed the request timeout. Because Promise.all rejects on the first failure, all successfully generated audio is discarded and nothing plays at all — not even the chunks that completed successfully.

Expected behavior

  • Audio chunks that were successfully generated should play, even if one chunk fails.
  • The first chunk should begin playback as soon as it's ready, not after every chunk in the batch has been fetched.
  • For local/self-hosted TTS backends, a failed chunk should be skipped (or retried) without aborting the entire playback sequence.

Actual behavior

  • All TTS requests for a message are fired simultaneously via Promise.all (packages/client/src/lib/tts-service.ts, line 234).
  • Nothing plays until every chunk has been fetched. Playback only begins in the playNext() callback, which runs after Promise.all resolves.
  • If any single chunk fails (e.g. timeout on a slow local backend), Promise.all rejects, the catch block sets state to "error", and all successfully fetched audio blobs are discarded. The user hears nothing.
  • On a local single-threaded TTS server, N parallel requests serialize at the model level (e.g. a global threading.RLock). Later requests in the queue wait for all earlier ones to finish, and can exceed the 60s provider timeout even though each individual synthesis takes only a few seconds.
  • Larger chat messages (more paragraphs, more dialogue turns) fail to play at all, because they produce more chunks → longer queue → higher chance of timeout. Retry usually works because the queue has cleared.

Steps to reproduce

  1. Configure TTS with an OpenAI-compatible source pointing at a self-hosted TTS server that processes one request at a time (e.g. single-GPU Pocket TTS, Kokoro, Coqui, etc.).
  2. Generate an assistant message long enough to produce 4+ TTS chunks (multi-paragraph RP response, multi-speaker dialogue, etc.).
  3. With TTS autoplay enabled, observe that all chunk requests fire simultaneously. On the TTS server side, they queue and process sequentially.
  4. If the total queue processing time exceeds the provider request timeout (60s on main), one or more chunks abort. Promise.all rejects. No audio plays at all — including chunks that the server successfully generated and returned.
  5. Retry — the previous requests are no longer queued, so the retried batch completes within the timeout and playback works.

Environment

  • Marinara Engine version: 2.0.5
  • Install type: source (git checkout, systemd service)
  • OS + version: Linux
  • Browser or app shell: Desktop browser (PWA)

Logs, screenshots, or video

Server-side (TTS provider) logs — 6 requests arrive simultaneously, serialize at model lock, last one aborts:

12:48:17  POST /v1/audio/speech — 200 OK   (6 requests in same second)
12:49:02  POST /v1/audio/speech — 200 OK   (queued request completes after ~45s wait)
12:49:12  POST /v1/audio/speech — 200 OK   (queued request completes after ~55s wait)
12:49:18  ERROR: Generation aborted by client disconnect   (60s timeout, mid-generation)

Marinara server logs:

12:49:17  ERROR: TTS provider request failed
          TimeoutError: The operation was aborted due to timeout
          POST /api/tts/speak -> 502 { "error": "TTS request timed out" }

Additional context

  • Related: #1987 (60s hardcoded timeout). That issue was addressed in the refactor branch by making the timeout configurable (PR #1990). However, raising the timeout ceiling is a band-aid — it doesn't fix the underlying architectural issue: all-or-nothing batch fetch with no progressive playback.
  • Root cause is in packages/client/src/lib/tts-service.ts, speakSequence() method (line 234): Promise.all waits for all requests before calling playNext(). The comment on lines 205–207 explains this is intentional ("keeps multi-speaker dialogue from starting until the whole spoken queue is ready"), but this design assumes cloud TTS providers where parallel requests return in milliseconds.
  • Two distinct problems:
    1. All-or-nothing failure: Promise.all rejects on first failure, discarding all successful audio. Promise.allSettled() would allow skipping failed chunks and playing the rest.
    2. No progressive playback: No audio plays until the slowest chunk completes. For local TTS at 4–5× realtime, chunks could begin playing while subsequent ones are still being generated, keeping the playback pipeline full.

Suggested fix — Progressive Playback toggle:

Add a "Progressive Playback" checkbox to the TTS settings card. When enabled:

  • Play each audio chunk as soon as it's fetched, rather than waiting for the entire batch.
  • Fetch subsequent chunks concurrently while current chunk plays.
  • Use Promise.allSettled() semantics so a failed chunk is skipped instead of aborting the entire sequence.

When disabled (default): current behavior is preserved for users who prefer gap-free multi-speaker dialogue on cloud TTS providers.

This gives users with local/self-hosted TTS backends a way to get reliable playback without modifying timeouts, while keeping the existing batch-then-play behavior as the default for cloud TTS users.

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read the template and provide the requested details.
Originally created by @kevin-ho on GitHub (Jun 28, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2949 Originally assigned to: @SpicyMarinara on GitHub. ## Summary The client-side TTS `speakSequence` method fetches all audio chunks for a message in parallel using `Promise.all`, then plays them sequentially. When used with self-hosted TTS backends that process requests sequentially (single GPU, no batching), concurrent requests queue up and later ones can exceed the request timeout. Because `Promise.all` rejects on the first failure, all successfully generated audio is discarded and **nothing plays at all** — not even the chunks that completed successfully. ## Expected behavior - Audio chunks that were successfully generated should play, even if one chunk fails. - The first chunk should begin playback as soon as it's ready, not after every chunk in the batch has been fetched. - For local/self-hosted TTS backends, a failed chunk should be skipped (or retried) without aborting the entire playback sequence. ## Actual behavior - All TTS requests for a message are fired simultaneously via `Promise.all` (`packages/client/src/lib/tts-service.ts`, line 234). - Nothing plays until **every** chunk has been fetched. Playback only begins in the `playNext()` callback, which runs after `Promise.all` resolves. - If any single chunk fails (e.g. timeout on a slow local backend), `Promise.all` rejects, the catch block sets state to `"error"`, and all successfully fetched audio blobs are discarded. The user hears nothing. - On a local single-threaded TTS server, N parallel requests serialize at the model level (e.g. a global `threading.RLock`). Later requests in the queue wait for all earlier ones to finish, and can exceed the 60s provider timeout even though each individual synthesis takes only a few seconds. - Larger chat messages (more paragraphs, more dialogue turns) fail to play at all, because they produce more chunks → longer queue → higher chance of timeout. Retry usually works because the queue has cleared. ## Steps to reproduce 1. Configure TTS with an OpenAI-compatible source pointing at a self-hosted TTS server that processes one request at a time (e.g. single-GPU Pocket TTS, Kokoro, Coqui, etc.). 2. Generate an assistant message long enough to produce 4+ TTS chunks (multi-paragraph RP response, multi-speaker dialogue, etc.). 3. With TTS autoplay enabled, observe that all chunk requests fire simultaneously. On the TTS server side, they queue and process sequentially. 4. If the total queue processing time exceeds the provider request timeout (60s on `main`), one or more chunks abort. `Promise.all` rejects. **No audio plays at all** — including chunks that the server successfully generated and returned. 5. Retry — the previous requests are no longer queued, so the retried batch completes within the timeout and playback works. ## Environment - Marinara Engine version: 2.0.5 - Install type: source (git checkout, systemd service) - OS + version: Linux - Browser or app shell: Desktop browser (PWA) ## Logs, screenshots, or video **Server-side (TTS provider) logs** — 6 requests arrive simultaneously, serialize at model lock, last one aborts: ``` 12:48:17 POST /v1/audio/speech — 200 OK (6 requests in same second) 12:49:02 POST /v1/audio/speech — 200 OK (queued request completes after ~45s wait) 12:49:12 POST /v1/audio/speech — 200 OK (queued request completes after ~55s wait) 12:49:18 ERROR: Generation aborted by client disconnect (60s timeout, mid-generation) ``` **Marinara server logs:** ``` 12:49:17 ERROR: TTS provider request failed TimeoutError: The operation was aborted due to timeout POST /api/tts/speak -> 502 { "error": "TTS request timed out" } ``` ## Additional context - Related: #1987 (60s hardcoded timeout). That issue was addressed in the refactor branch by making the timeout configurable (PR #1990). However, raising the timeout ceiling is a band-aid — it doesn't fix the underlying architectural issue: all-or-nothing batch fetch with no progressive playback. - Root cause is in `packages/client/src/lib/tts-service.ts`, `speakSequence()` method (line 234): `Promise.all` waits for all requests before calling `playNext()`. The comment on lines 205–207 explains this is intentional ("keeps multi-speaker dialogue from starting until the whole spoken queue is ready"), but this design assumes cloud TTS providers where parallel requests return in milliseconds. - Two distinct problems: 1. **All-or-nothing failure**: `Promise.all` rejects on first failure, discarding all successful audio. `Promise.allSettled()` would allow skipping failed chunks and playing the rest. 2. **No progressive playback**: No audio plays until the slowest chunk completes. For local TTS at 4–5× realtime, chunks could begin playing while subsequent ones are still being generated, keeping the playback pipeline full. **Suggested fix — Progressive Playback toggle:** Add a "Progressive Playback" checkbox to the TTS settings card. When enabled: - Play each audio chunk as soon as it's fetched, rather than waiting for the entire batch. - Fetch subsequent chunks concurrently while current chunk plays. - Use `Promise.allSettled()` semantics so a failed chunk is skipped instead of aborting the entire sequence. When disabled (default): current behavior is preserved for users who prefer gap-free multi-speaker dialogue on cloud TTS providers. This gives users with local/self-hosted TTS backends a way to get reliable playback without modifying timeouts, while keeping the existing batch-then-play behavior as the default for cloud TTS users. ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read the template and provide the requested details.
Author
Owner

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

Fixed on staging: TTS sequencing now keeps successful chunks when others fail, and a saved Progressive Playback option fetches one chunk ahead while playing for local/self-hosted TTS backends.

<!-- gh-comment-id:4827784742 --> @SpicyMarinara commented on GitHub (Jun 28, 2026): Fixed on staging: TTS sequencing now keeps successful chunks when others fail, and a saved Progressive Playback option fetches one chunk ahead while playing for local/self-hosted TTS backends.
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#1526
No description provided.