Skip to content

fix(opencode): recover malformed GLM/NVIDIA tool calls#25971

Open
ctharvey wants to merge 1 commit intoanomalyco:devfrom
ctharvey:codex/glm-nvidia-tool-call-recovery
Open

fix(opencode): recover malformed GLM/NVIDIA tool calls#25971
ctharvey wants to merge 1 commit intoanomalyco:devfrom
ctharvey:codex/glm-nvidia-tool-call-recovery

Conversation

@ctharvey
Copy link
Copy Markdown

@ctharvey ctharvey commented May 6, 2026

Issue for this PR

Closes #25970

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

This hardens the @ai-sdk/openai-compatible path against malformed tool-call payloads seen from nvidia/z-ai/glm-5.1.

It does three things:

  • supports legacy function_call responses alongside tool_calls
  • tolerates streamed tool calls that are missing id or receive function.name later
  • if a stream ends with finish_reason: "tool_calls" but no usable tool name, performs one non-stream recovery request and then raises a clear error instead of hanging

This keeps the provider bug from turning into a stalled OpenCode session.

How did you verify your code works?

  • bun typecheck from packages/opencode
  • bun test test/provider/copilot/openai-compatible-tool-call-id-fallback.test.ts --timeout 30000 from packages/opencode
  • bun run build -- --single --skip-embed-web-ui from packages/opencode
  • Reproduced with dist/opencode-windows-x64/bin/opencode.exe run --format json --dangerously-skip-permissions -m nvidia/z-ai/glm-5.1 "check your memory" on build 0.0.0-dev-202605060426

Notes:

  • repo-root bun typecheck currently fails in unrelated existing packages/enterprise/src/custom-elements.d.ts
  • the full packages/opencode suite also has existing Windows failures in unrelated PTY/symlink/filesystem tests, but the touched provider test passes

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GLM 5.1 on NVIDIA can hang on unnamed tool calls during memory bootstrap

1 participant