[GH-ISSUE #2940] [Issue]: {{random}}/{{roll}} show you a different value than the model receives (re-rolled separately for display, prompt, and preview) #1517

Closed
opened 2026-10-21 05:37:48 +07:00 by bsakaguchi · 1 comment
Owner

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

Originally assigned to: @SpicyMarinara on GitHub.

What's wrong

{{random}}, {{random::A::B}}, and {{roll:XdY}} give a different result to you than to the model. The number/choice shown in the chat is generated separately from the one put into the prompt, so they don't match. The same is true on every regenerate/swipe and in the prompt preview.

For a dice or random-pick feature this is the one thing that has to be consistent, so it's effectively broken for storytelling ("you rolled a 17" on screen, but the model was told 4).

How to reproduce (try it yourself)

  1. Give a character a greeting/first message (or send a message) containing: You rolled {{roll:1d100}}.
  2. Send it, then look at what the model responds to vs. what's shown.

You'll see: the number displayed in the chat bubble is one value; the model reacts as if it were a different value. Easiest way to confirm: open the prompt preview / dry-run for that turn — the {{roll}} there is a different number than the chat shows, and it changes again each time you reopen it.
Expected: the displayed value and the value the model receives should be the same, and stable for that message.

Where it is

packages/shared/src/utils/macro-engine.ts — {{random}} at line 907, {{random:X:Y}} at 919, {{roll}} at 926, weighted pick around 713 — each calls Math.random() fresh every time the text is resolved. The display path resolves the message separately from the server prompt path (and the preview resolves it yet again).

What's happening

Random/dice macros are pure Math.random() evaluated at resolution time, and the message is resolved more than once — once to build the prompt, once to render the chat, once for the preview — so each pass rolls new values.

Suggested fix

Resolve random/dice once per message and persist the result (e.g. cache the rolled value on the message so the display, the prompt, and the preview all read the same stored result), rather than re-rolling on every resolution pass.


Found by a code review of v2.0.6; please verify the reproduction before fixing.

Originally created by @kolacheee on GitHub (Jun 28, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2940 Originally assigned to: @SpicyMarinara on GitHub. **What's wrong** `{{random}}`, `{{random::A::B}}`, and `{{roll:XdY}}` give a **different result to you than to the model**. The number/choice shown in the chat is generated separately from the one put into the prompt, so they don't match. The same is true on every regenerate/swipe and in the prompt preview. For a dice or random-pick feature this is the one thing that has to be consistent, so it's effectively broken for storytelling ("you rolled a 17" on screen, but the model was told 4). **How to reproduce (try it yourself)** 1. Give a character a greeting/first message (or send a message) containing: `You rolled {{roll:1d100}}.` 2. Send it, then look at what the model responds to vs. what's shown. **You'll see:** the number displayed in the chat bubble is one value; the model reacts as if it were a different value. Easiest way to confirm: open the **prompt preview / dry-run** for that turn — the `{{roll}}` there is a *different* number than the chat shows, and it changes again each time you reopen it. **Expected:** the displayed value and the value the model receives should be the same, and stable for that message. **Where it is** `packages/shared/src/utils/macro-engine.ts` — `{{random}}` at line 907, `{{random:X:Y}}` at 919, `{{roll}}` at 926, weighted pick around 713 — each calls `Math.random()` fresh every time the text is resolved. The display path resolves the message separately from the server prompt path (and the preview resolves it yet again). **What's happening** Random/dice macros are pure `Math.random()` evaluated at resolution time, and the message is resolved more than once — once to build the prompt, once to render the chat, once for the preview — so each pass rolls new values. **Suggested fix** Resolve random/dice once per message and persist the result (e.g. cache the rolled value on the message so the display, the prompt, and the preview all read the same stored result), rather than re-rolling on every resolution pass. --- *Found by a code review of v2.0.6; please verify the reproduction before fixing.*
Author
Owner

@SpicyMarinara commented on GitHub (Jun 28, 2026):

Fixed on staging: random and dice macros now resolve consistently for the same message seed across stored message display, prompt generation, and prompt preview paths, including prompt-side regex replacement macros. Added prompt regression coverage for seeded random/roll stability. Validation: pnpm regression:prompt; pnpm check.

<!-- gh-comment-id:4827607972 --> @SpicyMarinara commented on GitHub (Jun 28, 2026): Fixed on staging: random and dice macros now resolve consistently for the same message seed across stored message display, prompt generation, and prompt preview paths, including prompt-side regex replacement macros. Added prompt regression coverage for seeded random/roll stability. Validation: pnpm regression:prompt; pnpm check.
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#1517
No description provided.