Skip to content

fix(daemon): use minimal PATH for gateway services#477

Closed
azade-c wants to merge 1 commit into
openclaw:mainfrom
azade-c:fix/minimal-service-path
Closed

fix(daemon): use minimal PATH for gateway services#477
azade-c wants to merge 1 commit into
openclaw:mainfrom
azade-c:fix/minimal-service-path

Conversation

@azade-c

@azade-c azade-c commented Jan 8, 2026

Copy link
Copy Markdown
Contributor

Summary

The gateway daemon now uses a minimal PATH that includes only:

  • ~/.bun/bin (bun runtime)
  • /usr/local/bin, /usr/bin, /bin (system tools)

This intentionally excludes version managers (nvm, fnm, volta) and package managers (pnpm, npm) since they're only needed at install time, not runtime.

Benefits

  • Cleaner service environment — no cruft from user shell
  • No hardcoded version-specific paths — won't break when you upgrade Node or switch versions via nvm
  • Consistent behavior across different user setups

Runtime variables

Variables like DISPLAY (for headless browser) should be set in ~/.clawdbot/.env, which is loaded early by the gateway via loadDotEnv(). This keeps runtime config separate from the service definition.

Changes

  • Add buildServiceEnvironment() helper in src/daemon/service-env.ts
  • Add buildMinimalServicePath() to construct a minimal PATH
  • Update all service.install() call sites to use the new helper
  • Add unit tests for the new helpers
  • Add documentation section in docs/gateway/troubleshooting.md

Testing

pnpm exec vitest run src/daemon/service-env.test.ts

Tested manually on Linux (systemd) — gateway starts correctly with the minimal PATH.

The gateway daemon now uses a minimal PATH that includes only:
- ~/.bun/bin (bun runtime)
- /usr/local/bin, /usr/bin, /bin (system tools)

This intentionally excludes version managers (nvm, fnm, volta) and
package managers (pnpm, npm) since they're only needed at install
time, not runtime. Benefits:

- Cleaner service environment
- No hardcoded version-specific paths that break on upgrades
- Consistent behavior across different user setups

Runtime variables like DISPLAY should be set in ~/.clawdbot/.env
which is loaded early by the gateway.

Also adds:
- buildServiceEnvironment() helper in src/daemon/service-env.ts
- Unit tests for the new helper
- Documentation in troubleshooting.md
@steipete

steipete commented Jan 8, 2026

Copy link
Copy Markdown
Contributor

Thanks! Landed already in main via 1cf8503 (fix(daemon): audit runtime best practices). That commit adds service-env + tests, wires it into daemon install/doctor/onboarding, and updates troubleshooting docs. It also keeps /opt/homebrew/bin and win32 PATH handling, so this PR would regress those. Closing as already addressed.

@steipete steipete closed this Jan 8, 2026
@steipete

steipete commented Jan 8, 2026

Copy link
Copy Markdown
Contributor

Made sure you are in the commit graph.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants