[PR #5924] [MERGED] feat(game): the GM rolls real dice, and the roll is a visible card #6994

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/5924
Author: @kolacheee
Created: 9/7/2026
Status: ✅ Merged
Merged: 9/8/2026
Merged by: @kolacheee

Base: staging ← Head: feat/game-mode-dice-tool


📝 Commits (10+)

  • e647d99 feat(tools): add a mode-level auto-attach channel for chat tools
  • 2135e37 fix(tools): narrow update_game_state to the updates that persist
  • 3d78b5a feat(game): roll real dice on game turns instead of letting the GM invent them
  • a8749b2 feat(game): show a GM-called dice roll while the turn is still running
  • 1203940 feat(chat): say what turning tool use on costs in a game chat
  • b1a38ec test(game): pin the Game Mode dice-tool contract
  • b6cbba3 fix(game): keep Force To Call off the dice tool and save whole tool turns
  • bdc15ce docs(changelog): say what happens to a saved GM roll on reload
  • d8de5e9 Merge branch 'fix/provider-tools-streaming' into feat/game-mode-dice-tool
  • e5c51c3 Merge branch 'codex/review-pr-5920-sep8' into codex/review-pr-5924-sep8

📊 Changes

28 files changed (+1280 additions, -115 deletions)

View changed files

📝 CHANGELOG.md (+8 -0)
📝 docs/game/dice-and-skill-checks.md (+2 -0)
📝 e2e/core-flows.e2e.ts (+3 -0)
➕ e2e/game-native-dice.e2e.ts (+268 -0)
📝 packages/client/src/components/chat/ChatMessage.tsx (+9 -17)
📝 packages/client/src/components/chat/ChatSettingsDrawer.tsx (+1 -0)
📝 packages/client/src/components/chat/ConversationMessageBubble.tsx (+16 -10)
📝 packages/client/src/components/chat/ConversationMessageLine.tsx (+34 -26)
📝 packages/client/src/components/chat/ConversationMessageShared.tsx (+11 -1)
📝 packages/client/src/components/dice/AnimatedDiceRoll.tsx (+0 -12)
📝 packages/client/src/features/chat-settings/sections/FunctionCallingSection.tsx (+8 -3)
📝 packages/client/src/hooks/use-generate.ts (+12 -1)
➕ packages/client/src/lib/dice-roll-result.ts (+18 -0)
📝 packages/client/src/localization/locales/en.json (+1 -0)
📝 packages/server/src/routes/generate.routes.ts (+50 -4)
📝 packages/server/src/services/agents/agent-progress.ts (+2 -1)
📝 packages/server/src/services/game/dice.service.ts (+28 -0)
📝 packages/server/src/services/game/gm-prompts.ts (+15 -0)
📝 packages/server/src/services/generation/generation-parameters.ts (+27 -0)
📝 packages/server/src/services/generation/tool-resolution-runtime.ts (+78 -16)

...and 8 more files

📄 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.

Important

Stacked PR, and merge-gated. Branch feat/game-mode-dice-tool sits on top of fix/provider-tools-streaming (Gemini and Anthropic no longer hold the whole reply back on a turn that carries tools). Review and merge that one first.

The gate is a live smoke, not a green suite. That branch must be exercised on real Gemini and Anthropic keys — one real turn each with tools attached, showing tokens arriving progressively and a tool call parsed out of the live stream — before this one merges. Without it, every Game Mode turn on those connections is held back for its whole generation, and the in-product hint this PR adds states that streaming keeps working there, so the claim ships to users either way.

Inherited from the branch below, stated so it is not discovered later: an Anthropic stream cut off in the middle of a tool call's arguments returns that call with empty arguments. That residual is named on the streaming PR; it is not introduced here.

This branch merges clean against feat/gm-sparse-checks-server-rolled (the engine-rolled skill checks). The two are independent lanes on the same problem and can land in either order.

Linked issue

Closes #5950

Tracking issue: #5950. Related issues #5798, #5898 and #5901 remain separate. The provider-streaming prerequisite and live-provider verification requirement above still apply.

Why this change

On a connection that can call tools, the number should exist before the narration does.

  • The GM used to make dice results up in prose. The other lane in this work (feat/gm-sparse-checks-server-rolled) fixes that by rolling the check on the server after the model has written the turn — honest, but one beat late: the model narrates up to the attempt and the consequence lands next turn.
  • A real tool call removes the lag entirely. The GM asks for a die, gets the true number mid-turn, and narrates once with it. That is the whole difference, and it is only available on connections that can actually call tools.
  • The obvious way to get the tool in front of the GM — telling players to switch "Enable Tool Use" on — is the wrong one. That toggle also arms the entire default-on tool set, the Spotify credential lookup, and the prompt injection that lists available functions on local endpoints. A mode that wants exactly one tool should not drag all of that along, and a player should not have to opt into it to get honest dice.

What changed

  1. A mode-level auto-attach channel, separate from the tools toggle. resolveGenerationTools now takes a list of tool names a chat mode requires and answers a new question — does this turn send tools at all — while enableChatTools keeps its exact previous meaning, so everything keyed on the player's toggle stays quiet. With no auto-attach names, tool resolution is byte-identical to before. Agent-only tools can never be attached this way, and a name that resolves to nothing leaves the turn exactly as it was.
  2. The GM gets roll_dice on every Game Mode turn, through that channel, whether or not the chat has tool use switched on — and the format reminder tells it to throw the tool the moment it needs a real number before it can keep writing. Both halves are load-bearing: the tool alone is never called, and the instruction alone has nothing to call. The [skill_check: ...] tag stays as the record of a resolved check rather than being replaced, and the prompt says to fall back to the tag where the tool is not available. Impersonation is excluded — it writes the player's own line, so there is nothing for the GM to resolve.
  3. The roll is visible. A successful roll_dice result is read back into the same shape /roll produces and carried on the live tool-result event, past the debug-only gate, so the animated dice card appears while the turn is still being written. Without this the tool path would be less legible than the tag path it replaces — a pause, then a number, with no die behind it. A saved roll also no longer swallows its message: the card stands in for the whole message body only where the message is nothing but a roll, and sits alongside the narration otherwise.
  4. The Function Calling panel now says what the toggle actually buys in a game chat, with claims that are each true of a specific connection rather than a blanket warning: game chats already roll real dice without this — it adds the rest of the tools, and each tool call costs an extra model round. Streaming keeps working on Gemini and Anthropic, except Gemini with thinking on. Claude and Grok subscription connections ignore tools entirely. The old blanket line saying Gemini and Anthropic stop streaming is gone, because the branch below makes it false; the Gemini-with-thinking carve-out stays because that rule is separate, older and deliberate.
  5. update_game_state narrowed to the two update types that persist. It advertised six and answered all six with "applied", while the route only ever writes back a location change and a time advance — a stat, inventory or quest update was accepted, reported as applied, and dropped. The schema now offers only the two that are stored, so the model stops asking for the others; the executor guards the same pair so the offer and the behaviour cannot drift apart; and a refusal now says what the tool can do instead of claiming success. Argument validation also names the allowed values on an enum failure, for every tool — "must be equal to one of the allowed values" told the model nothing it could act on. Whether those two updates should be written this way at all is #5898's question, not this change's.
  6. Two defects this branch's own auto-attach channel opened, fixed here. "Force To Call Tool" is a Function Calling panel setting the panel hides whenever tool use is off, so a chat can hold that flag with no way for its owner to see or clear it. It was inert until game turns started entering the tool loop with the toggle off — from there it made every game turn demand a tool call before the GM could write a word, with nothing in the UI connecting the symptom to the cause. The tool-choice decision now honours that flag only while the toggle is on. Separately, the tool loop kept one slot for Gemini's response parts and let the last round win, while the saved content is every round's text joined — so a two-round turn was saved as prose the player read in full beside parts covering only its second half. Rounds now fold together, keeping each round's text and its own thought signature.

The honest cost, stated up front

Native tool calls are not cheaper than a bracket tag, on any provider. A dice turn becomes two model rounds. Uncached that is roughly twice the prompt plus the tool schemas on input. With prompt caching on, the second round is a clean prefix hit and the marginal cost drops to roughly 10–25% of the prompt. Wall clock gains one extra round-trip, unconditionally — typically half a second to three seconds on a fast model.

What the extra round buys is correctness in one beat: the number exists before the narration does. Forced non-streaming used to be a third penalty on Gemini and Anthropic; that was an adapter bug, and the branch below removes it. So the real comparison is "slightly more expensive, honest in one beat" against "cheapest, honest one beat late" — and for dice, one beat is worth paying for.

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

Run in the review worktree, for information — the boxes above are yours to tick once you have seen this yourself:

  • pnpm check exited 0, with the whole chain reached through the production build. pnpm version:check in sync for 2.4.5.
  • game-mode-dice-tool.regression.ts, provider-compat.regression.ts and maintenance-lifecycle.regression.ts passed. Neighbours passed: dice-display, game-narration-phase, conversation-game-slash, prompt, context-fit.
  • Exactly one server logging line was added in the whole branch, at the right level, using the shared logger; no console.* added server-side.
  • Removing each of the guards this PR adds fails the regression lane — including the auto-attach condition, the card on the live tool result, the saved roll, the prompt instruction, and both halves of the Gemini parts fix.

Remaining manual verification (automated browser proof is recorded below):

  • Manually verify the prerequisite first: one real Gemini turn and one real Anthropic turn with tools attached, on the branch below, showing text arriving progressively and a tool call parsed. This PR should not merge before that.
  • Manually verify, in a Game Mode chat with "Enable Tool Use" left off, that a GM asked for something risky calls the dice tool, the animated card appears while the turn is still being written, and the number in the prose matches the number on the card.
  • Manually verify streaming is intact on that same turn — text keeps arriving during the roll rather than landing all at once at the end.
  • Manually verify /roll still behaves exactly as before in a game chat, as the comparison anchor for the card.
  • Manually verify the new Function Calling panel text reads correctly and appears only in a game chat, in both light and dark mode and at a mobile width.
  • Manually verify a chat that has "Force To Call Tool" set but tool use off no longer opens every game turn by demanding a tool call.
  • Manually verify update_game_state with a stat or inventory update now refuses with a message that says what it can do, instead of reporting success.
  • Manually decide the open design question below: should the game transcript redraw a dismissed dice card after a reload? If yes, that is a follow-up; if no, nothing further is needed — the changelog already says it does not.
  • Manually verify Peek Prompt on a turn that actually rolled — its contents change (see limitations) and this is a shipped feature.
  • Manually verify a game turn on a Claude or Grok subscription connection still writes normally and falls back to the check tag, since those connections ignore tools entirely.

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.md gains one entry under Added, which references #5798 and #5901 and points the open question at #5898. No version-bearing file is touched. One new English UI string is added for the panel hint; it is a new key, not a rename or a deletion, so nothing needs mirroring for translators — pnpm localization:check runs as part of pnpm check. docs/game/dice-and-skill-checks.md now distinguishes native same-turn dice from the two-turn fallback. Translation follow-up: #5951.

The reload caveat is in the changelog, in the same words the entry uses: the card appears while the turn is being written; the roll is saved with the message, but the game transcript does not draw the card again when you reload the chat. The Game surface renders game chats before the branches that read a saved roll off a message, and it draws its card from the live turn only. Saying only "kept with the message" would have been true of the stored row and invited an expectation a reload disproves.

UI evidence (if applicable)

The automated browser proof captures the native dice card during a paused model follow-up and the Game-only Function Calling hint, in light and dark themes on desktop Chromium, mobile Chromium, and mobile WebKit. These screenshots were inspected locally; the test can reproduce its attachments with the JSON reporter. Real-device and live-provider checks remain separate.


Known limitations, named here rather than left for review to find

  1. A turn that rolls more than once keeps only the last card. Each roll's result is honest and reaches the model; the visible card is overwritten by the following roll.
  2. The saved roll is not redrawn on reload (above). This is stated in the changelog rather than fixed, because whether the transcript should redraw a dismissed card is a design question for the browser pass, not something to settle inside this PR.
  3. Peek Prompt on a turn that rolled now shows the last tool round. It reflects what was actually sent for that round — the assistant's tool call and the tool result appended — rather than the clean prompt it showed before. Arguably more accurate, pre-existing for any chat with tools on, but it changes a shipped feature's output on every rolling game turn, so it is worth one look.
  4. One extra store read per game turn. Tool resolution now lists enabled custom tools on every game turn, where it previously did not. Small table, once per generation.
  5. The executor's guard on update_game_state update types has no test, deliberately. Argument validation refuses a removed type against the tool's schema long before that guard runs, so it is genuinely unreachable through the model. It is kept as defence in depth for a caller that arrives without that schema, and the code comment now says exactly that. Writing a test that reached past validation purely to turn it green would have manufactured coverage rather than proving anything.
  6. Claude and Grok subscription connections ignore tools entirely, so on those the GM never calls the die and falls back to writing the check tag. That is what the other lane in this work exists for; the panel hint says so plainly rather than leaving players to discover it.
  7. This PR does not touch the tools toggle's own behaviour. Turning "Enable Tool Use" on in a game chat still arms everything it always armed; the hint now describes that instead of the app changing it.

Maintainer staging integration

Updated this branch with current staging and the prerequisite provider-streaming fixes from #5920. Native tool guidance now records the actual roll as a complete skill check, avoiding a second engine roll after #5923; sparse fallback checks remain unchanged. The Function Calling hint replaces the contradictory generic disabled-tools description in Game mode. The dice regression now accepts the shared grammar's valid d20 and uses 1d0 as its invalid-input control.

Validation on the integrated branch:

  • pnpm check passed, including localization, lint, type checking and production build.
  • Native dice, skill-check resolution, provider compatibility, Experience lore selection, maintenance lifecycle, dice display, narration phase, Conversation/Game slash commands, GM capabilities, prompt and context-fit regressions passed.
  • pnpm exec playwright test e2e/game-native-dice.e2e.ts --workers 1 --reporter list,json: all 9 cases passed across desktop Chromium, mobile Chromium and mobile WebKit, including both Game themes and Classic Conversation multipart messages. The fixture uses the real server tool loop against a synthetic local provider, keeps the follow-up response unfinished until the dice card is shown, and checks the displayed/saved total, progressive buffer, default-off tool toggle and hidden force-tool flag. No paid provider is contacted. Its WebKit wait allows the existing 15-second SSE keepalive to deliver the deliberately tiny paused stream; it does not wait for generation completion or remove the live-card assertion.

Still blocking merge: the explicit live Gemini (thinking off) and Anthropic tool-streaming checks required by this PR and #5920 are not yet confirmed. Synthetic-provider proof is not a substitute. No live provider credentials were accessed or paid requests made. Human validation checkboxes remain unchecked.

Summary by CodeRabbit

  • New Features

    • Game Mode can roll real dice during generation and display results immediately, including alongside same-turn narration.
    • Dice results remain visible across streamed messages, continuations, and replayed conversations.
    • Game Mode supports dice rolling even when other tool use is disabled.
  • Bug Fixes

    • Improved dice-card rendering across message formats.
    • Game state updates now support only location and time changes, with clearer validation messages.
    • Improved provider streaming and tool-call handling.
  • Documentation

    • Added guidance for native dice rolls and fallback behavior when unsupported.

CodeRabbit follow-up (56ec55575)

All four review findings are addressed with narrow changes and regression proof: multipart assistant Conversation messages retain the existing dice card; continuations without another roll preserve it while regenerations clear it; auto-attached Game tools receive the existing local-endpoint guidance; and location/time updates no longer require unused target/key fields. The out-of-diff provider logging note from #5920 is also fixed here, honoring chat debug and explicit agent debug/DEBUG_AGENTS without logging auth headers.

pnpm check, the native dice, provider compatibility, agent progress and neighboring prompt/Game regression runs all pass. The browser fixture passes all 9 cases and exercises the real continuation/regeneration persistence paths. Red-before/green-after proof was obtained for the missing multipart card, missing local-tool prompt block, cleared continuation result, and minimal game-state tool arguments. #5920 was merged by @kolacheee; that merge does not itself establish live-provider test results, which remain unconfirmed here.

Final review follow-up (9c904048a)

Fixed the outside-diff Gemini replay finding: provider-issued call IDs are preserved in both raw-part replay and fallback serialization, and each function result returns the matching ID. Id-less Gemini calls still replay unchanged; Engine-only synthetic IDs are not sent as unmatched response IDs. This follows Google's FunctionCall/FunctionResponse contract. The local HTTP regression failed before the fix and passes after it, covering parallel calls to the same function and both replay paths.

The desktop CI failure was the Home lifecycle heap assertion. Its trace shows the baseline completed at 124.2s, but the chat's emoji/sticker/regex/lore initialization first ran at 135.9s during measured cycles. The test now waits for the actual chat composer before returning Home during both warm-up and measurement. The 3 MiB heap limit and every lifecycle assertion are unchanged. Three focused runs pass after the fix, with approximately 0.9–1.4 MiB retained heap growth. pnpm check and provider compatibility regressions also pass. Fresh CI and CodeRabbit must complete on this head before merge.

Scope clarification: provider replay and opt-in debug logging are follow-ups to prerequisite #5920 / #5918, used by the automatically attached Game dice tool. The location/time-only game-state contract was already part of this feature branch and relates to #5898. These are integration and review fixes, not a new provider or game-system redesign.

The live Gemini (thinking off) and Anthropic checks remain unconfirmed and still block merge; automated/synthetic proof does not satisfy that explicit prerequisite.


🔄 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/5924 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 9/7/2026 **Status:** ✅ Merged **Merged:** 9/8/2026 **Merged by:** [@kolacheee](https://github.com/kolacheee) **Base:** `staging` ← **Head:** `feat/game-mode-dice-tool` --- ### 📝 Commits (10+) - [`e647d99`](https://github.com/Pasta-Devs/Marinara-Engine/commit/e647d994c36fd4e6ad6450d7e3e45034504ee685) feat(tools): add a mode-level auto-attach channel for chat tools - [`2135e37`](https://github.com/Pasta-Devs/Marinara-Engine/commit/2135e37aec76d1805161decd3e5e965b758189dc) fix(tools): narrow update_game_state to the updates that persist - [`3d78b5a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/3d78b5ad0695048ae40984cdbc743109aeb1f1c7) feat(game): roll real dice on game turns instead of letting the GM invent them - [`a8749b2`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a8749b204697f8024f7649036de78a6d22806d1f) feat(game): show a GM-called dice roll while the turn is still running - [`1203940`](https://github.com/Pasta-Devs/Marinara-Engine/commit/12039405a2ddf32b7fafd4a8043c9f3a9e4d85e6) feat(chat): say what turning tool use on costs in a game chat - [`b1a38ec`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b1a38ecef937a0a9a766b78f569031be71d4d8d8) test(game): pin the Game Mode dice-tool contract - [`b6cbba3`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b6cbba330b09a1ad50f98d123e8e70b0485a022d) fix(game): keep Force To Call off the dice tool and save whole tool turns - [`bdc15ce`](https://github.com/Pasta-Devs/Marinara-Engine/commit/bdc15ceac2a82fc1e366f417a20f4c1b2a25e0b7) docs(changelog): say what happens to a saved GM roll on reload - [`d8de5e9`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d8de5e91db31de6fefc3d2f31ee79b1b057a0e6b) Merge branch 'fix/provider-tools-streaming' into feat/game-mode-dice-tool - [`e5c51c3`](https://github.com/Pasta-Devs/Marinara-Engine/commit/e5c51c3e9aceb3b8ce82eb958680a375cf589e7a) Merge branch 'codex/review-pr-5920-sep8' into codex/review-pr-5924-sep8 ### 📊 Changes **28 files changed** (+1280 additions, -115 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+8 -0) 📝 `docs/game/dice-and-skill-checks.md` (+2 -0) 📝 `e2e/core-flows.e2e.ts` (+3 -0) ➕ `e2e/game-native-dice.e2e.ts` (+268 -0) 📝 `packages/client/src/components/chat/ChatMessage.tsx` (+9 -17) 📝 `packages/client/src/components/chat/ChatSettingsDrawer.tsx` (+1 -0) 📝 `packages/client/src/components/chat/ConversationMessageBubble.tsx` (+16 -10) 📝 `packages/client/src/components/chat/ConversationMessageLine.tsx` (+34 -26) 📝 `packages/client/src/components/chat/ConversationMessageShared.tsx` (+11 -1) 📝 `packages/client/src/components/dice/AnimatedDiceRoll.tsx` (+0 -12) 📝 `packages/client/src/features/chat-settings/sections/FunctionCallingSection.tsx` (+8 -3) 📝 `packages/client/src/hooks/use-generate.ts` (+12 -1) ➕ `packages/client/src/lib/dice-roll-result.ts` (+18 -0) 📝 `packages/client/src/localization/locales/en.json` (+1 -0) 📝 `packages/server/src/routes/generate.routes.ts` (+50 -4) 📝 `packages/server/src/services/agents/agent-progress.ts` (+2 -1) 📝 `packages/server/src/services/game/dice.service.ts` (+28 -0) 📝 `packages/server/src/services/game/gm-prompts.ts` (+15 -0) 📝 `packages/server/src/services/generation/generation-parameters.ts` (+27 -0) 📝 `packages/server/src/services/generation/tool-resolution-runtime.ts` (+78 -16) _...and 8 more files_ </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. --> > [!IMPORTANT] > **Stacked PR, and merge-gated.** Branch `feat/game-mode-dice-tool` sits on top of `fix/provider-tools-streaming` (Gemini and Anthropic no longer hold the whole reply back on a turn that carries tools). Review and merge that one first. > > **The gate is a live smoke, not a green suite.** That branch must be exercised on real Gemini and Anthropic keys — one real turn each with tools attached, showing tokens arriving progressively and a tool call parsed out of the live stream — before this one merges. Without it, every Game Mode turn on those connections is held back for its whole generation, and the in-product hint this PR adds *states* that streaming keeps working there, so the claim ships to users either way. > > Inherited from the branch below, stated so it is not discovered later: an Anthropic stream cut off in the middle of a tool call's arguments returns that call with empty arguments. That residual is named on the streaming PR; it is not introduced here. > > This branch merges clean against `feat/gm-sparse-checks-server-rolled` (the engine-rolled skill checks). The two are independent lanes on the same problem and can land in either order. ## Linked issue Closes #5950 Tracking issue: #5950. Related issues #5798, #5898 and #5901 remain separate. The provider-streaming prerequisite and live-provider verification requirement above still apply. ## Why this change On a connection that can call tools, the number should exist **before** the narration does. - The GM used to make dice results up in prose. The other lane in this work (`feat/gm-sparse-checks-server-rolled`) fixes that by rolling the check on the server after the model has written the turn — honest, but one beat late: the model narrates up to the attempt and the consequence lands next turn. - A real tool call removes the lag entirely. The GM asks for a die, gets the true number mid-turn, and narrates once with it. That is the whole difference, and it is only available on connections that can actually call tools. - The obvious way to get the tool in front of the GM — telling players to switch "Enable Tool Use" on — is the wrong one. That toggle also arms the entire default-on tool set, the Spotify credential lookup, and the prompt injection that lists available functions on local endpoints. A mode that wants exactly one tool should not drag all of that along, and a player should not have to opt into it to get honest dice. ## What changed 1. **A mode-level auto-attach channel, separate from the tools toggle.** `resolveGenerationTools` now takes a list of tool names a chat mode requires and answers a new question — does this turn send tools at all — while `enableChatTools` keeps its exact previous meaning, so everything keyed on the player's toggle stays quiet. With no auto-attach names, tool resolution is byte-identical to before. Agent-only tools can never be attached this way, and a name that resolves to nothing leaves the turn exactly as it was. 2. **The GM gets `roll_dice` on every Game Mode turn**, through that channel, whether or not the chat has tool use switched on — and the format reminder tells it to throw the tool the moment it needs a real number before it can keep writing. Both halves are load-bearing: the tool alone is never called, and the instruction alone has nothing to call. The `[skill_check: ...]` tag stays as the record of a resolved check rather than being replaced, and the prompt says to fall back to the tag where the tool is not available. Impersonation is excluded — it writes the player's own line, so there is nothing for the GM to resolve. 3. **The roll is visible.** A successful `roll_dice` result is read back into the same shape `/roll` produces and carried on the live tool-result event, past the debug-only gate, so **the animated dice card appears while the turn is still being written**. Without this the tool path would be *less* legible than the tag path it replaces — a pause, then a number, with no die behind it. A saved roll also no longer swallows its message: the card stands in for the whole message body only where the message is nothing but a roll, and sits alongside the narration otherwise. 4. **The Function Calling panel now says what the toggle actually buys in a game chat**, with claims that are each true of a specific connection rather than a blanket warning: *game chats already roll real dice without this — it adds the rest of the tools, and each tool call costs an extra model round. Streaming keeps working on Gemini and Anthropic, except Gemini with thinking on. Claude and Grok subscription connections ignore tools entirely.* The old blanket line saying Gemini and Anthropic stop streaming is gone, because the branch below makes it false; the Gemini-with-thinking carve-out stays because that rule is separate, older and deliberate. 5. **`update_game_state` narrowed to the two update types that persist.** It advertised six and answered all six with "applied", while the route only ever writes back a location change and a time advance — a stat, inventory or quest update was accepted, reported as applied, and dropped. The schema now offers only the two that are stored, so the model stops asking for the others; the executor guards the same pair so the offer and the behaviour cannot drift apart; and a refusal now says what the tool *can* do instead of claiming success. Argument validation also names the allowed values on an enum failure, for every tool — "must be equal to one of the allowed values" told the model nothing it could act on. Whether those two updates should be written this way at all is #5898's question, not this change's. 6. **Two defects this branch's own auto-attach channel opened, fixed here.** "Force To Call Tool" is a Function Calling panel setting the panel *hides* whenever tool use is off, so a chat can hold that flag with no way for its owner to see or clear it. It was inert until game turns started entering the tool loop with the toggle off — from there it made every game turn demand a tool call before the GM could write a word, with nothing in the UI connecting the symptom to the cause. The tool-choice decision now honours that flag only while the toggle is on. Separately, the tool loop kept one slot for Gemini's response parts and let the last round win, while the saved content is every round's text joined — so a two-round turn was saved as prose the player read in full beside parts covering only its second half. Rounds now fold together, keeping each round's text and its own thought signature. ### The honest cost, stated up front **Native tool calls are not cheaper than a bracket tag, on any provider.** A dice turn becomes two model rounds. Uncached that is roughly twice the prompt plus the tool schemas on input. With prompt caching on, the second round is a clean prefix hit and the marginal cost drops to roughly 10–25% of the prompt. Wall clock gains **one extra round-trip, unconditionally** — typically half a second to three seconds on a fast model. What the extra round buys is correctness in one beat: the number exists before the narration does. Forced non-streaming used to be a third penalty on Gemini and Anthropic; that was an adapter bug, and the branch below removes it. So the real comparison is "slightly more expensive, honest in one beat" against "cheapest, honest one beat late" — and for dice, one beat is worth paying for. ## Validation <!-- Required: include commands run and/or manual checks performed --> - [ ] `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 Run in the review worktree, for information — the boxes above are yours to tick once you have seen this yourself: - `pnpm check` exited 0, with the whole chain reached through the production build. `pnpm version:check` in sync for 2.4.5. - `game-mode-dice-tool.regression.ts`, `provider-compat.regression.ts` and `maintenance-lifecycle.regression.ts` passed. Neighbours passed: `dice-display`, `game-narration-phase`, `conversation-game-slash`, `prompt`, `context-fit`. - Exactly one server logging line was added in the whole branch, at the right level, using the shared logger; no `console.*` added server-side. - Removing each of the guards this PR adds fails the regression lane — including the auto-attach condition, the card on the live tool result, the saved roll, the prompt instruction, and both halves of the Gemini parts fix. **Remaining manual verification (automated browser proof is recorded below):** - [ ] Manually verify the prerequisite first: one real Gemini turn and one real Anthropic turn with tools attached, on the branch below, showing text arriving progressively and a tool call parsed. This PR should not merge before that. - [ ] Manually verify, in a Game Mode chat with **"Enable Tool Use" left off**, that a GM asked for something risky calls the dice tool, the animated card appears while the turn is still being written, and the number in the prose matches the number on the card. - [ ] Manually verify streaming is intact on that same turn — text keeps arriving during the roll rather than landing all at once at the end. - [ ] Manually verify `/roll` still behaves exactly as before in a game chat, as the comparison anchor for the card. - [ ] Manually verify the new Function Calling panel text reads correctly and appears only in a game chat, in both light and dark mode and at a mobile width. - [ ] Manually verify a chat that has "Force To Call Tool" set but tool use off no longer opens every game turn by demanding a tool call. - [ ] Manually verify `update_game_state` with a stat or inventory update now refuses with a message that says what it can do, instead of reporting success. - [ ] Manually decide the open design question below: **should the game transcript redraw a dismissed dice card after a reload?** If yes, that is a follow-up; if no, nothing further is needed — the changelog already says it does not. - [ ] Manually verify Peek Prompt on a turn that actually rolled — its contents change (see limitations) and this is a shipped feature. - [ ] Manually verify a game turn on a Claude or Grok subscription connection still writes normally and falls back to the check tag, since those connections ignore tools entirely. ## 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.md` gains one entry under **Added**, which references #5798 and #5901 and points the open question at #5898. No version-bearing file is touched. One new English UI string is added for the panel hint; it is a new key, not a rename or a deletion, so nothing needs mirroring for translators — `pnpm localization:check` runs as part of `pnpm check`. `docs/game/dice-and-skill-checks.md` now distinguishes native same-turn dice from the two-turn fallback. Translation follow-up: #5951. **The reload caveat is in the changelog, in the same words the entry uses:** the card appears while the turn is being written; the roll *is* saved with the message, but the game transcript does not draw the card again when you reload the chat. The Game surface renders game chats before the branches that read a saved roll off a message, and it draws its card from the live turn only. Saying only "kept with the message" would have been true of the stored row and invited an expectation a reload disproves. ## UI evidence (if applicable) The automated browser proof captures the native dice card during a paused model follow-up and the Game-only Function Calling hint, in light and dark themes on desktop Chromium, mobile Chromium, and mobile WebKit. These screenshots were inspected locally; the test can reproduce its attachments with the JSON reporter. Real-device and live-provider checks remain separate. --- ### Known limitations, named here rather than left for review to find 1. **A turn that rolls more than once keeps only the last card.** Each roll's result is honest and reaches the model; the visible card is overwritten by the following roll. 2. **The saved roll is not redrawn on reload** (above). This is stated in the changelog rather than fixed, because whether the transcript *should* redraw a dismissed card is a design question for the browser pass, not something to settle inside this PR. 3. **Peek Prompt on a turn that rolled now shows the last tool round.** It reflects what was actually sent for that round — the assistant's tool call and the tool result appended — rather than the clean prompt it showed before. Arguably more accurate, pre-existing for any chat with tools on, but it changes a shipped feature's output on every rolling game turn, so it is worth one look. 4. **One extra store read per game turn.** Tool resolution now lists enabled custom tools on every game turn, where it previously did not. Small table, once per generation. 5. **The executor's guard on `update_game_state` update types has no test, deliberately.** Argument validation refuses a removed type against the tool's schema long before that guard runs, so it is genuinely unreachable through the model. It is kept as defence in depth for a caller that arrives without that schema, and the code comment now says exactly that. Writing a test that reached past validation purely to turn it green would have manufactured coverage rather than proving anything. 6. **Claude and Grok subscription connections ignore tools entirely**, so on those the GM never calls the die and falls back to writing the check tag. That is what the other lane in this work exists for; the panel hint says so plainly rather than leaving players to discover it. 7. **This PR does not touch the tools toggle's own behaviour.** Turning "Enable Tool Use" on in a game chat still arms everything it always armed; the hint now describes that instead of the app changing it. ## Maintainer staging integration Updated this branch with current `staging` and the prerequisite provider-streaming fixes from #5920. Native tool guidance now records the actual roll as a complete skill check, avoiding a second engine roll after #5923; sparse fallback checks remain unchanged. The Function Calling hint replaces the contradictory generic disabled-tools description in Game mode. The dice regression now accepts the shared grammar's valid `d20` and uses `1d0` as its invalid-input control. Validation on the integrated branch: - `pnpm check` passed, including localization, lint, type checking and production build. - Native dice, skill-check resolution, provider compatibility, Experience lore selection, maintenance lifecycle, dice display, narration phase, Conversation/Game slash commands, GM capabilities, prompt and context-fit regressions passed. - `pnpm exec playwright test e2e/game-native-dice.e2e.ts --workers 1 --reporter list,json`: all 9 cases passed across desktop Chromium, mobile Chromium and mobile WebKit, including both Game themes and Classic Conversation multipart messages. The fixture uses the real server tool loop against a synthetic local provider, keeps the follow-up response unfinished until the dice card is shown, and checks the displayed/saved total, progressive buffer, default-off tool toggle and hidden force-tool flag. No paid provider is contacted. Its WebKit wait allows the existing 15-second SSE keepalive to deliver the deliberately tiny paused stream; it does not wait for generation completion or remove the live-card assertion. **Still blocking merge:** the explicit live Gemini (thinking off) and Anthropic tool-streaming checks required by this PR and #5920 are not yet confirmed. Synthetic-provider proof is not a substitute. No live provider credentials were accessed or paid requests made. Human validation checkboxes remain unchecked. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Game Mode can roll real dice during generation and display results immediately, including alongside same-turn narration. * Dice results remain visible across streamed messages, continuations, and replayed conversations. * Game Mode supports dice rolling even when other tool use is disabled. * **Bug Fixes** * Improved dice-card rendering across message formats. * Game state updates now support only location and time changes, with clearer validation messages. * Improved provider streaming and tool-call handling. * **Documentation** * Added guidance for native dice rolls and fallback behavior when unsupported. <!-- end of auto-generated comment: release notes by coderabbit.ai --> ### CodeRabbit follow-up (56ec55575) All four review findings are addressed with narrow changes and regression proof: multipart assistant Conversation messages retain the existing dice card; continuations without another roll preserve it while regenerations clear it; auto-attached Game tools receive the existing local-endpoint guidance; and location/time updates no longer require unused target/key fields. The out-of-diff provider logging note from #5920 is also fixed here, honoring chat debug and explicit agent debug/DEBUG_AGENTS without logging auth headers. `pnpm check`, the native dice, provider compatibility, agent progress and neighboring prompt/Game regression runs all pass. The browser fixture passes all 9 cases and exercises the real continuation/regeneration persistence paths. Red-before/green-after proof was obtained for the missing multipart card, missing local-tool prompt block, cleared continuation result, and minimal game-state tool arguments. #5920 was merged by @kolacheee; that merge does not itself establish live-provider test results, which remain unconfirmed here. ### Final review follow-up (9c904048a) Fixed the outside-diff Gemini replay finding: provider-issued call IDs are preserved in both raw-part replay and fallback serialization, and each function result returns the matching ID. Id-less Gemini calls still replay unchanged; Engine-only synthetic IDs are not sent as unmatched response IDs. This follows Google's [FunctionCall/FunctionResponse contract](https://ai.google.dev/api/generate-content#FunctionResponse). The local HTTP regression failed before the fix and passes after it, covering parallel calls to the same function and both replay paths. The desktop CI failure was the Home lifecycle heap assertion. Its trace shows the baseline completed at 124.2s, but the chat's emoji/sticker/regex/lore initialization first ran at 135.9s during measured cycles. The test now waits for the actual chat composer before returning Home during both warm-up and measurement. The 3 MiB heap limit and every lifecycle assertion are unchanged. Three focused runs pass after the fix, with approximately 0.9–1.4 MiB retained heap growth. `pnpm check` and provider compatibility regressions also pass. Fresh CI and CodeRabbit must complete on this head before merge. Scope clarification: provider replay and opt-in debug logging are follow-ups to prerequisite #5920 / #5918, used by the automatically attached Game dice tool. The location/time-only game-state contract was already part of this feature branch and relates to #5898. These are integration and review fixes, not a new provider or game-system redesign. The live Gemini (thinking off) and Anthropic checks remain unconfirmed and still block merge; automated/synthetic proof does not satisfy that explicit prerequisite. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:15:34 +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#6994
No description provided.