Skip to content

fix(ai): send unsigned thinking back to GLM and DeepSeek models - #68071

Closed
rekram1-node wants to merge 1 commit into
devfrom
unsigned-glm-deepseek
Closed

rekram1-node wants to merge 1 commit into
devfrom
unsigned-glm-deepseek

Conversation

@rekram1-node

@rekram1-node rekram1-node commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Anthropic-compatible gateways that serve GLM or DeepSeek models can return thinking blocks with an empty signature. requireThinkingSignature required a signature for these model IDs, so their earlier reasoning was dropped on every later turn (#68060).

This adds bare glm- and deepseek model IDs to the existing list next to qwen and minimax-, so unsigned thinking is sent back with signature: "". Thinking with a real signature is sent back as before, and compatibility.requireSignature (#68062) still overrides the default. Vendor-prefixed IDs such as z-ai/glm-4.6 are deliberately left unchanged, to keep this conservative.

Checked live: DeepSeek's own Anthropic endpoint (deepseek-flash, deepseek-v4-pro) accepts an earlier thinking block with signature: "", 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.6 and a deepseek-v4-pro model. bun test test/provider/anthropic-messages.test.ts and bun run typecheck:tsc in packages/ai pass.

@rekram1-node
rekram1-node enabled auto-merge (squash) December 3, 2026 20:55

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-") ||

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 with glm- or deepseek. The Kimi check is the same as on base.
  • The test uses bare glm-4.6 and deepseek-v4-pro.
  • The requireSignature row in models.mdx lists glm- and deepseek and 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.

@rekram1-node
rekram1-node disabled auto-merge December 3, 2026 21:01
@rekram1-node
rekram1-node force-pushed the unsigned-glm-deepseek branch from e7a7ce0 to fc8a74c Compare December 3, 2026 21:01
@rekram1-node
rekram1-node enabled auto-merge (squash) December 3, 2026 21:02
@rekram1-node
rekram1-node disabled auto-merge December 3, 2026 21:02
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 (

@yoni-veksler yoni-veksler Dec 3, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@rekram1-node rekram1-node Dec 4, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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.

2 participants