[Bug] read_file result is cut by the 20,000-character cap, but the file is marked as fully read
Description
read_file returns up to 1500 lines, but the tool-result cap is 20,000 characters. For a file over about 20,000 characters the middle is dropped from what the model sees, and a second read answers "already in context", so the model cannot see the missing part.
Environment
- OS: Windows 11 Home 10.0.26300
- Node version: v22.22.3
- Nanocoder version: 1.32.0 (built from main at f92cce9c)
- Provider: Not provider-specific
- Model: Not model-specific
Steps to Reproduce
- Create
big.tswith 600 lines likeconst value_N = computeSomething(N); // line N+1(about 31,000 characters). - Call
read_filewith{"path": "big.ts"}and pass the result throughtruncateToolResult. - Call
read_filewith{"path": "big.ts"}again.
Expected Behavior
Either the whole result fits, or read_file itself returns only what fits plus a hint such as "continue at line 380". The file is not recorded as fully read.
Actual Behavior
The model gets 20,000 of 31,471 characters with line 300 missing, and the second read refuses to show the file again.
Logs/Screenshots
raw result: 31471 chars -> sent: 20000 chars, line 300 missing
[Output truncated: 31471 characters total; request a narrower result to inspect omitted content]
second read: [file: big.ts — already in context, unchanged since last read (600 lines, 31471 bytes). pass start_line/end_line to read the body again.]
Additional Context
- [x] I have searched existing issues to ensure this is not a duplicate
- [x] I can reproduce this issue consistently
- [x] This issue occurs with the latest version of nanocoder (main)
Suggested fix:
source/constants.ts:96(FILE_READ_PREVIEW_THRESHOLD_LINES = 1500) and:159(MAX_TOOL_RESULT_CHARS = 20_000) disagree. Makeread_fileapply the character cap itself (source/tools/read-file.tsxaround line 143), stop at a line boundary and say where to continue.- Only mark lines that were actually returned as read in the read tracker, so the "already in context" reply cannot hide the cut part.
Related: #2009, #1781 (other read_file problems, different cause).
I will pick this up. I will cap read_file output at line boundaries before generic tool-result truncation, report the next line to request, and only track the lines actually returned. I will add a large-file regression that verifies omitted content remains readable.