mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2327] [Issue]: Debounced manual world-state patch can overwrite chat.gameState with a stale target after a concurrent turn #1153
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#1153
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 (Jun 5, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2327
Originally assigned to: @Romuromylus on GitHub.
Summary
Severity: Low — Concurrency. The debounced manual world-state patcher captures its patch target (messageId/swipeIndex) at edit time. If an assistant turn completes during the 500ms debounce window, the queued flush still writes the old target's snapshot to
chat.gameState, clobbering the now-current turn's persisted state. The live UI is largely masked by re-resolution on read, but the persistedchat.gameStatebecomes inconsistent.Expected behavior
The flush should only write
chat.gameStatewhen its resolved target is still the current visible target; otherwise it should write only the per-message snapshot and let the visible-read path ownchat.gameState.Actual behavior
src/features/runtime/world-state/api/world-state-api.ts:281-283:targetis therequestedTargetcaptured at edit time by the debounced patcher (use-world-state-patcher.ts, 500ms debounce,getPatchTargetat edit time). When a turn for a newer message completes inside the window (itself writingchat.gameState), the queued flush saves correctly to the old message's snapshot but then unconditionally overwriteschat.gameStatewith that stale snapshot. There is no comparison betweentargetand the current visible target.Mitigations exist (so impact is bounded): the live UI reads from the store guarded by
reconcileVisibleGameState;getWorldStatere-resolves the visible snapshot on read; the generation baseline is snapshot-keyed (notchat.gameState); the next turn re-writeschat.gameState. The one genuinely-affected consumer isgameStateCarryoverPatch(game-api.ts:1150-1162), used when starting a new multi-session game — ifchat.gameStateis clobbered and a new session starts before another turn heals it, the new session starts from stale state.Steps to reproduce
chat.gameStateis overwritten with the prior message's snapshot.Impact area
Environment
b0e5561dLogs, screenshots, or video
Static source audit; cited to file:line above.
Regression notes
Found via static audit of the refactor branch; not verified against main. Transient persisted inconsistency that the next turn heals, with only the rare new-session-carryover-during-window path being user-visible, hence low.
Additional context
Suggested fix: re-resolve
latestAssistantTargetat flush time and only writechat.gameStatewhen the resolved target equals the current visible target; or skip thechat.gameStatewrite entirely for non-visible requested targets and let the visible-read path own it.Template check
Please uncheck the box below before submitting so we know you read the template. It is intentionally pre-checked:
@Romuromylus commented on GitHub (Jun 6, 2026):
Fixed by #2423, merged into
refactor.