Pull requests / #510

#510 fix(serve): safely handle malformed or partial tool call arguments in history

closed · @praveshkhatana · 0 commentaires · Sur GitHub

Server & API

Description

### Summary
When an agent client (e.g. coding agents, multi-turn assistant tools) sends conversation history containing an interrupted, partial, or malformed JSON argument in `tool_calls`, `serve/frontend.py` line 181 was calling `json.loads(args)` without exception handling.

Unlike lines 154, 360, and 469 (which gracefully catch JSON errors), an unhandled `json.JSONDecodeError` (`ValueError`) in line 181 immediately rejected the turn with `HTTP 400 invalid_request_error`. Because agent clients preserve turn history, subsequent requests repeatedly failed with a non-retryable 400 error, permanently breaking the session.

### Changes
1. **Safe Recovery:** Wrapped `json.loads(args)` in `openai_to_messages` with a `try ... except (ValueError, json.JSONDecodeError)` fallback (`{"raw": args}`), preventing historical tool calls from crashing the session.
2. **Diagnostic Logging:** Added logging of `ValueError` reasons in `server.py` for visibility into 400 client rejections.
3. **Unit Test:** Added `test_tool_call_malformed_arguments_fallback` in `serve/test_server.py`.

Sur le site

Liens install, modèles, releases.