## Problem The Codex PR reviewer (`gautam-chatgpt`) intermittently failed with `No valid JSON found in response` on `gbharg/pi-mono` PRs #28-32, posting `⚠️ Codex: Review failed` instead of a real review. The same PR sometimes parsed and sometimes did not, which pointed at output framing rather than a broken model call. ## Root cause `codex exec` does not always emit clean JSON on stdout. It can frame the answer with a session transcript, a leading `codex` marker line, and a trailing `tokens used` epilogue. That surrounding prose frequently contains stray `{`/`}` (shell snippets, file trees, JSON examples in skill docs). The old `parse-response.js` fell back to a naive `text.indexOf('{')` … `text.lastIndexOf('}')` slice. When a stray brace appeared before the real object, the slice spanned non-JSON prose and `JSON.parse` threw. Whether it failed depended on whether the transcript happened to contain stray braces — exactly the observed intermittency. This is codex-specific framing; gemini/claude emit clean or fenced JSON. ## Fix (`pr-review-shared/lib`) - `parse-response.js`: replace the first-`{`/last-`}` heuristic with a string-aware balanced-brace scan (a stack of open positions, so an unmatched stray `{` in prose can never absorb the real object). Prefer the LAST review-shaped object, since codex prints its answer after the transcript. Direct-parse and fence-strip fast paths are kept first, so gemini/claude are unaffected. - `parseReviewWithRepair()`: one repair re-ask that demands pure JSON, as a last-resort net for genuinely truncated/empty output. - `review-handler.js` (shared by codex/gemini/claude): call `parseReviewWithRepair`. ## Verification - Replayed the real failing codex prompt: the new parser extracts the correct review from the full ~19 KB codex session transcript (the exact shape the old parser choked on), and from clean stdout. - Added tests for transcript-framed, fenced, and stray-brace inputs plus the repair retry. `npm test` → **97 passed (97)**. - Deploy copy at `/home/claude/repos/pr-review-shared` updated identically; `codex-pr-reviewer` restarted and confirmed posting structured reviews again on pi-mono. Author: Gautam AI 🤖 Generated with [Claude Code](https://claude.com/claude-code)