Skip to content

fix: restore managed Gateway after update stop failure - #136285

Merged
steipete merged 3 commits into
openclaw:mainfrom
Schimuneck:fix/update-channel-persist-early
Sep 7, 2026
Merged

steipete merged 3 commits into
openclaw:mainfrom
Schimuneck:fix/update-channel-persist-early

Conversation

@Schimuneck

@Schimuneck Schimuneck commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where a managed Gateway can remain unloaded after openclaw update fails while stopping the service. On macOS, launchctl bootout can succeed before the subsequent busy-port check fails. The updater then loses the stop record and classifies the exception as an unsafe update mutation, so recovery cannot restore the original service.

Related: #127869.

Why This Change Was Made

The native service owner already reports lifecycle mutations. The updater now retains the stop record at that callback, before a later stop error can discard it, and classifies the failure before core activation. Recovery still verifies the original installation and revalidates current service ownership before restarting. A failed inspection or refused native stop produces no stopped-service claim.

The final change preserves the success-only channel-persistence contract documented in both current main and shipped versions 2026.8.1 and 2026.9.2. Failed core updates keep the prior channel. The release-channel guide now states that timing explicitly. The earlier catch-all stop-error wrapper and constructor-only tests were replaced by the native mutation callback and an update-level regression.

User Impact

An update that unloads its managed service and then fails before core activation can attempt verified recovery of the original Gateway. A stop failure before a lifecycle mutation does not trigger a restart. Requested update-channel changes remain persisted only after core update success.

Both contributor commits by @Schimuneck are preserved through rebase, followed by a maintainer repair commit.

Evidence

Baseline: 6aa09cbadb594c3d46d5bd49a28c514df1b256b0. Candidate: 53f09a1af257e8fbf8357317faa73779bf1cfa42.

  • The new update-level regression fails on baseline main for the intended reasons: a stop error is classified as update-failed with unsafe recovery, and a recorded bootout never starts recovery. It covers both errors before mutation and errors after mutation, verifies the original package remains installed, and asserts no channel write.
  • Three existing baseline tests pass: persist the requested channel only after package success; do not persist it after package failure; preserve the ancestry-preflight refusal without side effects.
  • Independent Codex P2 autoreview is scoped-clean for the final staged candidate. git diff --check and documentation discovery passed.
  • Exact-head CI: https://github.com/openclaw/openclaw/actions/runs/34149023208 — green on the exact candidate: 167 successful checks, 50 skipped, and 1 neutral; no pending or failed checks.
  • Isolated Linux proof (Node 24.19.0, pnpm 12.3.4) on the exact candidate succeeded: pnpm check:changed --base 6aa09cbadb594c3d46d5bd49a28c514df1b256b0 --head 53f09a1af257e8fbf8357317faa73779bf1cfa42, followed by the seven focused suites below and git diff --check. 852 tests passed, 25 platform-dependent tests skipped, including both new stop-boundary cases. The test wrapper also built the runtime for the process suites. The complete proof command exited successfully.
pnpm test src/cli/update-cli.test.ts \
  src/cli/update-cli/update-command.test.ts \
  src/cli/update-cli/update-command-service-maintenance.test.ts \
  src/cli/update-cli/update-command-service.integration.test.ts \
  src/cli/update-cli/update-command-post-update-recovery.test.ts \
  src/cli/update-cli/update-command-lease.test.ts \
  src/daemon/launchd.test.ts

Native macOS LaunchAgent execution remains a proof gap. Source inspection confirms bootout → native mutation callback → port validation, and existing launchd unit tests cover a busy port after recorded bootout. Linux process tests and mocked launchctl tests do not establish live macOS service behavior. No operator Gateway was stopped or restarted.

The earlier CI run's CLI failures were related to the removed early channel writes and catch-all error wrapping. Its protocol lane passed 210 tests and its guard lane completed checks before both failed on GitHub HTTPS authentication during cleanup; those infrastructure failures were unrelated to this patch.

@clawsweeper

clawsweeper Bot commented Sep 2, 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 cli CLI command changes size: S labels Sep 2, 2026
@Schimuneck
Schimuneck marked this pull request as ready for review September 2, 2026 12:06
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 2, 2026
@clawsweeper

clawsweeper Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed September 7, 2026, 2:13 PM ET / 18:13 UTC.

ClawSweeper review

What this changes

The PR preserves observed Gateway service-stop state so failed updates can attempt recovery, classifies pre-activation stop failures, and clarifies when channel changes persist.

Merge readiness

⛔ Blocked before merge - 2 items remain

The repair remains necessary on current main, and no blocking code defect was found. Earlier stop-state and channel-persistence concerns are resolved; native failed-stop recovery proof remains the merge blocker.

