[PR #3428] [CLOSED] Fix turn-game narration leaking model chain-of-thought into chat #5933

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/3428
Author: @Romuromylus
Created: 7/10/2026
Status: ❌ Closed

Base: staging ← Head: fix/turn-game-narration-thinking-leak


📝 Commits (1)

  • c78c76c Fix turn-game narration leaking model chain-of-thought into chat

📊 Changes

2 files changed (+29 additions, -6 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 packages/server/src/services/turn-games/turn-game-bot-runner.service.ts (+28 -6)

📄 Description

Linked issue

Closes #3427

Why this change

When the connected model is a reasoning model that emits its chain-of-thought inline in content (a leading <think>/<thinking> block) instead of a provider-native thinking channel, turn-game narration saves that reasoning verbatim as the character's chat message. With the previous 100/120-token narration budgets the reasoning routinely ate the whole budget, so what landed in chat was a truncated meta monologue ("The user wants me to say one short, natural line as … Let me think of something she would say -") instead of a spoken line. This affects all four turn games (UNO, chess, poker, 8-ball): both the bot's post-move table talk and the dealer/announcer lines.

The main generation pipeline already strips these blocks (extractLeadingThinkingBlocks in generate.routes.ts / game.routes.ts); the turn-game bot runner predates none of that but never adopted it.

What changed

All changes are in packages/server/src/services/turn-games/turn-game-bot-runner.service.ts (plus a CHANGELOG entry):

  • New stripInlineThinking() helper applied to both narration paths (narrateOutcome, narrateAnnouncements): strips leading inline thinking blocks using the same shared extractor as the generation pipeline, and — the case a plain strip cannot recover — returns an empty line when an unclosed opening tag remains at the front (maxTokens ran out mid-thought, so everything present is reasoning). Both call sites already fall back to the factual event summary on an empty line, so the worst case is now a dry-but-correct line instead of leaked chain-of-thought.
  • Narration maxTokens raised from 100/120 to 300 so reasoning models have headroom to finish thinking and still produce the spoken line.
  • Prompt hardening on both narration prompts: "Reply with the spoken line ONLY — no reasoning, no preamble."
  • The bot move call is untouched — it only consumes res.toolCalls, so inline reasoning there was never persisted.

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

Done so far:

  • pnpm check (typecheck + lint + build) passes locally.
  • Local unit tests on stripInlineThinking (11 cases): plain lines pass through; closed <think>/<thinking>/[think] blocks stripped (case-insensitive, multiple consecutive blocks); the exact truncated-unclosed-block shape from the bug report returns empty (fallback path); tags mentioned mid-line are not treated as thinking.

Still to verify manually before promoting:

  • Live turn-game session with a reasoning model: bot table talk and announcer lines contain only the spoken line.
  • Live session with a non-reasoning model: narration behavior unchanged.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Version/release files updated (only if this PR includes a version bump)

CHANGELOG entry added under [Unreleased] → Fixed. No version bump; no other docs reference turn-game narration internals.

UI evidence (if applicable)

Server-side narration fix — the user-visible effect is the absence of leaked reasoning in chat. The linked issue quotes the leaked message this fixes.


🔄 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/3428 **Author:** [@Romuromylus](https://github.com/Romuromylus) **Created:** 7/10/2026 **Status:** ❌ Closed **Base:** `staging` ← **Head:** `fix/turn-game-narration-thinking-leak` --- ### 📝 Commits (1) - [`c78c76c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/c78c76c085fd78c16e8c3bb441d61790f45a84b7) Fix turn-game narration leaking model chain-of-thought into chat ### 📊 Changes **2 files changed** (+29 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `packages/server/src/services/turn-games/turn-game-bot-runner.service.ts` (+28 -6) </details> ### 📄 Description ## Linked issue Closes #3427 ## Why this change When the connected model is a reasoning model that emits its chain-of-thought inline in `content` (a leading `<think>`/`<thinking>` block) instead of a provider-native thinking channel, turn-game narration saves that reasoning verbatim as the character's chat message. With the previous 100/120-token narration budgets the reasoning routinely ate the whole budget, so what landed in chat was a truncated meta monologue ("The user wants me to say one short, natural line as … Let me think of something she would say -") instead of a spoken line. This affects all four turn games (UNO, chess, poker, 8-ball): both the bot's post-move table talk and the dealer/announcer lines. The main generation pipeline already strips these blocks (`extractLeadingThinkingBlocks` in `generate.routes.ts` / `game.routes.ts`); the turn-game bot runner predates none of that but never adopted it. ## What changed All changes are in `packages/server/src/services/turn-games/turn-game-bot-runner.service.ts` (plus a CHANGELOG entry): - New `stripInlineThinking()` helper applied to both narration paths (`narrateOutcome`, `narrateAnnouncements`): strips leading inline thinking blocks using the same shared extractor as the generation pipeline, and — the case a plain strip cannot recover — returns an empty line when an **unclosed** opening tag remains at the front (maxTokens ran out mid-thought, so everything present is reasoning). Both call sites already fall back to the factual event summary on an empty line, so the worst case is now a dry-but-correct line instead of leaked chain-of-thought. - Narration `maxTokens` raised from 100/120 to 300 so reasoning models have headroom to finish thinking and still produce the spoken line. - Prompt hardening on both narration prompts: "Reply with the spoken line ONLY — no reasoning, no preamble." - The bot **move** call is untouched — it only consumes `res.toolCalls`, so inline reasoning there was never persisted. ## 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 Done so far: - `pnpm check` (typecheck + lint + build) passes locally. - Local unit tests on `stripInlineThinking` (11 cases): plain lines pass through; closed `<think>`/`<thinking>`/`[think]` blocks stripped (case-insensitive, multiple consecutive blocks); the exact truncated-unclosed-block shape from the bug report returns empty (fallback path); tags mentioned mid-line are not treated as thinking. Still to verify manually before promoting: - Live turn-game session with a reasoning model: bot table talk and announcer lines contain only the spoken line. - Live session with a non-reasoning model: narration behavior unchanged. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Version/release files updated (only if this PR includes a version bump) CHANGELOG entry added under [Unreleased] → Fixed. No version bump; no other docs reference turn-game narration internals. ## UI evidence (if applicable) Server-side narration fix — the user-visible effect is the *absence* of leaked reasoning in chat. The linked issue quotes the leaked message this fixes. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:05:19 +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#5933
No description provided.