Skip to content

fix(update): prevent Gateway respawn during package replacement - #103537

Merged
steipete merged 2 commits into
mainfrom
fix/quiesce-stopped-update-service
Aug 10, 2026
Merged

steipete merged 2 commits into
mainfrom
fix/quiesce-stopped-update-service

Conversation

@steipete

@steipete steipete commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Closes #103447

Related: #85133

What Problem This Solves

A managed update could replace package or checkout files while a loaded supervisor was between Gateway process instances. On macOS, a loaded enabled LaunchAgent uses KeepAlive; on Linux and Windows, the managed-update handoff records the same transition. The previous patch also risked restarting a persistently disabled LaunchAgent after a failed package replacement.

Why This Change Was Made

The launchd service owner now reads the authoritative persistent enabled state through launchctl print-disabled. The updater treats only loaded, enabled Darwin jobs as respawn-pending; a loaded but disabled job remains untouched, so generic failure recovery cannot revive it. Non-Darwin supervisors require the existing managed-update handoff marker. A definite foreign mutation root returns before any enabled-state probe or stop.

The rewrite builds on OwnedManagedUpdateContext and the existing service-control/recovery flow rather than introducing a second rollback owner. It deletes the stale PR's parallel signal, launcher-respawn, monolithic update, and exact-state snapshot machinery. The production surface is +64/-20 (net +44): the growth is required by the launchd service-control ownership boundary, which alone can authoritatively distinguish persistent operator disablement from a transient KeepAlive respawn window.

User Impact

Managed updates no longer race a respawned Gateway against package replacement, and failed updates do not enable or start a Gateway the operator persistently disabled. Ordinary stopped systemd units, ordinary stopped Scheduled Tasks, unloaded LaunchAgents, and services belonging to another mutation root remain untouched.

Evidence

  • Regression red proof: with the old Darwin predicate (loaded implies respawn-capable), the disabled-LaunchAgent failure test failed; the updater skipped the enabled-state probe and entered the stop/restart path.
  • Focused green proof: node scripts/run-vitest.mjs src/daemon/launchd.test.ts src/cli/update-cli.test.ts passed 159/159 daemon tests and 236/236 update CLI tests after the final rebase.
  • The regression holds service stop pending to prove mutation ordering, covers enabled and disabled Darwin jobs, explicit Linux/Windows handoffs, foreign-root isolation, print-disabled parsing/errors, and failed-update restart ordering.
  • node scripts/check-changed.mjs -- <five changed paths> passed all selected typecheck, lint, boundary, database-first, import-cycle, env-count, and guard checks on Testbox tbx_01kzmxdbsfktzk17yrq88gtdhx; Actions run https://github.com/openclaw/openclaw/actions/runs/31354316652.
  • Final full-branch Codex autoreview: clean, no accepted/actionable findings, confidence 0.96.
  • Production/test delta: production +64/-20 (net +44); tests +215/-1 (net +214).
  • ClawSweeper moves addressed: foreign-root isolation precedes quiescence; persistently disabled LaunchAgents are never stopped or restarted; focused disabled-and-loaded failure coverage is present; release-owned changelog and stale rollback paths remain removed.
  • No config, environment, protocol, public API, default, or schema changes.

@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes size: S maintainer Maintainer-authored PR gateway Gateway runtime size: M and removed size: S labels Jul 10, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 19704197e3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/daemon/launchd.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: eeaca4bfaa

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/cli/update-cli/update-command.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e28b9dfd5b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/cli/update-cli/update-command.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 08f8367270

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/cli/update-cli/update-command.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0c770f8be5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/daemon/launchd.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d14d7baae4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/cli/update-cli/update-command.ts Resolved
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. 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 Jul 10, 2026
@clawsweeper

clawsweeper Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed August 9, 2026, 6:55 PM ET / 22:55 UTC.

ClawSweeper review

What this changes

The PR makes managed package updates quiesce a loaded Gateway that may be between supervisor respawns before replacing its installation files.

Merge readiness

⛔ Blocked by patch quality or review findings - 5 items remain

Keep open: the patch reintroduces an operator-disabled macOS LaunchAgent after a package-update failure. The pre-mutation quiescence fix is useful, but failure recovery must preserve the prior disabled state.

