mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #824] [MERGED] fix(game-start): silent race recovery when an intro already exists #4792
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#4792
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/824
Author: @Romuromylus
Created: 5/14/2026
Status: ✅ Merged
Merged: 5/14/2026
Merged by: @Romuromylus
Base:
main← Head:fix/game-start-race-recovery📝 Commits (3)
f425513fix(game-start): silent race recovery when an intro already exists82bd06ffix(game-start): atomic ready→active claim via patchMetadata7542bddfix(game-start): make the entry guard idempotent on "active"📊 Changes
3 files changed (+63 additions, -3 deletions)
View changed files
📝
packages/client/src/components/game/GameSurface.tsx(+8 -1)📝
packages/client/src/hooks/use-game.ts(+6 -0)📝
packages/server/src/routes/game.routes.ts(+49 -2)📄 Description
Linked issue
Closes #821
Why this change
#821 reproduces the same Game Mode race as the earlier-fixed #321 — on 1.5.9, clicking Start Game snaps back to the idle Start Game screen mid-stream and a second click produces a duplicate GM intro turn. Confirmed in a live trace: two
POST /api/game/startcalls both return 200 because a concurrentchats.updateMetadata({ ...meta, … })writer revertsgameSessionStatusfrom"active"back to"ready"between the two clicks.#320 audited and migrated 7 stale-meta writes in
packages/server/src/routes/generate.routes.tsto thefreshChat→freshMeta→ field-only update pattern. All 6 remainingchats.updateMetadata(input.chatId, …)sites in that file now re-fetch, but at least one stale-write writer remains elsewhere (likely inpackages/server/src/routes/game.routes.ts) and the race still reproduces.A complete audit of every
chats.updateMetadata(…, { ...meta, … })and a migration of partial updates to the existing race-safechats.patchMetadata(…)helper at packages/server/src/services/storage/chats.storage.ts:303 is the proper root-cause fix. That is a large, code-touchy change. This PR ships a narrow defensive guard that makes the user-visible symptom impossible while the deeper audit happens separately.What changed
Server —
packages/server/src/routes/game.routes.tsPOST /game/startalready throws whenmeta.gameSessionStatus !== "ready". After that check it now also lists the chat's messages and looks for any non-emptyrole: "assistant"message. If one exists, the game has clearly already started — the only way we got back into the"ready"branch is the race. Instead of throwing (which leaves the UI stuck on Start Game with a generic 500 toast) the handler:logger.warndescribing the race recovery (so this is visible in logs if it fires in production),gameSessionStatus: "active"back to the DB,{ status: "active", alreadyStarted: true }.Client —
packages/client/src/hooks/use-game.tsandpackages/client/src/components/game/GameSurface.tsxThe
StartGameResponseinterface now carries an optionalalreadyStartedflag.GameSurface'suseStartGame.mutateonSuccesscallback checks that flag and skipsgenerateInitialGameTurnwhen it's true — so the second click no longer fires a second/api/generate. The chat detail invalidate that already runs onuseStartGame.onSuccessre-fetches the freshly-restored"active"status, and the existingawaitingFirstTurnlogic moves the UI past the Start Game screen.Validation
pnpm checkpasses locallyCONTRIBUTING.mdManual verification notes
I tested on a fork build autoDeployed to a private EasyPanel instance. Both the stuck-state recovery path and the full fresh-game flow were verified:
role: "assistant"messages back-to-back, no user message between)."ready"): clicked Start Game once on the existing stuck chat. Server emitted the[game/start] Race recoverywarn, returnedalreadyStarted: true, client skippedgenerateInitialGameTurn. UI progressed past Start Game on the next chat refetch. No duplicate intro. Note: post-stream hooks (scene-wrap, generate-assets) that failed to fire on the original stuck stream are not re-played — the saved intro lacks background art on a recovered chat. That's acceptable for a race-recovery edge; fresh games are unaffected./game/startand getsalreadyStarted: true, no duplicate intro, no error toast, UI lands in the active game with exactly one GM intro message.To-verify by upstream maintainers, on each platform's normal install (Docker / installer / source):
role: "assistant"message at the end of the intro./api/generateflow are unaffected — the new branch in/game/startonly runs on the start path.Docs and release impact
UI evidence (if applicable)
n/a — server-side guard + small client onSuccess branch. The user-visible difference is "second Start Game click no longer creates a duplicate intro turn."
Summary by CodeRabbit
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.