Skip to content

fix(agents): recover from non-object tool arguments - #5732

Merged
kovtcharov-amd merged 1 commit into
amd:mainfrom
jipeng6036-del:fix/recover-non-object-tool-arguments
Oct 26, 2026
Merged

kovtcharov-amd merged 1 commit into
amd:mainfrom
jipeng6036-del:fix/recover-non-object-tool-arguments

Conversation

@jipeng6036-del

Copy link
Copy Markdown
Contributor

Summary

Treat non-object tool arguments as a recoverable formatting error so the model can correct its call.

Why

A model sending a string or list instead of an argument object crashed the whole turn with a raw Python error. It now receives the tool name and the invalid argument type, retries, and can finish the request.

Linked issue

Closes #5471

Changes

  • Validate decoded calls before dispatch, preserving no-argument calls, conversational replies without a tool name, and closing-reply retries.
  • Cover streaming/non-streaming recovery, malformed parallel batches and retry exhaustion; document the behavior.

Test plan

  • New process_query regressions: original 48 failed/22 passed → candidate 70 passed.
  • Full Linux pytest tests/unit/ -n 4 --dist=worksteal --cov=src/gaia: original 27508 passed, candidate 27578 passed; each with 478 skips, 3 xfails and 41 passing subtests. Collection-skip guard passed unchanged.
  • Windows affected agent suite: 4170 passed/55 conditional skips; Python 3.10 import sweep + new regressions: 72 passed.
  • Separate chat/flagship/email package and email HTTP/confirmation lanes: 4425 passed/9 conditional skips (reasons in evidence); all three collection guards and the capability-matrix check passed.
  • CLI confirmation, database and context integration: 77 passed. python util/lint.py --all succeeded with its configured MyPy advisory; packaging: 13 passed, frontend/wheel builds passed.
  • Real gaia chat --query on original/source/installed wheel, plus the browser and HTTP/SSE proof below. Independent source and architecture review completed.
  • Next RC: watch tool_selection and error_recovery under the project's no-local-Strix-Halo eval exception. Real model evals were not run here.

Evidence

Commands, versions, exact commits, logs and all four before/after cases. Only the external model HTTP replies are scripted; the actual CLI, UI, provider decoding, agent loop and file_info tool run normally. This does not validate real model inference or GPU behavior.

Original: malformed string arguments crash the chat
Candidate: the model corrects its arguments and the real file_info tool answers

  • Agent UI / HTTP: four fresh JSON/native × string/list sessions each, persisted responses checked and candidate page reloaded.
  • CLI: original exits with code 1; source and independent installed wheel exit with code 0 and return the real file's metadata.
  • MCP: N/A; no MCP transport, tool schema or server surface changed.
🔍 Technical details

Baseline 82ad2a771c7ed5b6b26f4521b3e4eaad40820f85; candidate ada550c412069392b14df926401d4fcadcf15cb3. The manifest ties the complete local runs to the committed source blobs. Hosted checks are separate from these local results.

Checklist

  • Linked an issue and explained the user impact.
  • Ran local lint and tests.
  • Attached evidence from the affected user surface and marked the unchanged surface N/A.
  • Updated the behavior documentation.

Reject malformed argument values before tool dispatch so the existing recovery loop can ask the model to correct them. Preserve conversational replies and closing-answer retries, with process_query regressions and behavior documentation.
@github-actions github-actions Bot added documentation Documentation changes tests Test changes agents labels Oct 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve

Before this change, a model that sent a plain string or a list as a tool's arguments, instead of an object, crashed the whole chat turn with a raw Python error. Now the model is told which tool it called and what type it sent, and it gets a retry through the same retry budget that already handles malformed JSON. I found no blocking issues. The check runs before any tool executes, so one bad call in a parallel batch no longer lets the valid calls before it run.

Real-world evidence

N/A here: this run produced no evidence bundle, and pytest isn't installed on this review runner, so I couldn't run the new tests. My verdict rests on static review plus the author's evidence in the PR description. That evidence includes embedded before/after Agent UI screenshots, CLI exit codes (1 before, 0 after), and HTTP/SSE checks. Model replies are scripted there, so real-model behaviour still needs the next RC eval (tool_selection, error_recovery), as the PR notes.

