Skip to content

fix(daemon): preserve runtime paths during service reinstalls - #155265

Merged
steipete merged 2 commits into
mainfrom
upd/launchd-reinstall-env-file-arg
Sep 22, 2026
Merged

steipete merged 2 commits into
mainfrom
upd/launchd-reinstall-env-file-arg

Conversation

@steipete

Copy link
Copy Markdown
Contributor

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 to gateway 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

  • Eight focused Linux files: 383 passed, 26 existing platform skips. After the final Doctor guard, all 105 Doctor tests passed again; the other tested owners were unchanged.
  • The wrapper regression failed before the fix with exit 127; forced-install and Doctor regressions failed with the recorded Node path missing. The unsupported-Node guard also has a demonstrated red/green regression.
  • Final check:changed passed 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.
  • Codex P1 autoreview: scoped-clean, no accepted/actionable findings.

Single-worker wall measurements (pnpm test <file> --maxWorkers=1): launchd-service-files.test.ts 24.63s; service-audit.definition-facts.test.ts 20.60s; install.reinstall.test.ts 24.12s; final doctor-gateway-services.test.ts 21.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/launchctl boundaries 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.

Release Canonical env-file slot Unsafe wrapper Healthy unpinned Node may be reselected Persistent runtime pin
2026.9.5 Present Yes Yes Supported
2026.9.4 Present Yes Yes Not available
2026.7.1-2 Present Yes Yes Not available

Exact compiled array producers: 2026.9.5/dist/launchd-service-files-Chcm4HTZ.mjs:108, 2026.9.4/dist/launchd-runtime-CtX558Qq.mjs:108, and 2026.7.1-2/dist/launchd-CnFX3Ewj.js:489. All explicitly include envFilePath. The unsafe wrapper consumes $1 and 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 --force from the owning account/profile with a supported Node, followed by openclaw gateway status and openclaw 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/node option 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.

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.
@clawsweeper

clawsweeper Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime cli CLI command changes commands Command implementations size: M maintainer Maintainer-authored PR labels Sep 21, 2026
@steipete
steipete marked this pull request as ready for review September 21, 2026 23:23
@steipete
steipete enabled auto-merge (squash) September 21, 2026 23:27
@clawsweeper

clawsweeper Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 21, 2026, 7:29 PM ET / 23:29 UTC.

ClawSweeper review

What this changes

Preserves 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
Reviewed head: f84cd3a67c7ef76319eb94f1a68b57a91ccbe66c

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused implementation with meaningful regressions and no concrete correctness finding; native upgrade validation remains outstanding.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied maintainer classification exempts this PR from the external-contributor proof gate. Its exact-tree evidence exercises the generated shell wrapper, but native launchd upgrade proof remains a separate repository-policy requirement.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied maintainer classification exempts this PR from the external-contributor proof gate. Its exact-tree evidence exercises the generated shell wrapper, but native launchd upgrade proof remains a separate repository-policy requirement.
Evidence reviewed 10 items Introduced scope and current-main necessity: The four production files differ from fetched main by the same focused runtime-preservation and wrapper-validation changes reviewed in the pinned introduced delta. Current main still omits the recorded supported Node from both installation plans.
Selection precedence remains with existing owners: Doctor retains a recorded Node only when supported and no supplied runtime path, pin, or wrapper takes precedence. Its caller still supplies the system Node path for an applicable migration; the shared installer continues to prioritize explicit pins.
Shipped wrapper compatibility: The v2026.9.5 source contains the exact legacy wrapper recognized by this patch and the same generated environment-file header. It lacks the new input validation, so the wrapper improvement is not already in that release.
Findings None None.
Security None None.

How this fits together

Gateway 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]
Loading

Before merge

  • Resolve merge risk (P1) - Native macOS upgrade compatibility remains unverified: the wrapper now refuses invalid environment inputs, but the supplied Linux fixtures do not establish that a published updater refreshes an existing LaunchAgent and restores Gateway service successfully.
  • Complete next step (P2) - Supply the repository-required native macOS published-driver × candidate upgrade evidence before merge.
  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +82, Tests +155, Docs +19. Total +256 across 10 files.

