nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] nanocoder daemon start reports failure (exit 1) when the daemon takes more than 5s to boot, though it comes up

Open addyCooks opened this issue 1 month ago • 2 comments

Description

nanocoder daemon start waits a fixed 5 seconds for the daemon's lockfile (source/daemon/cli.ts:182). If the daemon needs longer (a large repo, a cold start, a busy disk), start prints a failure and exits with code 1, but the daemon keeps booting and is running a few seconds later. Scripts and service managers treat the exit code as a failure. A retry made before the lockfile exists starts a second daemon that fails with "Daemon already running".

Environment

  • OS: Windows 11 (10.0.26300)
  • Node version: 22.22.3
  • Nanocoder version: 1.31.0 (main at 9d88dda7)
  • Provider / Model: not relevant

Steps to Reproduce

  1. In a trusted git project, run nanocoder daemon start on a machine or repo where the daemon takes longer than 5 seconds to start. To simulate this, run it with NODE_OPTIONS="--require slow-boot.cjs", where slow-boot.cjs waits 8 seconds only when the process is daemon/entry.
  2. Run nanocoder daemon status right away, then again 14 seconds later.
  3. Run nanocoder daemon start again before the daemon has written its lockfile.
  4. Read .nanocoder/daemon.log.

Expected Behavior

start reports that the daemon is still starting (and exits 0), or waits long enough. A second start during boot does not launch another process.

Actual Behavior

Daemon process spawned but did not write a lockfile within 5s. Check the daemon log.      (exit 1)
status right after : Not running.
retry start        : Daemon process spawned but did not write a lockfile within 5s. ...
status 14s later   : Running. pid 26460, ..., uptime 14s.
daemon.log:  Daemon started for <project> (pid 26460).
             Daemon failed to start: Error: Daemon already running for <project> ...

The first, unslowed run on a cold machine also failed this way once and showed Running ... uptime 0s a moment later. With warm starts it took 4-5 seconds, right at the limit.

Suggested Fix

  • source/daemon/cli.ts:182-189: use a longer or configurable timeout. On timeout, if the child process is still alive, report Daemon is still starting (pid N). Run "nanocoder daemon status" to check. and exit 0 instead of failing.
  • Optional: write a "starting" lockfile as soon as the process begins, so a second start sees it.
  • Add a test that fakes a slow boot and checks the exit code.

Additional Context

  • Daemon CLI came from #1457. Open PR #1733 only changes stop.
  • [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

addyCooks avatar Oct 13 '26 11:10 addyCooks

Hi, I’d like to work on this. I’ll investigate the daemon startup timeout behavior, implement a safe status/timeout handling path, and add regression coverage for slow boot. Could you please assign it to me?

masyarakatai avatar Oct 14 '26 08:10 masyarakatai

hey @addyCooks i would like to work on this can you assign me this issue

Vishesh-Verma-07 avatar Oct 15 '26 08:10 Vishesh-Verma-07