Skip to content

fix(agent): surface HTTP errors from the unload_models tool - #286

Open
kevin9327 wants to merge 1 commit into
lightningpixel:devfrom
kevin9327:fix/agent-unload-error
Open

fix(agent): surface HTTP errors from the unload_models tool#286
kevin9327 wants to merge 1 commit into
lightningpixel:devfrom
kevin9327:fix/agent-unload-error

Conversation

@kevin9327

Copy link
Copy Markdown
Contributor

What

The unload_models chat tool discarded the response from POST /model/unload-all and unconditionally returned the success string, so a failed unload (any 4xx/5xx) still told the assistant — and the user — that VRAM had been freed.

Why it triggers

execute_tool (api/routers/agent.py) wraps every tool call in a shared except httpx.HTTPStatusError handler that turns an HTTP error status into "API error <status>: ...". But httpx does not raise on an error status unless you call raise_for_status(). Every other POST-based tool — list_models, decimate_mesh, smooth_mesh, get_generation_status — captures the response and calls raise_for_status(), and the MCP server's modly_unload_models does too. unload_models was the only one that fired the request and threw the response away, so a 500 from the unload endpoint was reported to the model as a success.

elif name == "unload_models":
    await client.post(f"{MODLY_API}/model/unload-all")   # response ignored
    return "All 3D generation models have been unloaded from VRAM.", None

Fix

Capture the response and call raise_for_status(), matching the sibling tools and the MCP server. The existing HTTPStatusError handler then surfaces the real failure.

Verification

  • Added api/tests/test_agent_router.py (unittest + httpx.MockTransport). test_http_error_is_surfaced fails before this change (it gets the success string back for a mocked 500) and passes after; test_success_still_reports_unloaded guards the happy path.
  • python -m unittest discover -s tests in api/ (venv with fastapi + python-multipart + httpx): all pass, 0 failures.

The unload_models tool discarded the response from POST /model/unload-all
and always returned the success string, so when the unload failed (any
4xx/5xx) the assistant and user were told VRAM had been freed when it had
not. Every other POST tool in execute_tool calls raise_for_status(), and
the MCP server's modly_unload_models does too; this brings the tool in
line so the shared HTTPStatusError handler reports the failure.

Adds api/tests/test_agent_router.py covering the error path (fails before
this change, passes after) and the success path.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

1 participant