View PR surface stats
Area Files Added Removed Net
Source 4 92 10 +82
Tests 5 183 28 +155
Docs 1 19 0 +19
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 294 38 +256

Review metrics

Metric Value Why it matters
Production versus regression coverage Production net +82 lines; tests and support net +155 lines Production growth implements runtime preservation and generated-wrapper validation; regression growth covers preservation, rejection, and legacy recognition.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/commands/doctor-gateway-runtime-plan.ts, migration/backfill/repair: src/daemon/launchd-service-files.ts, migration/backfill/repair: src/daemon/service-audit-launchd.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Complete native upgrade validation (recommended)
    Provide the required published-updater-to-candidate macOS evidence showing retained runtime and environment settings, legacy-wrapper refresh, and a healthy Gateway afterward.

Technical review

Best 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.

Labels

Label changes:

  • add P1: The patch addresses runtime reselection during service repair and improves diagnosis of a reported update-related Gateway outage.
  • add merge-risk: 🚨 compatibility: Generated LaunchAgent startup becomes stricter, and the required native upgrade evidence has not yet established compatibility with existing installations.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.

Label justifications:

  • P1: The patch addresses runtime reselection during service repair and improves diagnosis of a reported update-related Gateway outage.
  • merge-risk: 🚨 compatibility: Generated LaunchAgent startup becomes stricter, and the required native upgrade evidence has not yet established compatibility with existing installations.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.

Evidence

What I checked:

  • Introduced scope and current-main necessity: The four production files differ from fetched main by the same focused runtime-preservation and wrapper-validation changes reviewed in the pinned introduced delta. Current main still omits the recorded supported Node from both installation plans. (src/cli/daemon-cli/install.ts:372, f84cd3a67c7e)
  • Selection precedence remains with existing owners: Doctor retains a recorded Node only when supported and no supplied runtime path, pin, or wrapper takes precedence. Its caller still supplies the system Node path for an applicable migration; the shared installer continues to prioritize explicit pins. (src/commands/doctor-gateway-runtime-plan.ts:26, f84cd3a67c7e)
  • Shipped wrapper compatibility: The v2026.9.5 source contains the exact legacy wrapper recognized by this patch and the same generated environment-file header. It lacks the new input validation, so the wrapper improvement is not already in that release. (src/daemon/launchd-service-files.ts:74, ec9c1a13db89)
  • Upgrade safeguards remain centralized: Reconciliation still checks installation ownership, rejects unknown edits, captures backups, and installs through transaction hooks with current-authority checks and compensation. Recognizing the exact legacy wrapper does not bypass those safeguards. (src/daemon/service-reconciliation.ts:28, f84cd3a67c7e)
  • Validation identity and coverage: The captured PR body reports focused regression passes and check:changed on source tree 2036e50898952c83f3d2f79e623976c395b1fb4a; git confirms that is the reviewed head's tree. The generated wrapper executes under /bin/sh in the tests, while plutil and launchctl are mocked. The body explicitly states that no complete native macOS published-driver upgrade was executed. Tests were inspected, not rerun in this read-only review. (src/daemon/launchd-service-files.test.ts:104, f84cd3a67c7e)
  • Existing published-driver fixture does not cover launchd: The inspected published-driver fixture exercises a systemd unit, backup receipt, and warning history through the candidate installer. It supplements the new tests but does not establish macOS launchd upgrade behavior. (src/cli/daemon-cli/install.definition-repair.test.ts:352, f84cd3a67c7e)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • darkamenosa: Raw commit 9843b93 adds src/commands/doctor-gateway-runtime-plan.ts:18 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 9843b937e354; files: src/commands/doctor-gateway-runtime-plan.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Attach redacted native macOS published-updater-to-candidate results covering runtime retention, generated environment loading, and Gateway recovery.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit 000a635 into main Sep 22, 2026
179 checks passed
@steipete
steipete deleted the upd/launchd-reinstall-env-file-arg branch September 22, 2026 00:42
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 22, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes commands Command implementations docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant