Repository navigation
fix(cli): avoid macOS system CA exit hang in one-shot commands - #110341
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6ec12f42a6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // Node loads the macOS Keychain off-thread on the first TLS import, then joins | ||
| // that worker during shutdown. One-shot CLIs use the file-backed CA store instead; | ||
| // an explicit --use-system-ca remains the opt-in for Keychain-only trust. | ||
| childEnv.NODE_USE_SYSTEM_CA = "0"; |
There was a problem hiding this comment.
Preserve the documented system-CA env opt-in
When a macOS user has explicitly exported NODE_USE_SYSTEM_CA=1, this respawn path rewrites it to 0 unless they also know to pass --use-system-ca. That breaks the documented private-CA setup (docs/plugins/vault.md tells users to export NODE_USE_SYSTEM_CA=1, and the Vault integration forwards that env key), so one-shot commands that resolve Vault-backed SecretRefs against a server trusted only by the macOS trust store will stop trusting that CA and fail TLS before the command can run. Please distinguish OpenClaw’s own defaulted env from an operator-provided env opt-in, or continue honoring the documented env contract.
Useful? React with 👍 / 👎.
Respawn one-shot macOS commands with Node's OpenSSL-backed CA store when system CA loading is inherited. This avoids an indefinite shutdown join on the Keychain loader worker while preserving system CA for Gateway, interactive, and explicit --use-system-ca processes.
6ec12f4 to
3505c4b
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3505c4bd94
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| params.execArgv.includes(params.option) || | ||
| nodeOptions.some((token) => { | ||
| if (token === params.option) { |
There was a problem hiding this comment.
Recognize underscore CA flag aliases
When macOS operators use Node-supported underscore aliases such as --use_system_ca in process.execArgv or NODE_OPTIONS, this exact-match helper returns false, so the new Darwin branch treats the explicit system-CA opt-in as absent and rewrites NODE_USE_SYSTEM_CA to 0 / adds --use-openssl-ca. I verified Node accepts the underscore forms via process.allowedNodeEnvironmentFlags and node --use_openssl_ca; one-shot commands that rely on Keychain-only private CAs would therefore lose trust despite an explicit runtime flag.
Useful? React with 👍 / 👎.
|
Merged via squash.
|
Respawn one-shot macOS commands with Node's OpenSSL-backed CA store when system CA loading is inherited. This avoids an indefinite shutdown join on the Keychain loader worker while preserving system CA for Gateway, interactive, and explicit --use-system-ca processes.
What Problem This Solves
On macOS, every gateway-backed one-shot CLI command (
cron list/status/get/show/runs,channels list,agent,sessions,doctor, evenconfig validate) prints its complete output within ~1s and then never exits — the process idles toward the 600s command timeout. Any script, cron job, or CI step that runs the CLI and waits for exit hangs forever. Reproduced 6+ times across QA rounds, including on the canonical non-QA build.Why This Change Was Made
Root cause (confirmed by decisive A/B experiment): OpenClaw defaults
NODE_USE_SYSTEM_CA=1on darwin (src/bootstrap/node-startup-env.ts:36). Node's macOS system-CA support loads the Keychain trust store on a worker thread at first TLS import and joins that worker during process shutdown; under load that join does not complete, keeping the (respawned) CLI child alive (ProcessWrap+PipeWrapobserved viaprocess.getActiveResourcesInfo()).config validatewith default env = hang; identical command withNODE_USE_SYSTEM_CA=0= instant exit.User Impact
One-shot, non-interactive CLI invocations on macOS now respawn with
--use-openssl-ca(file-backed CA store) and exit promptly after completing. The trust-store scope is deliberate: foregroundgateway runskips the respawn wrapper entirely (shouldSkipRespawnForArgv) and the TUI/interactive commands are excluded (isTerminalInteractiveRespawnArgv), so long-lived processes that make provider TLS calls keep macOS Keychain trust (enterprise/corporate CAs). An explicit--use-system-ca(execArgv orNODE_OPTIONS) remains the opt-in for Keychain-only trust on one-shots, andNODE_EXTRA_CA_CERTSis unaffected. No respawn loop: the child env carriesNODE_USE_SYSTEM_CA=0, so the branch cannot re-trigger.Evidence
cron list --jsonandconfig validateEXIT with code 0; control run with explicit--use-system-careproduces the pre-fix hang, proving the opt-in path preserves old behavior.src/entry.respawn.test.ts) + new process-level regression proving a gateway-backed CLI process exits cleanly (src/cli/gateway-backed-exit.process.test.ts). All pass.check-changed: production/test tsgo, formatting, lint, guards green.