mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #5924] [MERGED] feat(game): the GM rolls real dice, and the roll is a visible card #6994
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#6994
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 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+)
e647d99feat(tools): add a mode-level auto-attach channel for chat tools2135e37fix(tools): narrow update_game_state to the updates that persist3d78b5afeat(game): roll real dice on game turns instead of letting the GM invent thema8749b2feat(game): show a GM-called dice roll while the turn is still running1203940feat(chat): say what turning tool use on costs in a game chatb1a38ectest(game): pin the Game Mode dice-tool contractb6cbba3fix(game): keep Force To Call off the dice tool and save whole tool turnsbdc15cedocs(changelog): say what happens to a saved GM roll on reloadd8de5e9Merge branch 'fix/provider-tools-streaming' into feat/game-mode-dice-toole5c51c3Merge 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
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.
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.What changed
resolveGenerationToolsnow takes a list of tool names a chat mode requires and answers a new question — does this turn send tools at all — whileenableChatToolskeeps 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.roll_diceon 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.roll_diceresult is read back into the same shape/rollproduces 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.update_game_statenarrowed 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.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 checkpasses locallyCONTRIBUTING.mdManual verification notes
Run in the review worktree, for information — the boxes above are yours to tick once you have seen this yourself:
pnpm checkexited 0, with the whole chain reached through the production build.pnpm version:checkin sync for 2.4.5.game-mode-dice-tool.regression.ts,provider-compat.regression.tsandmaintenance-lifecycle.regression.tspassed. Neighbours passed:dice-display,game-narration-phase,conversation-game-slash,prompt,context-fit.console.*added server-side.Remaining manual verification (automated browser proof is recorded below):
/rollstill behaves exactly as before in a game chat, as the comparison anchor for the card.update_game_statewith a stat or inventory update now refuses with a message that says what it can do, instead of reporting success.Docs and release impact
docs-i18nbranch updated to match, or a[docs-i18n]follow-up issue opened (see CONTRIBUTING.md § Translated documentation)CHANGELOG.mdgains 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:checkruns as part ofpnpm check.docs/game/dice-and-skill-checks.mdnow 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
update_game_stateupdate 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.Maintainer staging integration
Updated this branch with current
stagingand 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 validd20and uses1d0as its invalid-input control.Validation on the integrated branch:
pnpm checkpassed, including localization, lint, type checking and production build.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
Bug Fixes
Documentation
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 checkand 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.