[PR #1193] [MERGED] Surface failed agents in generation hot path #4969

Closed
opened 2026-10-22 04:12:07 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/1193
Author: @Romuromylus
Created: 5/25/2026
Status: ✅ Merged
Merged: 5/25/2026
Merged by: @Romuromylus

Base: refactor ← Head: fix/surface-failed-agents


📝 Commits (3)

  • bdc18ad Surface failed agents in generation hot path
  • 72ce2d8 Merge branch 'refactor' into fix/surface-failed-agents
  • 26cfb46 Scope retryAgents failure clear to retried types only

📊 Changes

2 files changed (+32 additions, -3 deletions)

View changed files

📝 src/features/runtime/generation/hooks/use-generate.ts (+22 -3)
📝 src/shared/stores/agent.store.ts (+10 -0)

📄 Description

Why this change

Closes #1192.

When an agent generation fails (provider 4xx, timeout, malformed output, anything that sets result.success: false), the failure is invisible in the UI. The existing empty-state panels render and no toast, badge, or retry surface appears. The store fields and UI consumers for failed agents already exist (failedAgentTypes, failedAgentFailures, the amber dot on the Agents nav button, RoleplayHUDActionsMenu's retry block, use-chat-timeline-actions retry handler) but nothing in the per-turn hot path ever populated them. applyAgentResultEffects would addResult to the per-agent map, then short-circuit on !result.success before any failure surface was touched. The only caller of clearFailedAgentTypes was the retryAgents flow, so the arrays stayed empty in normal usage.

This wasn't a regression — the gap has been there since the failure-arrays plumbing was added. The #1191 avatar-bloat fix removed one common trigger for silent agent failures, but the silent-failure shape itself stays open for any future cause (rate limits, auth errors, timeouts, malformed output), so closing the gap now keeps the original report from drifting.

What changed

  • src/shared/stores/agent.store.ts: add addFailedAgentFailure(failure) action. Dedupes by agentType so the same agent failing again on a later turn or a re-retry replaces the prior entry instead of stacking.
  • src/features/runtime/generation/hooks/use-generate.ts:
    • In applyAgentResultEffects, push the failure before the early return on !result.success. Uses toAgentFailure from shared/lib/agent-failures.ts so reasonLabel ("Context limit", "Timeout", "Rate limit", "Authentication", ...) is classified from the provider error string, which is what the retry block uses for human-readable copy.
    • In runGenerationWithUi, clear the failed-agent arrays at turn start so stale failures don't bleed across turns.
    • In retryAgents, replace the after-loop clearFailedAgentTypes() with a scoped clear at the top. If agentTypes is provided, only entries whose agentType is in that set are removed — the rest stay visible. If agentTypes is omitted (full retry), keep the existing full clear. This matters for the per-agent rerun buttons (illustrator/cyoa/lorebook-keeper/per-tracker) called from GameSurface, CyoaChoices, ChatSettingsDrawer, SecretPlotPanel, ContextInjectionPanel, and use-tracker-rerun: a successful targeted retry now leaves prior-turn failures for other agents visible instead of wiping them. The "Retry Failed Agents" all-button case (use-chat-timeline-actions.ts:377, passes the full failedAgentTypes) is functionally equivalent under either clear scope.

No UI work required — the existing consumers (PanelNavButtons badge, RoleplayHUDActionsMenu retry section, use-chat-timeline-actions handleRetryFailedAgents) all read from the store and react automatically.

Verification

  • pnpm check passes locally (architecture + frontend TS + cargo check + docs check).
  • Browser fast path (pnpm dev + Vite at localhost:1420): injected synthetic failures via useAgentStore.getState().addFailedAgentFailure(toAgentFailure({...})) for character-tracker (prompt-too-long), world-state (timeout), and illustrator (rate limit). Confirmed dedupe by agentType works, reasonLabel resolves correctly ("Context limit", "Timeout", "Rate limit"), and the amber failed-agent dot lights up on the Agents nav button. Then simulated a targeted retry of ["illustrator"]: the scoped-clear filter removed only the illustrator entry and the remaining two failures + the dot stayed visible. Untargeted retry (no agentTypes) clears everything as before. clearFailedAgentTypes() resets both arrays and the dot disappears.
  • Not yet verified in pnpm tauri dev: the real end-to-end repro path (trigger an actual provider failure in the desktop shell and confirm the retry block + retry button work). Will run that pass before promoting this PR out of draft.

Risk

  • Touches the per-turn hot path in applyAgentResultEffects, which is shared by chat / roleplay / game modes. Only adds a store write on the already-existing failure short-circuit, so behavior for successful results is unchanged.
  • retryAgents clear semantics changed from "always clear everything before the retry" to "scoped clear" when a targeted agentTypes list is supplied. This is a behavior change for the per-agent rerun buttons, but it's the intended one — without it, a successful targeted retry would hide prior-turn failures for agents that weren't even re-run.
  • The dedupe-by-agentType in addFailedAgentFailure overwrites a prior entry of the same type. The current agent runtime is one-per-type per turn, so this is correct; if a future change ever fans out per-character trackers under a single type, the dedupe would need to switch to a composite key.

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced tracking of agent failures during content generation for more accurate error reporting
    • Improved retry mechanism with support for targeted retries of specific agents
    • Refined failure history management to preserve prior failures when retrying individual agents

Review Change Stack


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/1193 **Author:** [@Romuromylus](https://github.com/Romuromylus) **Created:** 5/25/2026 **Status:** ✅ Merged **Merged:** 5/25/2026 **Merged by:** [@Romuromylus](https://github.com/Romuromylus) **Base:** `refactor` ← **Head:** `fix/surface-failed-agents` --- ### 📝 Commits (3) - [`bdc18ad`](https://github.com/Pasta-Devs/Marinara-Engine/commit/bdc18ad54e4eb47e4945275647aacf7383af82fa) Surface failed agents in generation hot path - [`72ce2d8`](https://github.com/Pasta-Devs/Marinara-Engine/commit/72ce2d84f1a91c7ca2b734754752b41e907c0a1f) Merge branch 'refactor' into fix/surface-failed-agents - [`26cfb46`](https://github.com/Pasta-Devs/Marinara-Engine/commit/26cfb462a88a77ec01ea33a3d882a640b12ec18d) Scope retryAgents failure clear to retried types only ### 📊 Changes **2 files changed** (+32 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `src/features/runtime/generation/hooks/use-generate.ts` (+22 -3) 📝 `src/shared/stores/agent.store.ts` (+10 -0) </details> ### 📄 Description ## Why this change Closes #1192. When an agent generation fails (provider 4xx, timeout, malformed output, anything that sets `result.success: false`), the failure is invisible in the UI. The existing empty-state panels render and no toast, badge, or retry surface appears. The store fields and UI consumers for failed agents already exist (`failedAgentTypes`, `failedAgentFailures`, the amber dot on the Agents nav button, `RoleplayHUDActionsMenu`'s retry block, `use-chat-timeline-actions` retry handler) but nothing in the per-turn hot path ever populated them. `applyAgentResultEffects` would `addResult` to the per-agent map, then short-circuit on `!result.success` before any failure surface was touched. The only caller of `clearFailedAgentTypes` was the `retryAgents` flow, so the arrays stayed empty in normal usage. This wasn't a regression — the gap has been there since the failure-arrays plumbing was added. The #1191 avatar-bloat fix removed one common trigger for silent agent failures, but the silent-failure shape itself stays open for any future cause (rate limits, auth errors, timeouts, malformed output), so closing the gap now keeps the original report from drifting. ## What changed - `src/shared/stores/agent.store.ts`: add `addFailedAgentFailure(failure)` action. Dedupes by `agentType` so the same agent failing again on a later turn or a re-retry replaces the prior entry instead of stacking. - `src/features/runtime/generation/hooks/use-generate.ts`: - In `applyAgentResultEffects`, push the failure before the early return on `!result.success`. Uses `toAgentFailure` from `shared/lib/agent-failures.ts` so `reasonLabel` ("Context limit", "Timeout", "Rate limit", "Authentication", ...) is classified from the provider error string, which is what the retry block uses for human-readable copy. - In `runGenerationWithUi`, clear the failed-agent arrays at turn start so stale failures don't bleed across turns. - In `retryAgents`, replace the after-loop `clearFailedAgentTypes()` with a scoped clear at the top. If `agentTypes` is provided, only entries whose `agentType` is in that set are removed — the rest stay visible. If `agentTypes` is omitted (full retry), keep the existing full clear. This matters for the per-agent rerun buttons (illustrator/cyoa/lorebook-keeper/per-tracker) called from `GameSurface`, `CyoaChoices`, `ChatSettingsDrawer`, `SecretPlotPanel`, `ContextInjectionPanel`, and `use-tracker-rerun`: a successful targeted retry now leaves prior-turn failures for other agents visible instead of wiping them. The "Retry Failed Agents" all-button case (`use-chat-timeline-actions.ts:377`, passes the full `failedAgentTypes`) is functionally equivalent under either clear scope. No UI work required — the existing consumers (`PanelNavButtons` badge, `RoleplayHUDActionsMenu` retry section, `use-chat-timeline-actions` `handleRetryFailedAgents`) all read from the store and react automatically. ## Verification - `pnpm check` passes locally (architecture + frontend TS + cargo check + docs check). - Browser fast path (`pnpm dev` + Vite at `localhost:1420`): injected synthetic failures via `useAgentStore.getState().addFailedAgentFailure(toAgentFailure({...}))` for `character-tracker` (prompt-too-long), `world-state` (timeout), and `illustrator` (rate limit). Confirmed dedupe by `agentType` works, `reasonLabel` resolves correctly ("Context limit", "Timeout", "Rate limit"), and the amber failed-agent dot lights up on the Agents nav button. Then simulated a targeted retry of `["illustrator"]`: the scoped-clear filter removed only the illustrator entry and the remaining two failures + the dot stayed visible. Untargeted retry (no `agentTypes`) clears everything as before. `clearFailedAgentTypes()` resets both arrays and the dot disappears. - Not yet verified in `pnpm tauri dev`: the real end-to-end repro path (trigger an actual provider failure in the desktop shell and confirm the retry block + retry button work). Will run that pass before promoting this PR out of draft. ## Risk - Touches the per-turn hot path in `applyAgentResultEffects`, which is shared by chat / roleplay / game modes. Only adds a store write on the already-existing failure short-circuit, so behavior for successful results is unchanged. - `retryAgents` clear semantics changed from "always clear everything before the retry" to "scoped clear" when a targeted `agentTypes` list is supplied. This is a behavior change for the per-agent rerun buttons, but it's the intended one — without it, a successful targeted retry would hide prior-turn failures for agents that weren't even re-run. - The dedupe-by-`agentType` in `addFailedAgentFailure` overwrites a prior entry of the same type. The current agent runtime is one-per-type per turn, so this is correct; if a future change ever fans out per-character trackers under a single type, the dedupe would need to switch to a composite key. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Enhanced tracking of agent failures during content generation for more accurate error reporting * Improved retry mechanism with support for targeted retries of specific agents * Refined failure history management to preserve prior failures when retrying individual agents <!-- review_stack_entry_start --> [![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/Pasta-Devs/Marinara-Engine/pull/1193?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack) <!-- review_stack_entry_end --> <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:12:07 +07:00
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#4969
No description provided.