[Bug]: read_document pages can exceed the model output budget after XML escaping
Affected component
Agent tool: read_document without a query.
Reproduction
Read a three-chunk document in reading order through read_document(id="doc-1"). Let the first two chunks each contain 2,800 ampersands and the third a short text. Use the default 24,000-rune tool budget. This represents text whose XML representation is larger than its indexed form.
Actual behavior
At main cbdcebab, a regression invoking the actual tool and model renderer receives 28,646 runes at offset 0. The page is selected using raw chunk text, before XML escaping and image enrichment. The ordinary page path does not share the estimate used by query mode.
Expected behavior
Defer the second chunk to the next page and return its reading-order offset; the caller can retrieve every chunk once. Preserve the existing first-chunk exception so the cursor can advance even for a single oversized chunk.
Related work
#5257 and #5260 addressed the query path; this reproduces with the query argument omitted.
Codex assisted with local reproduction and testing.