Repository navigation
perf(read): tell the model how much one more call can still return - #3723
Merged
bobleer merged 3 commits intoNov 4, 2026
Merged
Conversation
A Read window used to end with 'use offset=N and limit to continue', which pushed callers into 60-300 line windows even when the per-call budget (2000 lines / 64000 characters) covered the rest of the file, so large files cost many extra steps. Session transcripts show the same 200-400 line Python file read as five overlapping windows. The continuation note now reports the remaining line count, says when the rest fits in one call, and points at the per-call line and character budgets. The Read description and limit schema tell callers to omit limit and only narrow the window for a known range, and document continuation guidance does the same. Default budgets move to tool-runtime as the single source of truth.
Measure the rendered characters past the returned window so the continuation note claims a single follow-up call only when the remaining lines fit both the line and character budgets. Label the remaining count as lines, name both budgets when another call is needed, cover caller-supplied budgets in tests, and spell out which cap is per line in the tool description.
The inline cap for Read results was a hand-synced 72_000. Derive it from DEFAULT_READ_MAX_TOTAL_CHARS plus the wrapper headroom so the two cannot drift now that the per-call budget has a single source.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Readends a partial window withUse offset=N and limit to continue reading. That tells the model where to resume but not how much one more call can return, so callers page a large file in small windows even when the per-call budget (2000 lines / 64000 characters) covers everything that is left. This PR makes the continuation note state the remaining line count and the per-call budgets, and aligns the tool description with what comparable agents do: read the file in one call unless a narrower range is already known.Type and Areas
Type: performance / agent tool behavior
Areas: Agent runtime / core (Rust), Read tool presentation
Motivation / Impact
Session transcripts show the cost directly. For one ~300-line Python file the model requested windows of 160, 135, 58, 130, 250, 280, 310 and 175 lines, reading lines 128-262 twice, while a single default call could have returned the whole file.
Industry baseline from 11 agent implementations (Gemini CLI, Codex CLI, Claude Code, Cline, Roo Code, Zed, SWE-agent, OpenHands, Aider, ZCode, Grok Build): Gemini CLI, Claude Code and Roo Code all default to 2000 lines per read, and Claude Code's description says
it's recommended to read the whole file by not providing these parameters. None of them relies on small-window paging. The parameters here already match (2000 lines, 2000 chars per line, 64000 chars per call), so the gap was in the guidance, not the budget.After this change a partial read says:
[Showing lines 1-2 of 4 total (remaining: 2). All of it fits in one call: use offset=3 without limit.][Showing lines 1-10 of 2501 total (remaining: 2491). Use offset=11 without limit to read up to 2000 lines per call, or offset/limit for a known range.][Output truncated after reaching the Read tool size limit (remaining: 1). Use offset=2 without limit to read up to 64000 characters per call.]The only user-visible effect is fewer tool round-trips.
Verification
cargo test --locked -p tool-runtime --lib-> 167 passedcargo test --locked -p openbitfun-core --lib --features "agent-runtime,document-read" -- file_read_tool-> 20 passed (includes PDF/RTF/CSV document paths)cargo check --locked -p openbitfun-core --features "agent-runtime"-> finished, no errorspnpm run fmt:rs-> 2 files formattedNew tests:
continuation_guidance_reports_remaining_lines_beyond_one_call,continuation_guidance_names_the_character_cap_when_a_call_is_cut.Reviewer Notes
origin/mainsince this branch's base, and no open PR covers Read continuation guidance. This branch is cherry-picked ontoorigin/main(45ae3bd) and the two-file diff is byte-identical to the locally verified commit.limitschema text), plus moving the default budget constants intotool-runtimeso the 2000/64000 values have a single source. No persisted field, wire format or output schema change, so stored sessions and old tool calls replay unchanged.build_read_file_presentationkeeps its signature and now delegates tobuild_read_file_presentation_with_budget, so other callers of the lower crate are unaffected.Checklist
Review follow-ups
a18f7c358: "All of it fits in one call" now requires both budgets.ReadFileResult.remaining_charsmeasures the rendered characters past the returned window (same line numbering, per-line cap and[truncated]marker as a follow-up call), so a short-but-wide tail is no longer promised in one call. The note labels the count (N lines remaining), names both budgets when another call is needed, and the tool description says which cap is per line. New tests cover caller-suppliedReadCallBudget, the character-over-budget case, and thatremaining_charsequals the follow-up call's content length (including after a character cut and in tail mode).f6bf475c2:READ_MAX_TOOL_RESULT_CHARSis derived fromDEFAULT_READ_MAX_TOTAL_CHARSinstead of a hand-synced72_000.Verification for the follow-ups:
cargo test --locked -p tool-runtime --lib-> 178 passed;cargo test --locked -p openbitfun-core --lib --features "agent-runtime,document-read" -- file_read_tool tool_result_storage-> 26 passed.