Description
The logs() command in the daemon CLI is designed to return the last 64KB of the background daemon log. However, to do this, it calls fs.readFile() on the entire file, pulling hundreds of megabytes into memory just to run .slice(start) on it.
Environment
- OS: Any
- Node version: Node 18+
- Nanocoder version: 1.30.0
Steps to Reproduce
- Let the daemon run for a long time until the log file is 1GB.
- Run the command to fetch logs.
- The Node process will attempt to allocate 1GB of heap memory and crash/stall.
Expected Behavior
The command should stream only the tail end of the file.
Actual Behavior
readFile(logPath, 'utf-8') buffers the whole file into RAM.
Additional Context
Implementation Notes
Fix in source/daemon/cli.ts:251-253. Use fs.createReadStream(logPath, { start }) or child process tail -c 65536.
Description
The
logs()command in the daemon CLI is designed to return the last 64KB of the background daemon log. However, to do this, it callsfs.readFile()on the entire file, pulling hundreds of megabytes into memory just to run.slice(start)on it.Environment
Steps to Reproduce
Expected Behavior
The command should stream only the tail end of the file.
Actual Behavior
readFile(logPath, 'utf-8')buffers the whole file into RAM.Additional Context
Implementation Notes
Fix in
source/daemon/cli.ts:251-253. Usefs.createReadStream(logPath, { start })or child processtail -c 65536.