[GH-ISSUE #2729] [Issue]: Tracker re-run (retry-agents) diverges from first-generation — quest auto-remove and capability gate skipped #1373

Closed
opened 2026-10-21 05:32:34 +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/2729

Originally assigned to: @SpicyMarinara on GitHub.

Summary

The retry-agents (re-run / Retry button) path is a second, divergent copy of the tracker-persistence pipeline that does not match first-generation semantics. It omits the autoRemoveFullyCompleted option so re-running the quest tracker keeps fully-completed quests the first-gen path drops, and it omits the customAgentCanApplyResult / customAgentCanEmitResult capability gates so an unauthorized custom agent can write and leak tracker state on retry that it is blocked from writing on first-gen. Both produce state that differs depending on whether an agent ran during generation or via re-run, corrupting the committed snapshot that feeds the next prompt. Root cause: duplicated logic that drifted from the main route.


Bug 1 — Quest re-run does not auto-remove fully-completed quests (medium)

How it breaks the pipeline: The main route calls applyQuestUpdatesToPlayerStats(existingPS, updates, { autoRemoveFullyCompleted: true }); the retry route passes NO options, and the option defaults to false. So a quest the model marks fully complete is removed on first-gen but retained on re-run, sticking in the Active Quests panel as stale data.

Steps to replicate: Re-run the quest tracker on a turn where the model marks a quest fully complete; the completed quest reappears/sticks in Active Quests (vs first-gen which drops it).

Code trace: main generate.routes.ts:8059-8061 ({ autoRemoveFullyCompleted: true }); retry retry-agents-route.ts:2289 (no options); option default + gated removal quest-state.ts:240,271-281; persisted via buildLockedPlayerStatsArrayPatch (generate-route-utils.ts:86-109) then retry-agents-route.ts:2297-2303.

Bug 2 — Retry route bypasses the edit_trackers capability gate (medium)

How it breaks the pipeline: Every tracker persistence/emit block in the main route is gated by customAgentCanApplyResult(result,...,'edit_trackers') and customAgentCanEmitResult. applyRetryResultEffects has NO such gate on ANY tracker block, so a custom agent that emits a tracker result type but lacks edit_trackers (blocked on first-gen) silently overwrites GameState (presentCharacters, personaStats/status/inventory, customTrackerFields, activeQuests, world fields) and leaks the result to the client on Retry/re-run.

Steps to replicate: Configure (via the agent create/update API or import) a custom agent with resultType of a tracker type but without the edit_trackers capability; on first-gen it writes nothing, but clicking Retry on it persists and emits tracker state.

Code trace: main guards generate.routes.ts:7511-7516,7652-7657,7924-7929,7989-7994,8033-8038, emit :4613,4618; helpers :383-419, builtInAgentTypes :3409. Retry has zero capability checks (grep finds none): persistence blocks retry-agents-route.ts:2084-2123,2163-2207,2209-2237,2276-2310,2349-2374 gated only on result.success && result.type && result.data; unconditional emit loop :2986-3001. Reachable: resolveAgentResultType returns configured settings.resultType (agent-executor.ts:1864-1871); no capability filter at resolution.


Suggested Fix

  • Pass { autoRemoveFullyCompleted: true } to applyQuestUpdatesToPlayerStats in retry-agents-route.ts:2289 (or extract a shared helper so the two paths cannot drift). (Bug 1.)
  • Thread builtInAgentTypes (or a canApplyTracker(result) predicate) into applyRetryResultEffects and gate every tracker persistence block with customAgentCanApplyResult(result, resolvedAgents, builtInAgentTypes, 'edit_trackers'); gate the agent_result/game_state_patch sends with customAgentCanEmitResult. (Bug 2.)
  • Longer term, factor the tracker persistence/emit into one shared module used by both generate.routes.ts and retry-agents-route.ts so semantics and permission gates cannot diverge.

Template checklist

  • pnpm check passes (TypeScript + ESLint)
  • Manually verify re-running the quest tracker drops a fully-completed quest, matching first-gen
  • Manually verify a custom agent without edit_trackers cannot write/emit tracker state on Retry
  • Manually verify first-gen and re-run produce identical tracker state for the same agent output

Affected files

  • packages/server/src/routes/generate/retry-agents-route.ts
  • packages/server/src/routes/generate.routes.ts
  • packages/shared/src/utils/quest-state.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: MEDIUM. 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/2729 Originally assigned to: @SpicyMarinara on GitHub. ## Summary The retry-agents (re-run / Retry button) path is a second, divergent copy of the tracker-persistence pipeline that does not match first-generation semantics. It omits the `autoRemoveFullyCompleted` option so re-running the quest tracker keeps fully-completed quests the first-gen path drops, and it omits the `customAgentCanApplyResult` / `customAgentCanEmitResult` capability gates so an unauthorized custom agent can write and leak tracker state on retry that it is blocked from writing on first-gen. Both produce state that differs depending on whether an agent ran during generation or via re-run, corrupting the committed snapshot that feeds the next prompt. Root cause: duplicated logic that drifted from the main route. --- ### Bug 1 — Quest re-run does not auto-remove fully-completed quests (medium) **How it breaks the pipeline:** The main route calls `applyQuestUpdatesToPlayerStats(existingPS, updates, { autoRemoveFullyCompleted: true })`; the retry route passes NO options, and the option defaults to false. So a quest the model marks fully complete is removed on first-gen but retained on re-run, sticking in the Active Quests panel as stale data. **Steps to replicate:** Re-run the quest tracker on a turn where the model marks a quest fully complete; the completed quest reappears/sticks in Active Quests (vs first-gen which drops it). **Code trace:** main `generate.routes.ts:8059-8061` (`{ autoRemoveFullyCompleted: true }`); retry `retry-agents-route.ts:2289` (no options); option default + gated removal `quest-state.ts:240,271-281`; persisted via `buildLockedPlayerStatsArrayPatch` (`generate-route-utils.ts:86-109`) then `retry-agents-route.ts:2297-2303`. ### Bug 2 — Retry route bypasses the edit_trackers capability gate (medium) **How it breaks the pipeline:** Every tracker persistence/emit block in the main route is gated by `customAgentCanApplyResult(result,...,'edit_trackers')` and `customAgentCanEmitResult`. `applyRetryResultEffects` has NO such gate on ANY tracker block, so a custom agent that emits a tracker result type but lacks `edit_trackers` (blocked on first-gen) silently overwrites GameState (presentCharacters, personaStats/status/inventory, customTrackerFields, activeQuests, world fields) and leaks the result to the client on Retry/re-run. **Steps to replicate:** Configure (via the agent create/update API or import) a custom agent with `resultType` of a tracker type but without the `edit_trackers` capability; on first-gen it writes nothing, but clicking Retry on it persists and emits tracker state. **Code trace:** main guards `generate.routes.ts:7511-7516,7652-7657,7924-7929,7989-7994,8033-8038`, emit `:4613,4618`; helpers `:383-419`, `builtInAgentTypes :3409`. Retry has zero capability checks (grep finds none): persistence blocks `retry-agents-route.ts:2084-2123,2163-2207,2209-2237,2276-2310,2349-2374` gated only on `result.success && result.type && result.data`; unconditional emit loop `:2986-3001`. Reachable: `resolveAgentResultType` returns configured `settings.resultType` (`agent-executor.ts:1864-1871`); no capability filter at resolution. --- ## Suggested Fix - Pass `{ autoRemoveFullyCompleted: true }` to `applyQuestUpdatesToPlayerStats` in `retry-agents-route.ts:2289` (or extract a shared helper so the two paths cannot drift). (Bug 1.) - Thread `builtInAgentTypes` (or a `canApplyTracker(result)` predicate) into `applyRetryResultEffects` and gate every tracker persistence block with `customAgentCanApplyResult(result, resolvedAgents, builtInAgentTypes, 'edit_trackers')`; gate the `agent_result`/`game_state_patch` sends with `customAgentCanEmitResult`. (Bug 2.) - Longer term, factor the tracker persistence/emit into one shared module used by both `generate.routes.ts` and `retry-agents-route.ts` so semantics and permission gates cannot diverge. --- ## Template checklist - [ ] `pnpm check` passes (TypeScript + ESLint) - [ ] Manually verify re-running the quest tracker drops a fully-completed quest, matching first-gen - [ ] Manually verify a custom agent without `edit_trackers` cannot write/emit tracker state on Retry - [ ] Manually verify first-gen and re-run produce identical tracker state for the same agent output --- ### Affected files - `packages/server/src/routes/generate/retry-agents-route.ts` - `packages/server/src/routes/generate.routes.ts` - `packages/shared/src/utils/quest-state.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: **MEDIUM**. 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

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

Fixed in 1915404a.\n\nVerified against current code and addressed the still-valid retry-route drift:\n- retry quest updates now pass autoRemoveFullyCompleted: true, matching first-generation behavior\n- retry tracker persistence for world-state, character, persona, quest, and custom tracker results is now gated by edit_trackers for custom agents\n- retry agent_result emission is filtered through the same result-type capability model so unauthorized tracker output is not streamed to the client\n\nSkipped unrelated retry lorebook wording/behavior churn because this issue is specifically about tracker retry semantics. Per maintainer request, pnpm validation is deferred until the sweep is complete.

<!-- gh-comment-id:4761860875 --> @SpicyMarinara commented on GitHub (Jun 21, 2026): Fixed in 1915404a.\n\nVerified against current code and addressed the still-valid retry-route drift:\n- retry quest updates now pass autoRemoveFullyCompleted: true, matching first-generation behavior\n- retry tracker persistence for world-state, character, persona, quest, and custom tracker results is now gated by edit_trackers for custom agents\n- retry agent_result emission is filtered through the same result-type capability model so unauthorized tracker output is not streamed to the client\n\nSkipped unrelated retry lorebook wording/behavior churn because this issue is specifically about tracker retry semantics. Per maintainer request, pnpm validation is deferred until the sweep is complete.
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#1373
No description provided.