fix(agent): surface HTTP errors from the unload_models tool - #286
Open
kevin9327 wants to merge 1 commit into
Open
fix(agent): surface HTTP errors from the unload_models tool#286kevin9327 wants to merge 1 commit into
kevin9327 wants to merge 1 commit into
Conversation
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>
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
The
unload_modelschat tool discarded the response fromPOST /model/unload-alland 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 sharedexcept httpx.HTTPStatusErrorhandler that turns an HTTP error status into"API error <status>: ...". But httpx does not raise on an error status unless you callraise_for_status(). Every other POST-based tool —list_models,decimate_mesh,smooth_mesh,get_generation_status— captures the response and callsraise_for_status(), and the MCP server'smodly_unload_modelsdoes too.unload_modelswas 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.Fix
Capture the response and call
raise_for_status(), matching the sibling tools and the MCP server. The existingHTTPStatusErrorhandler then surfaces the real failure.Verification
api/tests/test_agent_router.py(unittest +httpx.MockTransport).test_http_error_is_surfacedfails before this change (it gets the success string back for a mocked 500) and passes after;test_success_still_reports_unloadedguards the happy path.python -m unittest discover -s testsinapi/(venv withfastapi+python-multipart+httpx): all pass, 0 failures.