[GH-ISSUE #2723] [Issue]: Committed tracker-context injection is lossy and divergent — active quests, objective progress, and dry-run preview drop or misrepresent state #1367

Closed
opened 2026-10-21 05:32:28 +07:00 by bsakaguchi · 2 comments
Owner

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

Originally assigned to: @SpicyMarinara on GitHub.

Summary

The committed-context block (injectCommittedTrackerContext) is what tells the model on the NEXT turn what the established tracker state is. It is the sole live tracker-context renderer (the richer expandWorldStateAgent is dead code), and it is lossy: it silently drops active quests whose objectives are all done, hard-codes every objective as an empty [ ] checkbox hiding all progress, and emits [object Object] / undefined/undefined for malformed rows. Worse, the prompt-preview / dry-run path renders tracker context with a completely DIFFERENT, ungated, non-lossy renderer, so a user debugging "why is the model ignoring my trackers" sees a preview that does not match what is actually sent. The net effect is the classic "tracker panel shows it, model forgets/re-narrates it" complaint.


Bug 1 — Active quest with all objectives complete is dropped from context (high)

How it breaks the pipeline: compactQuestProgressForContext removes any quest whose objectives are all complete even when quest.completed===false, so the quest is excluded from the injected Active Quests block while the panel still renders it as a normal open quest. The model is never told the quest exists and forgets/duplicates it.

Steps to replicate: Create/advance an active quest; tick every objective complete but do NOT mark the quest completed. Panel shows it at 100% / N/N; next turn the model has no knowledge of it.

Code trace: quest-state.ts:220-235 — :222 if(quest.completed) return []; :224 filter incomplete; :225 if(quest.objectives.length>0 && objectives.length===0) return [] drops the active-but-all-done quest. Consumed at committed-tracker-context.ts:105-116. Renderer QuestRow.tsx:60-63,99,152 still shows it active. Sibling injectors chats.routes.ts:298-305 and game.routes.ts:2843-2855 keep this exact state visible, confirming the inconsistency.

Bug 2 — Objective progress hidden: completed objectives stripped, survivors hard-coded '[ ]' (medium)

How it breaks the pipeline: The renderer prints every surviving objective as [ ] ${objective.text} with a literal empty checkbox and objective.completed is never read; combined with the compactor stripping completed objectives, a quest [done, done, pending] reaches the prompt as just [ ] pending, so the model re-narrates finished steps.

Steps to replicate: Quest with two completed and one pending objective; inspect the injected context — it shows only the pending objective with an empty checkbox, no signal of the two done.

Code trace: committed-tracker-context.ts:107-110 literal [ ]; quest-state.ts:224 filters completed objectives. The data exists (game-state.ts:133 {text;completed}). Dead marker-expander.ts:573-576 rendered [x]/[ ] correctly but is unreachable (Bug 3).

Bug 3 — Only live tracker-context renderer is the lossy one; richer renderer is dead code (medium)

How it breaks the pipeline: expandAgentData early-returns {content:''} for any agentType in AUTO_INJECTED_TRACKERS (incl. 'world-state') before the expandWorldStateAgent branch can run, so the richer renderer (full [x]/[ ], (completed) quests, uncommitted-snapshot fallback) never reaches the prompt — masking Bugs 1-2 and confusing maintainers who patch the wrong function.

Code trace: marker-expander.ts:448-455 AUTO_INJECTED_TRACKERS set + early return; :463-468 unreachable world-state branch; :494-599 dead expandWorldStateAgent. Live path: injectCommittedTrackerContext imported generate.routes.ts:356, called :4528.

Bug 4 — Present character with missing name injected as '[object Object]' (low)

How it breaks the pipeline: For an object entry lacking name, the renderer interpolates the object itself, stringifying to [object Object], polluting the model's view of who is present.

Steps to replicate: Have the character-tracker emit (or manually store) a present-character object with no name field; inspect the injected context line.

Code trace: committed-tracker-context.ts:84 `- ${character.emoji ?? ''} ${character.name ?? character}${detailStr}`; character.name ?? character yields the object. PresentCharacter.name declared required (game-state.ts:48-49) but unenforced at runtime (tool passthrough, chats.routes.ts:1481). Sibling code already filters nameless entries (game-gm-prompt-runtime.ts:251-252). Also a leading double space when emoji is absent.

Bug 5 — Stat values render 'undefined/undefined' into the prompt (low)

How it breaks the pipeline: Bar/stat value/max are interpolated with no finite-number guard, so a partial tracker write ({name:'Hunger'} with no value/max) injects - Hunger: undefined/undefined, degrading the model's grounding.

Code trace: committed-tracker-context.ts:93 `- ${bar.name}: ${bar.value}/${bar.max}` (unconditional); :127 ${stat.value}${stat.max ? '/'+stat.max : ''} (value unguarded). No Number.isFinite anywhere in the file; agent output uncoerced upstream (generate-route-utils.ts:136 stores verbatim). (Note: literal JS NaN is not reachable via JSON.parse; only undefined/string values occur.)

Bug 6 — Dry-run / prompt-preview uses different, ungated, non-lossy tracker rendering (medium)

How it breaks the pipeline: The dry-run route reimplements its own formatTrackersContextBlock that does NO active-agent gating and renders quests with real [x]/(completed), so the preview shows tracker sections and completed-objective state the real prompt never contains — directly misleading users debugging tracker issues.

Steps to replicate: With only world-state active, open prompt preview / extension dry-run; it shows Persona Stats / Inventory / Quests sections and completed-objective checkboxes that real generation gates out / strips.

Code trace: dry-run-route.ts:129-232 (no hasCharTracker/... gating; quests at :185-192 keep completed and use [x]/[ ]); callers :1113-1119, :1411-1414 gate only on the request flag. Live path committed-tracker-context.ts:45-134 gates each section and runs compactQuestProgressForContext. Both load the identical snapshot via getForGeneration. Route comments (dry-run-route.ts:722, :1567) state the preview must mirror real generation.


Suggested Fix

  • In compactQuestProgressForContext, only drop a quest when quest.completed===true; keep active-but-all-objectives-done quests (optionally with a 'ready to turn in' marker). (Bug 1.)
  • Render the full objective list with real [x]/[ ] from objective.completed (or at minimum a (done X/Y) summary) instead of stripping completed objectives and hard-coding [ ]. (Bug 2.)
  • Delete expandWorldStateAgent and the unreachable branch (or remove 'world-state' from AUTO_INJECTED_TRACKERS if it is the intended renderer) to keep one source of truth. (Bug 3.)
  • Guard the present-character line: skip/placeholder when name is missing and join non-empty [emoji, name] parts. (Bug 4.)
  • Coerce/validate value/max to finite numbers before rendering; skip or substitute when not finite. (Bug 5.)
  • Delete the dry-run copy and call the shared injectCommittedTrackerContext with the chat's real active-agent set so preview is byte-identical to generation. (Bug 6.)

Template checklist

  • pnpm check passes (TypeScript + ESLint)
  • Manually verify an active quest with all objectives complete still appears in the next prompt's committed context
  • Manually verify completed objectives render as [x] (or a done X/Y summary) in the injected context
  • Manually verify expandWorldStateAgent removal/rewire does not regress any marker expansion
  • Manually verify a nameless present-character entry does not produce [object Object]
  • Manually verify a partial persona-stat write does not inject undefined/undefined
  • Manually verify prompt preview / dry-run output matches the real generated prompt's tracker block for a world-state-only chat

Affected files

  • packages/shared/src/utils/quest-state.ts
  • packages/server/src/services/generation/committed-tracker-context.ts
  • packages/server/src/services/prompt/marker-expander.ts
  • packages/server/src/routes/generate/dry-run-route.ts
  • packages/server/src/routes/generate.routes.ts

Audit 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 staging working tree.

Note: this issue was AI-drafted from a static read of the code; the validation/test-plan boxes are intentionally left UNCHECKED for a human to verify before close.

Originally created by @kolacheee on GitHub (Jun 21, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2723 Originally assigned to: @SpicyMarinara on GitHub. ## Summary The committed-context block (`injectCommittedTrackerContext`) is what tells the model on the NEXT turn what the established tracker state is. It is the sole live tracker-context renderer (the richer `expandWorldStateAgent` is dead code), and it is lossy: it silently drops active quests whose objectives are all done, hard-codes every objective as an empty `[ ]` checkbox hiding all progress, and emits `[object Object]` / `undefined/undefined` for malformed rows. Worse, the prompt-preview / dry-run path renders tracker context with a completely DIFFERENT, ungated, non-lossy renderer, so a user debugging "why is the model ignoring my trackers" sees a preview that does not match what is actually sent. The net effect is the classic "tracker panel shows it, model forgets/re-narrates it" complaint. --- ### Bug 1 — Active quest with all objectives complete is dropped from context (high) **How it breaks the pipeline:** `compactQuestProgressForContext` removes any quest whose objectives are all complete even when `quest.completed===false`, so the quest is excluded from the injected Active Quests block while the panel still renders it as a normal open quest. The model is never told the quest exists and forgets/duplicates it. **Steps to replicate:** Create/advance an active quest; tick every objective complete but do NOT mark the quest completed. Panel shows it at 100% / N/N; next turn the model has no knowledge of it. **Code trace:** `quest-state.ts:220-235` — `:222` `if(quest.completed) return []`; `:224` filter incomplete; `:225` `if(quest.objectives.length>0 && objectives.length===0) return []` drops the active-but-all-done quest. Consumed at `committed-tracker-context.ts:105-116`. Renderer `QuestRow.tsx:60-63,99,152` still shows it active. Sibling injectors `chats.routes.ts:298-305` and `game.routes.ts:2843-2855` keep this exact state visible, confirming the inconsistency. ### Bug 2 — Objective progress hidden: completed objectives stripped, survivors hard-coded '[ ]' (medium) **How it breaks the pipeline:** The renderer prints every surviving objective as ` [ ] ${objective.text}` with a literal empty checkbox and `objective.completed` is never read; combined with the compactor stripping completed objectives, a quest `[done, done, pending]` reaches the prompt as just `[ ] pending`, so the model re-narrates finished steps. **Steps to replicate:** Quest with two completed and one pending objective; inspect the injected context — it shows only the pending objective with an empty checkbox, no signal of the two done. **Code trace:** `committed-tracker-context.ts:107-110` literal `[ ]`; `quest-state.ts:224` filters completed objectives. The data exists (`game-state.ts:133` `{text;completed}`). Dead `marker-expander.ts:573-576` rendered `[x]`/`[ ]` correctly but is unreachable (Bug 3). ### Bug 3 — Only live tracker-context renderer is the lossy one; richer renderer is dead code (medium) **How it breaks the pipeline:** `expandAgentData` early-returns `{content:''}` for any `agentType` in `AUTO_INJECTED_TRACKERS` (incl. 'world-state') before the `expandWorldStateAgent` branch can run, so the richer renderer (full `[x]`/`[ ]`, `(completed)` quests, uncommitted-snapshot fallback) never reaches the prompt — masking Bugs 1-2 and confusing maintainers who patch the wrong function. **Code trace:** `marker-expander.ts:448-455` `AUTO_INJECTED_TRACKERS` set + early return; `:463-468` unreachable `world-state` branch; `:494-599` dead `expandWorldStateAgent`. Live path: `injectCommittedTrackerContext` imported `generate.routes.ts:356`, called `:4528`. ### Bug 4 — Present character with missing name injected as '[object Object]' (low) **How it breaks the pipeline:** For an object entry lacking `name`, the renderer interpolates the object itself, stringifying to `[object Object]`, polluting the model's view of who is present. **Steps to replicate:** Have the character-tracker emit (or manually store) a present-character object with no `name` field; inspect the injected context line. **Code trace:** `committed-tracker-context.ts:84` `` `- ${character.emoji ?? ''} ${character.name ?? character}${detailStr}` ``; `character.name ?? character` yields the object. `PresentCharacter.name` declared required (`game-state.ts:48-49`) but unenforced at runtime (tool passthrough, `chats.routes.ts:1481`). Sibling code already filters nameless entries (`game-gm-prompt-runtime.ts:251-252`). Also a leading double space when emoji is absent. ### Bug 5 — Stat values render 'undefined/undefined' into the prompt (low) **How it breaks the pipeline:** Bar/stat value/max are interpolated with no finite-number guard, so a partial tracker write (`{name:'Hunger'}` with no value/max) injects `- Hunger: undefined/undefined`, degrading the model's grounding. **Code trace:** `committed-tracker-context.ts:93` `` `- ${bar.name}: ${bar.value}/${bar.max}` `` (unconditional); `:127` `${stat.value}${stat.max ? '/'+stat.max : ''}` (value unguarded). No `Number.isFinite` anywhere in the file; agent output uncoerced upstream (`generate-route-utils.ts:136` stores verbatim). (Note: literal JS `NaN` is not reachable via JSON.parse; only `undefined`/string values occur.) ### Bug 6 — Dry-run / prompt-preview uses different, ungated, non-lossy tracker rendering (medium) **How it breaks the pipeline:** The dry-run route reimplements its own `formatTrackersContextBlock` that does NO active-agent gating and renders quests with real `[x]`/`(completed)`, so the preview shows tracker sections and completed-objective state the real prompt never contains — directly misleading users debugging tracker issues. **Steps to replicate:** With only world-state active, open prompt preview / extension dry-run; it shows Persona Stats / Inventory / Quests sections and completed-objective checkboxes that real generation gates out / strips. **Code trace:** `dry-run-route.ts:129-232` (no `hasCharTracker/...` gating; quests at `:185-192` keep completed and use `[x]/[ ]`); callers `:1113-1119`, `:1411-1414` gate only on the request flag. Live path `committed-tracker-context.ts:45-134` gates each section and runs `compactQuestProgressForContext`. Both load the identical snapshot via `getForGeneration`. Route comments (`dry-run-route.ts:722`, `:1567`) state the preview must mirror real generation. --- ## Suggested Fix - In `compactQuestProgressForContext`, only drop a quest when `quest.completed===true`; keep active-but-all-objectives-done quests (optionally with a 'ready to turn in' marker). (Bug 1.) - Render the full objective list with real `[x]`/`[ ]` from `objective.completed` (or at minimum a `(done X/Y)` summary) instead of stripping completed objectives and hard-coding `[ ]`. (Bug 2.) - Delete `expandWorldStateAgent` and the unreachable branch (or remove 'world-state' from `AUTO_INJECTED_TRACKERS` if it is the intended renderer) to keep one source of truth. (Bug 3.) - Guard the present-character line: skip/placeholder when `name` is missing and join non-empty `[emoji, name]` parts. (Bug 4.) - Coerce/validate `value`/`max` to finite numbers before rendering; skip or substitute when not finite. (Bug 5.) - Delete the dry-run copy and call the shared `injectCommittedTrackerContext` with the chat's real active-agent set so preview is byte-identical to generation. (Bug 6.) --- ## Template checklist - [ ] `pnpm check` passes (TypeScript + ESLint) - [ ] Manually verify an active quest with all objectives complete still appears in the next prompt's committed context - [ ] Manually verify completed objectives render as `[x]` (or a done X/Y summary) in the injected context - [ ] Manually verify `expandWorldStateAgent` removal/rewire does not regress any marker expansion - [ ] Manually verify a nameless present-character entry does not produce `[object Object]` - [ ] Manually verify a partial persona-stat write does not inject `undefined/undefined` - [ ] Manually verify prompt preview / dry-run output matches the real generated prompt's tracker block for a world-state-only chat --- ### Affected files - `packages/shared/src/utils/quest-state.ts` - `packages/server/src/services/generation/committed-tracker-context.ts` - `packages/server/src/services/prompt/marker-expander.ts` - `packages/server/src/routes/generate/dry-run-route.ts` - `packages/server/src/routes/generate.routes.ts` ### Audit 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 `staging` working tree. > Note: this issue was AI-drafted from a static read of the code; the validation/test-plan boxes are intentionally left UNCHECKED for a human to verify before close.
Author
Owner

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

Veracity self-review — correction / clarification
Automated post-filing review of this issue against the current working tree. The reported bug remains valid; the notes below refine its scope, accuracy, or suggested fix for whoever implements it.

Scope/fix correction for Bug 6 — the dry-run route is NOT the only divergent preview renderer, and there is a second uncited offender.

formatPeekTrackerContextBlock in packages/server/src/routes/chats.routes.ts (defined L226-347, invoked at L2072 for the POST /:id/peek-prompt route at L1565, whose response source is "live_preview" at L2087) is a second tracker-context preview renderer with the same intended-mirror-but-divergent contract: its caller comment at L2061 says it must "mirror the read-only snapshot injection from /api/generate."

How it diverges from the real generation path (injectCommittedTrackerContext):

  • NON-lossy, unlike generation: it iterates stats.activeQuests directly with NO compactQuestProgressForContext (L298), so it keeps active-but-all-objectives-done quests (Bug 1) and renders q.completed ? " (completed)" (L303) plus real [x]/[ ] objective state (L301) that generation strips/hides (Bug 2).
  • Shares Bug 4 (- ${c.emoji ?? ""} ${c.name ?? c} at L270 → [object Object] for a nameless present character).
  • Shares Bug 5 (- ${b.name}: ${b.value}/${b.max} at L283, and ${s.value} at L317 — no finite-number guard).

Note one distinction from dry-run: peek IS gated by active agents (L234-240, and the caller guards on chatEnableAgents/activeAgentIds at L2069), whereas dry-run's formatTrackersContextBlock is UNGATED — so they are not identical. dry-run diverges on BOTH gating and lossiness; peek diverges only on lossiness + the malformed-row bugs.

Consequence for the suggested fix: the framing "injectCommittedTrackerContext … is the sole live tracker-context renderer" and Fix #6 ("Delete the dry-run copy and call the shared injectCommittedTrackerContext") are incomplete. Deleting only the dry-run copy leaves peek-prompt divergent, so the reported "preview doesn't match what is actually sent" symptom persists for the peek path.

Revised Fix #6: route BOTH preview renderers — dry-run formatTrackersContextBlock AND chats formatPeekTrackerContextBlock — through the shared injectCommittedTrackerContext (or a shared block-builder extracted from it) so all three paths share one lossy-or-corrected implementation. When implementing Fixes 1+2 (stop dropping active-but-all-done quests; render real [x]/[ ]), make the dead expandWorldStateAgent and both preview copies converge on the corrected renderer instead of being patched separately.

Add to Affected files: packages/server/src/routes/chats.routes.ts.

Add a test-plan item (leave unchecked): "Manually verify POST /:id/peek-prompt tracker output matches the real generated prompt for a world-state+quest chat that has an active quest with all objectives complete (it must appear, identically, in both)."

Non-blocking note: compactQuestProgressForContext also has live consumers at agent-executor.ts:158 and :1353 (via compactQuestPlayerStatsForContext); fixing Bug 1 in the shared util — as already proposed — correctly covers them.

<!-- gh-comment-id:4761102853 --> @kolacheee commented on GitHub (Jun 21, 2026): > **Veracity self-review — correction / clarification** > _Automated post-filing review of this issue against the current working tree. The reported bug remains valid; the notes below refine its scope, accuracy, or suggested fix for whoever implements it._ Scope/fix correction for Bug 6 — the dry-run route is NOT the only divergent preview renderer, and there is a second uncited offender. `formatPeekTrackerContextBlock` in `packages/server/src/routes/chats.routes.ts` (defined L226-347, invoked at L2072 for the `POST /:id/peek-prompt` route at L1565, whose response `source` is `"live_preview"` at L2087) is a second tracker-context preview renderer with the same intended-mirror-but-divergent contract: its caller comment at L2061 says it must "mirror the read-only snapshot injection from /api/generate." How it diverges from the real generation path (`injectCommittedTrackerContext`): - NON-lossy, unlike generation: it iterates `stats.activeQuests` directly with NO `compactQuestProgressForContext` (L298), so it keeps active-but-all-objectives-done quests (Bug 1) and renders `q.completed ? " (completed)"` (L303) plus real `[x]`/`[ ]` objective state (L301) that generation strips/hides (Bug 2). - Shares Bug 4 (`- ${c.emoji ?? ""} ${c.name ?? c}` at L270 → `[object Object]` for a nameless present character). - Shares Bug 5 (`- ${b.name}: ${b.value}/${b.max}` at L283, and `${s.value}` at L317 — no finite-number guard). Note one distinction from dry-run: peek IS gated by active agents (L234-240, and the caller guards on `chatEnableAgents`/`activeAgentIds` at L2069), whereas dry-run's `formatTrackersContextBlock` is UNGATED — so they are not identical. dry-run diverges on BOTH gating and lossiness; peek diverges only on lossiness + the malformed-row bugs. Consequence for the suggested fix: the framing "`injectCommittedTrackerContext` … is the sole live tracker-context renderer" and Fix #6 ("Delete the dry-run copy and call the shared `injectCommittedTrackerContext`") are incomplete. Deleting only the dry-run copy leaves peek-prompt divergent, so the reported "preview doesn't match what is actually sent" symptom persists for the peek path. Revised Fix #6: route BOTH preview renderers — dry-run `formatTrackersContextBlock` AND chats `formatPeekTrackerContextBlock` — through the shared `injectCommittedTrackerContext` (or a shared block-builder extracted from it) so all three paths share one lossy-or-corrected implementation. When implementing Fixes 1+2 (stop dropping active-but-all-done quests; render real `[x]`/`[ ]`), make the dead `expandWorldStateAgent` and both preview copies converge on the corrected renderer instead of being patched separately. Add to Affected files: `packages/server/src/routes/chats.routes.ts`. Add a test-plan item (leave unchecked): "Manually verify `POST /:id/peek-prompt` tracker output matches the real generated prompt for a world-state+quest chat that has an active quest with all objectives complete (it must appear, identically, in both)." Non-blocking note: `compactQuestProgressForContext` also has live consumers at `agent-executor.ts:158` and `:1353` (via `compactQuestPlayerStatsForContext`); fixing Bug 1 in the shared util — as already proposed — correctly covers them.
Author
Owner

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

Fixed in 2d238ae2. Active-but-open quests now stay in committed context with their full objective list, objectives render real [x]/[ ] state, malformed character/stat rows are guarded against [object Object] and undefined/undefined output, dry-run and peek-prompt now route through the shared committed tracker context renderer with real active-agent gating, and the unreachable world-state marker renderer was removed.

<!-- gh-comment-id:4761779558 --> @SpicyMarinara commented on GitHub (Jun 21, 2026): Fixed in 2d238ae2. Active-but-open quests now stay in committed context with their full objective list, objectives render real [x]/[ ] state, malformed character/stat rows are guarded against [object Object] and undefined/undefined output, dry-run and peek-prompt now route through the shared committed tracker context renderer with real active-agent gating, and the unreachable world-state marker renderer was removed.
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#1367
No description provided.