mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2722] [Issue]: Tracker field locks drift/orphan/corrupt the wrong row on agent re-runs, swipes, and renames (positional vs name-based identity mismatch) #1365
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#1365
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/2722
Originally assigned to: @SpicyMarinara on GitHub.
Summary
Field locks are the user's main defense against tracker re-runs overwriting manually-pinned values, but the lock-key identity scheme for the most common collections (persona/character stats, inventory, generic custom fields, quest objectives) is purely positional, while the server merge re-associates rows by name. The two disagree the moment an agent reorders, inserts, drops, or renames a row — so a pin silently stops protecting the row the user pinned, freezes an unrelated row, or stamps a locked value onto a brand-new row. Several related paths (re-swiping, character/custom-field renames, orphaned-snapshot PATCH) also lose or fail to persist locks. These are the literal source of the recurring "tracker ignored my lock / lost my manually-edited value" reports.
Bug 1 — Positional lock keys drift to the wrong row on agent reorder (high)
How it breaks the pipeline: Lock-key identity for stats/inventory/custom-fields/quest-objectives is a bare array index (
persona.stats.${index}.value,player.inventory.${index}.name, etc.), butapplyTrackerFieldLocksToGameStatePatch->mergeStatsWithLocks/mergeInventoryWithLocks/mergeCustomTrackerFieldsWithGenericLocksmatches the row by NAME viafindCurrentNamedIndexand emits the merged array in the agent's new order. After one reorder the lock key points at a different array slot, so the merge protects the wrong row and the pinned row is freely overwritten on the next turn.Steps to replicate:
[HP, MP]; lockpersona.stats.0.value(HP).[MP, {HP, value:999}].[MP, HP]; the panel now renders the lock badge on index 0 = MP.persona.stats.0.valueprotects MP; HP is unprotected and overwritten.Code trace:
packages/shared/src/utils/tracker-field-locks.ts:177-179personaStatTrackerLockKey->persona.stats.${index}.${field};:185-187inventory;:306-308custom;:278-285quest objective — all positional.:381-407mergeNamedRowsWithLocksmapsnextRowsand keys locks viakeyFor(currentIndex,...), output is in agent order.StatList.tsxgetLockKey=(index)=>personaStatTrackerLockKey(index,...),PersonaTrackerPanel.tsx:387,RoleplayHUDPanels.tsx:349-351.removeIndexedTrackerLocks(tracker-field-locks.ts:92-140) exists but is wired ONLY to manual-delete UI handlers, never to the agent-merge path — proving the maintainers knew positional locks need realignment but only covered user edits.characterLockRef(:193-200) andquestLockRef(:254-261) use stable id:/name: refs and do NOT drift.Bug 2 — Carrying a locked-but-dropped row to the array end breaks its positional key (high)
How it breaks the pipeline: When the agent omits a locked row,
mergeNamedRowsWithLocksre-appends it at the END of the merged array, but the lock key still encodes the row's ORIGINAL index, so the next merge cannot find the lock and the carried row becomes overwritable.Steps to replicate:
[HP(idx0,locked), MP(idx1)]; agent emits only[MP].[MP, HP](HP re-pushed to index 1) but its lock key is stillpersona.stats.0.value.[HP, MP]; HP resolves to currentIndex 1, keypersona.stats.1.valuenot locked -> HP value overwritten; MP at index 0 spuriously protected.Code trace:
tracker-field-locks.ts:402-406tail loop pushes unused-but-locked current rows atmerged.length;mergeQuestObjectivesWithLocks:482-485only carries TRAILING dropped objectives, dropping a locked non-trailing objective entirely. Merged array persisted verbatim viabuildLockedPersonaTrackerPatch(generate-route-utils.ts:151) whilefieldLocksis carried forward independently; no re-key pass exists.Bug 3 — Positional fallback stamps a locked value onto an unrelated/renamed row (high)
How it breaks the pipeline:
findCurrentNamedIndexfalls back to the positional index when the agent's row name matches nothing. Because every row has a (non-matching) name, the merge still resolves to the same slot and applies that slot's lock to the new row, writing the locked value into the wrong field — the lock both fails to protect AND actively corrupts an unrelated field.Steps to replicate:
[HP (value locked), MP].[Stamina](name matches nothing).findCurrentNamedIndex(Stamina,...,0)byName=-1 -> fallbackIndex 0 -> currentRow=HP ->isTrackerFieldLocked(persona.stats.0.value)true ->Stamina.value = HP's locked value.Code trace:
tracker-field-locks.ts:367-379(fallback),:409-425/:427-444(mergeStats/Inventory copy currentStat value when locked). Scenario C: inserting a NEW stat at front while keeping HP/MP named both present causes Stamina to consume slot 0 via fallback, blocking HP's legit name match (usedCurrent), silently losing HP's lock AND transplanting it.Bug 4 — Quest objectives matched purely by position during locked merge (medium)
How it breaks the pipeline: Quests match by id/name, but objectives have no id (
game-state.ts:133{text;completed}) andmergeQuestObjectivesWithLockspairs them by raw array index, so any objective reorder/removal mis-pairs the lock.Steps to replicate: Lock objective 'Find the key' (index 1, completed). Agent marks an earlier objective done and re-emits the list shifted; the lock now pins a different objective while 'Find the key' is overwritten.
Code trace:
tracker-field-locks.ts:470-471const currentObjective = current[index]positional pairing; lock keyquestObjectiveTrackerLockKey(quest,questIndex,index,...)positional (:278-285); clientQuestRow.tsx:223-224derives the same positional keys;quest-state.ts:261wholesale replacesobjectiveson update.Bug 5 — Locks set on a swipe lost when generating additional swipes / regenerating (high)
How it breaks the pipeline: Locks are stored per (messageId, swipeIndex) row. A new swipe's snapshot is cloned from the PREVIOUS message's snapshot, not from the sibling swipe the user locked, so the just-set lock never enters the new swipe's merge/persist path and disappears from the panel.
Steps to replicate:
Code trace:
generate.routes.ts:1350-1357buildsvisibleAnchor=resolveRegenerationGameStateAnchor(...)which slices messages BEFORE the target, resolving the PREVIOUS assistant message;baseGameStateSnapshot(:3967) = previous message's snapshot. World-state handler creates the new swipe row withfieldLocks: currentGameStateForLocks?.fieldLocks(:7597) = previous message's locks.updateByMessageclone path also sourcesfieldLocksfrombaseSnapshot(game-state.storage.ts:337). The locked sibling swipe is never read.Bug 6 — Renaming a character custom-field orphans its lock and duplicates the field (medium)
How it breaks the pipeline: Character custom-field locks are NAME-keyed via
characterCustomFieldTrackerLockKey(...encodeSegment(fieldName)), butupdateCustomFielddeletes the old key and adds the new key without migrating the lock; additionally the server'smergeCharacterCustomFieldsWithLocksre-adds the locked old-name key alongside the agent's renamed key, producing a duplicate stale field, so a NAME lock can never actually prevent a rename.Steps to replicate: Lock a character custom field 'HP'; rename it to 'Health'. Lock indicator disappears; next character-tracker run overwrites the value; both 'HP' and 'Health' appear.
Code trace:
CharacterTrackerCard.tsx:209-219/FeaturedCharacterTrackerCard.tsx:195-205updateCustomField(delete nextFields[oldName]; if(trimmedName) nextFields[trimmedName]=nextValue) with noonUpdateFieldLockscall;tracker-field-locks.ts:523-549mergeCharacterCustomFieldsWithLocksre-addsnext['HP']='10'leaving{Health, HP}. Sibling array pathmergeCustomTrackerFieldsWithGenericLocks(:454) restores name in place correctly, proving intended semantics.Bug 7 — Renaming an agent-generated (name-keyed) character drops all its locks (medium)
How it breaks the pipeline:
characterLockRefusesname:<name>whencharacterIdis absent (common for agent-emitted rows). The name-edit handler changes the name but does not migrate thecharacters.name:OLD.*lock prefix, so every lock orphans and the server merge re-derives keys from the NEW name and finds nothing locked.Steps to replicate: On an agent-produced character without
characterId, lock several fields, then edit the character's name. All locks unlock; the next tracker run overwrites all of them.Code trace:
tracker-field-locks.ts:193-200characterLockRef;CharacterTrackerCard.tsx:255onSave={(name)=>onUpdate({...character, name: name||'Character'})};use-tracker-mutations.ts:128-135updateCharacterpatchespresentCharactersonly, neverfieldLocks(unlikeremoveCharacter:142/removeQuest:212which migrate).mergeCharactersWithLocks(:558-583) derives keys from the renamed character.Bug 8 — Lock toggle silently dropped when the targeted snapshot is orphaned (low)
How it breaks the pipeline: When the client PATCHes an explicit (messageId, swipeIndex) target that can no longer be updated (target message deleted / belongs to another chat), all fallback writers are gated behind
!hasExplicitTarget, so thefieldLockswrite is dropped and a 404 returned while the client already shows the lock optimistically; the catch re-queues the same stale target, looping forever.Steps to replicate: Delete the assistant message whose snapshot is the current GET fallback, then toggle a lock against that orphaned snapshot. The lock appears set but never persists; next turn the field is overwritten.
Code trace:
chats.routes.ts:1489-1551—hasExplicitTargettrue,targetMessage?.chatIdguard at:1491leavesupdatednull, recovery blocks at:1501/1511/1525all gated!hasExplicitTarget, returns 404 at:1552; clientuse-game-state-patcher.ts:413-420set optimistically,:293requeues stale target. Orphan reachable becauseremoveMessagedoes not cascade snapshots (see Storage issue).Suggested Fix
characterLockRef/questLockRef): derive the ref from a stable name or synthetic id, key locks by that ref on both client renderers and the server merge, so locks follow rows through reorder/insert/drop. (Fixes Bugs 1-4.)findCurrentNamedIndexresolves via positional fallback (no name/id match), do NOT apply per-field locks; carry the locked original row forward separately rather than stamping its values onto an unrelated new row. (Bug 3.)fieldLocksfrom the sibling swipe(s) of the SAME messageId, not from the previous message's base. (Bug 5.)updateCustomField/updateCharacterrename paths, migrate the lock keys (read livefieldLocks, move<prefix>.<oldName>.<field>-><prefix>.<newName>.<field>); inmergeCharacterCustomFieldsWithLocks, when a name is locked detect and drop the agent's renamed counterpart instead of duplicating, OR migrate charactercustomFieldsto an array-of-{name,value}. (Bugs 6-7.)hasExplicitTargetbut the targeted snapshot cannot be updated, create/locate a snapshot for that exact (messageId, swipeIndex) so the lock persists, or surface an error and stop requeuing the same stale target. (Bug 8.)Template checklist
pnpm checkpasses (TypeScript + ESLint)pnpm db:pushrun if schema/storage touchedAffected files
packages/shared/src/utils/tracker-field-locks.tspackages/server/src/routes/generate.routes.tspackages/server/src/routes/generate/retry-agents-route.tspackages/server/src/routes/generate/generate-route-utils.tspackages/server/src/routes/chats.routes.tspackages/client/src/features/tracker-panel/components/character-card/CharacterTrackerCard.tsxpackages/client/src/features/tracker-panel/components/character-card/FeaturedCharacterTrackerCard.tsxpackages/client/src/features/tracker-panel/hooks/use-tracker-mutations.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
46b61440. Tracker locks now use stable row refs for stats, inventory, custom fields, and quest objectives; legacy positional locks are migrated from the current snapshot before display/merge/persist; fallback row matches no longer stamp locked values onto unrelated renamed rows; locked omitted rows/objectives are carried forward; rename paths migrate lock prefixes; new swipe tracker snapshots prefer sibling-swipe locks; explicit stale snapshot patches update existing orphan snapshots or stop requeueing permanent 404 targets.