[PR #7466] [MERGED] fix(game): empty purses, tool-round caps, leaner GM prompts, and stable game e2e specs #7746

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7466
Author: @kolacheee
Created: 10/12/2026
Status: ✅ Merged
Merged: 10/12/2026
Merged by: @kolacheee

Base: staging ← Head: fix/game-mode-fixes


📝 Commits (10+)

  • 7c27aab test(e2e): the Decision import notice by its catalog words; both coin toasts at once
  • 84f29a4 fix(game): tell the Game Master when a purse is empty
  • 37444ae fix(game): say the party in the empty-purse line, and load the book for coins in use
  • 1153771 Merge origin/staging into fix/stale-e2e-specs
  • 96a7e86 test(e2e): run Chromium with its audio output off
  • d276c8f test(e2e): three game specs that failed on current staging
  • e697af6 fix(game): give a Game Mode turn at most four tool rounds
  • b892dbb fix(llm): retell a tool loop's exchange as text for its last request
  • 3abb122 fix(agents): give an agent at most eight tool rounds, and its last request as text
  • 5443dcc Merge origin/staging into fix/stale-e2e-specs

📊 Changes

28 files changed (+612 additions, -60 deletions)

View changed files

📝 .env.example (+2 -1)
📝 CHANGELOG.md (+5 -0)
📝 docs/CONFIGURATION.md (+1 -1)
📝 docs/agents/custom-agents.md (+2 -0)
📝 docs/extending/writing-rulesets.md (+1 -1)
📝 docs/game/getting-started.md (+1 -1)
📝 e2e/game-npc-portraits.e2e.ts (+24 -14)
📝 e2e/game-ruleset-money.e2e.ts (+6 -2)
📝 e2e/game-tool-controls.e2e.ts (+3 -0)
📝 e2e/ruleset-wound-sheet.e2e.ts (+2 -2)
📝 packages/server/src/config/runtime-config.ts (+7 -0)
📝 packages/server/src/routes/game.routes.ts (+22 -6)
📝 packages/server/src/routes/generate.routes.ts (+29 -6)
📝 packages/server/src/routes/generate/retry-agents-route.ts (+3 -1)
📝 packages/server/src/services/agents/agent-executor.ts (+27 -4)
📝 packages/server/src/services/game/gm-prompts.ts (+17 -4)
📝 packages/server/src/services/tools/tool-executor.ts (+60 -1)
📝 packages/shared/src/features/rulesets/item-book.ts (+4 -2)
📝 playwright.config.ts (+18 -2)
📝 scripts/regressions/advanced-memory-post-generation.regression.ts (+3 -1)

...and 8 more files

📄 Description

Linked issue

Closes #7465

Why this change

  • In a Game Mode game with money, an empty purse was left out of the Game Master's prompt, so it could narrate buying bread for a player with no coins; the Engine then refused the buy and the story contradicted the bag. The prompt's item book was only loaded when the party held a ruleset item.
  • A Game Mode turn and an agent run used the general MAX_TOOL_ROUNDS of 100, so a model that kept asking for a roll could make up to a hundred paid requests in one turn. The loop's last request goes out without tools, and native Anthropic and Gemini formats cannot carry a tool exchange without them, so a cap makes that request routine and it has to be valid.
  • The end-of-session, recruit and character-sheet prompts pasted each party member's whole ruleset sheet; the model never edits a sheet there.
  • A few e2e specs and one regression lane failed for reasons of their own (below).

What changed

  • Empty purse: rulesetPurseText says "no coins" when the game has coins and the bag holds none; buildGmFormatReminder always prints the player's inventory line when a purse is said and says party members not listed carry nothing; generate.routes.ts loads the item book when the pinned ruleset has coins in use.
  • Tool rounds: GAME_TURN_MAX_TOOL_ROUNDS = 4 and AGENT_MAX_TOOL_ROUNDS = 16 (a lorebook backfill asks for 64, and no stored agent setting goes past that); a lower MAX_TOOL_ROUNDS still wins, and a run that uses every round is logged. toolRoundsAsText retells the last request's tool exchange as text, naming each call with its arguments (cut at 300 characters) so a receipt such as {"ok":true} still says what it was for. Docs: docs/CONFIGURATION.md, .env.example, docs/agents/custom-agents.md, docs/game/getting-started.md.
  • GM prompts: party cards go into the end-of-session, recruit and character-sheet prompts without their ruleset sheets.
  • Tests: Chromium runs with --disable-audio-output (a headless page could stall about 17 s opening its first audio device, so toasts vanished before they were checked); the coin spec waits for both of a turn's toasts at once; the tool controls spec gets the time its four reloads need; the NPC portrait spec waits as long after a reload as on first load; the storage writer lock lane finds the watcher under pnpm -s too. Staging had already fixed the Decision import notice, one-request dice and combat director specs its own way, so those files follow staging.
  • advanced-memory-post-generation (new on staging) spots a tool follow-up by its tool messages; it now also counts the last round's follow-up, which retells the results as text.
  • Lanes: game-ruleset-money, game-inventory-turn, game-tool-outcomes, agent-runtime, game-ruleset-setup, cjk-token-budgets, open-issues.

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
  • On this branch after merging staging aee076362: pnpm check green; node scripts/run-regressions.mjs 583/587, then advanced-memory-post-generation passes alone after the fix above. The three still failing (memory-recall-revectorize, regeneration-context, native-export-memory timeout) fail the same way on staging aee076362 in the same container.
  • Earlier, on the separate branches: money and markets e2e 6/6 on desktop and mobile Chromium; all 30 game specs on both Chromium projects (158 passed, 2 skipped by their own conditions); planted defects caught (10/10 empty purse, 7/7 tool rounds, 4/4 specs).

Manual verification notes

  • Empty purse: checked with a real model (Gemini Flash, an isolated instance): with an empty bag and "I buy the coat", the prompt carried the empty-purse line and the model narrated an empty pouch both times.
  • Tool rounds: a real run with MAX_TOOL_ROUNDS=1 on an Anthropic connection and an OpenAI-compatible Gemini connection both narrated the roll; a body-capture probe of each native formatter shows the last request carries no tool role, tool_calls or provider parts.
  • Not checked by a person yet: a native Anthropic or Gemini connection with a real key on a turn that rolls several times, and an agent backfill that saves many entries.

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)
  • CHANGELOG [Unreleased] entries added. docs/CONFIGURATION.md, docs/agents/custom-agents.md, docs/game/getting-started.md and docs/extending/writing-rulesets.md changed; the translations are tracked on the Game Mode catch-up issue #6813.

