[GH-ISSUE #272] grep/glob/ls tool results can exceed context window despite eviction #237

Closed
opened 2026-06-05 17:21:12 -04:00 by yindo · 1 comment
Owner

Originally created by @antonnak on GitHub (Mar 3, 2026).
Original GitHub issue: https://github.com/langchain-ai/deepagentsjs/issues/272

Problem

grep, glob, and ls can return hundreds of KB (observed: 772KB from a single grep). The eviction mechanism saves large results to the filesystem, but doesn't cap tool output — so the oversized result still enters the message history and causes model retries or blank responses before eviction can help.

read_file already has character-based truncation (#172). The same treatment is missing for search tools.

Proposed solution

Add an optional character/token cap to grep, glob, and ls tool results — matching the TOOL_RESULT_TOKEN_LIMIT * 4 threshold already used by eviction. When results exceed the cap, truncate and append guidance like:

... [results truncated — try narrowing your search with more specific parameters]

This is consistent with read_file's existing truncation behavior (#172).

Related

  • #82 — infinite loop from large read_file results (fixed by #172, same pattern)
  • #172 — added char truncation to read_file (merged, but grep/glob/ls not covered)
  • #228 — attempted post-summarization emergency truncation for 668KB glob (closed in favor of #234)
  • #234 — updated summarization behavior (merged, but no tool-level caps)
  • #248 — preserved ToolMessage metadata during eviction (merged, related infra)
  • #250 — OOM fix in conversation history offloading (merged, related)

Workaround

Custom middleware that intercepts grep/glob/ls ToolMessage results and truncates at 80K chars using createMiddleware({ wrapToolCall }). Works but shouldn't be necessary — the built-in tools should respect the same limits as read_file.

Originally created by @antonnak on GitHub (Mar 3, 2026). Original GitHub issue: https://github.com/langchain-ai/deepagentsjs/issues/272 ## Problem `grep`, `glob`, and `ls` can return hundreds of KB (observed: 772KB from a single grep). The eviction mechanism saves large results to the filesystem, but doesn't cap tool output — so the oversized result still enters the message history and causes model retries or blank responses before eviction can help. `read_file` already has character-based truncation (#172). The same treatment is missing for search tools. ## Proposed solution Add an optional character/token cap to `grep`, `glob`, and `ls` tool results — matching the `TOOL_RESULT_TOKEN_LIMIT * 4` threshold already used by eviction. When results exceed the cap, truncate and append guidance like: ``` ... [results truncated — try narrowing your search with more specific parameters] ``` This is consistent with `read_file`'s existing truncation behavior (#172). ## Related - #82 — infinite loop from large `read_file` results (fixed by #172, same pattern) - #172 — added char truncation to `read_file` (merged, but grep/glob/ls not covered) - #228 — attempted post-summarization emergency truncation for 668KB glob (closed in favor of #234) - #234 — updated summarization behavior (merged, but no tool-level caps) - #248 — preserved ToolMessage metadata during eviction (merged, related infra) - #250 — OOM fix in conversation history offloading (merged, related) ## Workaround Custom middleware that intercepts `grep`/`glob`/`ls` `ToolMessage` results and truncates at 80K chars using `createMiddleware({ wrapToolCall })`. Works but shouldn't be necessary — the built-in tools should respect the same limits as `read_file`.
yindo closed this issue 2026-06-05 17:21:12 -04:00
Author
Owner

@JadenKim-dev commented on GitHub (Mar 5, 2026):

I've opened PR #281 to address this issue.

Please review when you have a chance!

<!-- gh-comment-id:4009549412 --> @JadenKim-dev commented on GitHub (Mar 5, 2026): I've opened PR #281 to address this issue. Please review when you have a chance!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/deepagentsjs#237