[PR #510] [CLOSED] fix(serve): safely handle malformed or partial tool call arguments in history #2671

Closed
opened 2026-11-04 02:02:16 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/510
Author: @praveshkhatana
Created: 10/2/2026
Status: ❌ Closed

Base: main ← Head: fix/tool-call-argument-fallback


📝 Commits (1)

  • 6338666 fix(serve): safely handle malformed or partial tool call arguments in history

📊 Changes

3 files changed (+19 additions, -1 deletions)

View changed files

📝 serve/frontend.py (+7 -1)
📝 serve/server.py (+1 -0)
📝 serve/test_server.py (+11 -0)

📄 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.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/510 **Author:** [@praveshkhatana](https://github.com/praveshkhatana) **Created:** 10/2/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/tool-call-argument-fallback` --- ### 📝 Commits (1) - [`6338666`](https://github.com/Niko1221/Strata/commit/633866600c5918d9d28b8a4e0f90a8e5c370ed31) fix(serve): safely handle malformed or partial tool call arguments in history ### 📊 Changes **3 files changed** (+19 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `serve/frontend.py` (+7 -1) 📝 `serve/server.py` (+1 -0) 📝 `serve/test_server.py` (+11 -0) </details> ### 📄 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`. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-04 02:02:16 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#2671
No description provided.