mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2370] [Issue]: Persona-stats tracker merge clobbers player inventory / stat bars / status on empty agent output (roleplay data loss) #1170
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#1170
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/2370
Originally assigned to: @Romuromylus on GitHub.
Summary
Severity: High — data-loss (regression vs main). In roleplay mode the persona-stats tracker agent runs every turn, and the refactor's merge in
gameStatePatchFromAgentResultoverwrites the player's inventory, persona stat bars, and status whenever the agent under-produces (emitsinventory: [],stats: [], orstatus: ""). The cleared data is persisted tochat.gameStateand becomes the next turn's base, so the loss is permanent until the user manually re-adds everything. Main guards this merge and ignores empty output.Expected behavior
When the persona-stats agent returns an empty/partial result, the existing inventory, stat bars, and status should be preserved — only non-empty fields should overwrite. This is what main does, and it is also what the sibling custom-tracker merge in this very file already does.
Actual behavior
src/engine/generation/tracker-snapshots.ts:452-463assigns each field guarded only byArray.isArray(...)/ key-presence, which are all true for empty values:inventory: []→playerStats.inventoryis replaced with[], wiping every carried item.status: ""→playerStats.statusis cleared.stats: []→patch.personaStatsis replaced with[], wiping all persona stat bars.The emptied
playerStats/personaStatsare written to both the tracker snapshot andchat.gameState(tracker-snapshots.ts:519-521) and become the base for the next turn.normalizeGameStateonly re-reads the already-clobbered record, so there is no recovery — the loss shows inPersonaTrackerPanel/PersonaInventoryRow/RoleplayHUDPlayerWidgetand persists.This is exactly the routine LLM failure mode (truncated JSON, an agent momentarily omitting an array, cross-contaminated batch output) — not an edge case.
Steps to reproduce
inventory: [](orstats: [], orstatus: "") — common when output is truncated or the agent under-merges.Impact area
Environment
330f69a8Logs, screenshots, or video
Static source audit, cited to
src/engine/generation/tracker-snapshots.ts:452-463and:519-521.Regression notes
Regression vs main — worked on main, broken on refactor. Main guards the same merge with non-empty checks over a
{ ...existingPS }base in both the live and retry paths:packages/server/src/routes/generate.routes.ts:9123(if (bars.length > 0) updates.personaStats = ...),:9131(if (status) mergedPS.status = status),:9132(if (inventory.length > 0) mergedPS.inventory = inventory).packages/server/src/routes/generate/retry-agents-route.ts:1540,1547,1548.So on main an empty agent result is ignored and existing data is preserved. The refactor dropped all three guards.
Additional context
Fix-pattern-already-in-repo: the sibling custom-tracker merge in the same function,
mergeCustomTrackerFieldsFromAgent(src/engine/shared/game-state/player-stats.ts:188), already returns the previous fields whenincoming.length === 0. The persona-stats branch just needs the same treatment.Fix sketch: only assign
inventorywhen the parsed array is non-empty, only setstatuswhen the trimmed string is non-empty, and only setpatch.personaStatswhen the parsed stats array is non-empty:Not a duplicate of #2317 (world-state
manualOverridesnull path, fixed), #2327 (debounced stale-overwrite race), or #2294 (avatar toggle).Template check
@Romuromylus commented on GitHub (Jun 6, 2026):
Fixed by #2380, merged into
refactor(squashb2310dd7).