Priority: P1
Reviewed head: 53f09a1af257e8fbf8357317faa73779bf1cfa42

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The patch is focused and addresses earlier correctness concerns, but proof of the changed native recovery behavior remains outstanding.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: The changed update-to-service recovery path has focused regression coverage, but its stop callback and launchctl boundary are mocked. The captured body explicitly lacks an after-fix macOS run showing unload, subsequent stop failure, and verified original-Gateway recovery; Linux process-suite success does not establish that scenario. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The changed update-to-service recovery path has focused regression coverage, but its stop callback and launchctl boundary are mocked. The captured body explicitly lacks an after-fix macOS run showing unload, subsequent stop failure, and verified original-Gateway recovery; Linux process-suite success does not establish that scenario. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 9 items Current main still needs the repair: Fetched main calls service.stop without retaining its mutation callback and wraps a stop rejection in a generic Error, leaving the original failure mechanism intact.
Introduced repair: The pinned introduced diff records stop state through onStopped and classifies the exception before core activation; it introduces no early channel write.
Native failure mechanism: The default LaunchAgent stop reports bootout before checking port release, so a later busy-port error can follow a completed unload.
Findings None None.
Security None None.

How this fits together

The update CLI stages and validates an installation before stopping its managed Gateway service. If stopping fails after unloading the service, recovery verifies the original runtime and current service ownership before restarting it.

flowchart TD
  A[Update request] --> B[Validate candidate]
  B --> C[Stop managed Gateway]
  C --> D[Record observed service mutation]
  D --> E{Stop succeeds?}
  E -->|Yes| F[Activate update]
  E -->|No| G[Verify original runtime and ownership]
  G --> H[Restart and check readiness]
Loading

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The changed update-to-service recovery path has focused regression coverage, but its stop callback and launchctl boundary are mocked. The captured body explicitly lacks an after-fix macOS run showing unload, subsequent stop failure, and verified original-Gateway recovery; Linux process-suite success does not establish that scenario. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Complete next step (P2) - Add after-fix native macOS failed-stop recovery evidence before merge. Terminal output, logs, or a recording should show original Gateway readiness and the prior channel retained; redact credentials, private endpoints, IP addresses, and personal details. Update the PR body to trigger re-review; if it does not, ask a maintainer to comment @clawsweeper re-review.
Agent review details

Security

None.

PR surface

Source +9, Tests +30, Docs +3. Total +42 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 3 13 4 +9
Tests 1 30 0 +30
Docs 2 6 3 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 49 7 +42

Review metrics

None.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #127869
Summary: This PR is a candidate fix for the linked report's failed-stop service-recovery defect.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Technical review

Best possible solution:

A failed pre-activation stop should restore the verified original Gateway when ownership still matches, preserve the prior channel, and report the observed recovery outcome.

Do we have a high-confidence way to reproduce the issue?

Yes, source establishes the failure path: successful LaunchAgent bootout followed by a busy-port rejection loses the stop record on current main. Native reproduction was not executed during this read-only review.

Is this the best way to solve the issue?

Yes, retaining the native mutation observation and reusing verified recovery is a focused repair that preserves existing channel semantics; runtime confirmation remains outstanding.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against fae6778b125c.

Labels

Label justifications:

  • P1: A failed managed update can leave the Gateway unloaded and interrupt all connected channels.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The changed update-to-service recovery path has focused regression coverage, but its stop callback and launchctl boundary are mocked. The captured body explicitly lacks an after-fix macOS run showing unload, subsequent stop failure, and verified original-Gateway recovery; Linux process-suite success does not establish that scenario. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

  • Current main still needs the repair: Fetched main calls service.stop without retaining its mutation callback and wraps a stop rejection in a generic Error, leaving the original failure mechanism intact. (src/cli/update-cli/update-command-execution.ts:260, fae6778b125c)
  • Introduced repair: The pinned introduced diff records stop state through onStopped and classifies the exception before core activation; it introduces no early channel write. (src/cli/update-cli/update-command-execution.ts:209, 53f09a1af257)
  • Native failure mechanism: The default LaunchAgent stop reports bootout before checking port release, so a later busy-port error can follow a completed unload. (src/daemon/launchd-stop.ts:114, 53f09a1af257)
  • Recovery safeguards remain intact: Recovery requires an observed stop and verified runtime, rereads service ownership before activation, preserves the definition, and checks running-service health afterward. The callback records lifecycle state rather than replacing these authorization checks. (src/cli/update-cli/update-command-service-recovery.ts:172, 53f09a1af257)
  • Focused regression and proof limits: The new update-level cases distinguish rejection before mutation from rejection after bootout, assert restart selection, retain the original package, and prohibit channel writes. Their service stop is mocked; the existing service integration suite also mocks launchctl. (src/cli/update-cli.test.ts:8089, 53f09a1af257)
  • Captured discussion and re-review continuity: The supplied body for the pinned candidate reports 852 passing tests and 25 platform skips, explicitly acknowledges the native macOS proof gap, and now describes mutation-aware recovery and success-only channel persistence. This satisfies the previous description rank-up, but not the prior native recovery proof request. No scripts from the body were executed. (53f09a1af257)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

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

  • Add redacted after-fix terminal output or logs showing native failed-stop recovery, original Gateway readiness, and the unchanged update channel.

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.

