eca icon indicating copy to clipboard operation
eca copied to clipboard

Tool output can exceed context limit

Open treydavis opened this issue 9 months ago • 6 comments

To upvote this issue, give it a thumbs up. See this list for the most upvoted issues.

Describe the bug

The grep tool has no limit on line length. This can cause a problem when searching files with long lines (bundled JS).

To Reproduce

Steps to reproduce the behavior:

  1. Create a file with a very long sequence of characters without a newline (include matching sequence)
  2. Prompt an agent to search the file for matching sequence
  3. See error

Expected behavior

  • Grep should have a reasonable limit to line length of matches (200)
  • read tool also?

treydavis avatar Mar 03 '26 00:03 treydavis

@treydavis are you sure you are using latest eca server? check it via /doctor, because we do have some ways to avoid that should work for your case: https://eca.dev/config/context-management/

I will close this unless confirmed with a repro there is a bug or room for improvement in this term, LMK otherwise

ericdallo avatar Mar 03 '26 11:03 ericdallo

I'm now using ECA version: 0.110.1.

I was either mistaken about this being the fault of the grep tool or had an old version that was recently fixed. However, I can still reproduce this issue with the read-file tool:

(spit "/path/to/long-line.txt" (apply str (repeat (* 128 1024) "x")))
(count 
 (get-in 
  (read-file { "path" "/path/to/long-line.txt"
              "line_offset" 0
              "limit" 100
              } {:toolCall {:readFile {:maxLines 1}}})
  [:contents 0 :text])) ; 131072

If the agent attempts to read a file with very long lines, the result can exceed the context window. I have encountered this dealing with minified/bundled JS files.

treydavis avatar Mar 06 '26 16:03 treydavis

I see that the higher-level output truncation should catch this. I am able to reproduce in from the client. I will look into it more to be sure.

treydavis avatar Mar 06 '26 17:03 treydavis

Yeah I think outputTruncation is supposed to help with that, but maybe the default of kb is too high? suggestions are welcome on this part

ericdallo avatar Mar 06 '26 18:03 ericdallo

The issue was that the truncation was not truncating by max size, only by lines.

https://github.com/editor-code-assistant/eca/pull/346

treydavis avatar Mar 07 '26 14:03 treydavis

Nice catch, I did some small changes for performance, LMK if works, thank you!

ericdallo avatar Mar 08 '26 14:03 ericdallo