[GH-ISSUE #592] serve: a malformed "tools" value kills the request thread (connection reset / 502 instead of a 400) #278

Closed
opened 2026-11-04 01:41:35 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @MingShi350 on GitHub (Oct 3, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/592

What happens. A request whose tools is not a list of tool objects takes the request thread down with an
AttributeError. The connection closes with no reply at all — the same request through a reverse proxy shows as
502. A 400 naming the bad field would be right.

Seen on Windows, Strata 0.1.38, engine IQ3_XXS, 128K context, OpenAI endpoint, client on another PC.

Where. Two places, one line apart (both still on main):

  • serve/frontend.py:185 — an entry that is not {"type": "function", ...} is handed on unchanged:
    tools = [t.get("function", t) if isinstance(t, dict) and t.get("type") == "function" else t
             for t in req.get("tools") or []] or None
    
  • serve/server.py:2422 — the next consumer assumes every entry is a mapping:
    own = {t.get("name") for t in tools or []}
    

Traceback (the server's own console):

Exception occurred during processing of request from ('192.168.31.12', 40386)
Traceback (most recent call last):
  ...
  File "E:\AI\Strata-main\serve\server.py", line 2422, in _openai
    own = {t.get("name") for t in tools or []}
AttributeError: 'str' object has no attribute 'get'

Reproduce. Any of these:

curl -X POST http://127.0.0.1:8080/v1/chat/completions -H "Content-Type: application/json" \
  -d '{"messages":[{"role":"user","content":"hi"}],"tools":"auto","max_tokens":8}'
curl -X POST http://127.0.0.1:8080/v1/chat/completions -H "Content-Type: application/json" \
  -d '{"messages":[{"role":"user","content":"hi"}],"tools":["get_weather"],"max_tokens":8}'
curl -X POST http://127.0.0.1:8080/v1/chat/completions -H "Content-Type: application/json" \
  -d '{"messages":[{"role":"user","content":"hi"}],"tools":[{"name":"get_weather"}],"max_tokens":8}'

Expected: 400 saying what is wrong with tools.
Observed: no reply; the traceback above; the server itself stays up and the next request is answered normally.

The Anthropic path is the same shape, one line up at serve/frontend.py:235, where t["name"] on a string
raises TypeError: string indices must be integers for the same kind of input.

Suggested fix. Refuse a malformed tools where the request is parsed — openai_to_messages /
anthropic_to_messages already raise ValueError for other fields, and the caller turns that into a 400 — and
guard the consumer as a second line of defence:

own = {t.get("name") for t in tools or [] if isinstance(t, dict)}

I hit this from a client that put the wrong value in tools by mistake; the connection reset made it look like the
engine had died, so the clean 400 would have saved some hunting.

Originally created by @MingShi350 on GitHub (Oct 3, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/592 **What happens.** A request whose `tools` is not a list of tool objects takes the request thread down with an `AttributeError`. The connection closes with no reply at all — the same request through a reverse proxy shows as `502`. A `400` naming the bad field would be right. Seen on Windows, Strata 0.1.38, engine IQ3_XXS, 128K context, OpenAI endpoint, client on another PC. **Where.** Two places, one line apart (both still on `main`): - `serve/frontend.py:185` — an entry that is not `{"type": "function", ...}` is handed on unchanged: ```python tools = [t.get("function", t) if isinstance(t, dict) and t.get("type") == "function" else t for t in req.get("tools") or []] or None ``` - `serve/server.py:2422` — the next consumer assumes every entry is a mapping: ```python own = {t.get("name") for t in tools or []} ``` **Traceback** (the server's own console): ``` Exception occurred during processing of request from ('192.168.31.12', 40386) Traceback (most recent call last): ... File "E:\AI\Strata-main\serve\server.py", line 2422, in _openai own = {t.get("name") for t in tools or []} AttributeError: 'str' object has no attribute 'get' ``` **Reproduce.** Any of these: ```sh curl -X POST http://127.0.0.1:8080/v1/chat/completions -H "Content-Type: application/json" \ -d '{"messages":[{"role":"user","content":"hi"}],"tools":"auto","max_tokens":8}' curl -X POST http://127.0.0.1:8080/v1/chat/completions -H "Content-Type: application/json" \ -d '{"messages":[{"role":"user","content":"hi"}],"tools":["get_weather"],"max_tokens":8}' curl -X POST http://127.0.0.1:8080/v1/chat/completions -H "Content-Type: application/json" \ -d '{"messages":[{"role":"user","content":"hi"}],"tools":[{"name":"get_weather"}],"max_tokens":8}' ``` Expected: `400` saying what is wrong with `tools`. Observed: no reply; the traceback above; the server itself stays up and the next request is answered normally. **The Anthropic path is the same shape**, one line up at `serve/frontend.py:235`, where `t["name"]` on a string raises `TypeError: string indices must be integers` for the same kind of input. **Suggested fix.** Refuse a malformed `tools` where the request is parsed — `openai_to_messages` / `anthropic_to_messages` already raise `ValueError` for other fields, and the caller turns that into a `400` — and guard the consumer as a second line of defence: ```python own = {t.get("name") for t in tools or [] if isinstance(t, dict)} ``` I hit this from a client that put the wrong value in `tools` by mistake; the connection reset made it look like the engine had died, so the clean `400` would have saved some hunting.
Author
Owner

@Niko1221 commented on GitHub (Oct 4, 2026):

Fixed in 0.1.39: a tools value that is not a list of named tool objects (a string such as "auto", a list of names, an object without a name) now gets a 400 that says what tools must look like, on /v1/chat/completions and /v1/messages, instead of a dropped connection. A JSON-string list is decoded, as for messages, and the bare {"name": ...} shape is still accepted on the OpenAI path. Thanks for the precise report and the three curl cases, which are now tests.

<!-- gh-comment-id:5979960249 --> @Niko1221 commented on GitHub (Oct 4, 2026): Fixed in 0.1.39: a `tools` value that is not a list of named tool objects (a string such as "auto", a list of names, an object without a name) now gets a 400 that says what `tools` must look like, on /v1/chat/completions and /v1/messages, instead of a dropped connection. A JSON-string list is decoded, as for `messages`, and the bare `{"name": ...}` shape is still accepted on the OpenAI path. Thanks for the precise report and the three curl cases, which are now tests.
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#278
No description provided.