Skip to content

fix(infra): verify managed update handoff startup - #103278

Merged
steipete merged 2 commits into
mainfrom
codex/fix-managed-update-handoff-ready
Jul 10, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/fix-managed-update-handoff-ready

Conversation

@steipete

@steipete steipete commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Supersedes #101524. GitHub rejected the contributor fork's far-behind full-tree update, so this replacement keeps the same focused patch on a maintainer branch with the original contributor credited as co-author.

What Problem This Solves

Managed-service updates could crash the live Gateway when the detached handoff process failed to spawn. The original mitigation consumed the asynchronous child-process error, but then incorrectly reported the handoff as started and allowed the Gateway to shut down without a running updater.

This also affected the Linux systemd path: Node starts systemd-run first, while the requested helper is executed only after the user manager accepts the transient scope.

Why This Change Was Made

The handoff helper now emits a small readiness marker after loading its private parameter file. The parent waits for that marker before reporting started, closes the readiness pipe, and then unreferences the detached helper. Direct spawn errors, systemd launcher exits, output errors, and readiness timeouts reject through the existing failed-handoff paths.

If startup fails, OpenClaw removes the complete temporary handoff directory so the helper script, parameters, and restart metadata do not remain on disk. RPC and automatic-update callers retain their existing error handling and no longer schedule Gateway shutdown after failure.

User Impact

Managed updates now fail visibly and leave the running Gateway intact when the updater cannot start. Successful launchd, systemd, and Windows handoffs retain detached behavior.

Evidence

  • Node contract: inspected Node v22.19.0, v24.0.0, and v24.x child-process source and current type declarations; failed spawns report an asynchronous error and successful process creation emits spawn first.
  • systemd contract: inspected current src/run/run.c; scope mode completes StartTransientUnit and its start job before replacing systemd-run with the requested command.
  • Original untrusted head: sanitized AWS Crabbox cbx_1089f9628131, run run_bdad6b34bb5a, passed 124 focused tests.
  • Repaired head: Testbox-through-Crabbox tbx_01kx4v4zx7ecf61amvq5yf9742 passed 131 focused Gateway/infra tests and the full check:changed gate.
  • Real direct failure: missing executable rejected with ENOENT; zero new handoff directories remained.
  • Real direct success: helper returned started with a numeric PID, removed all three sensitive inputs, and retained its normal log.
  • Real systemd success: actual systemd-run --user --scope reached helper readiness and left zero residual test directories.
  • Real systemd failure: an invalid user-bus endpoint made the real launcher exit; OpenClaw rejected before reporting started and left zero residual directories.
  • Real timeout failure: a process that loaded its parameter file but missed readiness for 30 seconds was terminated before rejection and left zero residual directories.
  • Behavior contract: direct failure, direct success, systemd success, systemd-manager failure, cleanup, and caller no-restart clauses all passed.
  • Fresh autoreview: no accepted/actionable findings.

Exact pushed-head CI passed for f3a13fc10869f7386baf173672694805eace2bdb in run 29065636575, including the required Windows coverage selected by the workflow.

Merge Risk

Low-to-moderate and bounded to managed update handoff startup. The readiness wait has a 30-second fail-closed bound; after success the only parent pipe is destroyed before the child is unreferenced. No config, protocol, dependency, or steady-state storage surface changes.

AI-assisted: maintainer repair and validation performed with Codex; contributor credit preserved.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: M maintainer Maintainer-authored PR labels Jul 10, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready proof for exact head f3a13fc10869f7386baf173672694805eace2bdb:

  • The helper now emits readiness only after loading its private parameter file. Direct spawn errors, systemd launcher exits, readiness-pipe errors, and the 30-second deadline reject before either caller schedules Gateway shutdown.
  • A timed-out or pipe-failed helper is terminated as a detached process tree before failure returns; the complete temporary handoff directory is removed.
  • Node v22.19.0, v24.0.0, and v24.x child-process source/types were checked for asynchronous error versus spawn ordering. Current systemd src/run/run.c was checked for scope-mode manager wait followed by execvpe of the requested helper.
  • Sanitized AWS Crabbox baseline: cbx_1089f9628131, run run_bdad6b34bb5a, 124 focused original-head tests passed.
  • Testbox-through-Crabbox: tbx_01kx4v4zx7ecf61amvq5yf9742, 131 focused tests passed (src/gateway/server-methods/update.test.ts, src/infra/update-managed-service-handoff.test.ts, src/infra/update-startup.test.ts).
  • The same Testbox passed the full changed gate: typechecks, lint, import-cycle and database/storage guards all green.
  • Real Linux probes passed for direct ENOENT, direct helper success, actual systemd-run --user --scope success, and an invalid user-manager failure. All failure probes left zero new handoff directories.
  • Real 30-second timeout probe loaded the parameter file, rejected, confirmed the detached child was dead, and left zero handoff directories.
  • Final exact-head autoreview: clean, no accepted/actionable findings (correct 0.93).
  • Exact-head CI passed: run 29065636575.
  • Repo-native review artifacts validate READY FOR /prepare-pr with zero findings; OPENCLAW_TESTBOX=1 scripts/pr prepare-run 103278 passed hosted gates and verified the remote tree equals the prepared tree.

Known proof gap: real launchd and Windows Task Scheduler service-manager E2E were not rerun. Their launch shape is unchanged; focused cross-platform tests and exact-head CI cover those branches, while the dependency-sensitive systemd path was exercised live.

@steipete
steipete merged commit a1e75e0 into main Jul 10, 2026
103 checks passed
@steipete
steipete deleted the codex/fix-managed-update-handoff-ready branch July 10, 2026 03:03
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 10, 2026
* fix(infra): verify managed update handoff startup

Co-authored-by: 丁宇婷0668001435 <[email protected]>

* fix(infra): terminate timed-out update handoff

---------

Co-authored-by: 丁宇婷0668001435 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant