perf: bound tool I/O and trim tool surface - #172
Closed
huytg2610 wants to merge 4 commits into
Closed
Conversation
huytg2610
added a commit
to huytg2610/cheetahclaws
that referenced
this pull request
Jul 19, 2026
Four defects found by independent review of the bounded-I/O work: - files.py (SummarizeLargeFile): the PDF branch of _read_file_for_summary returned an Error whenever the bounded extractor appended its truncation marker, so summarizing any large PDF (papers/books — the tool's main use case) hard-failed and dead-ended ReadPDF's own redirect to it. Strip only the trailing marker and summarize the extracted text; genuine Error returns still propagate. - fs.py (_read_logical_line): a complete CRLF whose LF landed on the read-chunk boundary re-entered the bare-CR probe and swallowed a following blank line, shifting every later line number (Read line numbers drive Edit targeting). Probe only when the last selected byte is a bare CR. - files.py (_summarize_large_file reduce): a failed (None) chunk hit break and dropped all later chunk summaries; the reduce cap silently truncated the tail while the header still claimed all N chunks. Skip None chunks, report the chunks actually merged, and warn on incomplete coverage — including when the cap clips the last included chunk. - web.py (_DuckDuckGoResultParser): HTML void elements (<img>, <br>) inside a result title/snippet left the depth counters permanently offset, bleeding text between fields. Skip void tags in both start/end handlers. Adds no new deps. Verified with targeted repros and the bounded-I/O, summarize, tool-registry and prompt-assembly test suites.
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.
Bounded I/O and a smaller default tool surface
Motivation
Several high-volume tools could do substantial work before their output reached the normal tool-result truncation layer. In practice, this meant a large file, PDF, or slow HTTP response could consume unnecessary memory, latency, and context budget even when the final result was eventually shortened.
At the same time, every agent turn exposed the full tool catalog by default. This increased schema and prompt size for ordinary coding tasks and made it easier for the model to reason about tools that were not relevant to the current task.
This PR moves those limits and decisions closer to the source of the data.
What changed
Bounded input handling
Readnow processes files incrementally and enforces byte limits while preserving logical line boundaries, including CRLF handling.WebFetchandWebSearchnow enforce:SummarizeLargeFilewhen that tool is not available in the active profile.Tool profiles
The default
standardprofile contains the common coding tools only. Research, orchestration, and full tool surfaces are explicit opt-ins.The selected profile is now applied consistently across:
/configvalidation; andExisting configuration files without
tool_profilenow use the compactstandarddefault. Users who need the complete legacy surface can explicitly selectfull.Prompt and cache correctness
EnterPlanModeandExitPlanModeare active.Design notes
The goal is not to make every tool artificially restrictive. The limits are applied at the point where input is read or streamed, before that work can become an avoidable memory, latency, or token cost.
For web tools, the request deadline is enforced over the entire operation rather than reset at each redirect. The regression suite includes a local slow-drip HTTP server to verify that a response which stalls after sending initial bytes is cancelled near the configured deadline.
Validation
compileallandgit diff --checkpass.