#22929: Fix NODE_EXTRA_CA_CERTS missing from LaunchAgent environment on macOS
gateway
size: S
trusted-contributor
Cluster:
Node and macOS Enhancements
## Problem
When OpenClaw runs as a macOS LaunchAgent (installed via `openclaw gateway install`), Node's `undici`/`fetch` cannot locate the system CA bundle because `launchd` does not inherit the shell environment. This causes TLS verification failures for all HTTPS connections (Telegram, webhooks, etc.), while the same gateway works fine in a foreground terminal session.
Root cause: `buildServiceEnvironment` and `buildNodeServiceEnvironment` in `service-env.ts` did not include `NODE_EXTRA_CA_CERTS` in the generated plist environment.
Fixes #22856.
## Fix
Set `NODE_EXTRA_CA_CERTS` to `/etc/ssl/cert.pem` (the macOS system CA bundle) by default when building the service environment on macOS. A user-supplied `NODE_EXTRA_CA_CERTS` in the host environment always takes precedence.
The same default is applied to both `buildServiceEnvironment` (gateway) and `buildNodeServiceEnvironment` (node service) since both run under launchd on macOS.
## Changes
- `src/daemon/service-env.ts`: add `NODE_EXTRA_CA_CERTS` to the service environment on macOS, falling back to `/etc/ssl/cert.pem` when not set by the user
- `src/daemon/service-env.test.ts`: add 4 tests covering the default and user-override cases for both environment builders
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Fixes TLS verification failures for HTTPS connections when OpenClaw runs as a macOS LaunchAgent by setting `NODE_EXTRA_CA_CERTS` to the macOS system CA bundle path (`/etc/ssl/cert.pem`). The issue occurs because launchd services don't inherit the shell environment, preventing Node's undici/fetch from locating system certificates.
- Adds `NODE_EXTRA_CA_CERTS` environment variable to both `buildServiceEnvironment` and `buildNodeServiceEnvironment` functions
- Defaults to `/etc/ssl/cert.pem` on macOS (Darwin platform only)
- Respects user-provided `NODE_EXTRA_CA_CERTS` values as overrides
- Includes comprehensive test coverage for both default behavior and user override scenarios
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The implementation is clean, well-tested, and narrowly scoped. It adds a single environment variable that only affects macOS LaunchAgent environments, uses the correct system CA bundle path, properly respects user overrides, and includes comprehensive test coverage for all scenarios. The fix directly addresses a documented issue without introducing any breaking changes or side effects.
- No files require special attention
<sub>Last reviewed commit: 35c5a8e</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#18112: fix(daemon): gateway install on macOS ignores fnm/nvm node (#18090)
by yinghaosang · 2026-02-16
81.3%
#6064: fix(daemon): prefer bundled node from install-cli.sh over system node
by joyshmitz · 2026-02-01
78.0%
#22671: Preserve custom env vars in LaunchAgent plist across updates
by Clawborn · 2026-02-21
76.9%
#9200: Fix: Strip dangerous env vars from baseEnv in host execution
by vishaltandale00 · 2026-02-05
75.7%
#4709: fix(daemon): include user bin dirs in macOS LaunchAgent PATH
by ekson73 · 2026-01-30
75.7%
#17912: fix: configure git to use HTTPS instead of SSH for GitHub URLs
by MisterGuy420 · 2026-02-16
74.4%
#17951: fix: macOS app: Skill binary detection does not respect /etc/paths ...
by MisterGuy420 · 2026-02-16
74.1%
#20390: fix(daemon): fall back to /tmp for launchd logs on removable volumes
by lemoz · 2026-02-18
74.1%
#10182: fix: skip non-openclaw LaunchAgents in doctor gateway scan
by Yida-Dev · 2026-02-06
73.8%
#18792: docs: add macOS source-run troubleshooting for setup/auth issues
by yash27-lab · 2026-02-17
73.6%