Repository navigation
fix: return undecodable tool call arguments to the model instead of failing the turn - #438
Merged
Merged
Conversation
…ailing the turn
A tool call whose arguments are not a JSON object, usually because the
response was cut off at max_tokens, raised and ended the whole turn. It is
now a failed tool result the model can correct, saying so when the response
stopped at the output token limit. The call is recorded with `{}` arguments
so the tape replays on any provider.
A step that fails after the model answered is now recorded with its usage,
and ChatFinished and the tape's run event carry the finish reason.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
bub | 1fdcd99 | Commit Preview URL Branch Preview URL |
Dec 02 2026, 11:15 AM |
…honest
Review follow-ups on returning undecodable tool call arguments to the model:
- Such a call no longer reaches ToolExecutor, so no ToolCallStarted handler
is asked to approve or replace a call that cannot run.
- Arguments cut off before their first character, which arrive as `{}`,
are treated as cut off instead of running the tool. Only the last call of
a response that stopped at the token limit counts as cut off.
- Any ValueError or RecursionError from decoding is handled, not only
JSONDecodeError.
- A step that fails after the model answered records each call's outcome as
unknown instead of copying the step's error onto calls that succeeded, and
an error from recording no longer replaces the step's own error.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Undecodable arguments resolve to a placeholder tool that raises, the same way an unknown tool name does, so ToolExecutor turns the error into the call's result. This replaces the agent's own path that kept such calls out of the executor and merged their errors back into the results. ToolCallStarted and ToolCallFinished handlers see these calls again, with empty arguments. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The agent built a raising placeholder tool by hand for both an unknown tool name and undecodable arguments. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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 changed and why
A subagent run ended with
[invalid_input] Expected a function tool call with JSON object argumentsafter 24 healthy steps. The model had spent almost all of itsmax_tokenson reasoning (16,033 of 16,384 output tokens on the previous step), so the next tool call's arguments were cut off mid-JSON. Bub treated that as fatal and ended the turn, and recorded nothing about the failing step.ToolExecutorturns the error into the call's result. The real tool does not run; the model gets aninvalid_inputresult and can retry.length, the error on its last call says the arguments were cut off at the output token limit and asks for a shorter call. This includes arguments cut off before their first character, which arrive as{}and previously would have run the tool.{}arguments. The raw string would break replay on providers that parse arguments when building a request. The original text (first and last 500 characters when longer than 1,000) and its length are kept in the error details.ChatFinishedis emitted with the error, the new messages, the calls, and usage, before the exception propagates. Each call's result says its outcome is unknown, because the step failed before results were collected. An error raised while recording is logged and does not replace the step's own error.finish_reasonis recorded.ChatFinishedhas a newfinish_reasonfield, and the tape'srunevent stores it.Behavior to review
ToolCallStartedandToolCallFinishedhandlers see a call with undecodable arguments, under the tool's real name and with empty arguments. An approval handler may therefore ask about a call that will fail anyway.Known gaps, not addressed here
LLMCallFinishedhandler that raises after a complete response still leaves the step unrecorded.is_errorstays false). This is existing replay behavior and also applies to the new error results.Impacted modules
src/bub/core/agent.py: tool call resolution and step recordingsrc/bub/core/events.py,recorder.py,tape.py:finish_reasononChatFinishedand theruneventwebsite/src/content/docs/{docs,zh-cn/docs}/reference/python-api.mdx:ChatFinishedreferenceVerification
uv run pytest -q: 787 passed, 20 skippeduv run ruff check,uv run ty check: cleanBUB_MAX_TOKENS=1200, on an earlier revision of this branch: a tool call was cut off, the model received the truncation error and answered normally, and the tape'srunevent showedfinish_reason: lengthTests: the existing test that asserted invalid arguments raise now asserts the model receives a failed result and that the replayed call carries
{}. New tests cover the truncation message, empty arguments at the token limit, arguments that fail to decode with a non-JSON error, and a mixed batch where one call's handler raises after another call succeeded.🤖 Generated with Claude Code