Skip to content

fix(engine): anchor content search to obj_start in parse_messages_json#764

Open
somtri wants to merge 1 commit into
cactus-compute:mainfrom
somtri:fix/757-parse-messages-content-order
Open

fix(engine): anchor content search to obj_start in parse_messages_json#764
somtri wants to merge 1 commit into
cactus-compute:mainfrom
somtri:fix/757-parse-messages-content-order

Conversation

@somtri

@somtri somtri commented Jul 11, 2026

Copy link
Copy Markdown

Fixes #757.

parse_messages_json searches for "role" starting at the message object's opening brace, so it finds the role key regardless of where it appears in the object. The search for "content", however, started from the end of the parsed role value instead of the same starting point. When a message object serializes content before role (legal JSON, since key order isn't semantically significant, and something an unordered-map serializer such as Swift's JSONSerialization can produce), the content key sits earlier in the string than the search start, so it's never found within the object's bounds and msg.content is silently left empty.

This anchors the content search to obj_start, matching how role and the images/audio path arrays already search. The existing content_pos < obj_end bound is unchanged, so the search still can't cross into a later message object.

Added cactus-engine/tests/test_parse_messages.cpp, a standalone suite (no model weights needed) covering role-first order, content-first order, escaped content, mixed ordering across a multi-message array, and content-first with image/audio paths attached. Confirmed the content-first case fails on the unpatched function and passes after the fix.

Built and ran the full cactus-engine test component (all 15 targets) on an ARM64 Linux environment. No new failures. Two pre-existing, unrelated issues were investigated and ruled out as caused by this change: test_index needs CACTUS_INDEX_PATH set when run directly (passes once set); test_telemetry's concurrency race test fails identically on the unpatched tree (confirmed by reverting the fix and rerunning), most likely a timing margin issue under emulation, not related to this diff.

parse_messages_json searched "content" from role_end instead of
obj_start, so a message object serializing content before role (legal
JSON; key order isn't semantically significant) silently dropped its
content. role_pos and the images/audio path arrays already search from
obj_start; content_pos now matches.

Fixes cactus-compute#757

Signed-off-by: Som Tripathi <somtri@iastate.edu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

parse_messages_json drops a message's content when the JSON key order is content before role

1 participant