nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] `nanocoder daemon install` can install an auto-start that will never boot in an untrusted project

Open addyCooks opened this issue 2 months ago • 2 comments

Description

Follow-up to #1259 (raised by @will-lamerton in review and by nc-review).

Since #1259, nanocoder daemon start refuses to boot with exit code 1 unless the project root is in preferences.trustedDirectories. nanocoder daemon install was not updated to match: it writes a service definition whose command is nanocoder daemon start, with restart-on-failure set, and reports only Auto-start installed for <root>. (source/daemon/install.ts:268, 297, 332).

If a user installs auto-start before they have ever run nanocoder interactively in that project, the service manager starts a daemon that fails the trust gate immediately, then retries on its restart policy forever. Nothing tells the user why, and install reported success.

Affected on all three platforms:

  • systemd user unit: Restart=on-failure, RestartSec=5
  • launchd LaunchAgent: KeepAlive: true
  • Windows Task Scheduler: restart-on-failure

Steps to Reproduce

  1. Clone any repo you have never opened with nanocoder, so the path is not in trustedDirectories.
  2. Run nanocoder daemon install in it.
  3. Observe Auto-start installed for <root>.
  4. Start the service (or log in again) and check the service manager's state.

Expected Behavior

daemon install tells the user when the project root is not trusted yet, and how to fix it: run nanocoder there once and accept the disclaimer, or pass --trust-directory.

Actual Behavior

install reports plain success. The installed service fails at every start with exit 1 and is restarted indefinitely.

Proposed Fix

  1. In install, check trust for opts.projectRoot via isDirectoryTrusted from @/config/preferences.
  2. When untrusted, keep installing but add a clear warning to the result message naming both remedies.
  3. Cover it in source/daemon/install.spec.ts, trusted and untrusted.

nc-review also floated writing Environment=NANOCODER_TRUST_DIRECTORY=1 into the generated unit. I would not do that: it silently grants exactly the trust the gate exists to require, and it would be invisible in the CLI output. Happy to go that way if maintainers prefer.

Additional Context

  • Review thread: #1259
  • Original bug: #1245
  • Note: #1260 is an open alternative fix for #1245 touching source/daemon/. If it merges, this work needs rebasing onto it.

addyCooks avatar Sep 16 '26 06:09 addyCooks

Hey @will-lamerton, this is one of the two follow-ups from your review on #1259 happy to pick it up if you assign it to me

cc @akramcodez

addyCooks avatar Sep 16 '26 06:09 addyCooks

Picking this up - a fix will follow shortly.

awhite0030 avatar Sep 20 '26 00:09 awhite0030