Skip to content

[Bug] nanocoder logs buffers the entire log file into memory #1042

Description

@akramcodez

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

  1. Let the daemon run for a long time until the log file is 1GB.
  2. Run the command to fetch logs.
  3. 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

  • I have searched existing issues to ensure this is not a duplicate
  • I can reproduce this issue consistently
  • This issue occurs with the latest version of nanocoder

Implementation Notes

Fix in source/daemon/cli.ts:251-253. Use fs.createReadStream(logPath, { start }) or child process tail -c 65536.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions