anomalyco / anomalyco/opencode

Mistral GLM relay models fail on tool calls (missing tool_call id in continuation chunks)

Open
#49,692 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Description

Tool calls fail for every GLM model that Mistral relays (zai-glm-5, zai-glm-5-2, zai-glm-5-3, zai-glm-latest). The first tool call aborts:

✗ Read failed
Error: The read tool was called with invalid arguments:
  SchemaError(Missing key at ["filePath"]).

Error: Type validation failed ...
  "path": ["choices",0,"delta","tool_calls",0,"id"],
  "message": "Invalid input: expected string, received undefined"

The pinned @ai-sdk/mistral (3.0.51) declares id: z.string() for every entry in a tool_calls delta. Mistral sends id and function.name only in the first delta for a given index; continuation chunks carry arguments fragments alone and are meant to be accumulated by index. So the continuation chunk fails validation, the arguments are never assembled, and the tool gets called with an empty object.

Mistral's own models are unaffected because they don't fragment tool-call arguments — the whole tool call arrives in one chunk with id set, so the continuation path is never taken.

@ai-sdk/mistral 3.0.59 fixed this upstream (schema relaxed to id: z.string().nullish(), deltas routed through StreamingToolCallTracker, which falls back to accumulating by index). Bumping the pin is enough; I opened #49689 for that.

Plugins

None.

OpenCode version

1.18.29

Steps to reproduce
  1. opencode auth login with a Mistral API key
  2. Add zai-glm-5-3 under the mistral provider in opencode.json
  3. opencode run --model mistral/zai-glm-5-3 "read package.json and name the repo"

The missing id is visible in the raw stream:

curl -s https://api.mistral.ai/v1/chat/completions \
  -H "Authorization: Bearer $MISTRAL_API_KEY" -H 'Content-Type: application/json' \
  -d '{"model":"zai-glm-5-3","stream":true,
       "messages":[{"role":"user","content":"Read the file README.md"}],
       "tools":[{"type":"function","function":{"name":"read",
         "parameters":{"type":"object","properties":{"filePath":{"type":"string"}},
                       "required":["filePath"]}}}]}' \
  | grep -o '"tool_calls":.\{0,90\}'

Two chunks come back, and only the first carries an id. The same request against mistral-large-latest returns a single chunk with id present.

Screenshot and/or share link

n/a — terminal output is quoted above.

Operating System

Arch Linux (kernel 6.18.51)

Terminal

Ghostty

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The pinned @ai-sdk/mistral 3.0.51 dependency is the entry point; inspect its dependency configuration and PR #49689 first. Done means updating the pin so the relayed GLM tool-call reproduction no longer fails on continuation chunks.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, backend
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.