[PR #7180] [MERGED] fix(game): honour the configured text-generation timeout in GM mode #7612

Closed
opened 2026-10-24 04:05:51 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

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

Base: staging ← Head: fix/gm-generation-timeout-7177


📝 Commits (3)

  • 7ef8c25 fix(game): honour the configured text-generation timeout in GM mode
  • 1bdc014 fix(game): keep fixed total caps and give a setup retry the full wait
  • 34b9b6c Merge remote-tracking branch 'origin/staging' into fix/gm-generation-timeout-7177

📊 Changes

5 files changed (+136 additions, -30 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 packages/server/src/routes/game.routes.ts (+40 -23)
📝 packages/server/src/services/game/initial-game-setup.ts (+0 -2)
➕ scripts/regressions/game-generation-timeout.regression.ts (+94 -0)
📝 scripts/regressions/open-issues.regression.ts (+1 -5)

📄 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 #7177

Why this change

With Qwen3.8-27B on llama.cpp, a new Game Mode game failed with GameGenerationTimeoutError at exactly 300 seconds. Setting Request timeouts → Text generation or CHAT_GENERATION_TIMEOUT_MS to 3600 s or 20 s made no difference. With gemma-4-31B and a 20 s setting, setup ran past 300 s and succeeded. An earlier report was marked as fixed in staging, but neither earlier fix touched the Game routes.

Root cause: game.routes.ts runs every Game Master call through runGameChatComplete / runGameChatStream. Both use a watchdog that defaulted to a hard-coded GAME_GENERATION_TIMEOUT_MS = 5 * 60 * 1000, and only answer tokens (onToken) reset it.

  • Qwen: llama.cpp streams a reasoning model's thinking as reasoning_content. The OpenAI-compatible provider passes that to onThinking, not onToken, so the watchdog never resets while the model thinks. It fires at exactly 300 s whatever the setting says.
  • Gemma: it streams answer tokens. Each token resets the 5-minute watchdog, so a long reply runs past 300 s. A 20 s setting didn't stop it because the setting is a wait limit: it ends a request only after 20 s with no output, and a model that keeps streaming never hits it. Chats work the same way, as docs/CONFIGURATION.md describes.

The undici lead, checked and ruled out: 300 s is also undici's default headersTimeout/bodyTimeout. But llmFetch always passes both as CHAT_GENERATION_TIMEOUT_MS (base-provider.ts, llmAgentOptions), so undici's defaults never apply. The existing llm-first-chunk-timeout regression already proves undici follows the setting. Fastify and Node server timeouts only cover receiving the request, and the client's /game/setup call has no timeout.

Why earlier fixes missed it: #6359 added the Request timeouts settings, and #6971 (#6970) made undici's chunk wait follow the setting. Neither changed the Game watchdog. #3684 raised the setup route's response tracker to 500 s, but the 300 s watchdog inside it always fired first, so that change never took effect.

What changed

  • packages/server/src/routes/game.routes.ts
    • The Game watchdog reads getChatGenerationTimeoutMs() when each call starts, instead of using a fixed 5 minutes.
    • For streaming calls (those with onToken), streamed thinking (onThinking) resets the watchdog, as answer tokens already did. This matches the chat routes, where any streamed chunk counts. Calls without onToken keep a total cap, so thinking from providers that always stream (ChatGPT and Claude subscriptions) cannot stretch it.
    • The route-level response trackers (setup, recap, conclusion, conclusion regeneration, Lorebook Keeper, campaign progression, character sheet, recruit, map, Experience generation, party turn, scene wrap) also use the setting. Those that streamed tokens already kept alive are now kept alive by thinking too.
    • runGameChatComplete and runGameChatStream are exported for the regression.
    • Image-side calls keep their own total limits, unchanged: the illustration summarizer, storyboard illustrator, animation refinement and the dynamic image prompt, which uses its own Image prompt timeout (documented as a total cap).
    • New-game setup restarts its response timer for each attempt, so a non-streamed retry after invalid JSON gets the full configured wait instead of what the first attempt left. The old 500 s timer used to leave room for that retry.
  • packages/server/src/services/game/initial-game-setup.ts: removed the unused 500 s GAME_SETUP_GENERATION_TIMEOUT_MS. Its pinning assertion in open-issues.regression.ts is removed too.
  • New scripts/regressions/game-generation-timeout.regression.ts: a fake OpenAI-compatible server with fixed routes and fixed delays drives the real custom provider through runGameChatComplete, the way new-game setup does. Four calls run side by side, so it finishes in about 14 s:
    • Setting 10 s, a 12 s silence (kept busy with SSE comments, so undici can't end it): fails with Game setup timed out after 10 seconds in under 12 s. Shorter is enforced.
    • Setting 20 s, the same 12 s silence: succeeds. Longer is honoured.
    • Setting 10 s, 12 s of reasoning_content before the answer: succeeds. Thinking counts as progress.
    • A fixed 10 s total cap without onToken (like the image-prompt calls) on the same thinking stream: fails at about 10 s. Thinking does not stretch a total cap.
  • CHANGELOG entry.

Other generation paths (task item 4):

  • Roleplay, Conversation and in-session GM turns go through /api/generate. They already wrap provider calls in withLlmRequestTimeout(getChatGenerationTimeoutMs()), so they have no 300 s cap.
  • Agents use their own total cap, AGENT_CALL_TIMEOUT_MS.
  • Two unrelated fixed 5-minute values are left alone because they are separate code paths, listed here for follow-up:
    • services/conversation/auto-summary.service.ts: DEFAULT_SUMMARY_TIMEOUT_MS, for Conversation day/week summaries.
    • services/conversation/autonomous.service.ts: GENERATION_TIMEOUT_MS, a stale-lock reset, not a request timeout.

Known ceiling: routes that never streamed (recap, character sheet, recruit, map, party turn, scene wrap, Experience generation) keep one response timer per request. That timer is now the configured value, not 300 s. For a single non-streamed request this is the same as a wait limit. If Experience generation or scene wrap falls back to a second, streamed attempt after an empty reply, both attempts share that one timer, as they shared the 300 s before.

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 the agent ran (not a substitute for the checklist):

  • pnpm check: exit 0.
  • pnpm exec prettier --check on the changed files: clean.
  • The new regression fails on the old code: a 10 s setting did not end a 12 s silence, because the fixed 300 s governed. It passes with the fix.
  • Mutation check: with the thinking reset removed, the regression fails on the thinking case.
  • Scaled reproduction of the Qwen symptom on the old code: setting 3600 s, watchdog lowered to 5 s in place of 300 s, reasoning streamed every 500 ms. It failed with Game setup timed out after 5 seconds at 5.0 s. With the fix it completes at 8 s.
  • Related regressions pass: all 32 that import game.routes.ts (including open-issues, experience-generation and game-generation-parameters), plus llm-first-chunk-timeout and request-timeouts.
  • Local CodeRabbit (CLI 0.7.6, committed changes against the staging merge base): 0 findings on the first commit. The rerun after the review-fix commit was rate limited (32-minute wait), so that commit relies on the GitHub CodeRabbit review.
  • Review-fix commit: the new total-cap assertion fails on the first commit (thinking stretched the cap) and passes with the fix. The 32 game.routes.ts regressions, request-timeouts and llm-first-chunk-timeout pass again, and pnpm check exits 0.

To check by hand:

  • Manually verify with a slow reasoning model on llama.cpp (for example Qwen3 with reasoning_content) and Text generation set to 3600 s: starting a new Game Mode game gets past 300 s of thinking and finishes setup.
  • Manually verify with Text generation at 20 s and a model that takes longer than 20 s before its first output: new-game setup fails with the GM connection timed-out message after about 20 s, not 300 s.
  • Manually verify that a model that streams steadily, such as gemma, still finishes setup with a short setting as long as it keeps streaming. This matches chats.
  • Manually verify with streaming turned off and a slow model that new-game setup waits for the configured Text generation value.
  • Manually verify with a ChatGPT or Claude subscription connection and a reasoning model that a Game dynamic image prompt still stops at the Image prompt timeout.
  • Manually verify that session conclusion, campaign progression and Lorebook Keeper regeneration still complete on a reasoning model with streaming on.

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 already says CHAT_GENERATION_TIMEOUT_MS covers Game generations. This PR makes that true, so no docs change or translation follow-up is needed. Only CHANGELOG is updated.

UI evidence (if applicable)

Not applicable: server-only change.

Summary by CodeRabbit

  • Bug Fixes
    • Game generation now uses the configured chat timeout instead of a fixed five-minute limit for new-game startup and other Game Master requests.
    • For streaming responses, thinking and token output count as progress. The timeout applies while waiting for the first output and between outputs; requests without streaming callbacks retain a total timeout.
    • Retrying game setup restarts its response timer.
  • Documentation
    • Updated the unreleased notes to describe the timeout behavior.

🔄 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/7180 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 10/6/2026 **Status:** ✅ Merged **Merged:** 10/6/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/gm-generation-timeout-7177` --- ### 📝 Commits (3) - [`7ef8c25`](https://github.com/Pasta-Devs/Marinara-Engine/commit/7ef8c2504ccc9e4bc0025ba1c96e798754187d9c) fix(game): honour the configured text-generation timeout in GM mode - [`1bdc014`](https://github.com/Pasta-Devs/Marinara-Engine/commit/1bdc014b79654b27868fc560297e76c105f75a8c) fix(game): keep fixed total caps and give a setup retry the full wait - [`34b9b6c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/34b9b6cf89871b4fd056d6307505141c2949bbb9) Merge remote-tracking branch 'origin/staging' into fix/gm-generation-timeout-7177 ### 📊 Changes **5 files changed** (+136 additions, -30 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `packages/server/src/routes/game.routes.ts` (+40 -23) 📝 `packages/server/src/services/game/initial-game-setup.ts` (+0 -2) ➕ `scripts/regressions/game-generation-timeout.regression.ts` (+94 -0) 📝 `scripts/regressions/open-issues.regression.ts` (+1 -5) </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`. <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue Closes #7177 ## Why this change With Qwen3.8-27B on llama.cpp, a new Game Mode game failed with `GameGenerationTimeoutError` at exactly 300 seconds. Setting **Request timeouts → Text generation** or `CHAT_GENERATION_TIMEOUT_MS` to 3600 s or 20 s made no difference. With gemma-4-31B and a 20 s setting, setup ran past 300 s and succeeded. An earlier report was marked as fixed in staging, but neither earlier fix touched the Game routes. **Root cause:** `game.routes.ts` runs every Game Master call through `runGameChatComplete` / `runGameChatStream`. Both use a watchdog that defaulted to a hard-coded `GAME_GENERATION_TIMEOUT_MS = 5 * 60 * 1000`, and only answer tokens (`onToken`) reset it. - **Qwen:** llama.cpp streams a reasoning model's thinking as `reasoning_content`. The OpenAI-compatible provider passes that to `onThinking`, not `onToken`, so the watchdog never resets while the model thinks. It fires at exactly 300 s whatever the setting says. - **Gemma:** it streams answer tokens. Each token resets the 5-minute watchdog, so a long reply runs past 300 s. A 20 s setting didn't stop it because the setting is a wait limit: it ends a request only after 20 s with no output, and a model that keeps streaming never hits it. Chats work the same way, as `docs/CONFIGURATION.md` describes. **The undici lead, checked and ruled out:** 300 s is also undici's default `headersTimeout`/`bodyTimeout`. But `llmFetch` always passes both as `CHAT_GENERATION_TIMEOUT_MS` (`base-provider.ts`, `llmAgentOptions`), so undici's defaults never apply. The existing `llm-first-chunk-timeout` regression already proves undici follows the setting. Fastify and Node server timeouts only cover receiving the request, and the client's `/game/setup` call has no timeout. **Why earlier fixes missed it:** #6359 added the Request timeouts settings, and #6971 (#6970) made undici's chunk wait follow the setting. Neither changed the Game watchdog. #3684 raised the setup route's response tracker to 500 s, but the 300 s watchdog inside it always fired first, so that change never took effect. ## What changed - **`packages/server/src/routes/game.routes.ts`** - The Game watchdog reads `getChatGenerationTimeoutMs()` when each call starts, instead of using a fixed 5 minutes. - For streaming calls (those with `onToken`), streamed thinking (`onThinking`) resets the watchdog, as answer tokens already did. This matches the chat routes, where any streamed chunk counts. Calls without `onToken` keep a total cap, so thinking from providers that always stream (ChatGPT and Claude subscriptions) cannot stretch it. - The route-level response trackers (setup, recap, conclusion, conclusion regeneration, Lorebook Keeper, campaign progression, character sheet, recruit, map, Experience generation, party turn, scene wrap) also use the setting. Those that streamed tokens already kept alive are now kept alive by thinking too. - `runGameChatComplete` and `runGameChatStream` are exported for the regression. - Image-side calls keep their own total limits, unchanged: the illustration summarizer, storyboard illustrator, animation refinement and the dynamic image prompt, which uses its own **Image prompt** timeout (documented as a total cap). - New-game setup restarts its response timer for each attempt, so a non-streamed retry after invalid JSON gets the full configured wait instead of what the first attempt left. The old 500 s timer used to leave room for that retry. - **`packages/server/src/services/game/initial-game-setup.ts`:** removed the unused 500 s `GAME_SETUP_GENERATION_TIMEOUT_MS`. Its pinning assertion in `open-issues.regression.ts` is removed too. - **New `scripts/regressions/game-generation-timeout.regression.ts`:** a fake OpenAI-compatible server with fixed routes and fixed delays drives the real `custom` provider through `runGameChatComplete`, the way new-game setup does. Four calls run side by side, so it finishes in about 14 s: - Setting 10 s, a 12 s silence (kept busy with SSE comments, so undici can't end it): fails with `Game setup timed out after 10 seconds` in under 12 s. Shorter is enforced. - Setting 20 s, the same 12 s silence: succeeds. Longer is honoured. - Setting 10 s, 12 s of `reasoning_content` before the answer: succeeds. Thinking counts as progress. - A fixed 10 s total cap without `onToken` (like the image-prompt calls) on the same thinking stream: fails at about 10 s. Thinking does not stretch a total cap. - **CHANGELOG** entry. **Other generation paths (task item 4):** - Roleplay, Conversation and in-session GM turns go through `/api/generate`. They already wrap provider calls in `withLlmRequestTimeout(getChatGenerationTimeoutMs())`, so they have no 300 s cap. - Agents use their own total cap, `AGENT_CALL_TIMEOUT_MS`. - Two unrelated fixed 5-minute values are left alone because they are separate code paths, listed here for follow-up: - `services/conversation/auto-summary.service.ts`: `DEFAULT_SUMMARY_TIMEOUT_MS`, for Conversation day/week summaries. - `services/conversation/autonomous.service.ts`: `GENERATION_TIMEOUT_MS`, a stale-lock reset, not a request timeout. **Known ceiling:** routes that never streamed (recap, character sheet, recruit, map, party turn, scene wrap, Experience generation) keep one response timer per request. That timer is now the configured value, not 300 s. For a single non-streamed request this is the same as a wait limit. If Experience generation or scene wrap falls back to a second, streamed attempt after an empty reply, both attempts share that one timer, as they shared the 300 s before. ## 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 the agent ran (not a substitute for the checklist): - `pnpm check`: exit 0. - `pnpm exec prettier --check` on the changed files: clean. - The new regression fails on the old code: a 10 s setting did not end a 12 s silence, because the fixed 300 s governed. It passes with the fix. - Mutation check: with the thinking reset removed, the regression fails on the thinking case. - Scaled reproduction of the Qwen symptom on the old code: setting 3600 s, watchdog lowered to 5 s in place of 300 s, reasoning streamed every 500 ms. It failed with `Game setup timed out after 5 seconds` at 5.0 s. With the fix it completes at 8 s. - Related regressions pass: all 32 that import `game.routes.ts` (including `open-issues`, `experience-generation` and `game-generation-parameters`), plus `llm-first-chunk-timeout` and `request-timeouts`. - Local CodeRabbit (CLI 0.7.6, committed changes against the `staging` merge base): 0 findings on the first commit. The rerun after the review-fix commit was rate limited (32-minute wait), so that commit relies on the GitHub CodeRabbit review. - Review-fix commit: the new total-cap assertion fails on the first commit (thinking stretched the cap) and passes with the fix. The 32 `game.routes.ts` regressions, `request-timeouts` and `llm-first-chunk-timeout` pass again, and `pnpm check` exits 0. To check by hand: - Manually verify with a slow reasoning model on llama.cpp (for example Qwen3 with `reasoning_content`) and **Text generation** set to 3600 s: starting a new Game Mode game gets past 300 s of thinking and finishes setup. - Manually verify with **Text generation** at 20 s and a model that takes longer than 20 s before its first output: new-game setup fails with the GM connection timed-out message after about 20 s, not 300 s. - Manually verify that a model that streams steadily, such as gemma, still finishes setup with a short setting as long as it keeps streaming. This matches chats. - Manually verify with streaming turned off and a slow model that new-game setup waits for the configured **Text generation** value. - Manually verify with a ChatGPT or Claude subscription connection and a reasoning model that a Game dynamic image prompt still stops at the **Image prompt** timeout. - Manually verify that session conclusion, campaign progression and Lorebook Keeper regeneration still complete on a reasoning model with streaming on. ## 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` already says `CHAT_GENERATION_TIMEOUT_MS` covers Game generations. This PR makes that true, so no docs change or translation follow-up is needed. Only CHANGELOG is updated. ## UI evidence (if applicable) Not applicable: server-only change. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Game generation now uses the configured chat timeout instead of a fixed five-minute limit for new-game startup and other Game Master requests. * For streaming responses, thinking and token output count as progress. The timeout applies while waiting for the first output and between outputs; requests without streaming callbacks retain a total timeout. * Retrying game setup restarts its response timer. * **Documentation** * Updated the unreleased notes to describe the timeout behavior. <!-- 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-24 04:05:51 +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#7612
No description provided.