mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2940] [Issue]: {{random}}/{{roll}} show you a different value than the model receives (re-rolled separately for display, prompt, and preview) #1517
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#1517
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?
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)
You rolled {{roll:1d100}}.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 callsMath.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.
@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.