fix(review): tolerate unescaped inner quotes in review JSON#68
Merged
JohnnyVicious merged 1 commit intomainfrom Apr 14, 2026
Merged
fix(review): tolerate unescaped inner quotes in review JSON#68JohnnyVicious merged 1 commit intomainfrom
JohnnyVicious merged 1 commit intomainfrom
Conversation
Real-world report on v1.0.10: an adversarial review against PR #412
came back with a `summary` field that embeds a literal
`{"success": false, "error": "..."}` with unescaped inner quotes.
Strict `JSON.parse` dies at the first `"success"`, `tryParseJson`
returns null, and the companion then falls through to printing the
raw JSON text in the Claude Code chat AND embedding that same raw
JSON in the posted PR comment body. Both outputs looked like
garbage.
Replace `tryParseJson` with a schema-aware `tryParseReview` that:
1. Fast path: strict `JSON.parse` (+ ```json fence stripping). Same
behavior as before for well-formed reviews.
2. Lenient fallback: when strict parse fails, extract each known
top-level key by name — `verdict` via a closed-vocabulary regex,
`summary` by slicing between `"summary": "` and the next
`", "findings"` anchor (or the last `"` before `}` when findings
is absent), `findings` via a depth-aware bracket walker that
tracks JSON string state. If the extracted findings array fails
to parse, return an empty array — better to show verdict +
summary than nothing.
The new parser is narrowly tailored to our `{verdict, summary,
findings}` schema, not a general-purpose JSON repair library. That
makes it small (~200 lines, zero deps) and easy to reason about.
Delete the old `tryParseJson` helper — its only callers were the
two review handlers, both now use `tryParseReview`.
New test file `tests/review-parser.test.mjs` includes a regression
pinned to the exact broken shape from the real failure report, plus
coverage for the sliceMatchingBracket walker, fence stripping,
malformed-findings recovery, and the no-findings fallback path.
Full suite: 268/268 pass.
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.
Symptom
Real user report on v1.0.10: adversarial review against a real PR came back with pretty, approve-verdict prose — but the Claude Code chat showed the raw JSON object (not the rendered markdown) and the posted PR review on GitHub was the same raw JSON embedded as a code block. Both outputs looked like garbage:
```
{
"verdict": "approve",
"summary": "Change correctly closes the silent-failure gap ... all now return explicit {"success": false, "error": "..."} instead of ...",
"findings": []
}
```
Root cause
The model's `summary` field embeds a literal `{"success": false, "error": "..."}` with unescaped inner quotes. Strict `JSON.parse` bails at the first `"success"` (it thinks the `summary` string ended early), `tryParseJson` returns null, and the companion falls through to printing the raw text.
Fix
Replace `tryParseJson` with a schema-aware `tryParseReview` (new file `plugins/opencode/scripts/lib/review-parser.mjs`) that:
Narrowly tailored to our `{verdict, summary, findings}` schema. No general-purpose JSON repair library, no new dependencies.
Tests
Manual verification after merge
I'll ask the user to re-run `/opencode:adversarial-review --pr 412 --post` on the same branch and confirm both the chat output and the posted PR review render as the nice markdown.