Skip to content

fix: prevent infinite loops in malformed LFM2 tool calls - #827

Open
michboy wants to merge 1 commit into
cactus-compute:mainfrom
michboy:fix/lfm2-parser-synced
Open

michboy wants to merge 1 commit into
cactus-compute:mainfrom
michboy:fix/lfm2-parser-synced

Conversation

@michboy

@michboy michboy commented Oct 18, 2026 •

Copy link
Copy Markdown

Summary

Fixes #823.

The LFM2 tool-call parser can enter an infinite loop when processing malformed arguments with mismatched closing brackets, potentially causing unbounded memory growth.

This PR prevents the parser from getting stuck on malformed input.

Changes

  • Handle mismatched closing brackets in py_literal_to_json().
  • Return null for empty scalar values.
  • Skip unexpected closing brackets in extract_lfm2_tool_calls().
  • Ensure the parser makes forward progress on malformed arguments.
  • Add four regression test cases for valid and malformed tool calls.

Testing

Added cactus-engine/tests/test_chat_tools_823.cpp with four standalone C++ regression tests.

Local test results pending verification.

Attribution

The fix follows the approach originally proposed by @Rasaboun in #823, with regression tests added.

Signed-off-by: michboy <michboy@umich.edu>

This branch has not been deployed

No deployments
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.

LFM2 tool-call parser (chat_tools.h) loops forever with unbounded memory on a mismatched bracket; cactus_stop cannot interrupt it

1 participant