Skip to content

perf(read): tell the model how much one more call can still return - #3723

Merged
bobleer merged 3 commits into
openBitFun:mainfrom
Raing5Days:feat/read-continuation-guidance
Nov 4, 2026
Merged

bobleer merged 3 commits into
openBitFun:mainfrom
Raing5Days:feat/read-continuation-guidance

Conversation

@Raing5Days

@Raing5Days Raing5Days commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Read ends a partial window with Use 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 passed
  • cargo 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 errors
  • pnpm run fmt:rs -> 2 files formatted

New tests: continuation_guidance_reports_remaining_lines_beyond_one_call, continuation_guidance_names_the_character_cap_when_a_call_is_cut.

Reviewer Notes

  • Checked before implementing: both touched files are unchanged on origin/main since this branch's base, and no open PR covers Read continuation guidance. This branch is cherry-picked onto origin/main (45ae3bd) and the two-file diff is byte-identical to the locally verified commit.
  • Scope: model-visible strings only (continuation note, tool description, limit schema text), plus moving the default budget constants into tool-runtime so 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_presentation keeps its signature and now delegates to build_read_file_presentation_with_budget, so other callers of the lower crate are unaffected.
  • Rollback is a plain revert; there is no data migration.

Checklist

  • This PR is focused and does not include secrets, temporary prompts, generated scratch files, or unrelated artifacts.
  • Relevant verification is recorded above, or skipped checks are explained.
  • User-facing strings, docs, and locales are updated where applicable. (Tool descriptions are English only; no locale files are touched.)

Review follow-ups

  • a18f7c358: "All of it fits in one call" now requires both budgets. ReadFileResult.remaining_chars measures 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-supplied ReadCallBudget, the character-over-budget case, and that remaining_chars equals the follow-up call's content length (including after a character cut and in tail mode).
  • f6bf475c2: READ_MAX_TOOL_RESULT_CHARS is derived from DEFAULT_READ_MAX_TOTAL_CHARS instead of a hand-synced 72_000.
  • Trade-off: fewer round-trips, but a single read of a large file can bring up to the full 64000-character budget into context at once. That bound is unchanged; only how often the model reaches it changes.

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.

Raing5Days and others added 3 commits November 3, 2026 22:13
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.
@bobleer
bobleer merged commit f219bee into openBitFun:main Nov 4, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants