[PR #6971] [MERGED] fix(llm): let slow local models take more than two minutes for the first token #7411

Closed
opened 2026-10-23 04:19:31 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/6971
Author: @SpicyMarinara
Created: 10/2/2026
Status: ✅ Merged
Merged: 10/2/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/mari-first-token-timeout


📝 Commits (2)

  • d145ab2 fix(llm): wait for the first token as long as the text timeout allows
  • ce9ffa0 test: use fixed routes in the first-chunk timeout regression

📊 Changes

4 files changed (+44 additions, -7 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 docs/CONFIGURATION.md (+1 -1)
📝 packages/server/src/services/llm/base-provider.ts (+10 -6)
➕ scripts/regressions/llm-first-chunk-timeout.regression.ts (+32 -0)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #6970

Why this change

Professor Mari on a slow local model gave up if the first token took more than two minutes, and that limit wasn't documented or adjustable.

The limit was a fixed 2-minute wait between streamed chunks (LLM_BODY_TIMEOUT in base-provider.ts), used by every call without a timeout of its own. A local server like llama.cpp or KoboldCPP usually sends its response headers right away and then spends minutes reading a long prompt, and Mari's prompts are long. So the wait for the first token was capped at two minutes. Chats didn't have this problem, because their calls already use the configurable chat timeout.

What changed

  • base-provider.ts: the shared wait between chunks, including the wait for the first token, now follows CHAT_GENERATION_TIMEOUT_MS, the same setting that already decided the headers wait. In the app, that's Settings → Request timeouts → Text generation, 5 minutes by default and adjustable from 10 seconds to 1 hour. It stays finite, so half-open streams still can't hang forever.
  • docs/CONFIGURATION.md: says the setting covers Professor Mari and other background calls, for both the first token and the gap between chunks.
  • New regression llm-first-chunk-timeout.regression.ts: a test server sends headers at once and the first chunk later. With the setting at 10 seconds, a 3-second first chunk arrives and a 12-second one is cut off. The old fixed two minutes let the 12-second one through, so the test fails without the fix.
  • CHANGELOG entry.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

What I ran (not a replacement for the checklist):

  • Checks: pnpm check passes.

  • New regression: passes, and fails without the fix.

  • Existing regressions: request-timeouts and shutdown-deadline pass.

  • Local CodeRabbit: 0 findings.

To check by hand:

  • Ask Professor Mari something on a local model with a slow prompt read (more than two minutes to the first token), with the Text generation timeout at its default 5 minutes. The reply should come instead of the call being cut.
  • Lower the Text generation timeout below that time and check the call stops then.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

docs/CONFIGURATION.md has one updated row. The translated packs will follow in a docs-i18n PR.

UI evidence (if applicable)

Server-side only; the existing Text generation setting now covers this.

Summary by CodeRabbit

  • Bug Fixes
    • Background AI responses, including Professor Mari and timeline or reply updates, now use the configured text-generation timeout while waiting for a response or between streamed response chunks. The default is five minutes.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/6971 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 10/2/2026 **Status:** ✅ Merged **Merged:** 10/2/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/mari-first-token-timeout` --- ### 📝 Commits (2) - [`d145ab2`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d145ab2a5006f8ca33ca63b23f2edc704dacf3bc) fix(llm): wait for the first token as long as the text timeout allows - [`ce9ffa0`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ce9ffa00e38b204f915b6fac95574c12bdc03cd1) test: use fixed routes in the first-chunk timeout regression ### 📊 Changes **4 files changed** (+44 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `docs/CONFIGURATION.md` (+1 -1) 📝 `packages/server/src/services/llm/base-provider.ts` (+10 -6) ➕ `scripts/regressions/llm-first-chunk-timeout.regression.ts` (+32 -0) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. ## Linked issue Closes #6970 ## Why this change Professor Mari on a slow local model gave up if the first token took more than two minutes, and that limit wasn't documented or adjustable. The limit was a fixed 2-minute wait between streamed chunks (`LLM_BODY_TIMEOUT` in `base-provider.ts`), used by every call without a timeout of its own. A local server like llama.cpp or KoboldCPP usually sends its response headers right away and then spends minutes reading a long prompt, and Mari's prompts are long. So the wait for the first token was capped at two minutes. Chats didn't have this problem, because their calls already use the configurable chat timeout. ## What changed - **`base-provider.ts`:** the shared wait between chunks, including the wait for the first token, now follows `CHAT_GENERATION_TIMEOUT_MS`, the same setting that already decided the headers wait. In the app, that's **Settings → Request timeouts → Text generation**, 5 minutes by default and adjustable from 10 seconds to 1 hour. It stays finite, so half-open streams still can't hang forever. - **`docs/CONFIGURATION.md`:** says the setting covers Professor Mari and other background calls, for both the first token and the gap between chunks. - **New regression `llm-first-chunk-timeout.regression.ts`:** a test server sends headers at once and the first chunk later. With the setting at 10 seconds, a 3-second first chunk arrives and a 12-second one is cut off. The old fixed two minutes let the 12-second one through, so the test fails without the fix. - **CHANGELOG entry.** ## Validation - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` ### Manual verification notes What I ran (not a replacement for the checklist): - **Checks:** `pnpm check` passes. - **New regression:** passes, and fails without the fix. - **Existing regressions:** `request-timeouts` and `shutdown-deadline` pass. - **Local CodeRabbit:** 0 findings. To check by hand: - Ask Professor Mari something on a local model with a slow prompt read (more than two minutes to the first token), with the Text generation timeout at its default 5 minutes. The reply should come instead of the call being cut. - Lower the Text generation timeout below that time and check the call stops then. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) `docs/CONFIGURATION.md` has one updated row. The translated packs will follow in a `docs-i18n` PR. ## UI evidence (if applicable) Server-side only; the existing Text generation setting now covers this. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Background AI responses, including Professor Mari and timeline or reply updates, now use the configured text-generation timeout while waiting for a response or between streamed response chunks. The default is five minutes. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:19:31 +07:00
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#7411
No description provided.