mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2992] [Issue]: With no visible last-assistant message, tracker retries write directly onto a prior committed game-state snapshot (corrupts historical state) #1567
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#1567
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 29, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2992
Originally assigned to: @SpicyMarinara on GitHub.
What's wrong
When the retry path cannot resolve a last-assistant message (no assistant message at all, or in conversation/roleplay/VN mode every assistant message in the retry window is hidden-from-AI),
retryMessageIdbecomes the empty string. The persona/quest/custom-tracker effect handlers then resolve the target snapshot to a PRIOR turn's committed snapshot and write tracker data directly onto that snapshot's row, corrupting previously committed game state. The world-state and character-tracker handlers similarly write to a cross-chatmessageId=""row.How to reproduce (try it yourself)
You'll see: the tracker update is written onto the prior committed snapshot's id (persona/quest/custom), or a cross-chat
messageId=""snapshot is created (world/character) — corrupting historical/other-chat state.Expected: the tracker effect no-ops when there is no resolvable target message.
Where it is
packages/server/src/routes/generate/retry-agents-route.ts:3299(retryMessageId = lastAssistant?.id ?? ""),:2235-2242(loadRetryTargetGameStateSnapshotreturns the base snapshot when empty),:2469-2475(persona direct write tolatest.id),:2552-2556(quest),:2622-2626(custom_tracker),:2328/:2427(world-state/character-trackerupdateByMessage("")). Storage:packages/server/src/services/storage/game-state.storage.ts:138-146(getLatestCommitted),:244-251(getByMessageis unscoped, with an explicit cross-chat-collision warning).What's happening
retryMessageIdsilently degrades to"". The persona/quest/custom blocks lack theif (retryMessageId && ...)guard that the text_rewrite, context_injection, and CYOA blocks have, and they bypassupdateByMessageto write raw to whatever snapshotloadRetryTargetGameStateSnapshotreturns — which for an empty messageId isgetLatestCommitted(chatId), a prior committed row.Suggested fix
Do NOT use a blanket early return (it would drop the chat-scoped secret_plot and lorebook_update effects, which don't depend on retryMessageId). Instead guard exactly the six message/game-state-scoped blocks with
retryMessageId &&, matching the existing guarded blocks: world-state game_state_update (~2306-2313), character_tracker_update (~2392-2398), persona_stats_update (~2443-2449), quest_update (~2522-2528), custom_tracker_update (~2603-2609), and sprite_change (~2888). Additionally, as defense-in-depth, changeloadRetryTargetGameStateSnapshotat line 2236 fromif (!retryMessageId) return loadRetryBaseGameStateSnapshot();toif (!retryMessageId) return null;so even a missed guard cannot land a direct.where(eq(id, snap.id))write on a prior committed row. All changes are gated on the empty-retryMessageId case, so the happy path is byte-for-byte unchanged; leave the chat-scoped secret_plot (2485) and lorebook_update (2499) blocks unguarded so they keep running.AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.
@SpicyMarinara commented on GitHub (Jun 29, 2026):
Fixed in merged staging PR #3004.