UI evidence (if applicable)

Not applicable (server, prompts and tests).

Summary by CodeRabbit

  • New Features
    • Game Mode turns now allow up to four tool-call rounds, while agents allow up to 16 and lorebook backfills up to 64. A lower configured limit still takes precedence.
    • When tool calls finish, their results are included in the final request as readable text.
    • Empty purses are now clearly shown as “no coins” in supported game inventory summaries.
    • Game prompts no longer include ruleset sheets with character cards.

🔄 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/7466 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 10/12/2026 **Status:** ✅ Merged **Merged:** 10/12/2026 **Merged by:** [@kolacheee](https://github.com/kolacheee) **Base:** `staging` ← **Head:** `fix/game-mode-fixes` --- ### 📝 Commits (10+) - [`7c27aab`](https://github.com/Pasta-Devs/Marinara-Engine/commit/7c27aab2a6374f86d6d4ee9fb8098bbae647e2ba) test(e2e): the Decision import notice by its catalog words; both coin toasts at once - [`84f29a4`](https://github.com/Pasta-Devs/Marinara-Engine/commit/84f29a49bf92570fde2944bbdc224288866ed4ab) fix(game): tell the Game Master when a purse is empty - [`37444ae`](https://github.com/Pasta-Devs/Marinara-Engine/commit/37444ae1a883ba18cd22713cd7f7eba99cb37dc0) fix(game): say the party in the empty-purse line, and load the book for coins in use - [`1153771`](https://github.com/Pasta-Devs/Marinara-Engine/commit/11537714d6a94ad85acb89fcdc9e1cbe433789da) Merge origin/staging into fix/stale-e2e-specs - [`96a7e86`](https://github.com/Pasta-Devs/Marinara-Engine/commit/96a7e86b743da99968e8df342d4fd87ab2e89a8f) test(e2e): run Chromium with its audio output off - [`d276c8f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d276c8fc9ef394e495cbf2ceec57e80e1f0823f0) test(e2e): three game specs that failed on current staging - [`e697af6`](https://github.com/Pasta-Devs/Marinara-Engine/commit/e697af673591f2497542ab50f72ca869027cfff6) fix(game): give a Game Mode turn at most four tool rounds - [`b892dbb`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b892dbb63c0e6f4e0e9e3864f8a73d5ef897180c) fix(llm): retell a tool loop's exchange as text for its last request - [`3abb122`](https://github.com/Pasta-Devs/Marinara-Engine/commit/3abb1227f802607da61b45019055c5c73af60b93) fix(agents): give an agent at most eight tool rounds, and its last request as text - [`5443dcc`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5443dcc45bd098de8ac2b8bba2e34f0932937283) Merge origin/staging into fix/stale-e2e-specs ### 📊 Changes **28 files changed** (+612 additions, -60 deletions) <details> <summary>View changed files</summary> 📝 `.env.example` (+2 -1) 📝 `CHANGELOG.md` (+5 -0) 📝 `docs/CONFIGURATION.md` (+1 -1) 📝 `docs/agents/custom-agents.md` (+2 -0) 📝 `docs/extending/writing-rulesets.md` (+1 -1) 📝 `docs/game/getting-started.md` (+1 -1) 📝 `e2e/game-npc-portraits.e2e.ts` (+24 -14) 📝 `e2e/game-ruleset-money.e2e.ts` (+6 -2) 📝 `e2e/game-tool-controls.e2e.ts` (+3 -0) 📝 `e2e/ruleset-wound-sheet.e2e.ts` (+2 -2) 📝 `packages/server/src/config/runtime-config.ts` (+7 -0) 📝 `packages/server/src/routes/game.routes.ts` (+22 -6) 📝 `packages/server/src/routes/generate.routes.ts` (+29 -6) 📝 `packages/server/src/routes/generate/retry-agents-route.ts` (+3 -1) 📝 `packages/server/src/services/agents/agent-executor.ts` (+27 -4) 📝 `packages/server/src/services/game/gm-prompts.ts` (+17 -4) 📝 `packages/server/src/services/tools/tool-executor.ts` (+60 -1) 📝 `packages/shared/src/features/rulesets/item-book.ts` (+4 -2) 📝 `playwright.config.ts` (+18 -2) 📝 `scripts/regressions/advanced-memory-post-generation.regression.ts` (+3 -1) _...and 8 more files_ </details> ### 📄 Description ## Linked issue Closes #7465 ## Why this change - In a Game Mode game with money, an empty purse was left out of the Game Master's prompt, so it could narrate buying bread for a player with no coins; the Engine then refused the buy and the story contradicted the bag. The prompt's item book was only loaded when the party held a ruleset item. - A Game Mode turn and an agent run used the general `MAX_TOOL_ROUNDS` of 100, so a model that kept asking for a roll could make up to a hundred paid requests in one turn. The loop's last request goes out without tools, and native Anthropic and Gemini formats cannot carry a tool exchange without them, so a cap makes that request routine and it has to be valid. - The end-of-session, recruit and character-sheet prompts pasted each party member's whole ruleset sheet; the model never edits a sheet there. - A few e2e specs and one regression lane failed for reasons of their own (below). ## What changed - **Empty purse:** `rulesetPurseText` says "no coins" when the game has coins and the bag holds none; `buildGmFormatReminder` always prints the player's inventory line when a purse is said and says party members not listed carry nothing; `generate.routes.ts` loads the item book when the pinned ruleset has coins in use. - **Tool rounds:** `GAME_TURN_MAX_TOOL_ROUNDS = 4` and `AGENT_MAX_TOOL_ROUNDS = 16` (a lorebook backfill asks for 64, and no stored agent setting goes past that); a lower `MAX_TOOL_ROUNDS` still wins, and a run that uses every round is logged. `toolRoundsAsText` retells the last request's tool exchange as text, naming each call with its arguments (cut at 300 characters) so a receipt such as `{"ok":true}` still says what it was for. Docs: `docs/CONFIGURATION.md`, `.env.example`, `docs/agents/custom-agents.md`, `docs/game/getting-started.md`. - **GM prompts:** party cards go into the end-of-session, recruit and character-sheet prompts without their ruleset sheets. - **Tests:** Chromium runs with `--disable-audio-output` (a headless page could stall about 17 s opening its first audio device, so toasts vanished before they were checked); the coin spec waits for both of a turn's toasts at once; the tool controls spec gets the time its four reloads need; the NPC portrait spec waits as long after a reload as on first load; the storage writer lock lane finds the watcher under `pnpm -s` too. Staging had already fixed the Decision import notice, one-request dice and combat director specs its own way, so those files follow staging. - `advanced-memory-post-generation` (new on staging) spots a tool follow-up by its `tool` messages; it now also counts the last round's follow-up, which retells the results as text. - Lanes: `game-ruleset-money`, `game-inventory-turn`, `game-tool-outcomes`, `agent-runtime`, `game-ruleset-setup`, `cjk-token-budgets`, `open-issues`. ## Validation - [x] `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` - On this branch after merging staging aee076362: `pnpm check` green; `node scripts/run-regressions.mjs` 583/587, then `advanced-memory-post-generation` passes alone after the fix above. The three still failing (`memory-recall-revectorize`, `regeneration-context`, `native-export-memory` timeout) fail the same way on staging aee076362 in the same container. - Earlier, on the separate branches: money and markets e2e 6/6 on desktop and mobile Chromium; all 30 game specs on both Chromium projects (158 passed, 2 skipped by their own conditions); planted defects caught (10/10 empty purse, 7/7 tool rounds, 4/4 specs). ### Manual verification notes - Empty purse: checked with a real model (Gemini Flash, an isolated instance): with an empty bag and "I buy the coat", the prompt carried the empty-purse line and the model narrated an empty pouch both times. - Tool rounds: a real run with `MAX_TOOL_ROUNDS=1` on an Anthropic connection and an OpenAI-compatible Gemini connection both narrated the roll; a body-capture probe of each native formatter shows the last request carries no `tool` role, `tool_calls` or provider parts. - Not checked by a person yet: a native Anthropic or Gemini connection with a real key on a turn that rolls several times, and an agent backfill that saves many entries. ## Docs and release impact - [ ] No docs changes needed - [x] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [x] 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) - CHANGELOG `[Unreleased]` entries added. `docs/CONFIGURATION.md`, `docs/agents/custom-agents.md`, `docs/game/getting-started.md` and `docs/extending/writing-rulesets.md` changed; the translations are tracked on the Game Mode catch-up issue #6813. ## UI evidence (if applicable) Not applicable (server, prompts and tests). <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Game Mode turns now allow up to four tool-call rounds, while agents allow up to 16 and lorebook backfills up to 64. A lower configured limit still takes precedence. * When tool calls finish, their results are included in the final request as readable text. * Empty purses are now clearly shown as “no coins” in supported game inventory summaries. * Game prompts no longer include ruleset sheets with character cards. <!-- 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:07:05 +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#7746
No description provided.