Repository navigation
Conversation
parse_messages_json found where each message object ends by counting
every { and } in the JSON, including those inside content strings. A
message whose text has an unmatched brace ("why does `if (x) {` fail?")
never closes, so its object runs to the end of the array: every later
message is dropped and their images and audio are attached to it
instead. The model then answers an earlier turn.
Use find_matching_delimiter, which already skips string contents and is
used for tool_calls in the same function.
Signed-off-by: breken <hello@breken.ai>
This branch has not been deployed
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.
What
parse_messages_jsonfound the end of each message object by counting every{and}in the JSON, including those inside strings. This PR usesfind_matching_delimiterinstead, which skips string contents and already boundstool_callsin the same function. It changes one line.Why
When a message's text holds an unmatched brace, its object never closes and runs to the end of the array. In coding chats that is common, for example "why does
if (x) {not compile?". Every later message is dropped, and theirimages/audioare attached to the earlier message. Parsed onmain(fa094ce8):The model then answers an earlier turn and never sees the latest question.
Tests
I added
cactus-engine/tests/test_messages_json_braces.cpp. It needs no model.main, both tests fail:unbalanced_brace_in_content_keeps_later_messagesandimages_stay_with_their_message.test_bucket(10/10) andtest_kv_compress(29/29) still pass. The model-backed suites were not run: they need a bundle.This touches a different hunk of
parse_messages_jsonthan #764, so the two apply independently.AI disclosure
I found and fixed this with help from an AI coding assistant. I checked the code path by hand and reproduced the failure on
mainbefore writing the fix. The commit is signed off for the DCO.🤖 Generated with Claude Code