Skip to content

Improve tool call and session cancellation reliability - #769

Merged
alejandro-ao merged 3 commits into
huggingface:mainfrom
choongng:upstream/accurate-failures
Oct 23, 2026
Merged

alejandro-ao merged 3 commits into
huggingface:mainfrom
choongng:upstream/accurate-failures

Conversation

@choongng

Copy link
Copy Markdown
Contributor

Analysis of traces showed that models would often fail to recover from bad tool calls, in part because the error response from tau did not provide a clear reason for the failure (just "path must be a string"). This disproportionately affects smaller models. The main change in this PR is to provide a diagnostic about missing arguments, the most common failure that is also correctible with feedback. As a follow-on, during tool calls I noticed that session cancellation doesn't always work. Rather than spam ctrl-c, with the second change in this PR once is enough. Subjectively this makes tau usage more reliable but I do not have a quantitative comparison of the before/after.

All tests pass and these changes have been tested in many sessions.

choong added 2 commits October 13, 2026 09:04
When a run was cancelled during tool execution (the user cancelling a
running command, or a before_tool_call hook stopping the run), the loop
still started the next provider request. That request saw the cancel
mid-read and returned without a terminal event, so the run ended as an
error ("Provider stream ended without a terminal event") instead of as
aborted.

The loop now checks the signal before each request and ends the run with
stop_reason "aborted". If the tool call that cancelled the run returned
an error, its text becomes error_message, so a hook's reason is kept;
otherwise it is "Operation aborted".
…string"

Providers pass a tool call whose argument text is not valid JSON as
{"_raw_arguments": text}, usually a reply cut off at the output limit
(e.g. a write of a large file). The tool found no path and answered
"path must be a string", and models tend to resend the same oversized
call. Such a call now fails with an error that names the cut-off and
suggests sending less per call.

A call that omits a required string argument got the same error. It now
names the missing argument and the ones that were sent. A present value
of the wrong type still gets "must be a string".

@alejandro-ao alejandro-ao left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved after review and re-validation at merged head 0d2ec160 (PR head + latest main):

  • Full test suite: 2098 passed, 2 skipped
  • ruff check / ruff format --check: clean
  • mypy (strict): clean
  • Required CI checks on updated head: Python checks and Documentation build both pass

@alejandro-ao
alejandro-ao merged commit 1fb01ba into huggingface:main Oct 23, 2026
2 checks passed
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.

2 participants