History

Review history (4 earlier review cycles)
  • reviewed 2026-09-02T12:16:21.083Z sha f304d63dfa2942b37f71261f6019e31ba87a078f :: needs real behavior proof before merge. :: [P1] Retain the stop state before classifying its rejection as recoverable | [P1] Do not persist a channel before downgrade consent
  • reviewed 2026-09-02T12:25:35.723Z sha f304d63dfa2942b37f71261f6019e31ba87a078f :: needs real behavior proof before merge. :: [P1] Preserve the stopped service state on a stop error | [P1] Delay channel persistence until downgrade consent
  • reviewed 2026-09-02T16:32:14.405Z sha d3dcdc73e5266b527e7116ec649bb5ad3690212b :: needs real behavior proof before merge. :: [P1] Persist the channel before an initial schema refusal | [P1] Record an observed stop instead of stamping every error stopped
  • reviewed 2026-09-07T17:53:26.643Z sha 53f09a1 :: needs real behavior proof before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Sep 2, 2026
@Schimuneck

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Sep 2, 2026
Schimuneck and others added 3 commits September 7, 2026 10:40
…lures

Persist the requested update channel immediately after config validation,
before schema preflight or service-stop attempts. Previously the channel
was only saved in the finalize step, so any early failure (schema mismatch,
stop timeout, etc.) silently discarded the operator's intent.

Reclassify the managed-service stop failure in executeMutableUpdate as
UpdatePreMutationError so the outer handler can safely recover the original
runtime and re-enable the LaunchAgent instead of treating the untouched
checkout as a failed mutation.

Closes openclaw#127869

Co-authored-by: Cursor <[email protected]>
…top state through error boundary

Address ClawSweeper P1 findings:

1. Channel persistence moved from before target resolution to after the
   downgrade consent gate. A refused downgrade no longer changes
   update.channel — preserving the existing no-side-effect contract
   tested at update-cli.test.ts:3255.

2. ManagedServiceStopFailure carries the inspected pre-stop state
   through the error boundary so recovery can restart a LaunchAgent
   that was bootout'd before the error. The caller extracts
   inspectedState and populates preManagedServiceStop before throwing
   UpdatePreMutationError, enabling maybeRestartServiceAfterFailedMutableUpdate
   to find the stopped-service record it requires.

Co-authored-by: Cursor <[email protected]>
Retain native stop state before post-stop validation can fail, and classify failure before core activation so verified original-runtime recovery can run. Preserve success-only channel persistence documented by shipped releases. Replace constructor-only tests with update-level mutation boundary regressions.\n\nRelated: openclaw#127869 and openclaw#136285.
@steipete
steipete force-pushed the fix/update-channel-persist-early branch from d3dcdc7 to 53f09a1 Compare September 7, 2026 17:47
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: XS and removed size: S labels Sep 7, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Sep 7, 2026
@steipete steipete changed the title fix: persist update channel before mutable work and classify stop failures fix: restore managed Gateway after update stop failure Sep 7, 2026
@steipete
steipete merged commit ad682b4 into openclaw:main Sep 7, 2026
224 checks passed
@steipete

steipete commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 8, 2026
* fix: persist update channel before mutable work and classify stop failures

Persist the requested update channel immediately after config validation,
before schema preflight or service-stop attempts. Previously the channel
was only saved in the finalize step, so any early failure (schema mismatch,
stop timeout, etc.) silently discarded the operator's intent.

Reclassify the managed-service stop failure in executeMutableUpdate as
UpdatePreMutationError so the outer handler can safely recover the original
runtime and re-enable the LaunchAgent instead of treating the untouched
checkout as a failed mutation.

Closes openclaw#127869

Co-authored-by: Cursor <[email protected]>

* fix: delay channel persistence until after downgrade consent, carry stop state through error boundary

Address ClawSweeper P1 findings:

1. Channel persistence moved from before target resolution to after the
   downgrade consent gate. A refused downgrade no longer changes
   update.channel — preserving the existing no-side-effect contract
   tested at update-cli.test.ts:3255.

2. ManagedServiceStopFailure carries the inspected pre-stop state
   through the error boundary so recovery can restart a LaunchAgent
   that was bootout'd before the error. The caller extracts
   inspectedState and populates preManagedServiceStop before throwing
   UpdatePreMutationError, enabling maybeRestartServiceAfterFailedMutableUpdate
   to find the stopped-service record it requires.

Co-authored-by: Cursor <[email protected]>

* fix: recover updates after an observed service stop

Retain native stop state before post-stop validation can fail, and classify failure before core activation so verified original-runtime recovery can run. Preserve success-only channel persistence documented by shipped releases. Replace constructor-only tests with update-level mutation boundary regressions.\n\nRelated: openclaw#127869 and openclaw#136285.

---------

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

Labels

cli CLI command changes docs Improvements or additions to documentation P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants