fix: resolve Python FFI buffer limits and single-quote escaping in to…#761
Open
ApurveKaranwal wants to merge 1 commit into
Open
fix: resolve Python FFI buffer limits and single-quote escaping in to…#761ApurveKaranwal wants to merge 1 commit into
ApurveKaranwal wants to merge 1 commit into
Conversation
…ol calling Signed-off-by: ApurveKaranwal <apurvekaranwal282@gmail.com>
ApurveKaranwal
force-pushed
the
fix/ffi-buffer-and-tool-quotes
branch
from
July 11, 2026 08:11
023282e to
a967ab6
Compare
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.
Description
This Pull Request addresses three issues identified within the Python FFI bindings and tool-calling parameter parsing logic:
JSON Validation for Single-Quoted Parameter Parsing (
chat_tools.h): LiquidAI models (LFM2/LFM2.5) format tool calls as Python-like arguments (e.g.,my_tool(param='val')). If a parameter value contains an escaped single quote (\'), the parser functionpy_literal_to_jsontranslated it literally as\'inside the resulting double-quoted JSON string (producing"hello \'world\""). Per RFC 8259, this is an invalid escape sequence. As a result, standard JSON parsers (e.g. C++picojsonand python'sjsonmodule) threw syntax errors, aborting tool execution. This has been resolved by unescaping\'to'in the double-quoted JSON output.FFI Document Retrieval Buffer Limit (
cactus.py): The vector database supports indexing documents up to 65,535 bytes (Index::validate_documents). However, the Python FFI bindingcactus_index_getused a hardcoded buffer limit_INDEX_DOC_BUF_SIZE = 4096. Attempting to retrieve documents exceeding 4KB caused the FFI to return-1, raising aRuntimeErroron the Python side. The buffer limit has been increased to65536to safely accommodate the database's actual limit.RAG Query Buffer Limit (
cactus.py): Increased the query results buffer size incactus_rag_queryfrom 64KB to 1MB to safely support RAG queries that return multiple large snippets.Verification
cactus-engine/tests/test_chat_tools.cppto verify that Python-like literals and LFM2 tool calls containing apostrophes are extracted correctly and parsed successfully bypicojson.Please let me know if you would like any modifications or additions.
Fixes #760