Skip to content

[GLM-5.2] Tool results intermittently rendered as image content blocks instead of text (context-length correlated) #110

Description

@AlexThor-Omega0

Bug Description

When using GLM-5.2 via the OpenAI-compatible API (https://api.z.ai/api/coding/paas/v4/chat/completions) with an agentic framework (OpenClaw) that makes heavy use of tool/function calling, GLM-5.2 intermittently returns tool results as image content blocks instead of text. The model essentially "forgets" how to properly format tool call results after the context window accumulates a large number of tool results.

GLM-5.1 does NOT exhibit this behavior under identical conditions.

Reproduction

  1. Set up an agentic loop with GLM-5.2 that makes sequential tool calls (e.g., file reads, shell commands)
  2. Accumulate 75+ tool results in the conversation history
  3. After a threshold (~75-100 tool results), the model starts emitting tool call responses where the content type is incorrectly set to image instead of text
  4. The frontend then renders these as "attached image" placeholders instead of processing the text content

Key Observation: Context-Length Correlation

This is not random. Gateway logs show a clear correlation between accumulated tool result count and bug onset:

Tool results in context Behavior
7 (fresh session post-compaction) ✅ Works correctly
75 ❌ Bug appears (tool results as image)
116 ❌ Bug persistent
209 (long unbounded session) ❌ Bug persistent

After a session reset/compaction (context cleared), the bug disappears, then gradually returns as tool results accumulate again.

Environment

• Model: glm-5.2 (API endpoint: api.z.ai/api/coding/paas/v4/chat/completions)
• Framework: OpenClaw v2026.6.11 (agentic AI runtime, OpenAI-compatible)
• Usage pattern: Multi-turn agent sessions with heavy tool use (file read, shell exec, file edit) — sessions can run 100+ turns
• Streaming: SSE (stream: true)
• Comparison: glm-5.1 under identical conditions does NOT reproduce the bug

Gateway Log Evidence

Session with 209 accumulated tool results → bug active

[tool-result-truncation] Truncated 209 tool result(s) for prompt history (maxChars=64000 aggregateBudgetChars=256000)

Session with 75 accumulated tool results → bug active

[tool-result-truncation] Truncated 75 tool result(s) for prompt history

Session with 7 tool results (post-compaction) → bug NOT present

[tool-result-truncation] Truncated 7 tool result(s) for prompt history

All API calls return HTTP 200 with contentType=text/event-stream. The issue is in the response body content formatting, not transport.

Hypothesis

GLM-5.2 may have a regression in handling long contexts with many tool call/result pairs. When the context includes a high number of tool results (especially with long text payloads), the model's output formatter appears to misclassify content blocks — emitting type: "image" where it should emit type: "text".

This could be:

• A context-length-dependent formatting bug in the response generator
• A tool-use history processing issue that degrades with volume
• A regression specific to GLM-5.2's multimodal content handling (not present in 5.1)

Expected Behavior should consistently format tool call results as text content blocks regardless of context length or number of accumulated tool results — matching the behavior of GLM-5.1.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions