Skip to content

[Bug] ZCode resends a double-encoded Write tool call from conversation history, causing persistent HTTP 400 failures #160

Description

@peng-1127

提交前确认 · Pre-submission checklist

  • 我已搜索过现有 issue,确认这不是重复 / I searched existing issues and confirmed this isn't a duplicate.
  • 我已阅读 CONTRIBUTING.md / I've read CONTRIBUTING.md.

问题类别 · Category

工具调用 / MCP · Tool use / MCP

涉及的 Agent 框架 · Agent framework

ZCode Agent(自研)

严重程度 · Severity

阻塞使用 · Blocking (无法使用核心功能 / core function unusable)

复现频率 · Reproducibility

必现 · Always

问题描述 · Description

When using ZCode Agent with an OpenAI-compatible model endpoint, one existing long conversation began failing on every subsequent turn.

ZCode displays the following error:

Model request timed out.
Turn execution failed
model=deepseek-v4-flash
reason=timeout
Body Timeout Error

However, gateway-side investigation confirmed that the request did not time out. The upstream service immediately returned HTTP 400:

InvalidParameter: 'str' object has no attribute 'items'

We inspected the request body received by the gateway and found one anomalous historical tool call:

message_number: 727
function_name: Write
arguments_length: 2293
first_character: "
last_character: "

The Write tool definition itself is valid. Its schema correctly defines file_path and content as strings.

The anomaly is in the historical tool_calls[].function.arguments value. It appears to be double JSON-encoded: after one JSON decoding pass, the value is still a string instead of an object.

The other tool definitions and historical tool-call structures in the same request passed our checks. The malformed record was already present in the request body received from ZCode.

Because ZCode resends this historical record with every subsequent request, the affected conversation can no longer continue. Creating a new conversation may temporarily avoid the problem, but it does not recover the existing conversation.

In addition, ZCode reports this HTTP 400 response as a timeout, which makes troubleshooting difficult.

复现步骤 · Steps to reproduce

  1. Configure ZCode Agent to use an OpenAI-compatible model endpoint.
  2. Start a conversation that uses the built-in tools, including the Write tool.
  3. Continue using the same conversation for many turns.
  4. In the affected session, a historical Write tool call is stored or reconstructed with double-encoded function.arguments.
  5. Send another message in the same conversation.
  6. Observe that ZCode includes the malformed historical tool call in the new request.
  7. The model endpoint returns HTTP 400:
InvalidParameter: 'str' object has no attribute 'items'
  1. ZCode displays the failure as:
Model request timed out.
Body Timeout Error
  1. Retry in the same conversation. The request fails again because the malformed historical record is resent.

This issue depends on an affected conversation-history record. We have consistently reproduced the failure in that conversation, but we have not yet identified the exact initial action that caused the arguments to become double-encoded.

期望表现 · Expected behavior

ZCode should ensure that every historical tool_calls[].function.arguments value represents a valid JSON object before sending the request.

If a stored value is double-encoded, ZCode should safely normalize it or clearly identify the corrupted conversation record.

An existing conversation should not become permanently unusable because of one malformed historical tool call.

If the upstream endpoint returns HTTP 400, ZCode should display the actual upstream error instead of reporting it as a timeout.

实际表现 · Actual behavior

ZCode repeatedly resends a historical Write tool call whose function.arguments
value appears to be double JSON-encoded.

The upstream endpoint rejects the request immediately with HTTP 400:

InvalidParameter: 'str' object has no attribute 'items'

Every subsequent turn in the affected conversation fails, while ZCode reports
the failure as "Model request timed out".

ZCode 版本 · ZCode version

v3.3.6

设备 / 系统 / 浏览器 · Device / OS / Browser

ZCode Desktop / Windows 11 / OpenAI-compatible API through LiteLLM v1.91.3

截图 / 录屏 / 日志 · Screenshots / Recordings / Logs

ZCode UI error:

Model request timed out.
Turn execution failed
model=deepseek-v4-flash
reason=timeout
Body Timeout Error

Gateway evidence:

Observed time: 2026-07-20 14:41:48 CST
Gateway: LiteLLM v1.91.3
Actual upstream status: HTTP 400
Actual upstream error:
InvalidParameter: 'str' object has no attribute 'items'

Malformed historical tool-call evidence:

message_number: 727
function_name: Write
arguments_length: 2293
first_character: "
last_character: "

All 15 tool definitions were structurally valid. Other historical tool-call
structure checks passed. The Write tool definition was valid; the anomaly was
isolated to this historical invocation's function.arguments value.

Sensitive request content, internal addresses, credentials, and file contents
have been removed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions