[GH-ISSUE #2371] [Issue]: retryAgents drops the pre-retry game-state flush — manual tracker edits lost on Re-run Trackers / Retry Failed Agents from the roleplay HUD #1171

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

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

Originally assigned to: @Romuromylus on GitHub.

Summary

Severity: Medium — data-loss (regression vs main). The refactor's retryAgents no longer flushes pending manual tracker edits before re-running agents. The roleplay HUD's "Re-run Trackers", "Retry Failed Agents", and per-agent "Re-run" actions all call retryAgents with an unflushed, debounced manual edit still in memory, so the regenerated snapshot merges on top of the stale pre-edit chat.gameState and silently discards the user's edit. Main flushes first.

Expected behavior

Re-running trackers / retrying agents from the roleplay HUD should first flush any pending manual tracker edit (location/date/weather/forecast, a player/NPC stat, persona inventory, custom section) so the regeneration merges on top of the user's edit, not on top of the stale baseline. Main does this — retryAgents flushes internally and treats a failed flush as a hard error that aborts the retry.

Actual behavior

A manual tracker override is queued into the debounced patcher (src/features/runtime/world-state/.../use-world-state-patcher.ts, PATCH_DEBOUNCE_MS = 500) and only written back to chat.gameState on the debounce. The refactor's retryAgents (src/features/runtime/generation/hooks/use-generate.ts:1819-1900) has no flushPatch call before retryGenerationAgents — flushPatch appears nowhere under src/features/runtime/generation.

The roleplay HUD actions menu exposes (via use-chat-timeline-actions.ts):

  • handleRetryFailedAgents (:458)
  • handleRetryAgent (:463)
  • handleRerunTrackers (:472)
  • handleRerunSingleTracker (:479)

All call retryAgents() without flushing. retryGenerationAgents (src/engine/generation/start-generation.ts:2651) then reloads the chat from storage and persistTrackerSnapshotForTurn (tracker-snapshots.ts:495-503) merges agent output on top of the storage-persisted chat.gameState baseline — never the in-memory pending patch. So a manual edit made within the ~500ms debounce window is overwritten by the regenerated snapshot.

The per-section rerun via useTrackerRerun is exempt because that hook flushes explicitly (use-tracker-rerun.ts:36), and the timeline actions (delete/swipe/regen) flush via flushTrackerPatchesForTimelineAction — which is what makes this gap easy to miss. Only the actions-menu / failed-agent retry handlers regressed.

Steps to reproduce

  1. Start a roleplay chat with the tracker HUD visible.
  2. Edit any tracker field (type a new Location, or bump an NPC/player stat).
  3. Within ~500ms, open the Agents/Actions menu in the HUD and click "Re-run Trackers" (or "Retry Failed Agents", or a per-agent "Re-run").
  4. The manual edit is gone — overwritten by the regenerated snapshot. On main the same sequence preserves the edit.

Impact area

  • Roleplay mode
  • Runtime systems: generation, world-state, visuals, tracker, or haptics
  • Shared mode UI

Environment

  • Branch or commit: refactor @ 330f69a8
  • Run mode: Tauri desktop (applies to both desktop and web shell)
  • OS + version: not relevant (static source audit)
  • Node + pnpm versions: not relevant
  • Rust version, if relevant: not relevant
  • Remote Runtime URL configured? not relevant
  • Provider, model, or integration, if relevant: not relevant

Logs, screenshots, or video

Static source audit, cited to src/features/runtime/generation/hooks/use-generate.ts:1819-1900 and src/features/modes/shared/chat-ui/hooks/use-chat-timeline-actions.ts:458-479.

Regression notes

Regression vs main — worked on main, broken on refactor. Main's retryAgents (packages/client/src/hooks/use-generate.ts:1847-1853) flushes pending game-state edits internally before the retry and throws on flush failure; main's callers (ChatArea.tsx:968-991) call retryAgents raw and rely on that centralized flush. The refactor relocated the flush to only a subset of callers (per-section rerun + timeline actions) and left the HUD actions-menu retry handlers unflushed.

Additional context

Fix sketch: restore the flush inside the refactor's retryAgents (cleanest — one site covers all four handlers), mirroring main:

const flushPatch = useGameStateStore.getState().flushPatch; // or the world-state store's flush
if (flushPatch) {
  try { await flushPatch(); }
  catch (e) { throw new Error("Failed to flush pending game-state edits", { cause: e }); }
}

Place it after setProcessing(true) and before retryGenerationAgents. The already-correct per-section useTrackerRerun path is unaffected.

Not a duplicate of #2317 (pins nulled every turn, fixed), #2327 (a concurrent turn completing during the debounce — a different trigger), or #2294 (avatar toggle).

Template check

  • I DID NOT read this template and provide the requested details.
Originally created by @Romuromylus on GitHub (Jun 5, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2371 Originally assigned to: @Romuromylus on GitHub. ## Summary **Severity: Medium — data-loss (regression vs main).** The refactor's `retryAgents` no longer flushes pending manual tracker edits before re-running agents. The roleplay HUD's "Re-run Trackers", "Retry Failed Agents", and per-agent "Re-run" actions all call `retryAgents` with an unflushed, debounced manual edit still in memory, so the regenerated snapshot merges on top of the stale pre-edit `chat.gameState` and silently discards the user's edit. Main flushes first. ## Expected behavior Re-running trackers / retrying agents from the roleplay HUD should first flush any pending manual tracker edit (location/date/weather/forecast, a player/NPC stat, persona inventory, custom section) so the regeneration merges on top of the user's edit, not on top of the stale baseline. Main does this — `retryAgents` flushes internally and treats a failed flush as a hard error that aborts the retry. ## Actual behavior A manual tracker override is queued into the debounced patcher (`src/features/runtime/world-state/.../use-world-state-patcher.ts`, `PATCH_DEBOUNCE_MS = 500`) and only written back to `chat.gameState` on the debounce. The refactor's `retryAgents` (`src/features/runtime/generation/hooks/use-generate.ts:1819-1900`) has no `flushPatch` call before `retryGenerationAgents` — `flushPatch` appears nowhere under `src/features/runtime/generation`. The roleplay HUD actions menu exposes (via `use-chat-timeline-actions.ts`): - `handleRetryFailedAgents` (`:458`) - `handleRetryAgent` (`:463`) - `handleRerunTrackers` (`:472`) - `handleRerunSingleTracker` (`:479`) All call `retryAgents()` without flushing. `retryGenerationAgents` (`src/engine/generation/start-generation.ts:2651`) then reloads the chat from storage and `persistTrackerSnapshotForTurn` (`tracker-snapshots.ts:495-503`) merges agent output on top of the storage-persisted `chat.gameState` baseline — never the in-memory pending patch. So a manual edit made within the ~500ms debounce window is overwritten by the regenerated snapshot. The per-**section** rerun via `useTrackerRerun` is exempt because that hook flushes explicitly (`use-tracker-rerun.ts:36`), and the timeline actions (delete/swipe/regen) flush via `flushTrackerPatchesForTimelineAction` — which is what makes this gap easy to miss. Only the actions-menu / failed-agent retry handlers regressed. ## Steps to reproduce 1. Start a roleplay chat with the tracker HUD visible. 2. Edit any tracker field (type a new Location, or bump an NPC/player stat). 3. Within ~500ms, open the Agents/Actions menu in the HUD and click "Re-run Trackers" (or "Retry Failed Agents", or a per-agent "Re-run"). 4. The manual edit is gone — overwritten by the regenerated snapshot. On main the same sequence preserves the edit. ## Impact area - [x] Roleplay mode - [x] Runtime systems: generation, world-state, visuals, tracker, or haptics - [x] Shared mode UI ## Environment - Branch or commit: refactor @ 330f69a8 - Run mode: Tauri desktop (applies to both desktop and web shell) - OS + version: not relevant (static source audit) - Node + pnpm versions: not relevant - Rust version, if relevant: not relevant - Remote Runtime URL configured? not relevant - Provider, model, or integration, if relevant: not relevant ## Logs, screenshots, or video Static source audit, cited to `src/features/runtime/generation/hooks/use-generate.ts:1819-1900` and `src/features/modes/shared/chat-ui/hooks/use-chat-timeline-actions.ts:458-479`. ## Regression notes Regression vs main — worked on main, broken on refactor. Main's `retryAgents` (`packages/client/src/hooks/use-generate.ts:1847-1853`) flushes pending game-state edits internally before the retry and throws on flush failure; main's callers (`ChatArea.tsx:968-991`) call `retryAgents` raw and rely on that centralized flush. The refactor relocated the flush to only a subset of callers (per-section rerun + timeline actions) and left the HUD actions-menu retry handlers unflushed. ## Additional context Fix sketch: restore the flush inside the refactor's `retryAgents` (cleanest — one site covers all four handlers), mirroring main: ```ts const flushPatch = useGameStateStore.getState().flushPatch; // or the world-state store's flush if (flushPatch) { try { await flushPatch(); } catch (e) { throw new Error("Failed to flush pending game-state edits", { cause: e }); } } ``` Place it after `setProcessing(true)` and before `retryGenerationAgents`. The already-correct per-section `useTrackerRerun` path is unaffected. Not a duplicate of #2317 (pins nulled every turn, fixed), #2327 (a concurrent turn completing during the debounce — a different trigger), or #2294 (avatar toggle). ## Template check - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:28:18 +07:00
Author
Owner

@Romuromylus commented on GitHub (Jun 5, 2026):

Compounds with #2370: both wipe roleplay tracker data, and a single "Re-run Trackers" click can trigger both at once — this issue discards the pending manual edit, then #2370's unguarded merge can additionally clear inventory/stat bars/status if the re-run agent returns an empty array. Worth fixing together since both live on the tracker re-run path.

<!-- gh-comment-id:4635503465 --> @Romuromylus commented on GitHub (Jun 5, 2026): Compounds with #2370: both wipe roleplay tracker data, and a single "Re-run Trackers" click can trigger both at once — this issue discards the pending manual edit, then #2370's unguarded merge can additionally clear inventory/stat bars/status if the re-run agent returns an empty array. Worth fixing together since both live on the tracker re-run path.
Author
Owner

@Romuromylus commented on GitHub (Jun 6, 2026):

Fixed by #2429, merged into refactor.

<!-- gh-comment-id:4637949999 --> @Romuromylus commented on GitHub (Jun 6, 2026): Fixed by #2429, merged into `refactor`.
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#1171
No description provided.