Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): large DOCX and XLSX attachments keep their text up to the node limit #46592 (GitHub #46591)

OpenPruthvirajcodes(GitHub profile, opens in a new tab)wants to merge 4 commits intomain fromrefs/pull/46591/headopened View on GitHub

Problem

Fixes #46590. When one XML part of an attachment passes 200,000 elements, xml() throws Truncation and the whole part is discarded. A 10,000-row × 10-column sheet (290 KB), or a Word document of a few thousand real paragraphs, reaches the agent as only [Extracted text truncated at document extraction limits.] with none of its text. The other limits (output budget, row cap, column cap) keep the text before the cut.

Change

In apps/server/src/provider/documentTextWorker.ts:

  • Text parts are now read with readText(): the DOCX body, ODF content.xml, XLSX worksheets and shared strings, PPTX slides and EPUB chapters. When one of them reaches the node limit, parsing stops there and the elements still open are closed with their normal close handling, so hidden-text, merge and AlternateContent rules still apply.
  • The paragraph, table row or shared string that the cut landed in (p, h, si, row, tr, table-row) is dropped rather than closed. It is incomplete, and a later child can still hide it (an ODF text:hidden-paragraph field, for example). A partial row would also read as a complete row with fewer columns.
  • The text then ends right after that part with the usual notice (endIfCut). A cut slide, sheet or chapter is the last thing before the notice, the same as with the row limit.
  • Parts that decide structure or visibility are unchanged: styles, relationships, workbook, container.xml, footnotes, and the ODF styles.xml reads. A partial style table could let text hidden by a style defined after the cut leak through.

Scope

Bug fix: text is lost below the limits the worker advertises. One problem, server only. No contract or client changes.

Verification

  • I found the bug by generating synthetic files (script in #46590) and running extractDocumentText on them.
  • I extended the existing bounded-archive table in userInputAttachments.test.ts:
    • The DOCX node-limit row now cuts inside the second row of a table and expects Kept, then the notice, with Partial and Lost absent.
    • Two new XLSX rows cut inside a worksheet row and inside a shared string, with a later sheet present. They expect Kept, then the notice, with Partial, Lost and After absent.
    • These rows fail on main for the right reason: Kept is missing because the whole part was dropped. They pass with the fix.
  • vp run check:changed passes: format, lint, knip, typecheck, and the three affected test files (74 tests).
  • Runtime transcript with the worker's 192 MB heap cap (NODE_OPTIONS=--max-old-space-size=192), files from the #46590 script:
large.xlsx (289,280 bytes)
  main:  "## Sheet: Data\n\n[Extracted text truncated at document extraction limits.]"          271 ms, rss 209 MiB
  fixed: "## Sheet: Data\n0\t1\t2…95220\t…\t95229\n\n[Extracted text truncated …]"  (560,385 chars)  1030 ms, rss 250 MiB
large.docx (92,882 bytes)
  main:  "\n\n[Extracted text truncated at document extraction limits.]"                        384 ms, rss 225 MiB
  fixed: "Paragraph 0 starts here, …" (1,000,059 chars, ends at the output budget)              635 ms, rss 245 MiB
  • Peak RSS rises only by the cost of producing the text. The tree is still capped at 200,000 nodes, and the rest of a cut part is no longer parsed at all. A 31 MB worksheet now gives 1,000,058 chars at about 303 MiB RSS, against 272 MiB for the notice alone.
  • A separate review pass built adversarial fixtures and compared them with main. They cover a hidden style defined after the limit, an ODF hidden-paragraph field after the cut, a truncated EPUB container.xml, oversized ODF styles.xml and footnotes, and cuts inside mc:Choice, an ODS row, an ODP slide and a hidden XHTML div. Each gives the same output as main, or the kept text followed by the notice, with no hidden text.
  • Not covered: content held inside a single table row (a whole document laid out in one tbl > tr > tc) still gives only the notice, as on main. I did not test in a running desktop or web client; this is a server-only change with no UI surface.

Written by Claude Opus 5.5 in Claude Code (running in T3 Code), with Claude Fable 5.2 subagents for the investigation and code review.

🤖 Generated with Claude Code

    1. Pushed657f207

    2. juliusmarminge added labelstakeover:needs-julius

    3. juliusmarminge removed labelstakeover:in-progress

    4. I reviewed the truncation path on Windows at 657f207938. The stock attachment suite passed 68 of 70 tests. The two RTF code-page cases failed with the same output on the base. I found one inconsistency in which partial EPUB blocks are kept.

      @@ -318,3 +320,4 @@
      318320
      319321 type WordStyleRunHidden = (id: string | undefined, ancestors: readonly XmlNode[]) => boolean;
      320322
      323+const PARTIAL_DROPPED = new Set(["p", "h", "si", "row", "tr", "table-row"]);
      STiFLeR7(GitHub profile, opens in a new tab)commented

      Drop an incomplete XHTML heading at the node cap. I ran the production extractor on two EPUB fixtures with the same complete heading and paragraph, then a large block cut off at the 200,000-node limit. When the cut landed in a p, the output retained the complete blocks and skipped the unfinished paragraph. With an h2 in the same spot, it emitted ## Unfinished section start before the truncation notice, even though the rest of the heading had never been read. The untruncated h2 control emitted the full heading.

      paragraphs() treats h1–h6 as heading blocks, but the cutoff only drops p and h among the text blocks. A local trial adding h1–h6 to that cutoff check passed all three EPUB cases and the existing bounded office/EPUB archive test.

      Thanks, confirmed. paragraphs() reads h1–h6 as text blocks, but the cut only dropped p and h, so a cut XHTML heading was printed with only its start. f703571565 adds h1–h6 to PARTIAL_DROPPED. It also adds an EPUB row to the bounded-archive table for each of p and h2: a complete paragraph, then a block cut at the node limit, then a second chapter. The h2 case failed before the change (Partial leaked) and both pass now. vp run check:changed passes.

      Retested current head 8a3d98e7 on Windows with Node 24.11.0 using the same three synthetic EPUB cases: incomplete paragraph at the node cap, incomplete h2 at the cap, and a complete-h2 control. The current head drops both incomplete blocks while preserving completed text and the truncation notice. The complete-heading control retains its heading and later chapter.

      The original 657f2079 reproduces the unfinished-heading leak; f7035715 and current 8a3d98e7 pass the same assertions. This verifies the original reported path against the updated head. The check exercised the extracted production worker and input code; I did not rerun the complete attachment suite.

    1. Pushedf703571

    2. Pushed8a3d98e

Sign in to join this conversation.