feat(service): recover active work and reap restarted gateways - #60
Open
hannesrudolph wants to merge 7 commits into
Open
feat(service): recover active work and reap restarted gateways#60hannesrudolph wants to merge 7 commits into
hannesrudolph wants to merge 7 commits into
Conversation
hannesrudolph
marked this pull request as ready for review
July 27, 2026 21:26
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ocm service restart <env>restart immediately through OpenClaw's protocol-v1 recovery handoff so eligible interrupted work resumes after startup--forcerequirement--forceas an explicit emergency bypass when a gateway advertises recovery support but cannot accept the handoffWhy
The previous service restart path asked the supervisor to replace the child directly. An active agent turn could therefore be terminated mid-response and would only continue after another user message.
OpenClaw restart-handoff protocol v1 can record eligible interrupted work before an externally supervised restart and automatically continue it after startup. OCM now uses that negotiated path by default without delaying gateway development until active work finishes.
Supervisor state is also rebuilt by lifecycle commands outside the target gateway. Caller-only differences such as
PATH, package-manager environment, proxy/CA settings, or choosing the same installed OpenClaw entrypoint directly versus through OCM's managed Node fallback must not be interpreted as gateway configuration changes. OCM now preserves the persisted child specification for those equivalent cases while still applying meaningful binding, runtime, port, argument, path, and OpenClaw environment changes.Finally, a gateway child could exit after
try_wait()returnedNonebut before the process-group existence probe. The stop path then returned without a finalwait(), leaving the process-group leader as a zombie. OpenClaw's single-instance check could treat that defunct PID as the active gateway owner even though no process was listening, causing an endless supervised startup loop. All stop paths now converge on an unconditional wait for the leader after process-group cleanup.Existing users with older or wrapper-backed bindings keep the restart behavior they already have. They receive a warning that in-flight work may have been interrupted, but they do not need to add
--forcemerely to preserve compatibility.Behavior
--forceremains available as the explicit emergency bypass.openclaw.mjsand managed-Node launch forms.--force: directly replace the supervised child and report that the OpenClaw recovery handoff was bypassed.Upgrade transactions continue to request the existing synchronous forced restart explicitly in this PR. Recovery-aware upgrade orchestration remains a separate follow-up.
Validation
cargo fmt --checkgit diff --checkcargo test --test service_command_tests— 36 passedcargo test --test daemon_runtime_tests— 20 passedcargo clippy --all-targetscompleted with the same three baseline allowancesLive integration
Recovery-aware restart was tested with a disposable OCM environment bound to OpenClaw
2026.7.2-beta.3during a real 30-second tool turn:OCM_IMMEDIATE_RECOVERY_OKSupervisor reconciliation was tested against the live mixed-version setup:
PATHvalues and both direct and managed-Node launch resolutionThe child-reaping repair was then exercised against an intentionally failing temporary gateway:
58301exited with code 1