Priority: P1
Reviewed head: 05ab5145dd4b02441879e3d8cddd75eeb70a84eb

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The proposed repair has a concrete P1 recovery regression despite focused test coverage.
Proof confidence 🌊 off-meta tidepool Not applicable: This is maintainer-authored work, so the external-contributor proof gate does not apply; its claimed focused test evidence was not executed in this read-only review.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This is maintainer-authored work, so the external-contributor proof gate does not apply; its claimed focused test evidence was not executed in this read-only review.
Evidence reviewed 5 items PR enters recovery for stopped loaded LaunchAgents: The new predicate sends every loaded stopped Darwin service through stop/recovery; the added test expects a restart when package replacement fails.
Generic recovery restarts stopped services: A failed mutable update calls the generic service restart whenever the pre-update step reported stopped.
Launchd restart explicitly clears disabled state: The native restart adapter documents restart as explicit operator intent and runs launchctl enable before starting the LaunchAgent.
Findings 1 actionable finding [P1] Preserve an operator-disabled LaunchAgent on update failure
Security None None.

How this fits together

The updater inspects the installed Gateway service before mutating package files, then uses the platform service adapter for stop and recovery. It must distinguish a supervisor respawn window from an operator’s intentionally disabled service.

flowchart LR
  A[Managed update] --> B[Inspect Gateway service]
  B --> C{Respawn may occur}
  C -->|yes| D[Verify installation ownership]
  D --> E[Quiesce service]
  E --> F[Replace package]
  F --> G[Recover prior service state]
  C -->|no| F
Loading

Before merge

  • Preserve an operator-disabled LaunchAgent on update failure (P1) - A loaded LaunchAgent stopped with persistent disable is not running, so this new predicate enters the stop path and records stopped. If package replacement then fails, generic recovery calls restartLaunchAgent, which explicitly invokes launchctl enable and starts it. Carry the prior disabled state through recovery instead of reviving an operator-disabled Gateway.
  • Resolve merge risk (P1) - A failed package replacement can enable and start a Gateway that the operator had persistently disabled before the update.
  • Complete next step (P2) - A narrow source-proven recovery-state repair remains on this PR branch.
  • Improve patch quality - Restore the original launchd disabled state after failed update recovery.
  • Improve patch quality - Add a focused disabled-and-loaded LaunchAgent regression covering the update failure path.

Findings

  • [P1] Preserve an operator-disabled LaunchAgent on update failure — src/cli/update-cli/update-command-service.ts:472
Agent review details

Security

None.

PR surface

Source +5, Tests +131. Total +136 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 7 2 +5
Tests 1 131 0 +131
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 138 2 +136

Review metrics

Metric Value Why it matters
Production versus regression coverage production +7/-2; tests +131/-0 The narrow production change has substantial regression coverage, but the new coverage currently asserts the incorrect restart behavior for the disabled-state case.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #103447
Summary: This PR is the candidate repair for the linked package-mutation race, but its update-failure recovery still needs correction.

Members:

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

Merge-risk options

Maintainer options:

  1. Preserve disabled launchd state (recommended)
    Repair failed-update recovery so it restores an operator-disabled loaded LaunchAgent rather than invoking the explicit-start restart path.

Technical review

Best possible solution:

Make the launchd service owner capture and restore the exact prior disabled/loaded/running state for update recovery, while keeping the new owned respawn quiescence before mutation.

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

Yes. Current source shows the new stopped-loaded Darwin branch reaching generic failed-update recovery, whose launchd restart explicitly enables the service.

Is this the best way to solve the issue?

No. The update flow needs owner-provided restoration of the original disabled state; generic restart is intentionally an explicit start operation.

Full review comments:

  • [P1] Preserve an operator-disabled LaunchAgent on update failure — src/cli/update-cli/update-command-service.ts:472
    A loaded LaunchAgent stopped with persistent disable is not running, so this new predicate enters the stop path and records stopped. If package replacement then fails, generic recovery calls restartLaunchAgent, which explicitly invokes launchctl enable and starts it. Carry the prior disabled state through recovery instead of reviving an operator-disabled Gateway.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 810b99432c21.

Labels

Label changes:

  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🌊 off-meta tidepool and patch quality is 🦪 silver shellfish.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🦪 silver shellfish, so this older rating label is no longer current.

Label justifications:

  • P1: The patch can revive an operator-disabled Gateway after an otherwise failed update.
  • merge-risk: 🚨 compatibility: The changed lifecycle path overrides an existing persisted launchd disabled setting.
  • merge-risk: 🚨 availability: An unintended restart can alter Gateway availability and operator-controlled service state.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🌊 off-meta tidepool and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This is maintainer-authored work, so the external-contributor proof gate does not apply; its claimed focused test evidence was not executed in this read-only review.

Evidence

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs src/cli/update-cli.test.ts.
  • [P1] node scripts/run-vitest.mjs src/daemon/launchd.test.ts.
  • [P1] git diff --check.

What I checked:

  • PR enters recovery for stopped loaded LaunchAgents: The new predicate sends every loaded stopped Darwin service through stop/recovery; the added test expects a restart when package replacement fails. (src/cli/update-cli/update-command-service.ts:472, 05ab5145dd4b)
  • Generic recovery restarts stopped services: A failed mutable update calls the generic service restart whenever the pre-update step reported stopped. (src/cli/update-cli/update-command-execution.ts:270, 810b99432c21)
  • Launchd restart explicitly clears disabled state: The native restart adapter documents restart as explicit operator intent and runs launchctl enable before starting the LaunchAgent. (src/daemon/launchd.ts:1891, 810b99432c21)
  • Current-head provenance: The proposed head is not contained by the checked-out current main, so its repair is not already implemented there. (05ab5145dd4b)
  • Autoreview gate: The requested structured autoreview could not run because TruffleHog is unavailable; no code or test command was run in this read-only review. (05ab5145dd4b)

Likely related people:

  • steipete: The PR head and current-main blame of the reviewed updater path associate this contributor with the relevant service-control code. (role: current updater-path contributor; confidence: medium; commits: 05ab5145dd4b, 05cd389cac01; files: src/cli/update-cli/update-command-service.ts)
  • fuller-stack-dev: Merged related work on launchd update timing and recovery touches the native service owner adjacent to this failure path. (role: adjacent launchd updater contributor; confidence: medium; commits: ae27d7936447; files: src/daemon/launchd.ts)

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 (5 earlier review cycles)
  • reviewed 2026-07-10T11:24:21.351Z sha d14d7ba :: needs real behavior proof before merge. :: [P1] Restore launchd state on signal exits
  • reviewed 2026-07-10T13:39:16.121Z sha f1c644e :: needs real behavior proof before merge. :: [P3] Remove the release-owned changelog entry
  • reviewed 2026-07-31T04:19:56.547Z sha f1c644e :: needs real behavior proof before merge. :: [P2] Enable disabled jobs before rollback bootstrap
  • reviewed 2026-08-03T20:26:53.192Z sha f1c644e :: needs real behavior proof before merge. :: [P2] Enable disabled jobs before rollback bootstrap | [P3] Remove the release-owned changelog entry
  • reviewed 2026-08-09T19:44:55.448Z sha ed6f04369eda037b384bdcf5a4ca6c724cd89c9c :: found issues before merge. :: [P1] Preserve foreign mutation-root isolation before quiescing | [P1] Do not restart an operator-disabled LaunchAgent

@steipete steipete self-assigned this Jul 10, 2026
@steipete
steipete force-pushed the fix/quiesce-stopped-update-service branch from d14d7ba to f1c644e Compare July 10, 2026 13:06
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Exact head: f1c644e. The signal-exit blocker is fixed and its thread has exact-head Testbox/autoreview evidence. Final macOS and Windows live package proofs remain in progress; please re-review the code and deterministic evidence now.

@clawsweeper

clawsweeper Bot commented Jul 10, 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 repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f1c644e062

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/daemon/launchd.ts Outdated
Comment on lines +978 to +980
let canRestoreLoadedState = params.snapshot.disabled;
if (!params.snapshot.disabled) {
const enable = await execLaunchctl(["enable", params.serviceTarget]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Enable disabled LaunchAgents before rollback bootstrap

When the pre-update snapshot was loaded and disabled, this branch treats the job as ready to restore while skipping the temporary launchctl enable, so the later rollback attempts to bootstrap a still-disabled service. The launchctl enable|disable contract says a disabled service cannot be loaded until it is enabled; in the openclaw gateway stop --disable case that can leave a loaded/stopped disabled job, a failed update after quiescence will report rollback failure and leave the job booted out/disabled instead of restoring the prior loaded state. Fresh evidence beyond the earlier disabled-LaunchAgent threads is that the current exact-state rollback still skips the enable step specifically on the snapshot.disabled path.

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Jul 10, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 9, 2026
@steipete
steipete force-pushed the fix/quiesce-stopped-update-service branch from ed6f043 to 05ab514 Compare August 9, 2026 22:24
@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 Aug 9, 2026
@steipete
steipete force-pushed the fix/quiesce-stopped-update-service branch from 05ab514 to 314dc89 Compare August 10, 2026 04:12
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: M and removed size: S labels Aug 10, 2026
@steipete
steipete merged commit 7713e8f into main Aug 10, 2026
133 checks passed
@steipete
steipete deleted the fix/quiesce-stopped-update-service branch August 10, 2026 04:23
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes gateway Gateway runtime maintainer Maintainer-authored PR 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. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Background auto-update can mutate package while launchd gateway is running

1 participant