🔍 Technical details

Issues found

🟢 The two messages for a non-object native call disagree (src/gaia/agents/base/agent.py:5540). A raw native arguments value that is a list or int still fails the older check, whose message says "expected str or dict". The new wrapper says "expected a JSON object". Both recover correctly, but the model gets different guidance for the same mistake. Rewording the older message to match would keep the retry prompt consistent. This is optional.

Checked and fine

  • Every path that produces tool_calls (native at ~5534, markup at _parse_markup_tool_calls, embedded/regex JSON) sets both name and tool_args. That means call["tool_args"] / call["name"] in the new wrapper can't raise KeyError.
  • {"tool": "x"} with no tool_args still defaults to {}, and replies whose tool is empty or null skip validation. Tests cover both.
  • Raising ValueError sends the failure into the existing tool_call_parse_error recovery in process_query, which is in _RECOVERABLE_ERROR_TYPES and also covers the plan-parse path. The closing-reply path wraps it as _NotAnAnswer (line 7103), so it doesn't escape that retry.
  • The other parse paths still reach the decoder through _parse_llm_response. No caller outside base/agent.py uses the renamed _decode_llm_response (the email agent's _parse_llm_response is an unrelated module function).

Strengths

  • Validating at the parse boundary, instead of in each dispatch site, covers JSON, native, embedded, and streaming replies with one check.
  • The tests run the full process_query loop rather than the parser alone. They cover streaming and non-streaming, retry exhaustion, the closing-call retry, and the regression where a parallel batch runs its valid calls before the bad one.
  • The spec doc was updated in the same change.

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Oct 26, 2026
Merged via the queue into amd:main with commit 63538f4 Oct 26, 2026
38 checks passed
kovtcharov pushed a commit to kovtcharov/gaia that referenced this pull request Oct 26, 2026
…md#5734)

## Summary

Keep the original query error when saving that turn's undo history also
fails.

## Why

A turn that raises after changing a file can lose its real error if the
snapshot store also runs out of space. The sidecar then reports “This is
a bug” instead of the processing failure. The original error now
survives, undo still gets its warning, and both tracebacks are logged
even when the copy error suppresses exception context.

## Linked issue

Closes amd#5666

## Changes

- Retain the processing exception across the recording context's
finalization, without emitting a terminal event before recording ends.
- Add four endpoint regressions for different original exception types,
suppressed undo context, terminal ordering and session-lock cleanup.
- Document the dual-failure behavior in the SSE contract.

## Test plan

- [x] Final regression overlay on original production: **4 failed / 9
passed**; candidate endpoint suite: **13 passed**.
- [x] Complete Linux `pytest tests/unit/ -n 4 --dist=worksteal`: **27508
passed / 478 skipped / 3 xfailed**, with 41 passing subtests. Collection
guard passed unchanged.
- [x] Complete flagship package suite on Linux Python 3.12.14 and
Windows Python 3.12.13: **796 passed / 3 conditional skips** each. Linux
subprocess imports were explicitly bound to the candidate too.
- [x] Affected snapshot/changes/dispatch/relay contract suites: **206
passed / 2 conditional skips**; flagship collection guard and capability
matrix passed.
- [x] `python util/lint.py --all`: **17 passed / 1 configured
nonblocking MyPy advisory**; staged lane/path checks passed. Wheel/sdist
builds, Twine validation and independent installed-wheel import parity
passed.
- [x] Actual browser and HTTP/SSE proof below; native independent
code/architecture review completed.
- [ ] Next RC: watch `error_recovery` under the repository's
no-local-Strix-Halo eval exception. Real model evals were not run here.

An additional fixture-enabled relay-query diagnostic exposes the same
old fake-handler mismatch on both revisions (**1 failed / 3 passed**,
missing `set_relay_question`). It is recorded separately, not counted as
green. The configured contract run above retains its normal conditional
query skip; the actual browser proof uses the production handler and
passes.

## Evidence

[Exact commits, commands, versions, logs, controls and raw
screenshots](https://github.com/jipeng6036-del/gaia/tree/c4b13d8618dcc9ebbbef2631613b53113fdd41f3).

The real `gaia chat --ui` → browser → daemon → dev sidecar → GaiaAgent →
`write_file` chain runs on both revisions. Only model HTTP replies and
an isolated install receipt are fixtures. After the real file write, a
separate **1 MiB tmpfs** produces genuine snapshot `ENOSPC`; no
production Python code is monkeypatched. This tests the user path, not
real inference/GPU behavior or a frozen binary installation.

![Original: undo failure hides the processing error behind the generic
bug
message](https://raw.githubusercontent.com/jipeng6036-del/gaia/c4b13d8618dcc9ebbbef2631613b53113fdd41f3/baseline-ui.png)
![Candidate: the same two failures preserve the original processing
error](https://raw.githubusercontent.com/jipeng6036-del/gaia/c4b13d8618dcc9ebbbef2631613b53113fdd41f3/candidate-ui.png)

- **Agent UI / HTTP:** before/after pages, reload recovery, persisted
messages and six HTTP/SSE cases cover double failure plus
success/undo-only and processing-only controls.
- **CLI:** launched the actual `gaia chat --ui` command; logs and
arguments are in the evidence harness. The in-process one-shot CLI is
unchanged.
- **MCP:** N/A; no MCP transport or tool schema changed.

Baseline `82ad2a771c7ed5b6b26f4521b3e4eaad40820f85`; candidate
`529dc35fd434f9582c3490b2f7f39d1797464c6b`. The manifest ties validation
to all three committed blobs. The scripted processing error uses the
independently tracked amd#5471 baseline case; this fix does not stack
amd#5732's parser change. Hosted CI and human review are separate from
these local results.

## Checklist

- [x] Linked an issue and explained the user impact.
- [x] Ran required local lint and tests; recorded conditional skips and
diagnostic limits.
- [x] Attached evidence from the affected user surface and marked the
unchanged MCP surface N/A.
- [x] Updated behavior documentation.

AI-assisted implementation and verification; human review is pending.
@kovtcharov-amd kovtcharov-amd mentioned this pull request Oct 26, 2026
5 of 9 tasks
grtninja pushed a commit to grtninja/gaia that referenced this pull request Oct 26, 2026
## Why this matters

v0.25.2 is a bug-fix release on top of v0.25.1: setup and install no
longer stop at the first failed step, shell and file access handle
Windows paths and text encodings, the Agent UI and desktop app stop
showing misleading states, and document search, email and skills each
lose a handful of rough edges. 55 commits since v0.25.1; notes are in
`docs/releases/v0.25.2.mdx` and credit 15 outside contributors.

## Test plan

- [x] `python util/validate_release_notes.py docs/releases/v0.25.2.mdx
--tag v0.25.2` passes
- [x] `mintlify validate` (from `docs/`) passes
- [x] `python util/check_doc_links.py --internal-only`, `python
util/check_doc_versions.py` and `node
installer/version/bump-ui-version.mjs --check` pass
- [x] `python util/check_component_core_api.py --release-version 0.25.2`
passes
- [x] `pytest tests/unit/test_docs_json_release.py
tests/unit/test_check_component_core_api.py
tests/unit/test_release_tag.py
tests/unit/test_hub_core_version_gate.py`: 156 passed
- [ ] CI green on the merge commit
- [ ] `release_train_dryrun.yml` passes on that commit before the RC tag

## Evals to re-run on the RC tag

LLM-affecting PRs merged without per-PR evals; run these on
`v0.25.2-rc1`:

- `gaia_shell` and shell/safety (amd#5794, amd#5751, amd#5768)
- `gaia_honesty` (amd#5753)
- `gaia_skills_tasks` and `gaia_skills_lifecycle` (amd#5422, amd#5755)
- `rag_retrieval` and `rag_quality` (amd#5742, amd#5754, amd#5761, amd#5817, amd#5812)
- email scenarios (amd#5767, amd#5811)
- `tool_selection` and `error_recovery` (amd#5732)
- Claude provider thinking replay (amd#5072)
- memory categories (amd#5818 merged; amd#5756 has not)

## Release checklist

- [ ] Freeze main, wait for green CI on the exact commit, pass
`release_train_dryrun.yml`, then push `v0.25.2-rc1`
- [ ] Extend the changelog if main gains commits before the tag
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents documentation Documentation changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Agent turn crashes when a model sends tool arguments that aren't an object

2 participants