[GH-ISSUE #1896] Agent JSON repair corrupts valid strings containing comment-like text #920

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

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

Originally assigned to: @SpicyMarinara on GitHub.

Summary

src/engine/agents-runtime/executor/agent-executor.ts repairs JSON by stripping // and block comments before first attempting JSON.parse. That can corrupt valid JSON string values that contain //, such as URLs or literal text.

Evidence

Refactor behavior:

  • repairJson removes //[^\n]* before parsing.
  • A valid payload like {"url":"https://example.com/a","text":"keep // inside"} is transformed into invalid/truncated text before parse.

Legacy behavior:

  • The legacy agent executor attempted JSON.parse first.
  • Repair only ran after parse failure, so valid JSON strings containing URLs or // text were preserved.

Scratch repro from the parity pass:

const input = '{"url":"https://example.com/a","text":"keep // inside"}';

Result: refactor repair path fails; legacy parse-first path succeeds.

Impact

Agents that return valid JSON containing URLs, markdown-ish text, comments as literal text, or other // string values can fail parsing or lose data. This can break structured agent outputs even when the model produced valid JSON.

Expected

Valid JSON should be parsed as-is before repair. Repair should only run after parse failure, and repair logic should avoid modifying content inside JSON strings.

Candidate Fix

Restore the legacy parse-first guard and use string-aware repair for fallback cleanup.

Originally created by @Xelvanis on GitHub (Jun 2, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/1896 Originally assigned to: @SpicyMarinara on GitHub. ### Summary `src/engine/agents-runtime/executor/agent-executor.ts` repairs JSON by stripping `//` and block comments before first attempting `JSON.parse`. That can corrupt valid JSON string values that contain `//`, such as URLs or literal text. ### Evidence Refactor behavior: - `repairJson` removes `//[^\n]*` before parsing. - A valid payload like `{"url":"https://example.com/a","text":"keep // inside"}` is transformed into invalid/truncated text before parse. Legacy behavior: - The legacy agent executor attempted `JSON.parse` first. - Repair only ran after parse failure, so valid JSON strings containing URLs or `//` text were preserved. Scratch repro from the parity pass: ```js const input = '{"url":"https://example.com/a","text":"keep // inside"}'; ``` Result: refactor repair path fails; legacy parse-first path succeeds. ### Impact Agents that return valid JSON containing URLs, markdown-ish text, comments as literal text, or other `//` string values can fail parsing or lose data. This can break structured agent outputs even when the model produced valid JSON. ### Expected Valid JSON should be parsed as-is before repair. Repair should only run after parse failure, and repair logic should avoid modifying content inside JSON strings. ### Candidate Fix Restore the legacy parse-first guard and use string-aware repair for fallback cleanup.
Author
Owner

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

Fixed on refactor in a4ba3c90: agent JSON extraction now parses valid JSON before repair, and fallback cleanup is string-aware so URLs and literal comment-like text inside strings are preserved. Verification passed: typecheck, architecture, docs, build, cargo check, diff check.

<!-- gh-comment-id:4601637237 --> @SpicyMarinara commented on GitHub (Jun 2, 2026): Fixed on refactor in a4ba3c90: agent JSON extraction now parses valid JSON before repair, and fallback cleanup is string-aware so URLs and literal comment-like text inside strings are preserved. Verification passed: typecheck, architecture, docs, build, cargo check, diff check.
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#920
No description provided.