mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2724] [Issue]: Tracker merge silently drops or mis-applies agent output (absent-vs-empty no-ops, empty-array clobber, tool-loop trap, combat clobbers world-state) #1369
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#1369
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/2724
Originally assigned to: @SpicyMarinara on GitHub.
Summary
The tracker merge layer mishandles legitimate structured agent output in several distinct ways. (1) The combat agent shares the
game_state_updateresult type with world-state and re-runs the world-statecreate()path off a stale baseline, reverting the scene every combat turn. (2) Empty-array / empty-string outputs are treated as "no update" at the patch-construction guards, so trackers can never empty an inventory, clear a status, empty the persona bar list, or wipe custom fields — yet an emptypresentCharactersarray DOES clobber existing characters client-side. (3) Theupdate_game_statetool is advertised as trackers' default tool, which routes them through a tool loop that only echoes and loses the JSON snapshot. (4)quest_updateis missing from the custom-agent capability map, so custom quest agents persist nothing. The shared theme: the merge cannot distinguish "field absent" from "field present but empty," and result-type routing is overloaded/inconsistent.Bug 1 — Combat agent reverts world-state scene advancement (high)
How it breaks the pipeline:
combatmaps toresult.type==='game_state_update', the same type as world-state. Both pass the world-state handler gate (noagentTypediscriminator; combat is built-in). Both computeprevSnapfrom the same stalebaseGameStateSnapshotand both callgameStateStore.create(), which deletes the existing (messageId, swipeIndex) row first. World-state runs first and advances date/time/location; combat runs second, emits no scene fields, falls back to the OLD baseline, and itscreate()deletes world-state's row — reverting the scene every combat turn.Steps to replicate: Game mode with World State + Combat agents enabled; during an active encounter, take a turn that advances time/location. The HUD reverts date/time/location to the previous turn.
Code trace:
agent-executor.ts:1822combat: 'game_state_update'; gategenerate.routes.ts:7511-7517(no agentType exclusion);baseGameStateSnapshotconst:3967; world-stateprevSnap:7525-7527; combat schema emits no scene fields (agent-prompts.ts:203-228) ->coerceGameStateTextValue(undefined)-> falls back to old base;create()delete-then-insertgame-state.storage.ts:237-243;RESULT_ORDER:7193; post_processing (world-state) ordered before parallel (combat):7048-7056. (Requires manual-trackers off so world-state runs in-pipeline,:4643-4645.)Bug 2 — Persona-stats can never empty inventory or clear status (medium)
How it breaks the pipeline:
buildLockedPersonaTrackerPatchadds inventory/status to the patch only when non-empty, so an emittedinventory:[](last item consumed) orstatus:''is dropped before locks/diff and the previous value persists forever.Steps to replicate: Consume the last inventory item so the persona agent emits
inventory:[]. The item stays in the tracker indefinitely.Code trace:
generate-route-utils.ts:139if(status)...,:140if(inventory.length>0)...; field never added ->:160Array.isArray(lockedPlayerStatsPatch.inventory)false -> existing kept;changedstays false -> no persist/SSE. Same in retry pathretry-agents-route.ts:2209-2237. Prompt defines full-snapshot semantics (agent-prompts.ts:281-300).Bug 3 — personaStats bar array can never be emptied (medium)
How it breaks the pipeline: Same root defect at a distinct line:
if (stats.length > 0) rawPatch.personaStats = stats;drops an emitted empty bar list, so obsolete bars (e.g. a combat-only Stamina bar) linger forever.Code trace:
generate-route-utils.ts:136;personaStatsChangedrequiresArray.isArray(patch.personaStats)(:149-150) which is false -> never written. Both callers gate on non-emptyupdates(generate.routes.ts:7954,retry-agents-route.ts:2224).Bug 4 — Custom-tracker agent can never clear all custom fields (low)
How it breaks the pipeline: The entire custom-field write is gated on
rawFields.length > 0, so an explicitfields:[](full wipe) is silently treated as no-op, even thoughbuildLockedPlayerStatsArrayPatchwould clear correctly if called.Code trace:
generate.routes.ts:7998-7999const rawFields=(ctData.fields as any[])??[]; if(rawFields.length>0){...}; helper diffgenerate-route-utils.ts:86-109computeschangedcorrectly viaisDeepStrictEqual([], existing). Same guard duplicatedretry-agents-route.ts:2352-2353. Empty-as-delete is documented intent (agent-prompts.ts:306).Bug 5 — Empty/partial presentCharacters array clobbers existing unlocked characters (high)
How it breaks the pipeline: Inversely to Bugs 2-4, the client merge
applyGameStatePatchToStorespecial-cases empty arrays ONLY foractiveQuests; an emittedpresentCharacters:[]replaces existing characters wholesale (lock layer only preserves locked rows), and the server character-tracker path emitspresentCharactersunconditionally even when empty.Steps to replicate: Character-tracker returns valid JSON of
{}or{presentCharacters:[]}. All unlocked present characters vanish from the HUD/panel.Code trace: Client
use-generate.ts:830-845(onlyactiveQuestsempty-guard at:836-842); server emits unconditionallygenerate.routes.ts:7661,7886-7887andretry-agents-route.ts:2171,2203. Maintainers' own commentgenerate.routes.ts:7602-7604names this clobber vector for world-state but did not harden the character path. (inventory/personaStats are NOT emitted empty by the server, so only presentCharacters is the live clobber.)Bug 6 — update_game_state default tool routes trackers through a lossy tool loop (medium)
How it breaks the pipeline: Tracker manifests advertise
defaultTools:['update_game_state']; enabling it attaches atoolContextso the tracker runs viaexecuteAgentWithTools. The tool impl only echoes ({applied:true,...}) and never writes the snapshot; the merge readsresult.data, so if the model 'calls the tool' and returns prose/partial JSON, the snapshot is empty or established characters get wiped.Steps to replicate: On a tracker agent, confirm
update_game_stateis toggled on (it is by default), run a turn with a model that calls the tool. Tracker stops updating or presentCharacters wipes to[].Code trace:
character-tracker/manifest.ts:12(and persona/world/custom/quest:12); seedingagent.ts:598-600,agents.routes.ts:131,308; UI exposureAgentEditor.tsx:1234-1242; tool-context attachtool-resolution-runtime.ts:671-766; routingagent-pipeline.ts:152-181; echo-only impltool-executor.ts:413-426; merge ignores tool callsgenerate.routes.ts:7651-7682.Bug 7 — Custom quest_update agents persist nothing (medium)
How it breaks the pipeline:
quest_updateis the only tracker result type missing fromCUSTOM_AGENT_RESULT_CAPABILITY, so a custom agent withresultType='quest_update'is never auto-grantededit_trackers; emit is allowed (default:true) but the persist gate (customAgentCanApplyResult(...,'edit_trackers')) returns false, so nothing is saved.Code trace:
agent.ts:483-493(omits quest_update);normalizeCustomAgentCapabilities:517-520; emit gategenerate.routes.ts:394-421(no quest_update case -> default true); persist gate:8033-8038. Reachable via the agent create/update API / import (agent.schema.ts:14accepts quest_update) even though the editor UI excludes it.Suggested Fix
create()handler onresult.agentType(route combat through its own handler that never callscreate()), OR makecreate()merge-update the existing (messageId, swipeIndex) row instead of delete-and-rebuild, OR have latergame_state_updateemitters re-read the just-written snapshot asprevSnap. (Bug 1.)[]/''when the key is present. Apply to status/inventory/personaStats (generate-route-utils.ts:136,139,140) and custom fields (generate.routes.ts:7998,retry-agents-route.ts:2352). (Bugs 2-4.)activeQuests), OR have the character-tracker path skip emitting emptypresentCharacterslike world-state/persona-stats do. (Bug 5.)update_game_statefrom tracker manifests'defaultTools(trackers are pure-JSON snapshot agents), or hide/disable it in the editor for snapshot trackers, or make the tracker handlers consumeupdate_game_statetool-call args. (Bug 6.)quest_update:'edit_trackers'toCUSTOM_AGENT_RESULT_CAPABILITYand acase 'quest_update':arm tocustomAgentCanEmitResultso emit and apply are gated identically. (Bug 7.)Template checklist
pnpm checkpasses (TypeScript + ESLint)pnpm db:pushrun if storage/schema touchedfields:[]wipes all custom fieldsupdate_game_statedisabled (or that enabling it no longer loses the snapshot)quest_updateactually persists quest changesAffected files
packages/server/src/routes/generate.routes.tspackages/server/src/routes/generate/generate-route-utils.tspackages/server/src/routes/generate/retry-agents-route.tspackages/server/src/services/storage/game-state.storage.tspackages/shared/src/types/agent.tspackages/shared/src/features/agents/character-tracker/manifest.tspackages/client/src/hooks/use-generate.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
eb403162. Combat game_state_update results no longer run through the world-state snapshot path, persona/custom tracker outputs now distinguish absent fields from intentional empty values, empty/missing character tracker presence is treated as no-op instead of clobbering snapshots, tracker built-ins no longer default-enable update_game_state, and quest_update is gated through edit_trackers for custom agents.