Skip to content

[BUG] Chat output truncation at 8KB - XML tool calls appear as raw text in chat #707

Description

@myk1yt

A Note from the User

This is a message from me, a human user. I asked AI to handle the rest of the issue report.

I tried to patch the problems I encountered while using Zoo Code myself. The patches may be incomplete or may not work correctly. Please, the bug fix team, judge them directly. I hope Zoo Code continues to grow and mature.


Problem

When the model generates a response longer than 8,000 characters, tool call XML tags appear as raw text in the chat output instead of being parsed as tool calls. The 8KB guard in extension.js disables tool-call detection after the buffer exceeds 8,000 characters.

Context

  • OS: Windows 11, PowerShell 5.1
  • Zoo Code Version: v3.63.100188
  • Model: mimo-v2.5-pro
  • Trigger: Responses exceeding 8,000 characters

Reproduction Steps

  1. Ask the model a complex question requiring a long response (8,000+ characters)
  2. Model generates tool call XML within the response
  3. XML tags appear as raw text in the chat instead of being parsed as tool calls

Expected Result

Tool call XML should be parsed and executed, with only regular text displayed in chat.

Actual Result

Tool call XML tags appear as raw text in the chat. Here are actual examples from diagnostics:

Example 1: Truncated function tag displayed as text

function>
</invoke>

Example 2: Parameter tags with file paths displayed as text

<parameter=path>c:\\Users\\myuser\Projects\\MyProject

Example 3: Mixed text and XML fragments in a single content block

<parameter=path>C:\Users\developer\projects\\myownsettings
<parameter=timeout>180</parameter>
</function>
</invoke>

Root Cause

The bug is in extension.js line 5369, inside the case"text": branch of the stream consumer switch:

  1. Buffer accumulation: D += q.text accumulates all text chunks into a module-scoped variable D across the entire stream lifetime.
  2. 8KB hard cutoff: if (D.length < 8e3 && __detect.test(D)) - the XML tool-call detection logic is completely disabled when D exceeds 8,000 characters.
  3. Raw XML passthrough: Once D exceeds 8KB, the __detect.test(D) branch is skipped entirely. Subsequent text chunks containing XML markers are pushed directly into assistantMessageContent as plain text.
  4. Cross-chunk contamination: File paths like 1yt/Projects/ZooChat are fragments from parameter tags that leaked into chat text rendering.

Impact

Aspect Impact
User Visibility Raw XML tags displayed in chat
UX Degradation Sentence breaks, trailing text contamination
Reproduction Rate 100% when model output exceeds 8KB
Affected Models All XML-style tool-call models (mimo-v2.5-pro and others)

Proposed Fix

Recommended: Remove 8KB guard + add buffer size cap

Remove the D.length < 8e3 guard and replace with a 64KB memory protection cap:

  • Remove the 8000-character hard cutoff from the XML detection condition
  • Add a 65536-byte (64KB) cap on the accumulation buffer D
  • When D exceeds 64KB, reset it (existing memory protection behavior)
  • Keep the existing v7 tool-call extraction logic unchanged

Advantages: Enables tool-call detection at all response lengths. Memory protection handled by separate 64KB cap.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    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