mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #320] [MERGED] fix(game): preserve concurrent metadata writes during /generate stream #4560
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#4560
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/320
Author: @Romuromylus
Created: 4/30/2026
Status: ✅ Merged
Merged: 5/3/2026
Merged by: @SpicyMarinara
Base:
main← Head:fix/game-start-stale-metadata-write📝 Commits (3)
b7db371fix(game): preserve concurrent metadata writes during /generate stream9a6ddfdMerge branch 'main' into fix/game-start-stale-metadata-writec67c01fMerge branch 'main' into fix/game-start-stale-metadata-write📊 Changes
1 file changed (+47 additions, -9 deletions)
View changed files
📝
packages/server/src/routes/generate.routes.ts(+47 -9)📄 Description
Linked issue
Closes #321
Why this change
In Game Mode 1.5.6, clicking Start Game on a freshly-set-up game shows the intro typewriter, then snaps back to the Start Game screen mid-stream. The user clicks again and the chat ends up with two
[Start the game]user messages and starts at scene 2. Repros across all GM models (Opus / GPT / DeepSeek), so it is not a model issue.Root cause: several persistence sites in
packages/server/src/routes/generate.routes.tscapturechat.metadataonce at request start (line 397) and pass the parsed copy back tochats.updateMetadatalater in the stream.updateMetadatareplaces the metadata column wholesale, so any of those late writes clobbers concurrent updates from other endpoints — in particular/game/start, which flipsgameSessionStatusfrom"ready"→"active"while the[Start the game]generation is in flight.When the stale write lands first, the client's
chatMetarefetches"ready"again.GameSurface's clearing effect atpackages/client/src/components/game/GameSurface.tsx:5159-5164had already fired (it ran while status was briefly"active") and clearedstartGameRequested. WithsessionStatus === "ready"andintroPresented === false, the surface drops back to the idle Start Game phase. The user clicks Start a second time, which fires another[Start the game]and walks the GM into a "session continuation" framing — the visible "scene 2" start.The combat agent at
generate.routes.ts:6361-6365already handles this correctly with a re-fetch-then-merge pattern. The other persistence sites do not.A previous attempt at this bug (3e13514, reverted by 518dc92 on the contributor's fork) tried to fix this client-side via query invalidation. That couldn't have worked because the actual race is server-side metadata clobbering.
What changed
Convert the at-risk persistence sites in
generate.routes.tsto match thefreshChatpattern used by the combat agent — re-fetch metadata immediately before the merge, write only the specific fields being updated:entryStateOverridespersistence (~line 887)entryStateOverridespersistence (3 occurrences around lines 2049, 2090, 2980)lastMapPositionpersistence (~line 2856)gameMapsync (~line 5942)chat_summaryrolling-summary persistence (~line 6402)mariContextdata-fetched persistence (~line 7590)Each site now does:
No behavior change for any single-write request. Concurrent writes from
/game/start(and any other endpoint that updates chat metadata while a generation is streaming) are no longer lost.Validation
pnpm checkpasses locallyCONTRIBUTING.mdManual verification notes
Tested on a fork build deployed to a private VPS instance running the same Dockerfile from
main. Steps run by the contributor:Before the fix, the screen snapped back to idle mid-stream, requiring a second Start click and producing a duplicate
[Start the game]user message. After the fix, that no longer happens on the same setup. Reproducer was previously consistent across Opus, GPT, and DeepSeek.To-verify by upstream maintainers:
[Start the game]user message after a successful start.Docs and release impact
UI evidence (if applicable)
n/a — fix is server-side; user-visible effect is "Start Game no longer requires a second click."
Summary by CodeRabbit
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.