[GH-ISSUE #2735] [Issue]: REGRESSION (#2730) — tracker field-lock merge duplicates/mis-attributes same-named rows (findCurrentCharacterMatch/QuestMatch missing usedCurrent guard) #1375

Closed
opened 2026-10-21 05:32:37 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @kolacheee on GitHub (Jun 21, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2735

Originally assigned to: @SpicyMarinara on GitHub.

Summary

Regression introduced by #2730 (the #2722 field-lock rewrite) — half-applied refactor. The new lock-merge helper findCurrentNamedMatch correctly takes a usedCurrent: Set<number> so each emitted row claims a distinct current row. But its two siblings — findCurrentCharacterMatch and findCurrentQuestMatch — were left without that dedup guard. When the tracker agent emits two rows with the same name (or same id), both resolve to the same current row, both inherit that row's locked field, and the unclaimed current row is then re-appended by the trailing "carry locked rows" loop. Result: the collection grows by a phantom duplicate every turn, and distinct same-named entities lose their individual data.

This is a data-corruption regression on a core game-mode persistence path, and same-named NPCs ("Guard", "Bandit", "Villager", "Soldier") are extremely common.

Sub-bugs (same root cause)

1. Characters — HIGH

Two present characters named "Guard" both match current[0]; both copy current[0]'s locked field; current[1] is never marked used and gets re-pushed. Per turn the list grows and the two Guards' mood/outfit/thoughts/stats collapse onto one. The trigger is design-permitted: agent-prompts.ts:262 tells the model characterId may be "ID or name".

2. Quests — LOW (latent)

findCurrentQuestMatch has the same gap. Currently hard to trigger because every quest reaching the merge has a questEntryId (so id-matching disambiguates) and the manual UI assigns unique ids — but it's the same defect and a defense-in-depth gap.

3. Blank-name / positional-lock rows — LOW

In mergeNamedRowsWithLocks, the locked index-fallback early-return (return row;) skips usedCurrent.add(currentIndex), so the trailing loop re-pushes that locked current row → one-row duplicate per affected turn. Affects blank-name stats/inventory/custom rows with a positional lock.

How it degrades the UX

A user playing game mode with multiple same-named NPCs (or who locks a field) sees the character/quest/stat list silently accrue duplicate rows turn over turn, and individual NPCs' tracked details bleed together — the exact "tracker shows wrong/duplicated data" class of report, now introduced by the lock fix.

Steps to replicate

  1. Game mode with the character tracker active; have two present characters both named "Guard".
  2. Lock any field on a Guard.
  3. Take several turns. Observe the present-characters list grow with duplicate "Guard" rows and the two Guards' details converge.

Code trace (staging)

  • packages/shared/src/utils/tracker-field-locks.ts:564-579 — findCurrentNamedMatch takes usedCurrent and checks !usedCurrent.has(index) in both the by-name find (:572) and the fallback (:576). ✅ correct.
  • packages/shared/src/utils/tracker-field-locks.ts:526-545 — findCurrentCharacterMatch takes no usedCurrent; by-id (:533), by-name (:538) and fallback (:542) all use plain findIndex/index with no used-check. ❌
  • packages/shared/src/utils/tracker-field-locks.ts:547-562 — findCurrentQuestMatch same gap. ❌
  • mergeCharactersWithLocks (~:790) calls findCurrentCharacterMatch with no used-set; locked-field copy at ~:802-806; trailing re-push at ~:822-825.
  • Live persist path: packages/server/src/routes/generate.routes.ts (~:7945) → applyTrackerFieldLocksToGameStatePatch against the previous snapshot, written back as next-turn current, so corruption compounds.
  • Regression origin: #2730 commit 46b61440 authored findCurrentNamedMatch with the guard but findCurrentCharacterMatch/findCurrentQuestMatch without it.

Suggested fix

Thread a usedCurrent: Set<number> through findCurrentCharacterMatch and findCurrentQuestMatch exactly like findCurrentNamedMatch (skip already-used indices in the by-id, by-name, and fallback lookups), and instantiate the set once in mergeCharactersWithLocks / mergeQuestsWithLocks before the .map(). Additionally, in mergeNamedRowsWithLocks, call usedCurrent.add(currentIndex) before the locked index-fallback early-return so the trailing loop doesn't re-append it.

Template checklist

  • pnpm check passes (TypeScript + ESLint)
  • Manually verify two same-named "Guard" NPCs keep distinct mood/outfit/stats across turns with a lock set
  • Manually verify the present-characters / quests lists do not grow phantom duplicate rows turn-over-turn
  • Manually verify a blank-name positional-locked stat/inventory row is not duplicated

Found by a post-merge verification sweep of #2730; characters case verified by direct read at the cited file:line. Boxes left unchecked for human verification.

Originally created by @kolacheee on GitHub (Jun 21, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2735 Originally assigned to: @SpicyMarinara on GitHub. ## Summary **Regression introduced by #2730 (the #2722 field-lock rewrite) — half-applied refactor.** The new lock-merge helper `findCurrentNamedMatch` correctly takes a `usedCurrent: Set<number>` so each emitted row claims a *distinct* current row. But its two siblings — `findCurrentCharacterMatch` and `findCurrentQuestMatch` — were left **without** that dedup guard. When the tracker agent emits two rows with the same name (or same id), both resolve to the **same** current row, both inherit that row's locked field, and the unclaimed current row is then **re-appended** by the trailing "carry locked rows" loop. Result: the collection **grows by a phantom duplicate every turn**, and distinct same-named entities lose their individual data. This is a data-corruption regression on a core game-mode persistence path, and same-named NPCs ("Guard", "Bandit", "Villager", "Soldier") are extremely common. ## Sub-bugs (same root cause) ### 1. Characters — HIGH Two present characters named "Guard" both match `current[0]`; both copy `current[0]`'s locked field; `current[1]` is never marked used and gets re-pushed. Per turn the list grows and the two Guards' mood/outfit/thoughts/stats collapse onto one. The trigger is design-permitted: `agent-prompts.ts:262` tells the model `characterId` may be "ID or name". ### 2. Quests — LOW (latent) `findCurrentQuestMatch` has the same gap. Currently hard to trigger because every quest reaching the merge has a `questEntryId` (so id-matching disambiguates) and the manual UI assigns unique ids — but it's the same defect and a defense-in-depth gap. ### 3. Blank-name / positional-lock rows — LOW In `mergeNamedRowsWithLocks`, the locked index-fallback early-return (`return row;`) skips `usedCurrent.add(currentIndex)`, so the trailing loop re-pushes that locked current row → one-row duplicate per affected turn. Affects blank-name stats/inventory/custom rows with a positional lock. ## How it degrades the UX A user playing game mode with multiple same-named NPCs (or who locks a field) sees the character/quest/stat list silently accrue duplicate rows turn over turn, and individual NPCs' tracked details bleed together — the exact "tracker shows wrong/duplicated data" class of report, now *introduced* by the lock fix. ## Steps to replicate 1. Game mode with the character tracker active; have two present characters both named "Guard". 2. Lock any field on a Guard. 3. Take several turns. Observe the present-characters list grow with duplicate "Guard" rows and the two Guards' details converge. ## Code trace (staging) - `packages/shared/src/utils/tracker-field-locks.ts:564-579` — `findCurrentNamedMatch` takes `usedCurrent` and checks `!usedCurrent.has(index)` in both the by-name find (`:572`) and the fallback (`:576`). ✅ correct. - `packages/shared/src/utils/tracker-field-locks.ts:526-545` — `findCurrentCharacterMatch` takes **no** `usedCurrent`; by-id (`:533`), by-name (`:538`) and fallback (`:542`) all use plain `findIndex`/index with no used-check. ❌ - `packages/shared/src/utils/tracker-field-locks.ts:547-562` — `findCurrentQuestMatch` same gap. ❌ - `mergeCharactersWithLocks` (~`:790`) calls `findCurrentCharacterMatch` with no used-set; locked-field copy at ~`:802-806`; trailing re-push at ~`:822-825`. - Live persist path: `packages/server/src/routes/generate.routes.ts` (~`:7945`) → `applyTrackerFieldLocksToGameStatePatch` against the previous snapshot, written back as next-turn `current`, so corruption compounds. - Regression origin: #2730 commit `46b61440` authored `findCurrentNamedMatch` **with** the guard but `findCurrentCharacterMatch`/`findCurrentQuestMatch` **without** it. ## Suggested fix Thread a `usedCurrent: Set<number>` through `findCurrentCharacterMatch` and `findCurrentQuestMatch` exactly like `findCurrentNamedMatch` (skip already-used indices in the by-id, by-name, and fallback lookups), and instantiate the set once in `mergeCharactersWithLocks` / `mergeQuestsWithLocks` before the `.map()`. Additionally, in `mergeNamedRowsWithLocks`, call `usedCurrent.add(currentIndex)` before the locked index-fallback early-return so the trailing loop doesn't re-append it. ## Template checklist - [ ] `pnpm check` passes (TypeScript + ESLint) - [ ] Manually verify two same-named "Guard" NPCs keep distinct mood/outfit/stats across turns with a lock set - [ ] Manually verify the present-characters / quests lists do not grow phantom duplicate rows turn-over-turn - [ ] Manually verify a blank-name positional-locked stat/inventory row is not duplicated --- _Found by a post-merge verification sweep of #2730; characters case verified by direct read at the cited file:line. Boxes left unchecked for human verification._
bsakaguchi 2026-10-21 05:32:37 +07:00
  • closed this issue
  • added the
    in-pr
    label
Author
Owner

@SpicyMarinara commented on GitHub (Jun 21, 2026):

Addressed in PR #2747.

<!-- gh-comment-id:4763115473 --> @SpicyMarinara commented on GitHub (Jun 21, 2026): Addressed in PR #2747.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#1375
No description provided.