mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2726] [Issue]: Client tracker mutations and live-write races lose manual edits and agent writes; rerun lifecycle not flagged #1370
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#1370
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 21, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2726
Originally assigned to: @SpicyMarinara on GitHub.
Summary
Manual tracker edits and concurrent agent writes race each other with no reconciliation, producing the historically top-reported "tracker lost my manually-edited value" symptom. Array mutations (stats/inventory/quests/characters/custom) rebuild the next array from a stale closure-captured render prop instead of the live store, so a concurrent agent write to the same array is silently dropped. Manual debounced PATCHes can flush AFTER an agent's SSE write lands and overwrite it. The tracker re-run path never sets the
isRefreshingflag, so the only edit-drop guard is inert during a rerun and mid-rerun edits are clobbered by the final refresh GET. A detached NPC-avatar generation does a multi-second read-modify-write of the wholepresentCharactersarray with no concurrency guard, overwriting any edit/retry write landing in the window. And avatar upload resolves the target NPC by a positional index captured at click time, so a reorder during the OS file dialog sends the image to the wrong character.Bug 1 — Array mutations use a stale render prop, losing concurrent agent writes (high)
How it breaks the pipeline:
updateInventoryItem/updateQuest/updatePersonaStats/updateCustomFields/updateCharacterspread the closure-captured prop array (the last render's snapshot), notuseGameStateStore.getState().current. The whole array is sent topatchPlayerStats/patchField, overwriting any newer rows the agent added/changed since that render.Steps to replicate: During/after a tracker re-run, the agent adds an inventory item; the user edits a different inventory row; the new item vanishes (same for quests/personaStats/customTrackerFields/presentCharacters).
Code trace:
use-tracker-mutations.ts:169-216,233-237rebuild from propsinventory/quests/personaStats/customFields(sourced render-timeTrackerSectionList.tsx:93-98);patchPlayerStatsField(use-game-state-patcher.ts:422-425) merges only OTHER playerStats fields from the live store, taking the array verbatim from the stale prop. Server_applyUpdatereplaces playerStats wholesale (game-state.storage.ts:377-378). ContrasthandleAvatarUpload(use-tracker-mutations.ts:91-98) which deliberately re-reads the live store — pattern known but not applied to array editors.Bug 2 — Manual debounced PATCH overwrites a concurrent agent write (medium)
How it breaks the pipeline: Manual edits debounce the server PATCH by 500ms with
manual:true; an agent SSEgame_state_patchoverwrites the store immediately. When the older debounced manual patch flushes after the agent's write landed, it PATCHes the pre-agent value, clobbering the agent's update and pinning a manual override.Steps to replicate: Edit a tracker field within ~500ms of a tracker agent finishing mid-generation; the HUD shows the agent value then snaps back to the user value, which persists.
Code trace:
use-game-state-patcher.ts:35debounce const,:216-243queue/timer,:288flush PATCH,:415guard only onstore.isRefreshing(not set during streaming); store applyuse-generate.ts:823-852; server applies field-only partial to last assistant snapshot (chats.routes.ts:1465-1513).Bug 3 — Re-run never sets the refreshing flag; edit-drop guard inert (medium)
How it breaks the pipeline:
retryAgentsonly callssetProcessing(true)on the agent store, neversetRefreshingChat, sogameStateStore.isRefreshingstays false for the whole re-run. ThepatchGameStateFieldisRefreshingguard does not block edits during a re-run, inline inputs are not gated ontrackerRetryBusy, and the always-onrefreshVisibleGameStateAfterGenerationGET in the finally overwrites the store with authoritative state — losing a mid-rerun edit until reload.Code trace:
use-generate.ts:2406-2424(setProcessingonly),:2692-2700finally GET; guarduse-game-state-patcher.ts:415; refresh:744-762; swipe path DOES set/clear (ChatArea.tsx:1189/1232).Bug 4 — NPC avatar generation clobbers newer presentCharacters (medium)
How it breaks the pipeline: A detached IIFE awaits multi-second
generateImage, then re-readspresentCharacters, overlays avatar paths, and writes the WHOLE array back viaupdateByMessage(full replace) with no version/abort guard. Any presentCharacters write between the read and write (manual edit or retry-agents) is overwritten.Steps to replicate: With auto NPC avatar generation enabled, after a character-tracker introduces a new NPC, edit that NPC's mood/outfit while avatars generate; the edit is overwritten when the avatar write lands.
Code trace:
generate.routes.ts:7744detached IIFE,await generateImage:7786, re-read:7819-7820, write:7839-7848;_applyUpdatefull replacegame-state.storage.ts:376-406; racersuse-tracker-mutations.ts:128-134/use-game-state-patcher.ts:287-288andretry-agents-route.ts:2193-2202; locks only protect locked fields:7831-7834.Bug 5 — Avatar upload uses a stale click-time array index (low)
How it breaks the pipeline:
openAvatarUpload(index)stores the render-time positional index and opens the file picker;handleAvatarUploadlater indexes that into the LIVE store array at file-pick time. If a tracker re-run reorders/inserts presentCharacters while the OS dialog is open, the image is attached to the wrong NPC (and the id-based write-back derives from the wrong character, so it consistently writes to the wrong row).Code trace:
use-tracker-mutations.ts:55-65(store index, open picker),:117-126(read index, call handler),:63-65,68(live array + targetCharacterId from wrong row); reorder sourceretry-agents-route.ts:2171,2203+use-generate.ts:832.Suggested Fix
useGameStateStore.getState().current, guard chatId, re-locate the row by id/index) for all array editors, mirroringhandleAvatarUpload. (Bug 1.)discardPendingGameStatePatch/ suppressqueuePatch), or make the server PATCH revision/version-aware. (Bugs 2-3.)setRefreshingChat/clearRefreshingChat(as swipe/delete do), gate inline tracker edits ontrackerRetryBusy, and/or re-flush pending patches before the final refresh GET. (Bug 3.)avatarPathon the freshly-read row (or guard with a snapshot id/updatedAt check, skip if changed). (Bug 4.)characterIdatopenAvatarUploadtime and resolve byfindIndex(characterId)inhandleAvatarUpload. (Bug 5.)Template checklist
pnpm checkpasses (TypeScript + ESLint)Affected files
packages/client/src/features/tracker-panel/hooks/use-tracker-mutations.tspackages/client/src/hooks/use-game-state-patcher.tspackages/client/src/hooks/use-generate.tspackages/server/src/routes/generate.routes.tspackages/server/src/services/storage/game-state.storage.tsAudit provenance
Found by a multi-agent static audit of the trackers/widgets subsystem (Round 1 + round-2 gap sweep + completeness critic, each finding adversarially verified). Severity: HIGH. Line numbers are against the
stagingworking tree.@SpicyMarinara commented on GitHub (Jun 21, 2026):
Fixed in
dc41ffa0. Tracker array mutations now re-read the live game-state store before applying row edits/adds/removals, avatar upload targets a stable characterId instead of a click-time index, retry-agent tracker runs set/clear the game-state refreshing flag so edit guards engage, and incoming tracker SSE patches discard stale queued manual patches before applying authoritative state. Skipped as already addressed in current code: the NPC avatar generation path re-fetches the latest snapshot after image generation and overlays generated avatarPath values onto those fresh character rows instead of writing the original stale array.