[PR #681] [CLOSED] serve: a malformed "tools" is a 400, not a dead request thread #2760

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

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/681
Author: @hireymage
Created: 10/3/2026
Status: ❌ Closed

Base: main ← Head: fix-tools-400


📝 Commits (1)

  • 176850c serve: a malformed "tools" is a 400, not a dead request thread

📊 Changes

2 files changed (+45 additions, -4 deletions)

View changed files

📝 serve/frontend.py (+19 -4)
📝 serve/test_server.py (+26 -0)

📄 Description

Issue: #592

A request whose "tools" is not the list of tool objects it is meant to be ("auto", ["get_weather"], a bare
number, a dict) took the request thread down with an AttributeError — the connection closes with no reply at
all, a reverse proxy shows a 502. It happened two lines apart, both still on main:

  • serve/frontend.py — the OpenAI mapping handed non-dict entries on unchanged, and the next consumer
    (serve/server.py, own = {t.get("name") for t in tools or []}) assumed every entry is a mapping;
  • serve/frontend.py's Anthropic path had the same shape one level earlier (t["name"] on a non-dict).

The fix

The same treatment double-encoded "messages" got in #460 (_object_list): what is not a list of object-shaped
tools is a ValueError naming the field, which the server answers with its 400 invalid_request_error:

  • both paths accept a JSON string of the list (decoded, not iterated character by character);
  • the OpenAI path validates each entry: a function-type entry needs its "function" object with a non-empty
    "name", the llama style needs a name (the working shape from the issue's repro {"name": "get_weather"}
    keeps working exactly as before);
  • the Anthropic path validates its name-bearing tool definitions the same way.

Tests

serve/test_server.py's test_tools_must_be_an_object_list covers the crashing shapes from the issue end to end,
the entry-level rejections (a function entry without its function object, an empty or non-string name), the
double-decode, and the valid shapes mapping as before (119 tests, suite green).


🔄 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/681 **Author:** [@hireymage](https://github.com/hireymage) **Created:** 10/3/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix-tools-400` --- ### 📝 Commits (1) - [`176850c`](https://github.com/Niko1221/Strata/commit/176850c0d66be49258fe18f7048abaf97a42f016) serve: a malformed "tools" is a 400, not a dead request thread ### 📊 Changes **2 files changed** (+45 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `serve/frontend.py` (+19 -4) 📝 `serve/test_server.py` (+26 -0) </details> ### 📄 Description **Issue:** #592 A request whose `"tools"` is not the list of tool objects it is meant to be (`"auto"`, `["get_weather"]`, a bare number, a dict) took the request thread down with an `AttributeError` — the connection closes with no reply at all, a reverse proxy shows a 502. It happened two lines apart, both still on main: - `serve/frontend.py` — the OpenAI mapping handed non-dict entries on unchanged, and the next consumer (`serve/server.py`, `own = {t.get("name") for t in tools or []}`) assumed every entry is a mapping; - `serve/frontend.py`'s Anthropic path had the same shape one level earlier (`t["name"]` on a non-dict). ### The fix The same treatment double-encoded `"messages"` got in #460 (`_object_list`): what is not a list of object-shaped tools is a `ValueError` naming the field, which the server answers with its 400 `invalid_request_error`: - both paths accept a JSON string of the list (decoded, not iterated character by character); - the OpenAI path validates each entry: a `function`-type entry needs its `"function"` object with a non-empty `"name"`, the llama style needs a name (the working shape from the issue's repro `{"name": "get_weather"}` keeps working exactly as before); - the Anthropic path validates its name-bearing tool definitions the same way. ### Tests `serve/test_server.py`'s `test_tools_must_be_an_object_list` covers the crashing shapes from the issue end to end, the entry-level rejections (a `function` entry without its function object, an empty or non-string name), the double-decode, and the valid shapes mapping as before (119 tests, suite green). --- <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:55 +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#2760
No description provided.