[GH-ISSUE #6118] A Game turn that rolls dice can lose the move or world change it just narrated #3394

Closed
opened 2026-10-21 06:02:38 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @kolacheee on GitHub (Sep 13, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/6118

Originally assigned to: @SpicyMarinara on GitHub.

When a Game-mode turn resolves a skill check or dice tag, the engine rewrites the whole narration in a second model call. Any command the first narration issued - moving the party to a new place on the map, or an Experience package command like granting an item or changing the weather - is thrown away at that point. The player reads a narration saying they walked into the crypt or picked up the key, but the location readout never changes and the item never appears, with no warning anywhere.

How to reproduce (try it yourself)

  1. Install the World Maps agent package and restart Marinara. Add it to a chat under Chat Settings -> Agents -> Tracker Agents.
  2. Create a Game-mode chat with World Maps enabled. In the map editor, author two places in one region named exactly Chapel and Crypt, connect them, and set Chapel as the starting location. Save and confirm the location readout says Chapel.
  3. Turn OFF any other world-state or game-state tracker agent on this chat. A tracker can move the party on its own through a separate path, which hides the failure and makes the result look random.
  4. Control turn: send exactly I walk from the chapel into the crypt. One narration streams in and the readout flips to Crypt. This turn asked for no dice, so only one model request fires.
  5. Reset so the current location is Chapel again (delete that turn, or start a fresh game from the same map).
  6. Bug turn: send exactly I walk into the crypt and search the sarcophagus. The arrival is stated by the player, so the game master is allowed to emit the movement command in its first draft, while the search is what draws the dice roll. Do not phrase it as "the door is stuck, I force it open" - the game master is told to describe an unresolved attempt and stop, so no movement command is written in the first place and there is nothing to lose.
  7. Watch the turn. A first narration streams in, then a few seconds later the entire message is silently replaced by a different narration plus the roll card. That swap is the second model request.

What you'll see: on the turns where the rewritten narration does not happen to restate the command, the narration says you are in the crypt and the location readout still says Chapel. Nothing warns you, nothing is logged. Because the second call may restate the command on its own, some attempts look fine - expect to try this a few times.

What should happen: the location should flip to Crypt, exactly as it did on the control turn, unless the roll itself invalidated the move. A dice roll in the same turn must not be able to quietly delete a movement or an item grant.

Same bug in the Experience-package flavour: on a game whose Experience package ships commands (inventory grants, quest updates, weather), phrase one message that both requires a check and should trigger one, e.g. I pick the lock on the chest and take whatever is inside. The check resolves and the narration says you took the item; the world state often does not change. The same sentence with no check in it (I open the unlocked chest and take what is inside.) does change it.

The rewrite only fires when the engine itself resolved a [skill_check:] or [dice:] text tag. A turn whose dice came only from the built-in roll_dice tool leaves a fully filled-in tag, skips the rewrite, and keeps its commands. That is why the bug reads as flaky rather than broken.

Where it is

packages/server/src/routes/generate.routes.ts at staging 52799569c, in the streaming generate handler:

  • :7896 - fullResponse = parsedSpatial.cleanContent removes the [spatial_move:] text from the draft.
  • :7930 - fullResponse = verbScan.content (after parseAndStripGmVerbCalls) removes every package command from the draft.
  • :7960 - the rewrite gate if (rolled.resolved || generalRolls.rolled) {.
  • :7971 - the assistant message handed to the rewrite call is that already-stripped fullResponse.
  • :7974 - the rewrite instruction: Include only commands still justified by these outcomes.
  • :8042 and :8045 - assistantSpatialDirective = ... spatial.directive and collectedGmVerbCalls = [], both reassigned unconditionally from the rewritten text.
  • :8346 / :8356 - executeCollectedGmVerbCalls(...) and materializeAssistantSpatialState({ ..., directive: assistantSpatialDirective }), the consumers that read whatever those two lines left behind.

What's happening

The commands are pulled out of the draft before the rewrite prompt is built, so the second model call is shown a narration with its own commands deleted, and is then told to keep only the commands still justified. It still has the command grammar and the current map state from the ordinary game prompt, so it can write a command again from scratch - but it has no record of what the first draft decided. Whatever it does not restate is gone, because the two variables holding the first draft's results are overwritten unconditionally right after the rewrite, one of them emptied outright. There is no fallback, no log line, and no frame on the wire, so the state change simply never happens and nothing says so.

A scripted run against the real route with a matched pair of turns - the same first draft, differing only by one skill-check tag - showed the no-roll turn applying both the movement and the package command, and the rolling turn applying neither.

Suggested fix

Build the assistant message for the rewrite call from the pre-strip text, so the model can see the commands it is being asked to filter. That matches the instruction already in the prompt, and it lets the model legitimately drop a command the roll invalidated (you failed the check, so you did not get inside), which appears to be what the design wanted.

Then make the post-rewrite assignment conditional: replace the carried movement directive and package command list only when the rewritten text actually emitted its own. Carrying them forward is not sufficient on its own and should not be done alone - reinstating a movement decided before the die was rolled is the state-level version of the contradiction that issue #5961 was filed about, so the rewrite must keep the power to drop a command.

This needs a regression in the game dice lane pinning the matched pair: the same draft with and without a check, both applying the same movement and package command. All four existing dice regression suites pass against this today.

Context

Introduced by PR #5979 ("keep every roll and resolve text dice requests"), merged 2026-09-09, which closed issues #5956, #5959, #5960 and #5961 and added the post-roll rewrite. The package command surface it discards comes from the game-master write-back work in #5798. The PR body describes this as discarding "superseded package/movement commands", but the code discards them whether or not anything superseded them. Unreleased on staging - it landed after v2.4.4, so no released build is affected. Practical blast radius today is limited - the only package shipping game-master commands is Pixelforge, which is pre-alpha and whose two commands are set-until-set-again states that the next turn usually re-asserts - so the sharper edge is the map movement loss.

Found by an AI-assisted sweep of merged PR #5979 against its original issues, then re-verified against staging 52799569c on 2026-09-13. Please verify before fixing.

Originally created by @kolacheee on GitHub (Sep 13, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/6118 Originally assigned to: @SpicyMarinara on GitHub. When a Game-mode turn resolves a skill check or dice tag, the engine rewrites the whole narration in a second model call. Any command the first narration issued - moving the party to a new place on the map, or an Experience package command like granting an item or changing the weather - is thrown away at that point. The player reads a narration saying they walked into the crypt or picked up the key, but the location readout never changes and the item never appears, with no warning anywhere. ## How to reproduce (try it yourself) 1. Install the World Maps agent package and restart Marinara. Add it to a chat under Chat Settings -> Agents -> Tracker Agents. 2. Create a Game-mode chat with World Maps enabled. In the map editor, author two places in one region named exactly `Chapel` and `Crypt`, connect them, and set `Chapel` as the starting location. Save and confirm the location readout says `Chapel`. 3. Turn OFF any other world-state or game-state tracker agent on this chat. A tracker can move the party on its own through a separate path, which hides the failure and makes the result look random. 4. Control turn: send exactly `I walk from the chapel into the crypt.` One narration streams in and the readout flips to `Crypt`. This turn asked for no dice, so only one model request fires. 5. Reset so the current location is `Chapel` again (delete that turn, or start a fresh game from the same map). 6. Bug turn: send exactly `I walk into the crypt and search the sarcophagus.` The arrival is stated by the player, so the game master is allowed to emit the movement command in its first draft, while the search is what draws the dice roll. Do not phrase it as "the door is stuck, I force it open" - the game master is told to describe an unresolved attempt and stop, so no movement command is written in the first place and there is nothing to lose. 7. Watch the turn. A first narration streams in, then a few seconds later the entire message is silently replaced by a different narration plus the roll card. That swap is the second model request. **What you'll see:** on the turns where the rewritten narration does not happen to restate the command, the narration says you are in the crypt and the location readout still says `Chapel`. Nothing warns you, nothing is logged. Because the second call may restate the command on its own, some attempts look fine - expect to try this a few times. **What should happen:** the location should flip to `Crypt`, exactly as it did on the control turn, unless the roll itself invalidated the move. A dice roll in the same turn must not be able to quietly delete a movement or an item grant. Same bug in the Experience-package flavour: on a game whose Experience package ships commands (inventory grants, quest updates, weather), phrase one message that both requires a check and should trigger one, e.g. `I pick the lock on the chest and take whatever is inside.` The check resolves and the narration says you took the item; the world state often does not change. The same sentence with no check in it (`I open the unlocked chest and take what is inside.`) does change it. The rewrite only fires when the engine itself resolved a `[skill_check:]` or `[dice:]` text tag. A turn whose dice came only from the built-in roll_dice tool leaves a fully filled-in tag, skips the rewrite, and keeps its commands. That is why the bug reads as flaky rather than broken. ## Where it is `packages/server/src/routes/generate.routes.ts` at staging 52799569c, in the streaming generate handler: - `:7896` - `fullResponse = parsedSpatial.cleanContent` removes the `[spatial_move:]` text from the draft. - `:7930` - `fullResponse = verbScan.content` (after `parseAndStripGmVerbCalls`) removes every package command from the draft. - `:7960` - the rewrite gate `if (rolled.resolved || generalRolls.rolled) {`. - `:7971` - the assistant message handed to the rewrite call is that already-stripped `fullResponse`. - `:7974` - the rewrite instruction: `Include only commands still justified by these outcomes.` - `:8042` and `:8045` - `assistantSpatialDirective = ... spatial.directive` and `collectedGmVerbCalls = []`, both reassigned unconditionally from the rewritten text. - `:8346` / `:8356` - `executeCollectedGmVerbCalls(...)` and `materializeAssistantSpatialState({ ..., directive: assistantSpatialDirective })`, the consumers that read whatever those two lines left behind. ## What's happening The commands are pulled out of the draft before the rewrite prompt is built, so the second model call is shown a narration with its own commands deleted, and is then told to keep only the commands still justified. It still has the command grammar and the current map state from the ordinary game prompt, so it can write a command again from scratch - but it has no record of what the first draft decided. Whatever it does not restate is gone, because the two variables holding the first draft's results are overwritten unconditionally right after the rewrite, one of them emptied outright. There is no fallback, no log line, and no frame on the wire, so the state change simply never happens and nothing says so. A scripted run against the real route with a matched pair of turns - the same first draft, differing only by one skill-check tag - showed the no-roll turn applying both the movement and the package command, and the rolling turn applying neither. ## Suggested fix Build the assistant message for the rewrite call from the pre-strip text, so the model can see the commands it is being asked to filter. That matches the instruction already in the prompt, and it lets the model legitimately drop a command the roll invalidated (you failed the check, so you did not get inside), which appears to be what the design wanted. Then make the post-rewrite assignment conditional: replace the carried movement directive and package command list only when the rewritten text actually emitted its own. Carrying them forward is not sufficient on its own and should not be done alone - reinstating a movement decided before the die was rolled is the state-level version of the contradiction that issue #5961 was filed about, so the rewrite must keep the power to drop a command. This needs a regression in the game dice lane pinning the matched pair: the same draft with and without a check, both applying the same movement and package command. All four existing dice regression suites pass against this today. ## Context Introduced by PR #5979 ("keep every roll and resolve text dice requests"), merged 2026-09-09, which closed issues #5956, #5959, #5960 and #5961 and added the post-roll rewrite. The package command surface it discards comes from the game-master write-back work in #5798. The PR body describes this as discarding "superseded package/movement commands", but the code discards them whether or not anything superseded them. Unreleased on staging - it landed after v2.4.4, so no released build is affected. Practical blast radius today is limited - the only package shipping game-master commands is Pixelforge, which is pre-alpha and whose two commands are set-until-set-again states that the next turn usually re-asserts - so the sharper edge is the map movement loss. Found by an AI-assisted sweep of merged PR #5979 against its original issues, then re-verified against staging 52799569c on 2026-09-13. Please verify before fixing.
bsakaguchi 2026-10-21 06:02:38 +07:00
Author
Owner

@SpicyMarinara commented on GitHub (Sep 13, 2026):

@SpicyMarinara is taking this report through the issue sweep in draft PR #6137, with Codex assisting. The affected current-code path has been checked; implementation and focused regression verification are in progress.

<!-- gh-comment-id:5651922733 --> @SpicyMarinara commented on GitHub (Sep 13, 2026): @SpicyMarinara is taking this report through the issue sweep in draft PR #6137, with Codex assisting. The affected current-code path has been checked; implementation and focused regression verification are in progress.
Author
Owner

@SpicyMarinara commented on GitHub (Sep 13, 2026):

Fixed in #6137, now merged to staging (e044997a2). Dice correction retains valid world commands from the original draft and applies only the corrected result.

<!-- gh-comment-id:5652782285 --> @SpicyMarinara commented on GitHub (Sep 13, 2026): Fixed in #6137, now merged to staging (`e044997a2`). Dice correction retains valid world commands from the original draft and applies only the corrected result.
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#3394
No description provided.