t3code icon indicating copy to clipboard operation
t3code copied to clipboard

[Bug]: Large DOCX and XLSX attachments reach the agent as only the truncation notice, with none of their text

Open Pruthvirajcodes opened this issue 22 hours ago • 0 comments

Before submitting

  • [X] I searched existing issues and did not find a duplicate.
  • [X] I included enough detail to reproduce or investigate the problem.

Area

apps/server

Steps to reproduce

  1. Make two ordinary files with the script below: python3 make_repro.py writes large.xlsx (10,000 rows × 10 numbers, 290 KB) and large.docx (30,000 short paragraphs, 93 KB).
  2. Attach either file to a message in a thread, or run extractDocumentText from apps/server/src/provider/documentTextWorker.ts on it.
  3. Look at the attachment text the agent receives.
make_repro.py
import zipfile
W = 'xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"'
CT = '<?xml version="1.0"?><Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="xml" ContentType="application/xml"/><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/></Types>'
R = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'
with zipfile.ZipFile("large.xlsx", "w", zipfile.ZIP_DEFLATED) as z:
    z.writestr("[Content_Types].xml", CT)
    z.writestr("_rels/.rels", f'<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="r1" Type="{R}/officeDocument" Target="xl/workbook.xml"/></Relationships>')
    z.writestr("xl/workbook.xml", f'<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="{R}"><sheets><sheet name="Data" sheetId="1" r:id="s1"/></sheets></workbook>')
    z.writestr("xl/_rels/workbook.xml.rels", f'<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="s1" Type="{R}/worksheet" Target="worksheets/sheet1.xml"/></Relationships>')
    rows = "".join(f'<row r="{r + 1}">' + "".join(f"<c><v>{r * 10 + c}</v></c>" for c in range(10)) + "</row>" for r in range(10_000))
    z.writestr("xl/worksheets/sheet1.xml", f'<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><sheetData>{rows}</sheetData></worksheet>')
with zipfile.ZipFile("large.docx", "w", zipfile.ZIP_DEFLATED) as z:
    z.writestr("[Content_Types].xml", CT)
    z.writestr("_rels/.rels", f'<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="r1" Type="{R}/officeDocument" Target="word/document.xml"/></Relationships>')
    paras = "".join(f"<w:p><w:r><w:t>Paragraph {i} starts here,</w:t></w:r><w:r><w:t xml:space=\"preserve\"> continues,</w:t></w:r><w:r><w:t xml:space=\"preserve\"> and ends.</w:t></w:r></w:p>" for i in range(30_000))
    z.writestr("word/document.xml", f"<w:document {W}><w:body>{paras}</w:body></w:document>")

Expected behavior

The agent gets the text up to the extraction limits, followed by [Extracted text truncated at document extraction limits.]. The other limits already work this way: the 1M-character output budget, the 10,000-row cap and the 512-column cap all keep the text before the cut.

Actual behavior

The agent gets no content at all, only the truncation notice:

large.xlsx  ->  "## Sheet: Data\n\n[Extracted text truncated at document extraction limits.]"
large.docx  ->  "\n\n[Extracted text truncated at document extraction limits.]"

Cause: xml() in apps/server/src/provider/documentTextWorker.ts throws Truncation on the 200,001st element of a part (if (++nodes > 200_000 || …) throw new Truncation("XML structure limit")). read() rethrows it, so the whole part is discarded before anything from it is yielded.

A worksheet costs about one element per row plus two per valued cell, so any sheet over roughly 95k cells hits this before the 10,000-row cap. A sheet with more than 10 columns hits it before 10,000 rows. If sharedStrings.xml holds more than about 100k strings, the output is the notice alone, without even the sheet heading. Word markup is denser than in this repro (run properties, bookmarks, proofing marks), so real documents reach the limit at a few thousand paragraphs.

Impact

Major degradation or frequent failure

Version or commit

main @ 42f4bcf63f

Environment

Linux (Debian 13), Node 26.13.1. Not provider-specific: this is server-side attachment text extraction.

Logs or stack traces

# extractDocumentText on main, worker heap capped at 192 MB as in DocumentText.ts
large.xlsx (289280 bytes): "## Sheet: Data\n\n[Extracted text truncated at document extraction limits.]"
large.docx (92882 bytes):  "\n\n[Extracted text truncated at document extraction limits.]"

Screenshots, recordings, or supporting files

No response

Workaround

Split the workbook or document into smaller files before attaching it.


Found and written up by Claude Opus 5.5 in Claude Code (T3 Code), with Claude Fable 5.2 subagents for the investigation.

Pruthvirajcodes avatar Dec 01 '26 07:12 Pruthvirajcodes