Conversation
…match (danielmiessler#2189) `/[{[][\s\S]*[}\]]/` runs from the first opening bracket to the last closing bracket anywhere in the output, so any later `]` or `}` — a markdown link, an `item[3]`, a second object — is swallowed into the fragment and JSON.parse fails. A case asserting the agent emitted JSON went red whenever the model also wrote a link, which the runner reports as a real regression. Scan each opening bracket for its balanced partner (string-aware, so a brace inside a JSON string value does not confuse the count) and pass on the first span that parses. The shipped self-test only covered `prefix {"a":1} suffix`, which has no trailing bracket, so it passed and hid this. Four cases added: JSON followed by a markdown link, JSON followed by `item[3]`, a brace inside a string with a trailing `]`, and a negative (brackets and braces that are not JSON). Self-test 20/20. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PuS77R8a6Lhp7jK6dnwdTh
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.
Fixes #2189.
/[{[][\s\S]*[}\]]/is greedy: it runs from the first opening bracket to the last closing bracket anywhere in the output, so any later]or}(a markdown link, anitem[3], a second object) is swallowed into the fragment andJSON.parsefails. A case asserting the agent emitted JSON went red whenever the model also wrote a link, which the runner reports as a real regression.This scans each opening bracket for its balanced partner, string-aware so a brace inside a JSON string value does not confuse the count, and passes on the first span that parses.
The shipped self-test only covered
prefix {"a":1} suffix, which has no trailing bracket, so it passed and hid the bug. Four cases added: JSON followed by a markdown link, JSON followed byitem[3], a brace inside a string with a trailing], and a negative. Self-test 20/20.🤖 Generated with Claude Code
https://claude.ai/code/session_01PuS77R8a6Lhp7jK6dnwdTh