Accept prose before a bare JSON object in douwebot's OpenCode answer, and keep a rejected answer out of the job log

Merged
DS
22d ago
+52-6

This pull request was posted by Claude Code using claude-opus-5-5 on behalf of David.

No issue: fixes the douwebot OpenCode fallback failures on https://github.com/pydantic/pydantic-ai/pull/13268 and https://github.com/pydantic/pydantic-ai/pull/13269.

Why we make these changes

When OpenCode Go refuses douwebot's fallback run with a 429, zai-coding-plan/glm-5.3-flash serves it. That model writes a paragraph, then the requested JSON object without a code fence. review_result passed that text to ReviewResult unchanged, so "Validate completed review" failed with json_invalid and no review was published (run 43266067725, run 43265435601). Nine douwebot runs since 2026-11-05 failed this way.

The uncaught ValidationError also printed both ends of the model's answer into the public job log.

New public surface

None. CI scripts only.

User-visible behavior

 answer: I've completed a thorough review of the changed files.⏎⏎{"verdict": "REQUEST_CHANGES", ...}
-pydantic_core.ValidationError: ... input_value='I\'ve completed a thorou...."}], "discussion": ""}'
+review published
  • After unfenced(), review_result validates the answer from its first {. Prose before a bare JSON object passes, on its own line or the same line.
  • An unterminated opening fence before a complete object also passes in douwebot, as a side effect: the fence line is prose before the first {. Nothing handles it specially.
  • Still rejected: text after the object or the closing fence, nested fences, and prose that itself holds a {.
  • A rejected answer exits with OpenCode returned an invalid review: <reason>, as Category Classify does. The job log no longer carries model text.
  • unfenced(), PR Review Checks and Category Classify are unchanged: https://github.com/pydantic/pydantic-ai/pull/13220 chose their rule.

Verification

bots.yml runs main's copy of these scripts, so this PR's own douwebot run uses the old parser. The fix is first exercised after merge.

What changes for existing users

Nothing for library users. In CI, douwebot publishes a fallback review whose answer has prose before a bare JSON object.

PR decisions

2026-11-12 · fix the shared unfenced(), not douwebot alone · iter -

  • Decision: David chose the shared unfenced(), so douwebot, PR Review Checks and Category Classify accept prose before a bare JSON object; the two .github/workflows/AGENTS.md fence sentences change with it
  • Why: The defect reproduces in code on the PR Review Checks path, five glm-5.3-flash PR Review Checks runs since 2026-11-05 failed with validation failed: json_invalid, and dropping prose before the first { changes output only for inputs that already fail on main at all three callers; an input that starts with { is unchanged
  • Source: https://github.com/pydantic/pydantic-ai/actions/runs/43266067725
  • Session: d7da7ee3-d40d-4b54-a357-4590b94bcd5b

2026-11-12 · drop prose before the first { · iter -

  • Decision: unfenced() returns text from its first { when no fence ends it; prose that holds a { itself still fails, as it does on main
  • Why: Two lines and linear; the full answers were not retained, so the prose/JSON separator is unknown, and this shape covers both a newline and a space; a reverse brace-matching scan would also handle prose with { but costs about 20 lines
  • Source: https://github.com/pydantic/pydantic-ai/actions/runs/43266067725
  • Session: d7da7ee3-d40d-4b54-a357-4590b94bcd5b

2026-11-12 · PR Review Checks now accepts prose before bare JSON and an unterminated fence · iter -

  • Decision: The text-before-bare-json and unterminated-fence cases in test_run_pr_review_check.py move from rejected to accepted
  • Why: #13220 listed both as still rejected only as its scope boundary, with no reason against them; an unterminated fence line followed by a complete object is prose before the first {, and the object is still validated against the strict schema
  • Source: https://github.com/pydantic/pydantic-ai/pull/13220
  • Session: d7da7ee3-d40d-4b54-a357-4590b94bcd5b
  • Supersedes: #13220 decision: prose before bare JSON and an unterminated fence still fail

2026-11-12 · fold the main() traceback fix into this PR · iter -

  • Decision: main() catches ValueError and exits with rejection_reason(), as category_classify_opencode.main does, in its own commit; AGENTS.md names douwebot in the sentence that keeps model text out of job logs
  • Why: Same file and topic; the uncaught ValidationError printed both ends of the model's answer into the public job log
  • Source: https://github.com/pydantic/pydantic-ai/actions/runs/43266067725
  • Session: d7da7ee3-d40d-4b54-a357-4590b94bcd5b

2026-11-12 · douwebot tests: unterminated fence moves to accepted too · iter -

  • Decision: test_douwebot_opencode_result.py moves its unterminated-fence case to the accepted prose cases, and pins that text after a bare object still fails
  • Why: Same rule as the PR Review Checks cases: the opening fence line is prose before the first {
  • Source: https://github.com/pydantic/pydantic-ai/pull/13172
  • Session: d7da7ee3-d40d-4b54-a357-4590b94bcd5b

2026-11-12 · pre-push review 1 of 3 at 41ffb19b0e31a38a9e8a6639c3ef06c1827c7b1d · iter -

2026-11-12 · pre-push review 1 of 3 at 41ffb19b0e31a38a9e8a6639c3ef06c1827c7b1d · iter -

2026-11-12 · exempt delta 41ffb19b0..80c5ca296 · iter -

2026-11-12 · narrow the prose fix to douwebot; PR Review Checks and Category Classify stay as on main · iter -

  • Decision: review_result drops prose before the first { after unfenced(); unfenced(), test_run_pr_review_check.py, the classifier test and the two AGENTS.md fence sentences return to main; douwebot keeps the job-log sentence and gains one sentence on its parsing; an unterminated fence before a complete object passes in douwebot only because the opening fence line is prose before the first {, with no handling added for it
  • Why: #13220 records David's explicit choice for PR Review Checks that 'text after the fence, an unterminated fence and prose before bare JSON still fail'; reversing it is David's call, and the PR Review Checks evidence is in-code only because its answer text is hidden
  • Source: https://github.com/pydantic/pydantic-ai/pull/13220
  • Session: d7da7ee3-d40d-4b54-a357-4590b94bcd5b
  • Supersedes: fix the shared unfenced(), not douwebot alone; PR Review Checks now accepts prose before bare JSON and an unterminated fence

2026-11-12 · pre-push review 2 of 3 at 5ba0c83b094b96b550650d1a18dbfa10a2903222 · iter -

2026-11-12 · pre-push review 2 of 3 at 5ba0c83b094b96b550650d1a18dbfa10a2903222 · iter -

2026-11-12 · exempt delta 5ba0c83b0..0b379ea87 · iter -

2026-11-12 · hold douwebot on 0b379ea87; merge-over-gate decision goes to David · iter -

  • Decision: Do not re-apply douwebot; options (a) retry after the Claude window resets, (b) David merges over the douwebot gate, (c) retry now go to David with (b) recommended; stay in monitor mode
  • Why: Two douwebot runs in a row failed; the second hit this PR's own bug in main's parser, and PRs 13268, 13269, 13271 and 13289 wait on this merge
  • Source: https://github.com/pydantic/pydantic-ai/actions/runs/43280506899
  • Session: d7da7ee3-d40d-4b54-a357-4590b94bcd5b

Checklist

  • No breaking changes in accordance with the version policy.
  • Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it.
  • PR title is fit for the release changelog.

https://claude.ai/code/session_01HhQjZCQ96bvHiTdumcUjTF