Repository navigation
fix(ai): send unsigned thinking back to GLM and DeepSeek models - #68071
rekram1-node wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
The fix works for bare model IDs, but GLM models with a vendor-prefixed ID still lose their thinking.
I ran the CLI from source against a mock Anthropic-compatible server whose thinking block has signature: "", using run and then run --continue. On the base, the second request dropped the thinking for glm-4.6 and deepseek-v4-pro. With this PR, both send it back with signature: "". z-ai/glm-4.6 (OpenRouter's ID) is still dropped (see the inline comment). The anthropic-messages tests and typecheck:tsc in packages/ai pass.
Public API: no config keys or schema change. Only the default of compatibility.requireSignature changes for model IDs starting with glm- or deepseek, and an explicit setting still overrides it.
Related: #68060
| if ( | ||
| model.startsWith("qwen") || | ||
| model.startsWith("minimax-") || | ||
| model.startsWith("glm-") || |
There was a problem hiding this comment.
startsWith("glm-") misses vendor-prefixed IDs such as OpenRouter's z-ai/glm-4.6, which the description says was checked. With the mock server and that model ID, the thinking block is still dropped on the next turn. deepseek/… and qwen/… only match because the vendor prefix happens to be the model name. Matching on the last path segment (for example model.split("/").pop()) would cover gateways without adding a list of vendor prefixes.
There was a problem hiding this comment.
Fixed in 9981a59: the check now matches the model name after the last /, so z-ai/glm-4.6 (and alibaba/qwen…) are covered too. The test now uses z-ai/glm-4.6.
There was a problem hiding this comment.
This fix works. In requireThinkingSignature (anthropic-messages.ts ~L751), model.slice(model.lastIndexOf("/") + 1) leaves a bare ID like glm-4.6 unchanged (lastIndexOf returns -1, so the slice starts at 0). For z-ai/glm-4.6 and alibaba/qwen… it strips everything up to the last /. Models that matched before still match, and Claude IDs still require a signature, so nothing that worked before changes.
I checked this on pr/head (0a5165a) in a temporary worktree: bun test test/provider/anthropic-messages.test.ts gives 82 pass, 0 fail. The test now uses z-ai/glm-4.6. I didn't re-run typecheck or any live gateway calls.
There's one small gap left. The Kimi check a few lines up still uses model.startsWith("kimi-") on the full ID. OpenRouter's moonshotai/kimi-k2 doesn't match it, because the provider there is openrouter, not moonshotai. So Kimi's unsigned thinking would still be dropped on OpenRouter. Moving name above that block and using name.startsWith("kimi-") would fix it, but that's outside this PR's scope, so it could go in a follow-up.
I didn't edit anything in repo/. The bun.lock modification was already there, and I left it alone.
There was a problem hiding this comment.
Reverted the vendor-prefix matching (and the Kimi change): we are keeping this conservative and only matching bare glm- / deepseek IDs. OpenRouter routes through its own provider, and gateways with prefixed IDs can set compatibility.requireSignature: false.
There was a problem hiding this comment.
The revert is clean, and the conservative scope makes sense. pr/head is back at fc8a74c, which has only the original change:
requireThinkingSignature(anthropic-messages.ts~L751–757) matches only bare IDs starting withglm-ordeepseek. The Kimi check is the same as on base.- The test uses bare
glm-4.6anddeepseek-v4-pro. - The
requireSignaturerow inmodels.mdxlistsglm-anddeepseekand doesn't mention vendor-prefixed IDs, so the docs match the code.
One limit to keep in mind: an ID like z-ai/glm-4.6 on a non-OpenRouter gateway still has its unsigned thinking dropped unless the user sets compatibility.requireSignature: false. The PR description already says this.
I ran bun test test/provider/anthropic-messages.test.ts on pr/head in a temporary worktree, which I've since removed: 82 pass, 0 fail. I didn't re-run typecheck. I made no edits in repo/, and the bun.lock modification that was already there is untouched.
e7a7ce0 to
fc8a74c
Compare
| return false | ||
| if (provider.includes("xiaomi") || model.includes("mimo") || baseURL.includes("xiaomimimo.com")) return false | ||
| if (model.startsWith("qwen") || model.startsWith("minimax-")) return false | ||
| if ( |
There was a problem hiding this comment.
Only Claude endpoints require a signature, so why not invert this and require it only for Claude models? Otherwise this list needs a new entry for every open model.
A prefix list also misses gateway aliases, where the model id is a routing alias rather than glm-…. vercel-ai-gateway already does the inverse for anthropic/ ids.
There was a problem hiding this comment.
There are many gateways like Bedrock that people use that host anthropic models without a claude alias, some labs that do serve models over msg apis also populate the signatures, x It's a little difficult to have a good default that works for everyone... And changing it now breaks it for other people from before which is also annoying
Some other agents will make unsigned reasoning get sent as plain text blocks which is also rlly bad cause it can cause a lot of hallucinations and degrade things
I think there is a better approach though: send reasoning back exactly as the endpoint gave it to us. If your gateway returns signature: "" for a completed turn, we send "" back; we'd only stay strict for reasoning that came from a different model or a cut-off stream, since that's the only way an unsigned block can reach Anthropic. That fixes your case without a list of model names or a new default that breaks other setups. We'll try that in a separate PR and close this one. Until then, compatibility.requireSignature: false works for your gateway.
Anthropic-compatible gateways that serve GLM or DeepSeek models can return thinking blocks with an empty signature.
requireThinkingSignaturerequired a signature for these model IDs, so their earlier reasoning was dropped on every later turn (#68060).This adds bare
glm-anddeepseekmodel IDs to the existing list next toqwenandminimax-, so unsigned thinking is sent back withsignature: "". Thinking with a real signature is sent back as before, andcompatibility.requireSignature(#68062) still overrides the default. Vendor-prefixed IDs such asz-ai/glm-4.6are deliberately left unchanged, to keep this conservative.Checked live: DeepSeek's own Anthropic endpoint (
deepseek-flash,deepseek-v4-pro) accepts an earlier thinking block withsignature: "", and so does an Anthropic-compatible gateway serving DeepSeek and GLM. DeepSeek's own endpoint already returns real signatures, so it isn't affected.Tests: extended the existing empty-signature inference test with a
glm-4.6and adeepseek-v4-promodel.bun test test/provider/anthropic-messages.test.tsandbun run typecheck:tscinpackages/aipass.