[GH-ISSUE #1704] Marinara sends OpenAI object-form tool_choice that LM Studio rejects (HTTP 400) #846

Closed
opened 2026-10-21 05:21:49 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @aeriondyseti on GitHub (May 31, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/1704

Originally assigned to: @cha1latte on GitHub.

Summary

Professor Mari sends tool_choice to the LLM provider as a JSON object (the
modern OpenAI Chat Completions spec form), but LM Studio's local OpenAI-compatible
server rejects the object form entirely — it only accepts string values
("none" | "auto" | "required"). Result: Mari is unusable on LM Studio for any code
or library question (which automatically trigger the forced-tool path).

Surfaced during the Ubuntu re-test of smoke test #1480 (Professor Mari Deeper Pass).

Steps to reproduce

  1. Install and run LM Studio (tested on the latest available version as of 2026-05-30).
  2. Load a chat model in LM Studio and start its Local Server (default
    http://localhost:1234/v1).
  3. In Marinara, create a custom connection pointing to LM Studio.
  4. Open Professor Mari, select that connection, and ask any "looks like a codebase
    question" prompt (e.g. "What does src/app/shell/AppShell.tsx do?").
  5. Observe the error rendered in the chat.

Expected behavior

Mari should either:

  • Send a tool_choice value that any OpenAI-API-compatible server accepts (e.g. the
    string "required"), or
  • Detect that the selected provider rejects the object form and fall back gracefully.

In either case the request should complete and Mari should produce a tool-grounded
answer.

Actual behavior

Mari surfaces this in-chat error (no crash — error handling is correct, only the request
shape is the bug):

LLM error: Provider Error: llm_provider_error:
Provider returned HTTP 400 Bad Request:
Invalid tool_choice type: 'object'. Supported string values: none, auto, required

Wire-level evidence

The actual JSON request body Marinara sent to LM Studio (captured from LM Studio's local
server logs):

{
  "max_tokens": 2048,
  "messages": [
    { "role": "system",  "content": "You are Professor Mari... [truncated]" },
    { "role": "user",    "content": "What does src/app/shell/AppShell.tsx do, and where is the sidebar-toggle button defined?" }
  ],
  "model": "qwen3.5-27b-heretic-i1",
  "stream": false,
  "temperature": 0.4,
  "tool_choice": {
    "function": { "name": "search_marinara_code" },
    "type": "function"
  },
  "tools": [
    { "type": "function", "function": { "name": "read_marinara_library",       "parameters": { ... } } },
    { "type": "function", "function": { "name": "search_marinara_code",        "parameters": { ... } } },
    { "type": "function", "function": { "name": "read_marinara_code_file",     "parameters": { ... } } },
    { "type": "function", "function": { "name": "edit_marinara_code_file",     "parameters": { ... } } },
    { "type": "function", "function": { "name": "create_marinara_extension",   "parameters": { ... } } },
    { "type": "function", "function": { "name": "create_marinara_custom_agent","parameters": { ... } } }
  ]
}

The tools array is fine; LM Studio's complaint is specifically and only about
tool_choice being an object rather than a string.

Code reference

src-tauri/src/commands/storage/mari.rs:191-201:

if !tools.is_empty() && !has_tool_result && looks_like_codebase_question(latest_user) {
    parameters["toolChoice"] = json!({
        "type": "function",
        "function": { "name": "search_marinara_code" }
    });
} else if !tools.is_empty() && !has_tool_result && looks_like_library_question(latest_user) {
    parameters["toolChoice"] = json!({
        "type": "function",
        "function": { "name": "read_marinara_library" }
    });
}

Both branches hardcode the object form. There's no fall-through path that would send
the string form, and no per-provider knowledge that LM Studio only accepts strings.

Suggested fix directions

Pick one:

  1. Send tool_choice: "required" always. Simplest. Cost: Marinara loses its ability
    to force a specific tool — the model picks from the registered tools list. For the
    single-tool-registered case this is equivalent. For Mari's 6-tool registry, the system
    prompt already guides tool selection strongly enough that this is probably acceptable.

  2. Provider-aware tool_choice. Keep the object form for providers known to support
    it (e.g. openai, openai_chatgpt, openrouter), fall back to "required" for
    custom and other less-strict providers. More precise; more code.

  3. Spec-compliance fallback. Try the object form first; on HTTP 400 with a
    tool_choice-related error, retry once with the string form. Most defensive; adds a
    round-trip on failure.

This is the second documented Marinara/LM-Studio interop bug of the same family
(Marinara sends a newer-spec OpenAI request shape; LM Studio rejects it):

  • #496 (closed): response_format.type rejected by LM Studio.
  • This issue: tool_choice object form rejected by LM Studio.

A more general fix might be to maintain a per-provider capability table (which OpenAI
extensions each custom-like server supports) rather than patching each parameter
individually.

Environment

  • Marinara Engine branch: refactor @ 5ea8a10c
  • OS: Ubuntu (Wayland)
  • GPU: NVIDIA RTX 5060 Ti
  • Run mode: Tauri desktop (pnpm tauri dev)
  • LM Studio: latest available as of 2026-05-30 (AppImage build, exact version not
    recoverable — the updated build crashed at startup with SIGTRAP shortly after,
    separate problem; the wire-level evidence above was captured from the previous
    working LM Studio version which also rejected the object form, so this is not version
    specific)
  • Model loaded in LM Studio: qwen3.5-27b-heretic-i1 (uncensoring finetune — model
    capability is a separate concern; this bug surfaces before the model sees the request
    at all)
Originally created by @aeriondyseti on GitHub (May 31, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/1704 Originally assigned to: @cha1latte on GitHub. ## Summary Professor Mari sends `tool_choice` to the LLM provider as a JSON **object** (the modern OpenAI Chat Completions spec form), but LM Studio's local OpenAI-compatible server rejects the object form entirely — it only accepts string values (`"none" | "auto" | "required"`). Result: Mari is unusable on LM Studio for any code or library question (which automatically trigger the forced-tool path). Surfaced during the Ubuntu re-test of smoke test #1480 (Professor Mari Deeper Pass). ## Steps to reproduce 1. Install and run LM Studio (tested on the latest available version as of 2026-05-30). 2. Load a chat model in LM Studio and start its Local Server (default `http://localhost:1234/v1`). 3. In Marinara, create a `custom` connection pointing to LM Studio. 4. Open Professor Mari, select that connection, and ask any "looks like a codebase question" prompt (e.g. *"What does `src/app/shell/AppShell.tsx` do?"*). 5. Observe the error rendered in the chat. ## Expected behavior Mari should either: - Send a `tool_choice` value that any OpenAI-API-compatible server accepts (e.g. the string `"required"`), or - Detect that the selected provider rejects the object form and fall back gracefully. In either case the request should complete and Mari should produce a tool-grounded answer. ## Actual behavior Mari surfaces this in-chat error (no crash — error handling is correct, only the request shape is the bug): ``` LLM error: Provider Error: llm_provider_error: Provider returned HTTP 400 Bad Request: Invalid tool_choice type: 'object'. Supported string values: none, auto, required ``` ## Wire-level evidence The actual JSON request body Marinara sent to LM Studio (captured from LM Studio's local server logs): ```json { "max_tokens": 2048, "messages": [ { "role": "system", "content": "You are Professor Mari... [truncated]" }, { "role": "user", "content": "What does src/app/shell/AppShell.tsx do, and where is the sidebar-toggle button defined?" } ], "model": "qwen3.5-27b-heretic-i1", "stream": false, "temperature": 0.4, "tool_choice": { "function": { "name": "search_marinara_code" }, "type": "function" }, "tools": [ { "type": "function", "function": { "name": "read_marinara_library", "parameters": { ... } } }, { "type": "function", "function": { "name": "search_marinara_code", "parameters": { ... } } }, { "type": "function", "function": { "name": "read_marinara_code_file", "parameters": { ... } } }, { "type": "function", "function": { "name": "edit_marinara_code_file", "parameters": { ... } } }, { "type": "function", "function": { "name": "create_marinara_extension", "parameters": { ... } } }, { "type": "function", "function": { "name": "create_marinara_custom_agent","parameters": { ... } } } ] } ``` The `tools` array is fine; LM Studio's complaint is specifically and only about `tool_choice` being an object rather than a string. ## Code reference `src-tauri/src/commands/storage/mari.rs:191-201`: ```rust if !tools.is_empty() && !has_tool_result && looks_like_codebase_question(latest_user) { parameters["toolChoice"] = json!({ "type": "function", "function": { "name": "search_marinara_code" } }); } else if !tools.is_empty() && !has_tool_result && looks_like_library_question(latest_user) { parameters["toolChoice"] = json!({ "type": "function", "function": { "name": "read_marinara_library" } }); } ``` Both branches hardcode the object form. There's no fall-through path that would send the string form, and no per-provider knowledge that LM Studio only accepts strings. ## Suggested fix directions Pick one: 1. **Send `tool_choice: "required"` always.** Simplest. Cost: Marinara loses its ability to *force a specific* tool — the model picks from the registered tools list. For the single-tool-registered case this is equivalent. For Mari's 6-tool registry, the system prompt already guides tool selection strongly enough that this is probably acceptable. 2. **Provider-aware tool_choice.** Keep the object form for providers known to support it (e.g. `openai`, `openai_chatgpt`, `openrouter`), fall back to `"required"` for `custom` and other less-strict providers. More precise; more code. 3. **Spec-compliance fallback.** Try the object form first; on HTTP 400 with a tool_choice-related error, retry once with the string form. Most defensive; adds a round-trip on failure. ## Related pattern This is the **second** documented Marinara/LM-Studio interop bug of the same family (Marinara sends a newer-spec OpenAI request shape; LM Studio rejects it): - #496 (closed): `response_format.type` rejected by LM Studio. - This issue: `tool_choice` object form rejected by LM Studio. A more general fix might be to maintain a per-provider capability table (which OpenAI extensions each `custom`-like server supports) rather than patching each parameter individually. ## Environment - Marinara Engine branch: `refactor` @ `5ea8a10c` - OS: Ubuntu (Wayland) - GPU: NVIDIA RTX 5060 Ti - Run mode: Tauri desktop (`pnpm tauri dev`) - LM Studio: latest available as of 2026-05-30 (AppImage build, exact version not recoverable — the updated build crashed at startup with SIGTRAP shortly after, separate problem; the wire-level evidence above was captured from the *previous* working LM Studio version which also rejected the object form, so this is not version specific) - Model loaded in LM Studio: `qwen3.5-27b-heretic-i1` (uncensoring finetune — model capability is a separate concern; this bug surfaces before the model sees the request at all) ## Related - Smoke test: #1479 / #1480 (Ubuntu re-test) - Pattern duplicate: #496
bsakaguchi 2026-10-21 05:21:49 +07:00
Author
Owner

@aeriondyseti commented on GitHub (May 31, 2026):

Corroboration: tool_choice object form works fine with Ollama

Continuing the smoke test that surfaced this issue, switched the Marinara custom
connection to point at Ollama (http://localhost:11434/v1) without changing any
Marinara code. The exact same tool_choice object form that LM Studio rejected
with HTTP 400 is accepted by Ollama for tool-capable models (verified with
qwen2.5:7b-instruct and qwen3:8b), and Mari'​s ReAct loop completed end-to-end —
multiple tool calls observed in journalctl -u ollama per user message, no protocol
errors.

This isolates the bug as LM-Studio-specific, not a Marinara/wider compatibility
break. Marinara is sending OpenAI-spec-compliant requests; LM Studio is implementing
a narrower-than-spec tool_choice subset.

(Bonus data point: Ollama also gates capabilities by model — switching the same
connection's model to deepseek-r1:14b returned a clean
registry.ollama.ai/library/deepseek-r1:14b does not support tools error, surfaced
safely in Mari's chat. Demonstrates the right pattern for custom-protocol servers
to reject tool requests for models that can't handle them — something LM Studio could
adopt.)

<!-- gh-comment-id:4585620923 --> @aeriondyseti commented on GitHub (May 31, 2026): ### Corroboration: `tool_choice` object form works fine with Ollama Continuing the smoke test that surfaced this issue, switched the Marinara `custom` connection to point at Ollama (`http://localhost:11434/v1`) without changing any Marinara code. The **exact same** `tool_choice` object form that LM Studio rejected with HTTP 400 is accepted by Ollama for tool-capable models (verified with `qwen2.5:7b-instruct` and `qwen3:8b`), and Mari'​s ReAct loop completed end-to-end — multiple tool calls observed in `journalctl -u ollama` per user message, no protocol errors. This isolates the bug as **LM-Studio-specific**, not a Marinara/wider compatibility break. Marinara is sending OpenAI-spec-compliant requests; LM Studio is implementing a narrower-than-spec `tool_choice` subset. (Bonus data point: Ollama also gates capabilities by model — switching the same connection's model to `deepseek-r1:14b` returned a clean `registry.ollama.ai/library/deepseek-r1:14b does not support tools` error, surfaced safely in Mari's chat. Demonstrates the right pattern for `custom`-protocol servers to reject tool requests for models that can't handle them — something LM Studio could adopt.)
Author
Owner

@cha1latte commented on GitHub (May 31, 2026):

Fixed in #1740

<!-- gh-comment-id:4587867040 --> @cha1latte commented on GitHub (May 31, 2026): Fixed in #1740
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
Pasta-Devs/Marinara-Engine#846
No description provided.