LLM response body truncated: intermittent JSON parse failure #47

Closed
opened 2026-05-07 07:20:58 +00:00 by rodin · 0 comments
Owner

Bug

review-bot intermittently fails to parse the LLM response with "unexpected end of JSON input" even when the response body is complete valid JSON.

Evidence

From gargoyle CI run 1736 (job 4559), gpt-review log:

level=INFO  msg="LLM response received" bytes=4357
level=ERROR msg="failed to parse LLM response" error="parse LLM response as JSON: unexpected end of JSON input
Raw response: {..."

The raw response logged is complete, valid JSON (REQUEST_CHANGES verdict + 6 findings). json.Unmarshal still returns "unexpected end of JSON input."

This suggests the response body is being partially read before being passed to the JSON parser. The logged bytes (4357) match what the server reported, but the buffer passed to json.Unmarshal is truncated.

Impact

  • Causes gpt-review CI job to fail and exit 1
  • Always succeeds on retry — purely transient
  • Observed in 3 of last 50 runs (6%)

Fix

Audit HTTP response body reading in review-bot. Likely suspect: buffered reader not fully draining before passing to json.Unmarshal. Consider:

  1. Using io.ReadAll instead of buffered reads
  2. Adding explicit retry on JSON parse error (defensive)

Linked

gargoyle issue #652

## Bug `review-bot` intermittently fails to parse the LLM response with `"unexpected end of JSON input"` even when the response body is complete valid JSON. ## Evidence From gargoyle CI run 1736 (job 4559), gpt-review log: ``` level=INFO msg="LLM response received" bytes=4357 level=ERROR msg="failed to parse LLM response" error="parse LLM response as JSON: unexpected end of JSON input Raw response: {..." ``` The raw response logged is complete, valid JSON (REQUEST_CHANGES verdict + 6 findings). `json.Unmarshal` still returns "unexpected end of JSON input." This suggests the response body is being partially read before being passed to the JSON parser. The logged bytes (4357) match what the server reported, but the buffer passed to `json.Unmarshal` is truncated. ## Impact - Causes gpt-review CI job to fail and exit 1 - Always succeeds on retry — purely transient - Observed in 3 of last 50 runs (6%) ## Fix Audit HTTP response body reading in `review-bot`. Likely suspect: buffered reader not fully draining before passing to `json.Unmarshal`. Consider: 1. Using `io.ReadAll` instead of buffered reads 2. Adding explicit retry on JSON parse error (defensive) ## Linked gargoyle issue #652
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: rodin/review-bot#47