You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
filesystem: read_text_file head/tail mishandle line endings (tail drops a line after a final newline; head keeps \r on CRLF) #5187
tailFile in src/filesystem/lib.ts splits the decoded tail on \n and keeps the last N segments. For a file that ends with a newline, the empty segment after the final \n counts as one of the N lines: tail: 1 on "a\nb\nc\n" returns an empty string, and tail: 2 returns only c. The test in src/filesystem/__tests__/server-tools.test.ts that counts the trailing newline as a line pins this today. head does not have the trailing-newline problem, but it has a line-ending one: headFile splits on \n without normalizing CRLF, so on a CRLF file every line it returns still ends in \r, while tail normalizes to LF.
Expected
A final newline ends the last line and is not counted as an extra empty line, for LF and CRLF files and across the chunk boundary tailFile reads in. The pinning test changes with the fix. head returns CRLF files' lines without a trailing \r, normalized to LF the same way tail is, so head and tail agree on line endings.
Scope widened during work on #5316 to cover head's CRLF handling too, since both are read_text_file's line modes.
The PR(s) above targeted the pre-refactor code and are closed as part of the backlog triage in #4875; this issue is where the work continues, with the PR(s) as a prototype. Thank you to their authors.
changed the title [-]filesystem: read_text_file tail returns one line too few when the file ends with a newline[/-][+]filesystem: read_text_file head/tail mishandle line endings (tail drops a line after a final newline; head keeps \r on CRLF)[/+]on Oct 27, 2026
Activity
cliffhall commentedon Oct 20, 2026
Triage: Priority Medium (total 6)
buglabelFiled from the PR backlog triage (#4877). Board: Servers V2 (#43), Status
Incoming, awaiting maintainer review (no milestone yet).[-]filesystem: read_text_file tail returns one line too few when the file ends with a newline[/-][+]filesystem: read_text_file head/tail mishandle line endings (tail drops a line after a final newline; head keeps \r on CRLF)[/+]cliffhall commentedon Oct 27, 2026
Fixed by #5316 (tail) and #5324 (head CRLF), both merged into v2/main.
fix(filesystem): tail no longer counts a final newline as a line
fix(filesystem): head returns CRLF lines without their \r