[GH-ISSUE #2479] [Issue]: Batch agent result parser truncates content at a literal </result substring #1221

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

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

Originally assigned to: @SpicyMarinara on GitHub.

Summary

Severity: Low — correctness. The batched-agent result-block parser closes each agent's segment at the last bare </result substring (lastIndexOf("</result")), so an agent whose content legitimately contains that token gets truncated, marking it failed and forcing a redundant individual retry.

Expected behavior

Match the closing tag with a strict pattern (e.g. /<\/result\s*>/i) and prefer the first balanced close after the content start, so agent content that merely mentions </result is not truncated.

Actual behavior

// src/engine/agents-runtime/executor/agent-executor.ts:937 (extractResultBlocks, fn at :920)
const closeIndex = segment.toLowerCase().lastIndexOf("</result");
const content = (closeIndex >= 0 ? segment.slice(0, closeIndex) : segment).trim();

The open-tag side (:923) is strict, but the close side matches the bare prefix </result. Any agent content containing that literal substring (HTML agent output, </resultset>, JSON/prose mentioning it) truncates the block; lastIndexOf also picks the last occurrence, so a stray late </result drops everything before it. The affected agent then falls into the individual-retry path, so it self-heals at the cost of an extra LLM call.

Steps to reproduce

  1. Run a batched agent whose output text contains the literal substring </result (e.g. an HTML-emitting agent, or prose discussing the tag).
  2. Its parsed content is truncated at that point; it is marked failed and retried individually.

Impact area

  • React-free engine behavior, contracts, agents, or capability ports

Environment

  • Branch or commit: refactor @ 1fae2c42
  • Run mode: Tauri desktop / web shell
  • OS + version: found via static source audit (not runtime-reproduced)
  • Node + pnpm versions: n/a (static audit)
  • Rust version, if relevant: n/a (static audit)
  • Remote Runtime URL configured? not relevant
  • Provider, model, or integration, if relevant: multi-agent batch

Logs, screenshots, or video

Static trace: agent-executor.ts:937 (lastIndexOf("</result")), open-tag pattern at :923.

Regression notes

Not a regression — main uses a strict close pattern too, and in the well-formed common case both implementations agree; the divergent degenerate case (missing real close) also fails under main's patterns. Filing as a refactor bug (robustness hardening). Self-heals via retry, hence Low.

Additional context

Fix: replace the bare-prefix lastIndexOf("</result") with a strict /<\/result\s*>/i match, preferring the first balanced close after the content start.

Template check

Please uncheck 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 @Romuromylus on GitHub (Jun 6, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2479 Originally assigned to: @SpicyMarinara on GitHub. ## Summary **Severity: Low — correctness.** The batched-agent result-block parser closes each agent's segment at the last bare `</result` substring (`lastIndexOf("</result")`), so an agent whose content legitimately contains that token gets truncated, marking it failed and forcing a redundant individual retry. ## Expected behavior Match the closing tag with a strict pattern (e.g. `/<\/result\s*>/i`) and prefer the first balanced close after the content start, so agent content that merely mentions `</result` is not truncated. ## Actual behavior ```ts // src/engine/agents-runtime/executor/agent-executor.ts:937 (extractResultBlocks, fn at :920) const closeIndex = segment.toLowerCase().lastIndexOf("</result"); const content = (closeIndex >= 0 ? segment.slice(0, closeIndex) : segment).trim(); ``` The open-tag side (`:923`) is strict, but the close side matches the bare prefix `</result`. Any agent content containing that literal substring (HTML agent output, `</resultset>`, JSON/prose mentioning it) truncates the block; `lastIndexOf` also picks the last occurrence, so a stray late `</result` drops everything before it. The affected agent then falls into the individual-retry path, so it self-heals at the cost of an extra LLM call. ## Steps to reproduce 1. Run a batched agent whose output text contains the literal substring `</result` (e.g. an HTML-emitting agent, or prose discussing the tag). 2. Its parsed content is truncated at that point; it is marked failed and retried individually. ## Impact area - [x] React-free engine behavior, contracts, agents, or capability ports ## Environment - Branch or commit: refactor @ 1fae2c42 - Run mode: Tauri desktop / web shell - OS + version: found via static source audit (not runtime-reproduced) - Node + pnpm versions: n/a (static audit) - Rust version, if relevant: n/a (static audit) - Remote Runtime URL configured? not relevant - Provider, model, or integration, if relevant: multi-agent batch ## Logs, screenshots, or video Static trace: `agent-executor.ts:937` (`lastIndexOf("</result")`), open-tag pattern at `:923`. ## Regression notes Not a regression — main uses a strict close pattern too, and in the well-formed common case both implementations agree; the divergent degenerate case (missing real close) also fails under main's patterns. Filing as a refactor `bug` (robustness hardening). Self-heals via retry, hence Low. ## Additional context Fix: replace the bare-prefix `lastIndexOf("</result")` with a strict `/<\/result\s*>/i` match, preferring the first balanced close after the content start. ## Template check Please uncheck 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.
bsakaguchi 2026-10-21 05:29:16 +07:00
Author
Owner

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

Fixed on refactor in 038b7220.

Batch agent result parsing now only treats a strict closing tag as the result terminator, preserving literal </result text in generated content.

Verification: pnpm typecheck; pnpm build; pnpm check:architecture; cargo check --manifest-path src-tauri/Cargo.toml --workspace; focused Rust backup/profile tests; git diff --check; no .test.ts/.test.tsx files present.

<!-- gh-comment-id:4638719028 --> @SpicyMarinara commented on GitHub (Jun 6, 2026): Fixed on refactor in 038b7220. Batch agent result parsing now only treats a strict </result> closing tag as the result terminator, preserving literal </result text in generated content. Verification: pnpm typecheck; pnpm build; pnpm check:architecture; cargo check --manifest-path src-tauri/Cargo.toml --workspace; focused Rust backup/profile tests; git diff --check; no .test.ts/.test.tsx files present.
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#1221
No description provided.