[GH-ISSUE #2988] [Issue]: Regeneration aborts on any non-critical pre-gen agent failure, while a fresh message continues (mismatched failure gates) #1561

Closed
opened 2026-10-21 05:39:10 +07:00 by bsakaguchi · 1 comment
Owner

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

Originally assigned to: @SpicyMarinara on GitHub.

What's wrong
The fresh-message pre-generation failure gate treats only secret_plot failures as critical and lets generation continue past every other failed pre-gen agent. The regeneration gate — despite a comment claiming it is "the same as the new-message path" — treats EVERY failed pre-gen agent (except knowledge-retrieval, knowledge-router, secret-plot-driver) as fatal and aborts the whole regeneration with a user-facing error. So the exact same transient failure (e.g. a pre_generation Director or a custom context_injection agent hitting a rate-limit/timeout/parse error) silently continues on a fresh message but hard-fails a regeneration.

How to reproduce (try it yourself)

  1. Configure a pre_generation-phase agent that is not secret_plot (e.g. Narrative Director in pre_generation, or a custom context_injection agent).
  2. Ensure the regen path re-runs pre-gen (no cached contextInjections for that swipe — e.g. the original generation produced no cached injections).
  3. Cause that agent's LLM call to fail once (rate limit / timeout / invalid JSON).
  4. Send a fresh message, then separately regenerate a message under the same failing condition.

You'll see: the fresh message proceeds (failure logged as non-critical); the regeneration aborts with "Pre-generation agent(s) failed (...): ... Please try again."
Expected: both degrade gracefully the same way — only a critical (secret_plot) failure should abort.

Where it is
packages/server/src/routes/generate.routes.ts:5671-5690 (regen gate) vs :5512-5527 (fresh gate).

What's happening
There are two separate failure-gate implementations with mismatched criticality definitions. The fresh path classifies criticality by RESULT type (!success && r.type === "secret_plot"). The regen path uses an allowlist by AGENT type (only knowledge-retrieval/knowledge-router/secret-plot-driver are non-fatal), so every other pre-gen failure aborts. The misleading "same as the new-message path" comment masks the divergence.

Suggested fix
Make the regen gate mirror the fresh gate's criticality classification. Replace the body at generate.routes.ts:5671-5690:

  const regenPreGenResults = pipeline.results.filter(
    (r) =>
      r.agentType !== "knowledge-retrieval" &&
      r.agentType !== "knowledge-router" &&
      r.agentType !== "secret-plot-driver",
  );
  const criticalFailedRegen = regenPreGenResults.filter((r) => !r.success && r.type === "secret_plot");
  const nonCriticalFailedRegen = regenPreGenResults.filter((r) => !r.success && r.type !== "secret_plot");
  if (criticalFailedRegen.length > 0) {
    const failedNames = criticalFailedRegen.map((r) => r.agentType).join(", ");
    const firstError = criticalFailedRegen[0]!.error ?? "unknown error";
    logger.error(`[pre-gen] FATAL: critical agent(s) failed on regen (${failedNames}) — aborting generation`);
    sendSseEvent(reply, {
      type: "error",
      data: `Critical pre-generation agent failed (${failedNames}): ${firstError}. Please try again.`,
    });
    return;
  }
  if (nonCriticalFailedRegen.length > 0) {
    const failedNames = nonCriticalFailedRegen.map((r) => r.agentType).join(", ");
    logger.warn(`[pre-gen] Non-critical agent(s) failed on regen (${failedNames}) — continuing generation`);
  }

No regression: secret_plot never runs on the regen path (the secret-plot agent is gated on !regenerateMessageId and excluded from the regen pre-gen filter), so criticalFailedRegen is always empty there and the gate becomes a correct warn-only no-op; continuing past a non-critical failure is already safe because injection-building skips !success results. Recommended: extract a shared const isCriticalPreGenFailure = (r) => !r.success && r.type === "secret_plot"; and use it in both gates so they cannot drift again.


AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.

Originally created by @kolacheee on GitHub (Jun 29, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2988 Originally assigned to: @SpicyMarinara on GitHub. **What's wrong** The fresh-message pre-generation failure gate treats only secret_plot failures as critical and lets generation continue past every other failed pre-gen agent. The regeneration gate — despite a comment claiming it is "the same as the new-message path" — treats EVERY failed pre-gen agent (except knowledge-retrieval, knowledge-router, secret-plot-driver) as fatal and aborts the whole regeneration with a user-facing error. So the exact same transient failure (e.g. a pre_generation Director or a custom context_injection agent hitting a rate-limit/timeout/parse error) silently continues on a fresh message but hard-fails a regeneration. **How to reproduce (try it yourself)** 1. Configure a pre_generation-phase agent that is not secret_plot (e.g. Narrative Director in pre_generation, or a custom context_injection agent). 2. Ensure the regen path re-runs pre-gen (no cached contextInjections for that swipe — e.g. the original generation produced no cached injections). 3. Cause that agent's LLM call to fail once (rate limit / timeout / invalid JSON). 4. Send a fresh message, then separately regenerate a message under the same failing condition. You'll see: the fresh message proceeds (failure logged as non-critical); the regeneration aborts with "Pre-generation agent(s) failed (...): ... Please try again." Expected: both degrade gracefully the same way — only a critical (secret_plot) failure should abort. **Where it is** `packages/server/src/routes/generate.routes.ts:5671-5690` (regen gate) vs `:5512-5527` (fresh gate). **What's happening** There are two separate failure-gate implementations with mismatched criticality definitions. The fresh path classifies criticality by RESULT type (`!success && r.type === "secret_plot"`). The regen path uses an allowlist by AGENT type (only knowledge-retrieval/knowledge-router/secret-plot-driver are non-fatal), so every other pre-gen failure aborts. The misleading "same as the new-message path" comment masks the divergence. **Suggested fix** Make the regen gate mirror the fresh gate's criticality classification. Replace the body at generate.routes.ts:5671-5690: ```ts const regenPreGenResults = pipeline.results.filter( (r) => r.agentType !== "knowledge-retrieval" && r.agentType !== "knowledge-router" && r.agentType !== "secret-plot-driver", ); const criticalFailedRegen = regenPreGenResults.filter((r) => !r.success && r.type === "secret_plot"); const nonCriticalFailedRegen = regenPreGenResults.filter((r) => !r.success && r.type !== "secret_plot"); if (criticalFailedRegen.length > 0) { const failedNames = criticalFailedRegen.map((r) => r.agentType).join(", "); const firstError = criticalFailedRegen[0]!.error ?? "unknown error"; logger.error(`[pre-gen] FATAL: critical agent(s) failed on regen (${failedNames}) — aborting generation`); sendSseEvent(reply, { type: "error", data: `Critical pre-generation agent failed (${failedNames}): ${firstError}. Please try again.`, }); return; } if (nonCriticalFailedRegen.length > 0) { const failedNames = nonCriticalFailedRegen.map((r) => r.agentType).join(", "); logger.warn(`[pre-gen] Non-critical agent(s) failed on regen (${failedNames}) — continuing generation`); } ``` No regression: secret_plot never runs on the regen path (the secret-plot agent is gated on `!regenerateMessageId` and excluded from the regen pre-gen filter), so `criticalFailedRegen` is always empty there and the gate becomes a correct warn-only no-op; continuing past a non-critical failure is already safe because injection-building skips `!success` results. Recommended: extract a shared `const isCriticalPreGenFailure = (r) => !r.success && r.type === "secret_plot";` and use it in both gates so they cannot drift again. --- *AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.*
Author
Owner

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

Fixed in merged staging PR #3004.

<!-- gh-comment-id:4832279796 --> @SpicyMarinara commented on GitHub (Jun 29, 2026): Fixed in merged staging PR #3004.
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#1561
No description provided.