mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
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#397
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 @Romuromylus on GitHub (May 14, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/821
Originally assigned to: @Romuromylus on GitHub.
Summary
Game Mode regression: clicking Start Game sometimes snaps back to the idle Start Game screen mid-stream and a second click fires another GM intro generation. This is the same underlying race as #321 (which was fixed by #320), but the user-visible shape has shifted — the chat ends up with two
role: "assistant"GM intro messages back-to-back with no user message between them, instead of two[Start the game]user messages. The chat still effectively starts at "scene 2".Expected behavior
After clicking Start Game once on a freshly-set-up Game Mode chat, the intro typewriter plays through, the GM streams the opening scene, the Continue button replaces the Start screen, and the chat contains exactly one assistant GM turn.
Actual behavior
After clicking Start Game:
assistantGM messages back-to-back with nousermessage between them — the second one continues the scene as if the first never invited player input.gameNarrationIndexstays at 0 so the user only sees the first message in the live narration UI, but the duplicate is visible in Logs.Steps to reproduce
/game/setup(any genre / setting / tone).Reproduced twice in a row on 1.5.9 against a real game setup. Network-trace evidence (next section) confirms two
POST /api/game/startcalls both returned 200, meaning the server sawgameSessionStatus === "ready"at both call times — even though the first call had just written"active".Environment
Logs, screenshots, or video
Client-side fetch interceptor captured this sequence around the bug (timestamps UTC,
duris the resolve time for fetch — for/api/generatethat's just SSE headers, not the full stream):Server-side independent verification: probing
POST /api/game/startagainst the same chat right now (after the bug, chat still ingameSessionStatus: "active") returns 500 — confirming themeta.gameSessionStatus !== "ready"guard atpackages/server/src/routes/game.routes.ts:3464works correctly. The only way the 2nd call during the bug returned 200 is that some other handler wrote"ready"back to the DB between the two/game/startcalls.Additional context
PR #320 audited
packages/server/src/routes/generate.routes.tsand converted 7 stale-meta writes (preset entry-state-overrides, lorebook entry-state-overrides x3,lastMapPosition, game-state-patchgameMapsync,chat_summary,mariContext) to thefreshChat→freshMeta→ field-only update pattern. All 6 remainingchats.updateMetadata(input.chatId, …)sites ingenerate.routes.tsuse re-fetched meta and look safe.The remaining race must be in another handler that runs concurrently with the stream and still uses
{...meta, …}from an early read. Likely candidates inpackages/server/src/routes/game.routes.tsthat wrote during the trace's race window (10:39:23 → 10:40:05):app.post("/weather/update")atgame.routes.ts:5440— synchronous read+write, but worth confirming.app.put("/:chatId/widgets")atgame.routes.ts:5629— same pattern, fires twice in the trace.app.post("/scene-wrap")(game.routes.ts:6065) andapp.post("/generate-assets")(game.routes.ts:6830) appear to uselatestMeta/freshMetacorrectly.A separate audit pass over every
chats.updateMetadata(…, { ...meta, … })inpackages/server/src/routes/game.routes.ts(and ideally migration of partial updates to the existingchats.patchMetadata(…)helper atpackages/server/src/services/storage/chats.storage.ts:303, which uses a per-chat queue and is race-safe) is the proper root-cause fix.Proposed defensive fix in this issue: add a second guard to
/api/game/startthat rejects the call when the chat already contains a non-emptyrole: "assistant"message — making the duplicate-intro symptom impossible regardless of which exact route is clobbering the status. Even a fully successful/game/startrace becomes a no-op error toast on the second click, rather than spending a paid generation on a second intro. The deeperupdateMetadataaudit can be a separate PR.Reference to original issue: #321. Reference to original fix attempt: #320.
Template check
Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked: