fix(agents): recover schema-valid agent JSON output#145
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
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
npx vitest run src/core/agents/json-extract.test.ts src/core/agents/rovodev.test.ts src/core/agents/acp.test.tsnpx vitest run src/core/agentsPipeline
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-extractLastJsonObjectreturns 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 theacceptspredicate,parseAgentJsonstill 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.tsnpx 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 undersrc/core/agents/, but the change addsjson-extract.tsas 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 documentjson-extract.tsand when agent integrations should use it instead of ad-hocJSON.parsehandling.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 ✅