[GH-ISSUE #2696] [Issue]: Custom-agent cadence anchors on failed runs, blocking the agent for the full interval after a transient failure #1341

Closed
opened 2026-10-21 05:31:50 +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/2696

Originally assigned to: @SpicyMarinara on GitHub.

Summary

Custom-agent cadence (run-every-N) anchors on the most recent run regardless of success, so a single failed run resets the cadence timer and blocks the agent for its full interval — the agent doesn't retry after a transient failure. Built-in agents anchor on the last successful run and don't have this problem; the inconsistency means custom agents skip turns they should run on.

Expected behavior

A custom agent with runInterval > 1 should anchor its cadence on its last successful run (matching built-in agents), so a transient failure on one turn doesn't suppress it for the next runInterval messages.

Actual behavior

userMessagesSinceLastAgentRun calls agentsStore.getLastRunByType — the most recent run regardless of success. Pre-gen custom-agent runs are persisted by iterating preGenResults with no success filter, so a failed run is saved with a valid messageId (the latest user message) and becomes the cadence anchor. On the next turn the "messages since last run" count is small (< runInterval), so the agent is gated out — even though its last successful run was much earlier or never. By contrast, the built-in cadence helper shouldSkipAgentByAssistantInterval uses getLastSuccessfulRunByType.

How it breaks the pipeline

Code trace (staging @ b826f8f4):

  • packages/server/src/routes/generate.routes.ts:3410-3417 — userMessagesSinceLastAgentRun → getLastRunByType (:3411, success-agnostic); custom agent removed by cadence at :3446.
  • :4967 — preGenResults (all pipeline results minus KR/router, no success filter); persisted at :4978-4986 with messageId = latest user message (:4973-4976).
  • packages/server/src/services/agents/agent-cadence.ts:37 — built-in shouldSkipAgentByAssistantInterval uses getLastSuccessfulRunByType (the correct, success-anchored behavior).

Steps to reproduce

  1. Create a custom pre-gen agent with runInterval: 3.
  2. On a turn where it errors (e.g. provider 500), the failed run is still persisted.
  3. Over the next 2 user messages the agent is gated out by cadence even though its last successful run was much earlier (or it has never succeeded).

Suggested fix

Make cadence anchor on success consistently — either use getLastSuccessfulRunByType in userMessagesSinceLastAgentRun (generate.routes.ts:3411), or only persist successful custom runs at :4978 (skip results where !result.success). Pick one to match the built-in cadence semantics.

Environment

  • Marinara Engine version: 2.0.0 (staging @ b826f8f4)
  • Install type: source
  • OS + version: All (code-level defect, platform-independent)
  • Browser or app shell: All

Additional context

Found via a systematic multi-agent audit of conditional prompt insertion. Causes custom agents to silently skip turns after a transient failure. Part of a set of conditional-injection issues filed together.

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @kolacheee on GitHub (Jun 21, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2696 Originally assigned to: @SpicyMarinara on GitHub. ## Summary Custom-agent cadence (run-every-N) anchors on the most recent run **regardless of success**, so a single failed run resets the cadence timer and blocks the agent for its full interval — the agent doesn't retry after a transient failure. Built-in agents anchor on the last *successful* run and don't have this problem; the inconsistency means custom agents skip turns they should run on. ## Expected behavior A custom agent with `runInterval > 1` should anchor its cadence on its last **successful** run (matching built-in agents), so a transient failure on one turn doesn't suppress it for the next `runInterval` messages. ## Actual behavior `userMessagesSinceLastAgentRun` calls `agentsStore.getLastRunByType` — the most recent run regardless of success. Pre-gen custom-agent runs are persisted by iterating `preGenResults` with **no success filter**, so a failed run is saved with a valid `messageId` (the latest user message) and becomes the cadence anchor. On the next turn the "messages since last run" count is small (`< runInterval`), so the agent is gated out — even though its last *successful* run was much earlier or never. By contrast, the built-in cadence helper `shouldSkipAgentByAssistantInterval` uses `getLastSuccessfulRunByType`. ## How it breaks the pipeline Code trace (staging @ `b826f8f4`): - `packages/server/src/routes/generate.routes.ts:3410-3417` — `userMessagesSinceLastAgentRun` → `getLastRunByType` (`:3411`, success-agnostic); custom agent removed by cadence at `:3446`. - `:4967` — `preGenResults` (all pipeline results minus KR/router, no success filter); persisted at `:4978-4986` with `messageId` = latest user message (`:4973-4976`). - `packages/server/src/services/agents/agent-cadence.ts:37` — built-in `shouldSkipAgentByAssistantInterval` uses `getLastSuccessfulRunByType` (the correct, success-anchored behavior). ## Steps to reproduce 1. Create a custom pre-gen agent with `runInterval: 3`. 2. On a turn where it errors (e.g. provider 500), the failed run is still persisted. 3. Over the next 2 user messages the agent is gated out by cadence even though its last *successful* run was much earlier (or it has never succeeded). ## Suggested fix Make cadence anchor on success consistently — either use `getLastSuccessfulRunByType` in `userMessagesSinceLastAgentRun` (`generate.routes.ts:3411`), or only persist successful custom runs at `:4978` (skip results where `!result.success`). Pick one to match the built-in cadence semantics. ## Environment - Marinara Engine version: 2.0.0 (staging @ `b826f8f4`) - Install type: source - OS + version: All (code-level defect, platform-independent) - Browser or app shell: All ## Additional context Found via a systematic multi-agent audit of conditional prompt insertion. Causes custom agents to silently skip turns after a transient failure. Part of a set of conditional-injection issues filed together. ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
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.

Correction to the code trace: the built-in cadence helper is at packages/server/src/services/generation/agent-cadence.ts:37, NOT packages/server/src/services/agents/agent-cadence.ts — that server path does not exist and never did (verified via git ls-tree b826f8f4; the file was already under generation/ at the cited commit). The cited line :37 and the symbol shouldSkipAgentByAssistantInterval → getLastSuccessfulRunByType are exactly correct; only the directory in the path is wrong.

All other anchors verified in the current tree:

  • generate.routes.ts:3411 still calls getLastRunByType (success-agnostic) — bug present, not fixed.
  • Save loop is at generate.routes.ts:4978-4990 (issue cited :4978-4986); it only skips built-in agents, no !result.success filter.
  • agents.storage.ts:289 saveRun stores success: String(input.result.success), so a failed run persists as success="false".
  • agents.storage.ts:309-318 getLastRunByType has no success filter; :297-306 getLastSuccessfulRunByType filters success="true".
  • getLastRunByType has exactly one call site (3411); every other anchor consumer already uses the success-filtered variant, so scope is complete.

Recommended fix: prefer option A — change getLastRunByType to getLastSuccessfulRunByType in userMessagesSinceLastAgentRun at generate.routes.ts:3411. This is a one-line change that unifies custom cadence with the built-in helper and keeps failed-run diagnostics intact (success/error columns remain queryable via getRunWithConfig). Option B (skipping persistence of failed runs at :4978) is inferior — it discards the only records where success="false"/error are retained, which is the only reason failed runs are persisted.

<!-- gh-comment-id:4761102291 --> @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._ Correction to the code trace: the built-in cadence helper is at `packages/server/src/services/generation/agent-cadence.ts:37`, NOT `packages/server/src/services/agents/agent-cadence.ts` — that server path does not exist and never did (verified via `git ls-tree b826f8f4`; the file was already under `generation/` at the cited commit). The cited line `:37` and the symbol `shouldSkipAgentByAssistantInterval` → `getLastSuccessfulRunByType` are exactly correct; only the directory in the path is wrong. All other anchors verified in the current tree: - generate.routes.ts:3411 still calls `getLastRunByType` (success-agnostic) — bug present, not fixed. - Save loop is at generate.routes.ts:4978-4990 (issue cited :4978-4986); it only skips built-in agents, no `!result.success` filter. - agents.storage.ts:289 `saveRun` stores `success: String(input.result.success)`, so a failed run persists as `success="false"`. - agents.storage.ts:309-318 `getLastRunByType` has no success filter; :297-306 `getLastSuccessfulRunByType` filters `success="true"`. - `getLastRunByType` has exactly one call site (3411); every other anchor consumer already uses the success-filtered variant, so scope is complete. Recommended fix: prefer option A — change `getLastRunByType` to `getLastSuccessfulRunByType` in `userMessagesSinceLastAgentRun` at generate.routes.ts:3411. This is a one-line change that unifies custom cadence with the built-in helper and keeps failed-run diagnostics intact (success/error columns remain queryable via `getRunWithConfig`). Option B (skipping persistence of failed runs at :4978) is inferior — it discards the only records where `success="false"`/`error` are retained, which is the only reason failed runs are persisted.
Author
Owner

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

Fixed in branch codex/spicy-issue-sweep-2026-06-21.

What changed:

  • Custom-agent cadence now uses getLastSuccessfulRunByType, matching built-in cadence behavior.
  • Failed runs remain persisted for diagnostics, but no longer reset the run interval timer.

Final repo checks will run after the full issue sweep.

<!-- gh-comment-id:4761540524 --> @SpicyMarinara commented on GitHub (Jun 21, 2026): Fixed in branch `codex/spicy-issue-sweep-2026-06-21`. What changed: - Custom-agent cadence now uses `getLastSuccessfulRunByType`, matching built-in cadence behavior. - Failed runs remain persisted for diagnostics, but no longer reset the run interval timer. Final repo checks will run after the full issue sweep.
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#1341
No description provided.