Repository navigation
fix(llmcore): reconstruct pseudo-XML tool calls and never execute a truncated one - #873
Closed
leonsong09 wants to merge 3 commits into
Closed
leonsong09 wants to merge 3 commits into
leonsong09 wants to merge 3 commits into
Conversation
added 3 commits
November 11, 2026 17:11
…runcated one Issue lsdefine#863: some upstreams emit the tool call as plain content text instead of a native `tool_calls` array. `_parse_text_tool_calls` only understood a trailing `tool_use` JSON array and `<tool_use>`/`<tool_call>` JSON wrappers, so every observed spelling fell through to `do_no_tool`, which had no matching guard, and the turn ended silently with no error. llmcore * `_parse_pseudo_xml_tool_calls`: rebuild closed blocks into MockToolCall. Handles `<code_run><script>`, `<parameter name=|name=>`, a stray quote after the tool name, `<function=name>`, and the `||DSML||` shell. Names are validated against assets/tools_schema.json; fenced and inline code is masked out so quoted examples are never executed. * `textual_tool_residue`: 'unclosed' / 'empty' / 'orphan' / 'invalid' for anything that cannot be executed, so callers can retry instead of delivering it. * The safety gate lives inside `_parse_text_tool_calls`, not in `do_no_tool`: a truncated call must not become a real tool_call first. A cut that happens to leave valid Python is rejected too, and a closed block whose script fails to parse is reported as residue rather than silently dropped. ga * `do_no_tool` retries on any residue, naming the bogus formats in the prompt so the model does not simply re-emit them. * `_retry_or_exit` now yields a visible abort note instead of returning `should_exit=True` with nothing printed - same "silent stop" failure mode. tests/test_text_tool_call.py covers shapes A-H, the cut-but-valid-Python case, the closed-but-broken-script case, and the negatives (prose, inline code, fenced block, JSON example).
正文里解释格式("用法: <parameter name=…>")不该触发重试。残渣判定与块扫描
保持同一条边界: 只有独立成行的标签才算泄漏。形状 D 仍命中(它的 <type> 与
<parameter> 各自独占一行)。
tests: 8 passed (新增 2: 说明句不误报 / 孤行 orphan 仍重试)。
Author
|
superseded by #880 — see #880 / #881. Folded into #880 as the first commit, unchanged: the pseudo-XML reconstruction, the Closing to keep one open diff per change; the branch is untouched if you'd rather look at it in isolation. |
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.
Closes #863.
What this fixes
Some upstreams emit the tool call as plain content text instead of a native
tool_callsarray._parse_text_tool_callsonly understood a trailingtool_useJSON array plus
<tool_use>/<tool_call>JSON wrappers, so every observed spellingfell through to
do_no_tool; no guard matched there, and the turn ended silentlywith no error and nothing executed.
Reproduced with the eight shapes from #863 (plain content, zero native tool calls):
<code_run><script>…<parameter name="script"><file_read">(stray quote)<type>-wrapped parameters||DSML||invoke<function=code_run><parameter=script></code_run><code_run></code_run>Where the cut-off guard lives
The guard is inside
_parse_text_tool_calls, not indo_no_tool. A call that wascut mid-stream must not become a real
tool_callin the first place: once it is, thenormal response path runs it and
do_no_toolis never reached. This matters beyondsyntax errors — a cut that happens to leave valid Python would otherwise run half a
script.
textual_tool_residue(content)classifies what could not be executed:unclosed— the stream was cut mid-callempty— block closes but carries no argumentsorphan—<parameter>with no tool name (<type>-wrapped)invalid— block closes, but the rebuilt call cannot run safely (half a script,or a script that fails
ast.parse)do_no_toolretries on any of them.Also
_retry_or_exitused to returnStepOutcome({}, should_exit=True)with nothingprinted after three unusable replies — the same silent stop, one level up. It now
yields a visible
[任务中止]note first.Scope and risk
is in
assets/tools_schema.json, and at least one argument is recoverable.never executed.
tool_calls; the fallback only runs whentool_callsis empty.Tests
pytest tests/test_text_tool_call.py -q→ 8 passedCovers A–H, the cut-but-valid-Python case, the closed-but-broken-script case, and the
negatives (prose, inline code, fenced block, JSON example).