Repository navigation
fix(macos): fence Gateway recovery installs with the observed runtime pin - #165044
Conversation
… pin Same-version Node rollback and prior-build hosting restoration still spawned the retained CLI, which cannot accept --expected-runtime-pin, so an operator repin between the app's final custody check and that CLI's snapshot was overwritten. The bundled CLI could not be substituted because the installer derives the service entrypoint, shim PATH, dev mode and Bun SQLite library from its own process. Core adds a hidden `gateway install --restore-service-cli` option that plans the service for an explicitly supplied retained executable, entrypoint and SQLite library. It requires --expected-runtime-pin and an explicit --runtime, keeps pinning owned by --runtime-path, and does not require the failed replacement service to be running. The app runs both recovery paths through its bundled installer with the CLI-observed expectation; Swift never derives the revision. A pin refusal during Node migration now clears activation intent like the hosting-change refusal. Move the auth-profile service-env collectors into a sibling module so daemon-install-helpers.ts drops below the max-lines cap; its suppression and baseline entry are removed.
|
🦞👀 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: needs maintainer review before merge. Reviewed October 4, 2026, 2:34 PM ET / 18:34 UTC. ClawSweeper reviewWhat this changesThe macOS app uses its bundled installer to restore retained Gateway runtimes while preserving concurrent operator service or runtime changes. Merge readiness✅ Ready for maintainer review This remains necessary: current main leaves both recovery installs unfenced, and the merged predecessor explicitly reserved this follow-up. No blocking introduced defect was found. Likely related people: steipete (high confidence, recent merged work on these recovery owners). Priority: P2 Review scores
Verification
How this fits togetherThe macOS app manages Gateway hosting and recovery through the OpenClaw CLI. The installer translates the retained runtime, package, environment, and observed operator selection into a launchd service. flowchart TD
A[Gateway recovery request] --> B[Retained runtime and package]
B --> C[Bundled installer]
D[Observed operator selection] --> C
C --> E[Check current service and pin]
E --> F[Restore launchd service]
E --> G[Preserve newer selection and report refusal]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +123, Tests +273, Docs +1, Other +295. Total +692 across 22 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep recovery under the existing installer and native service owners, preserving the retained package while refusing stale operator selections. Do we have a high-confidence way to reproduce the issue? Yes: current-main recovery dispatches through retained CLIs without the observed pin expectation, leaving the reported pre-snapshot overwrite window. This review inspected source; the PR separately records a real launchd reproduction and after-fix replay. Is this the best way to solve the issue? Yes: selecting the retained service through the existing fence-capable installer preserves command and environment ownership without sending unsupported flags to published CLIs. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 0816aa1b57dc. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
… pin (openclaw#165044) Same-version Node rollback and prior-build hosting restoration still spawned the retained CLI, which cannot accept --expected-runtime-pin, so an operator repin between the app's final custody check and that CLI's snapshot was overwritten. The bundled CLI could not be substituted because the installer derives the service entrypoint, shim PATH, dev mode and Bun SQLite library from its own process. Core adds a hidden `gateway install --restore-service-cli` option that plans the service for an explicitly supplied retained executable, entrypoint and SQLite library. It requires --expected-runtime-pin and an explicit --runtime, keeps pinning owned by --runtime-path, and does not require the failed replacement service to be running. The app runs both recovery paths through its bundled installer with the CLI-observed expectation; Swift never derives the revision. A pin refusal during Node migration now clears activation intent like the hosting-change refusal. Move the auth-profile service-env collectors into a sibling module so daemon-install-helpers.ts drops below the max-lines cap; its suppression and baseline entry are removed.
What Problem This Solves
Fixes: the macOS app's Gateway recovery can overwrite an operator's runtime pin or service change when it lands between the app's final custody check and the recovery installer's own snapshot. Affected paths are the same-version Node rollback after a failed Bun migration, and restoring a hosting change onto the service's previous bundled build.
User Impact
Every app-owned recovery install is now fenced the way #164616 fenced forward installs. If an operator repins or changes the service first, recovery stops, preserves the newer selection, and reports it without retrying or starting anything. Recovery still restores exactly what it restored before: the retained npm Node package with its own Node, or the previous build's Bun, entrypoint and SQLite library. It also keeps working when the failed replacement service is not running.
Why This Change Was Made
#164616 left these two recovery paths unfenced (its "Residual Recovery Window" section). Both spawn the retained, older CLI, and a published CLI cannot accept
--expected-runtime-pin. The app also cannot just run its bundled CLI instead. The installer builds the service command from its own process:process.argv[1]selects the entrypoint (src/daemon/program-args.ts:169), theopenclawshim PATH dirs, and dev-mode detection.OPENCLAW_SQLITE_LIBRARYcomes from the installer's own environment.Substituting the bundled CLI therefore installs the app's own package instead of the retained one. A live run during this work did exactly that: an unfenced bundled install moved the service onto the installer's Node and package.
Core: a hidden
gateway install --restore-service-cli '{"executable","entrypoint","sqliteLibrary"}'option tells the installer to plan the service as that retained CLI would have. All argv- and execPath-derived inputs use the retained values, and the SQLite library is set only in the service-target environment, never the installer's. It is accepted only together with--expected-runtime-pinand an explicit--runtime. It refuses wrappers, update-owned reconciliation, a--runtime-paththat names a different executable, and anything that is not an OpenClaw entrypoint. Pinning stays with--runtime-path: Node rollback stays unpinned, and prior-build restore keeps its Bun pin. A restore dropsrequireRunning, because recovery replaces the app's own failed service and a crash-looping replacement often isn't "running". The definition and pin-revision binding still fences operator changes.App: one owner,
runDaemonCommand(restoring:). Recovery runs the fence-capable bundled installer with the retained service environment, keeps the retained CLI's path and authority checks before spawn, and sends the restore option plus the CLI-observed expectation. Swift never computes the revision. Node rollback uses this app build's validated bundled runtime (BundledRuntime.resolve(bundle:)), never seeding, because seeding can replace the legacy CLI wrapper. Prior-build restoration uses the hosting change's prepared current build. The retained CLI is still used, but only for read-only--versionprobes. A pin refusal during Node migration now clears activation intent, matching the hosting-change refusal, so nothing reattaches or retries.There is deliberately no unfenced fallback. If the app's bundled runtime is missing or incompatible, recovery stops with "reinstall OpenClaw.app". That only matters when Resume restores an absent legacy Node service; a present original service is only verified, not reinstalled. The core updater step (step 1 of the migration) still runs the installed CLI and remains out of scope, as documented.
Release-note context: macOS app Gateway recovery (Node rollback after a failed Bun switch, and restoring the previous hosting mode) now preserves an operator's concurrent runtime or service change instead of overwriting it.
Update behavior
Capability comes from choosing the bundled installer, not from a version check. Retained or published CLIs never receive the new option. They now run only read-only
--versionand absence probes during recovery; the core updater step is unchanged.Measured live: a runtime-pin write by a newer CLI forward-migrates the state database. Status reads and no-op pin assertions do not. Recovery pin writes now use the bundled writer, but in both real flows the same writer already ran earlier in the same operation:
uninstallalready ran through the current bundled CLI and committed the pin deletion.So recovery adds no new schema transition. A prior build that cannot open a newer schema was already unrecoverable by the old path too, because the retained CLI refuses that database.
Published-driver × candidate: published
[email protected]restarts, health-checks and reports status for a service restored by this branch's installer (table below).Evidence
Live launchd, real CLIs (macOS, throwaway
--profile, own LaunchAgent label, random port). The published 2026.9.8 npm package plays the retained CLI; this branch's CLI plays the bundled installer. All jobs, plists, state, and logs were removed afterwards.--restore-service-cli(Cellar-realpath Node, as the app sends it) + observed pininstalled;ProgramArguments,WorkingDirectoryand generated env byte-identical to the published self-install (Cellar path stabilized to/opt/homebrew/opt/node@24/bin/node)install --force --runtime nodeinstalled; operator pin silently removed (the defect)loaded=false); candidate fenced restoreinstalled; published Gatewayrunning, RPC OKgateway restartrestarted;healthok--runtime bun --runtime-path <bun> --restore-service-cli {bun, openclaw.mjs, sqlite}[bun, --no-install, <retained>/dist/index.js, gateway, --port …]; generated envOPENCLAW_SQLITE_LIBRARY= retained libraryReplay at the committed head
d015175d606brepeated the parity, race, stopped-service and Bun cells with the same results. The full generated env file, token included, matched byte for byte.Harness caveats:
mainis at state schema 20 while still reporting version 2026.9.8. When a candidate pin write migrated a throwaway state database, the published 2026.9.8 Gateway correctly refused to start on it. That refusal is how the pin-write rule above was found and isolated.healthcall without the profile's port in config targets the profile default port; RPC status on the service port is the liveness check used here.Regressions that fail on the original defect
operator repin before Node rollback dispatch is preserved, not overwrittenandoperator repin before prior-build restoration dispatch is preserved, not overwritten. The fake installer models core: the operator's pin lands as the CLI spawns; an install without--expected-runtime-pinoverwrites it, and one with it is refused. Against the original production Swift both fail, with the pin deleted and health verification proceeding. With the fix both pass: the pin survives, health is not checked, and the exact restore and expectation arguments go through the bundled installer prefix.install.test.ts, covering refusal without a fence, a malformed spec, missing--runtime, a wrapper, a mismatched--runtime-path, update-owned reconciliation, a stale expectation, Node unpinned with norequireRunning, Bun pinned, and the SQLite library override or removal. Swapping in the originalinstall.tsgives 16 failures. A real-builder test indaemon-install-path.test.tsproves the planned command and shim PATH dirs come from the retained package, never the installer's.Tests and gates
--maxWorkers=1)pnpm test src/cli/daemon-cli/install.test.tspnpm test src/commands/daemon-install-path.test.tspnpm test src/cli/daemon-cli/register-service-commands.test.tspnpm test src/commands/daemon-install-helpers.test.ts(moved block)pnpm test src/daemon/program-args.test.tspnpm test src/cli/daemon-cli/install-environment.test.tspnpm test src/commands/node-daemon-install-helpers.test.tsManagedNodeGatewayMigrationTestsGatewayLaunchAgentManagerTestsGatewayHostingChangeTestsGatewayHostingTestsGatewayProcessManagerTestshosting/restoration selectionNo new timers, sleeps, process boots, or worker pins. CI seconds will be added once the run exists. The Swift filters ran in an isolated checkout verified byte-identical to this branch, because this worktree lacks generated Mermaid resources for the native build.
Other gates:
node scripts/check-changed.mjs: exit 0 across the core, coreTests, apps, docs, and tooling lanes, including core and core-test typecheck, the line-cap and max-lines ratchets, and format.scripts/lint-swift.sh macos,scripts/format-swift.sh macos,pnpm native:i18n:verify,git diff --check: all pass.Size. Production is +173 lines: core +123, of which about +8 is the pure-move extraction's imports and exports, and Swift +50. Tests are +519. The growth is a new installer capability plus its single app owner. A round of compressing unrelated secret and host-env service code to reach LOC-neutral was deliberately reverted: that code is security-relevant, and implicit
...paramsspreads into the secret collectors would be harder to audit than the lines they save. The extraction is the sanctioned fix for the line-cap ratchet; it letsdaemon-install-helpers.tsdrop its grandfatheredmax-linessuppression and baseline entry.Codex review of the final tree against merge base
aad828fe5bb: scoped-clean, no actionable P0–P2 findings ("patch is correct").