Repository navigation
fix(daemon): preserve runtime paths during service reinstalls - #155265
Conversation
Retain supported recorded Node paths during forced reinstall and Doctor repair, without overriding explicit runtime selection, pins, wrappers, or migration. Reject invalid generated LaunchAgent environment inputs with repair guidance, and recognize the published legacy wrapper during backed-up definition refresh. Related: #155229. Thanks to @Philbones49 for the report. The original operation that replaced the env-file slot remains unidentified; normal install and restart already share the canonical argument generator.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. Reviewed September 21, 2026, 7:29 PM ET / 23:29 UTC. ClawSweeper reviewWhat this changesPreserves supported recorded Node paths during service reinstalls and Doctor repairs, validates generated macOS service environment files, and adds diagnostics, recovery documentation, and regression coverage. Merge readiness⛔ Blocked before merge - 3 items remain This remains a useful, focused fix absent from current main. No introduced correctness defect was found; the original malformed-plist investigation remains separate. Priority: P1 Review scores
Verification
How this fits togetherGateway service installation turns runtime choices and environment settings into operating-system service definitions. On macOS, launchd starts a generated shell wrapper that loads the private environment file before executing the Gateway. flowchart TD
A[Install or Doctor repair] --> B[Inspect recorded runtime]
B --> C[Apply explicit selection and migration rules]
C --> D[Shared service installer]
D --> E[LaunchAgent and private environment file]
E --> F[Validate environment input]
F --> G[Start Gateway or report repair guidance]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +82, Tests +155, Docs +19. Total +256 across 10 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep runtime selection and wrapper generation in their existing owners, with demonstrated macOS upgrade compatibility and actionable recovery diagnostics. Do we have a high-confidence way to reproduce the issue? Yes for runtime reselection and unsafe wrapper consumption: current source establishes both paths, and the PR reports failing-before/passing-after regressions. The operation that originally corrupted the plist remains unverified. Is this the best way to solve the issue? Yes for the bounded defects: carrying the supported runtime into the existing installer and validating its generated environment input avoids a competing implementation. Native upgrade validation remains necessary. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 3fbca4b968bf. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
…aw#155265) Retain supported recorded Node paths during forced reinstall and Doctor repair, without overriding explicit runtime selection, pins, wrappers, or migration. Reject invalid generated LaunchAgent environment inputs with repair guidance, and recognize the published legacy wrapper during backed-up definition refresh. Related: openclaw#155229. Thanks to @Philbones49 for the report. The original operation that replaced the env-file slot remains unidentified; normal install and restart already share the canonical argument generator.
Related: #155229. Thanks to @Philbones49 for the report and the concrete broken/correct argument arrays.
What Problem This Solves
Forced reinstall could switch a working recorded Node executable, and a malformed macOS LaunchAgent could source the Node binary as its environment file and exit 127.
User Impact
Forced reinstall and Doctor repair retain the recorded Node when it remains supported and no explicit selection or runtime migration takes precedence. Generated LaunchAgent wrappers reject missing, unreadable, or non-generated environment inputs with an actionable repair message. Status and Doctor identify the malformed env-file slot and the legacy wrapper.
Why This Change Was Made
Install and restart already use one canonical argument generator,
prepareLaunchAgentProgramArguments; it emits shell, wrapper, env file, then the Gateway command. The updater delegates its reinstall togateway install --force. The confirmed runtime bug was that install successfully probed the recorded Node but discarded its path. Doctor likewise omitted the recorded Node when constructing its repair plan. Both now carry that path into the existing installer.The wrapper verifies its generated env-file header before sourcing. The audit recognizes the exact published legacy wrapper and permits the normal backed-up service refresh. Existing custom-wrapper, explicit-pin, unsupported-runtime migration, backup, and rollback boundaries remain in their owners.
The operation that originally replaced the reporter's env-file argument with Node is not established. Neither current main nor the three inspected published generators drops that slot. This PR does not claim to reconstruct arbitrary malformed definitions or close the original corruption investigation.
Evidence
check:changedpassed on a Blacksmith Linux Testbox, including core typechecking, all 25 test-type graphs, lint (0 warnings/errors), format, import cycles, unused exports, and the repository guards. Tested source tree:2036e50898952c83f3d2f79e623976c395b1fb4a.Single-worker wall measurements (
pnpm test <file> --maxWorkers=1):launchd-service-files.test.ts24.63s;service-audit.definition-facts.test.ts20.60s;install.reinstall.test.ts24.12s; finaldoctor-gateway-services.test.ts21.23s. Each changed file spends less than one second executing tests; shared compiler preparation dominates. Hosted PR CI timings are pending at author handoff.Production +92/-10 LOC; tests/test support +183/-28; docs +19/-0.
The initial added round-trip fixture omitted the strict reader's expected wrapper/env paths; supplying the same options as the production reader fixed that deterministic fixture failure. The first changed check rejected growth in existing over-cap Doctor files; the final implementation and related test now reside in their existing runtime modules, without baseline or suppression changes.
Mac-specific argument generation, audit, and lifecycle logic are exercised on Linux with the native
plutil/launchctlboundaries mocked. The generated shell wrapper itself executes under/bin/sh. No operator Gateway or real OpenClaw state was touched. A complete native macOS published-driver upgrade was not executed; the candidate installer is covered under the existing published-driver marker and backup/rollback fixtures.Published release carry and recovery
All three npm tarballs were packed with scripts disabled and inspected on the Testbox.
Exact compiled array producers:
2026.9.5/dist/launchd-service-files-Chcm4HTZ.mjs:108,2026.9.4/dist/launchd-runtime-CtX558Qq.mjs:108, and2026.7.1-2/dist/launchd-CnFX3Ewj.js:489. All explicitly includeenvFilePath. The unsafe wrapper consumes$1and sources any regular file in all three. Their reader does not recognize the reported malformed pair, so a restart can preserve an already-broken array.For recovery, back up the plist and private service environment file, then run
openclaw gateway install --forcefrom the owning account/profile with a supported Node, followed byopenclaw gateway statusandopenclaw health. Keep service-only environment values available to reinstall because malformed arguments can prevent reading the prior env file. On 2026.9.5, use the existing--runtime-path /opt/homebrew/opt/node@24/bin/nodeoption to explicitly select and persist that runtime; older inspected releases do not offer this option. A manually edited plist path alone is not a durable pin on those releases. A damaged explicit-pin definition requires explicit reselection. Current main supports Node 26.1+ subject to the SQLite capability checks, so Node 26.5 is not intrinsically outside the current version range.