fix: repair truncated JSON, reduce summon/MOIM log noise#8280
fix: repair truncated JSON, reduce summon/MOIM log noise#8280eugenio wants to merge 2 commits intoblock:mainfrom
Conversation
- Add `repair_truncated_json()` fallback to `safely_parse_json()` that closes unclosed strings and brackets in truncated tool call arguments. Fixes large-payload EOF errors (col 27409+) from streaming models. (block#8272) - Downgrade summon frontmatter parse warning from WARN to DEBUG and include the source file path for easier debugging. Files without a `name` field are expected (non-extension markdown) and should not pollute logs. (block#8273) - Add "Merged text content", "Removed trailing assistant message", and "Trimmed trailing whitespace from assistant message" to the MOIM expected-issues list so they no longer trigger WARN-level log entries on every LLM call. (block#8274) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e5f4680f67
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
crates/goose/src/providers/utils.rs
Outdated
| // Close an unclosed string | ||
| if in_string { | ||
| repaired.push('"'); | ||
| } |
There was a problem hiding this comment.
Handle dangling escape when repairing truncated JSON
When truncation happens immediately after a backslash inside a JSON string, escape_next is left true at end-of-input, but the repair logic still appends only " and closers. That produces invalid JSON like {"k":"abc\"} (the appended quote is escaped), so safely_parse_json still fails for a common truncation boundary in streamed tool arguments (e.g., paths or escaped content). The repair path should account for a dangling escape before closing the string.
Useful? React with 👍 / 👎.
When truncation occurs immediately after a backslash inside a JSON
string, the appended closing quote would be escaped, producing invalid
JSON like {"k":"abc\"}. Drop the trailing backslash before closing
the string.
Addresses Codex review feedback on block#8280.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Superseded by #8310 which includes the truncated JSON repair and all other fixes from this PR. |
Summary
Three targeted fixes for log noise and tool call reliability when using non-Anthropic models via OpenAI-compatible proxies:
safely_parse_json): Adds a third fallback that closes unclosed strings, braces, and brackets in truncated tool call arguments. Fixes the-32602: EOF while parsing a string at line 1 column 27409errors that occur when models stream largewritetool payloads. Ref: bug: Tool call JSON parse failures with large payloads and streaming fragments #8272"Failed to parse frontmatter: missing field name"from WARN to DEBUG and includes the source file path. These warnings fire on every startup (2x) and every subagent invocation for non-extension markdown files that lack anamefield. Ref: bug: Summon extension emits 'missing field name' frontmatter warnings on every startup #8273"Merged text content","Removed trailing assistant message", and"Trimmed trailing whitespace from assistant message"to the expected-issues filter ininject_moim(). These are normal side-effects of MOIM injection but were triggering WARN-level logs on every LLM call (142+ per session). Ref: bug: MOIM injection produces hundreds of warnings per session (log spam) #8274Test plan
test_safely_parse_jsonupdated — truncated JSON now repaired instead of erroringtest_repair_truncated_jsonadded — covers unclosed strings, nested objects, arrays, large payloadsproviders::utils,conversation,agents::moim)🤖 Generated with Claude Code