Skip to content

fix(agents): recover schema-valid agent JSON output#145

Merged
kunchenguid merged 6 commits into
mainfrom
ezoss/fix-144-20260507-164914-diclkajilzyo-1
May 7, 2026
Merged

fix(agents): recover schema-valid agent JSON output#145
kunchenguid merged 6 commits into
mainfrom
ezoss/fix-144-20260507-164914-diclkajilzyo-1

Conversation

@kunchenguid
Copy link
Copy Markdown
Owner

Summary

  • Added shared schema-aware JSON extraction for agent responses so fenced or prose-wrapped final payloads can be recovered consistently.
  • Updated Rovo Dev to validate recovered output against the run schema and reused the shared parser in ACP instead of bespoke extraction logic.
  • Added focused coverage for JSON recovery and Rovo Dev output parsing, and documented the shared helper for future agent integrations.

Risk Assessment

✅ Low: The change is narrowly scoped to JSON recovery and schema validation for agent outputs, with tests covering the previously identified edge cases and no remaining material issues found in the changed code.

Testing

  • Summary: Exercised the new shared agent JSON extraction helper and the affected Rovo Dev/ACP agent parsing paths; all relevant agent tests passed.
  • npx vitest run src/core/agents/json-extract.test.ts src/core/agents/rovodev.test.ts src/core/agents/acp.test.ts
  • npx vitest run src/core/agents
  • Outcome: ✅ passed across 1 run (34.5s)

Pipeline

Updates from git push no-mistakes

✅ **Rebase** - passed

Round 1 - passed ✅

🔧 **Review** - 1 issue found → auto-fixed (3)

Round 1 - found 1 warning

  • ⚠️ src/core/agents/rovodev.ts:763 - RovoDev now extracts any parseable JSON object from the final text, then casts it directly to AgentOutput. If the agent still returns prose that happens to contain a JSON fragment instead of the required final payload, gnhf can proceed with missing summary/key arrays or an unintended success value; validate the parsed object against the run schema before returning it.

Round 2 (auto-fix) - found 1 warning

  • ⚠️ src/core/agents/json-extract.ts:68 - extractLastJsonObject returns the first parseable object found while scanning from the right, so a valid recovered RovoDev payload can be rejected if any later string field contains a JSON-looking fragment such as {} and the agent also emitted prose. Prefer the outer object that validates against the agent schema, or continue scanning after a parsed candidate fails validation.

Round 3 (auto-fix) - found 1 warning

  • ⚠️ src/core/agents/json-extract.ts:93 - When the whole cleaned message is valid JSON but fails the accepts predicate, parseAgentJson still falls through to nested-object extraction. For RovoDev this can accept a schema-shaped child object from an invalid top-level response and silently ignore top-level fields or validation errors; only run extraction when parsing the whole message fails, or surface the top-level schema failure to the caller.

Round 4 (auto-fix) - passed ✅

✅ **Test** - passed

Round 1 - passed ✅

  • npx vitest run src/core/agents/json-extract.test.ts src/core/agents/rovodev.test.ts src/core/agents/acp.test.ts
  • npx vitest run src/core/agents
🔧 **Document** - 1 issue found → auto-fixed

Round 1 - found 1 info

  • ℹ️ AGENTS.md:39 - The agent architecture docs list the shared responsibilities and notable helper modules under src/core/agents/, but the change adds json-extract.ts as a shared parser used by both Rovo Dev and ACP to recover schema-valid final JSON from fenced or prose-wrapped assistant output. Update this section to document json-extract.ts and when agent integrations should use it instead of ad-hoc JSON.parse handling.

Round 2 (auto-fix) - passed ✅

🔧 **Lint** - 3 issues found → auto-fixed

Round 1 - found 3 issues (1 error, 2 warnings)

  • 🚨 src/core/agents/json-extract.ts:79 - ESLint reported an empty block statement (no-empty).
  • ⚠️ src/core/agents/json-extract.test.ts:1 - Prettier reported formatting differences.
  • ⚠️ src/core/agents/rovodev.ts:1 - Prettier reported formatting differences.

Round 2 (auto-fix) - passed ✅

✅ **Push** - passed

Round 1 - passed ✅

@kunchenguid kunchenguid merged commit b5ffc2d into main May 7, 2026
5 checks passed
@kunchenguid kunchenguid deleted the ezoss/fix-144-20260507-164914-diclkajilzyo-1 branch May 7, 2026 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant