fix(zai): set tool_stream=true to avoid api.z.ai 30s idle timeout - #12758
Open
aarongxa wants to merge 1 commit into
Open
fix(zai): set tool_stream=true to avoid api.z.ai 30s idle timeout#12758aarongxa wants to merge 1 commit into
aarongxa wants to merge 1 commit into
Conversation
GLM models (4.6, 4.7, 5, 5.1) batch tool_call argument generation in a single chunk by default. When the tool args are large (long file writes, big shell commands), the model goes silent for 30+ seconds while generating them, and api.z.ai's 30s server-side idle timeout kills the connection with ECONNRESET — surfacing as a "timeout" in Hermes. Z.AI's documented fix is to send tool_stream=true alongside stream=true, which makes the model emit tool args incrementally and keeps chunks flowing within the 30s window. This patch injects extra_body.tool_stream=true in _build_api_kwargs whenever the provider is "zai" or the base URL points at api.z.ai or open.bigmodel.cn, and only when tools are present (no benefit otherwise). A user-supplied extra_body.tool_stream wins via setdefault. Refs: - https://docs.z.ai/guides/capabilities/stream-tool - vercel/ai#12949 (30s idle timeout root cause analysis) - opencode#15350 (ECONNRESET on zai-coding-plan) Made-with: Cursor
19 tasks
Contributor
|
Thanks for identifying the Z.AI idle-timeout failure mode. The requested wire behavior is still absent on current main, but this patch targets a request-builder body that was extracted after the branch was created. Problems
Suggested changes
Automated hermes-sweeper review. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
GLM models (4.6, 4.7, 5, 5.1) batch tool_call argument generation in a single chunk by default. When the tool args are large (long file writes, big shell commands), the model goes silent for 30+ seconds while generating them, and
api.z.ai's 30-second server-side idle timeout kills the connection withECONNRESET— surfacing as a "timeout" inside Hermes mid-tool-call.Z.AI's documented fix is to send
tool_stream=truealongsidestream=true. That makes the model emit tool args incrementally and keeps chunks flowing within the 30s window.What this changes
In
_build_api_kwargs(chat-completions branch), injectextra_body["tool_stream"] = Truewhenever:self.provider == "zai", OR the base URL containsz.aiorbigmodel.cn, ANDself.toolsis non-empty (no benefit to streaming tool args when no tools are bound)A user-supplied
extra_body.tool_streamwins viasetdefault, so it's overrideable.Why it's safe
self.tools— never sent on toolless calls.extra_bodyfields gracefully on routes that don't support it (legacy GLM-4.5 and earlier), so even an over-broad match would be a no-op there. Per Z.AI docs,tool_streamis supported on GLM-4.6, 4.7, 5, and 5.1 — i.e. every currently-shipping GLM coding model.setdefaultpreserves any explicit override.Test plan
pytest tests/run_agent/test_run_agent.py -k "ZaiToolStream or zai or glm"— 8 passed (5 new + 3 pre-existing)pytest tests/run_agent/test_provider_parity.py tests/run_agent/test_strict_api_validation.py— 80 passedReferences