Roo-Code loses instructions after reading a large file - how to prevent context overwrite?
In Roo-Code v3.8.4 with the VS Code LM API and Claude 3.5 Sonnet, the agent loses all instructions and prior conversation after reading a large file, such as a big JSON API response or a 150+ KB source file, and starts acting like a plain chatbot. Why does this happen, and what can I do to stop one large read from wiping out the whole context?
Originally asked on GitHub: https://github.com/RooCodeInc/Roo-Code/issues/1532
5 answers
The issue is closed as completed in the Roo-Code repo. In the thread, a Roo collaborator said they were working on supporting partial file reads with a reasonable default for maximum lines read, but no fixed release version is mentioned in the discussion.
The root cause is context overflow: when a single file, log, or API response is large enough to fill the remaining context window, the system prompt, instructions, and history get dropped, so the model no longer knows its task and answers like a generic chatbot.
Workarounds that helped in the thread:
-
Tell the model explicitly not to read data that is too large and instead ask for a smaller excerpt. The reporter said doing this manually usually works.
-
Create a custom "large-file QA mode" locked to a Gemini model. The parent task spawns a subtask that switches to this mode, analyzes the large file, answers the question, and returns the result to the parent task. One commenter reported this worked for their problem.
-
Use a model with a much larger context window, such as Gemini 2.0 Flash Thinking or Gemini 2.0 Pro, when large inputs are expected. This was suggested in the thread, but the reporter did not confirm it fully solved the issue.
-
For a 150+ KB source file (src/core/Cline.ts), Roo could not read it because the file exceeded the 128K context length; that reporter switched to Cursor for the same task.
As general advice, keeping project files and API outputs reasonably sized or steering the agent away from very large files will reduce the chance of accidental context overwrite until partial file reads are available.
Did this work for you?-
What @liush2yuxjtu tried on GitHub (Worked)
Create a custom "large-file QA mode" locked to Gemini. The parent task creates a subtask that switches to this mode to answer questions about the large file, then returns to the parent task. The commenter reported this worked for their problem.
Source: https://github.com/RooCodeInc/Roo-Code/issues/1532#issuecomment-2720280058 (opens external site)
Did this work for you?What @FarbrorMartin tried on GitHub (Worked)
Manually instruct the model not to read data that is too large and instead ask the user for a smaller excerpt. The reporter said doing this manually usually works.
Source: https://github.com/RooCodeInc/Roo-Code/issues/1532#issuecomment-2710309058 (opens external site)
Did this work for you?What @complyue tried on GitHub (Didn't work)
Ask Roo to read a 150+ KB source file (src/core/Cline.ts), which failed because the file exceeded the 128K context length. The reporter switched to Cursor to complete the task.
Source: https://github.com/RooCodeInc/Roo-Code/issues/1532#issuecomment-2724022257 (opens external site)
Did this work for you?What @notlousybook tried on GitHub (Outcome unclear)
Switch to a model with a larger context window, such as Gemini 2.0 Flash Thinking or Gemini 2.0 Pro. This was suggested but there is no confirmation in the thread that it fully solved the problem.
Source: https://github.com/RooCodeInc/Roo-Code/issues/1532#issuecomment-2710257113 (opens external site)
Did this work for you?