Skip to content

fix(updater): harden launchd replacement timing - #117030

Merged
fuller-stack-dev merged 5 commits into
openclaw:mainfrom
fuller-stack-dev:codex/live-updater-timing-hardening
Jul 31, 2026
Merged

fuller-stack-dev merged 5 commits into
openclaw:mainfrom
fuller-stack-dev:codex/live-updater-timing-hardening

Conversation

@fuller-stack-dev

@fuller-stack-dev fuller-stack-dev commented Jul 31, 2026 •

Copy link
Copy Markdown
Member

Summary

  • derive the native Gateway stopped-proof window from the managed LaunchAgent ExitTimeOut, with a bounded teardown margin and lower-frequency polling
  • fully generate, rewrite, lint, reparse, and validate the replacement plist before bootout, then atomically publish it only after native process/listener stopped proof
  • reject an existing system LaunchDaemon owner before downtime and recheck ownership around plist publication and activation
  • make replacement publication reversible and recover the old deployment if build, install, bootstrap, readiness, audit, or runtime verification fails after bootout
  • emit structured restart timing for bootout, process exit/start, listener, healthz, readyz, deep RPC, Discord, Telegram, total outage, and cold start
  • capture OPENCLAW_GATEWAY_STARTUP_TRACE=1 for only the replacement bootstrap without leaving permanent launchd environment state

Root cause

Wilfred's July 31 update had a managed plist with ExitTimeOut=20, while the updater allowed only 100 x 100ms (10 seconds) for native stopped proof. The Gateway closed its listener and logged clean shutdown in about 210ms, but launchd/process teardown exceeded 8-10 seconds, so the updater failed before launchd's own stop ceiling.

The old updater also crossed the downtime boundary before all replacement validation was complete and did not restore the original plist/deployment after a post-bootout failure. The canonical owner is the updater's launchd replacement transaction: preflight all fallible local work, prove the old native service stopped, atomically publish, and recover the previous deployment on failure.

Behavior

  • missing or malformed finite ExitTimeOut values use the canonical 20-second default
  • ExitTimeOut=0 and values above 300 seconds fail preflight rather than creating an unbounded maintenance wait
  • stopped proof observes process exit and listener closure independently and records both milestones
  • replacement plist preparation completes before downtime; install uses same-filesystem rename after stopped proof and refuses to overwrite a plist changed concurrently
  • system LaunchDaemon ownership is checked before downtime, immediately around publication, and before activation; an ownership race after rename restores the original plist
  • any post-bootout failure stops a partial replacement, restores the original plist, bootstraps the prior deployment, and proves /readyz before returning the primary error
  • startup tracing is armed only for the replacement process and restored immediately after replacement PID observation
  • disconnected or unconfigured channel records do not fail readiness, while connected Discord/Telegram milestones are recorded when present

Native before/after benchmark

This benchmark used disposable, uniquely labeled macOS LaunchAgents with ExitTimeOut=20, real launchctl bootstrap/bootout/print, real TCP listeners, and lsof observation. The synthetic Gateway closed its listener about 202-203 ms after SIGTERM; process teardown was configured independently. Every profile ran both normally and under nice -n 15.

Slow teardown: 15 seconds

Profile Baseline Repaired Proof attempts Replacement outage Cold start
normal 0/5 updates completed 5/5 completed 100 -> 55 avg 15,568 ms avg 644 ms avg
low priority 0/5 updates completed 5/5 completed 100 -> 54.8 avg 15,631 ms avg 626 ms avg

The baseline failed all 10 trials at its fixed proof ceiling after about 12.89 seconds and never started the replacement. The repaired flow completed all 10 trials, observing process exit at about 15.0 seconds. This is a reliability improvement, not a claim that launchd itself shuts down faster; proof polling work fell by about 45%.

Fast teardown: 250 ms

Profile Baseline Repaired Proof time delta Replacement outage delta
normal 3/3 completed 3/3 completed +16.3 ms avg +21 ms avg
low priority 3/3 completed 3/3 completed +21.3 ms avg +93 ms avg

The fast-path control stayed successful in all 12 trials. The repaired proof used two polling attempts instead of three; observed overhead remained small relative to the correctness window.

Raw evidence:

  • unlisted benchmark bundle with harness, exact-head notes, and all 32 JSONL trial records: https://gist.github.com/fuller-stack-dev/75b61f0d895d3d0ccbd193d0cc0346cf
  • 32 unique disposable LaunchAgent labels; no labels, processes, listeners, or temporary roots remained
  • live ai.openclaw.gateway PID, listener, and plist SHA-256 were identical before and after the run
  • harness SHA-256: ced944926dbddc6ef5adfd24408e98967955f46b28b3fc7e31e28716505a1963
  • slow JSONL SHA-256: 508062e323aee08847bfab10f22e87db25a8cdd0a45323ca98e3732093cd1119
  • fast JSONL SHA-256: 12f17d3a441956f2d79c4ec594172062d61a3fba3d6fc6f4c43d8b044802b926
  • source-blind behavior validation passed all seven contract clauses, including timing completeness and host cleanup

Validation

Exact proposed head: eac016a572cc37619d6fd7f0d17336f10bd39c93

The computational remote proof ran through Blacksmith Testbox. The native launchd benchmark ran on an isolated local macOS host because the direct brokered AWS macOS Crabbox route lacked an active Crabbox broker access login. It is native macOS launchd proof, not a simulated process-only test.

Duplicate search

Live GitHub PR and issue searches immediately before this update found no open work directly covering update-main.mjs launchd stopped-proof timing, reversible plist publication, or post-bootout recovery.

Notes

  • no changelog entry: this is internal fleet updater hardening
  • maintainer accepted the bounded maintenance window and test-backed rollback evidence boundary for landing

@openclaw-barnacle openclaw-barnacle Bot added size: L maintainer Maintainer-authored PR labels Jul 31, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jul 31, 2026
@clawsweeper

clawsweeper Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 31, 2026, 5:52 PM ET / 21:52 UTC.

ClawSweeper review

What this changes

The PR hardens the macOS live updater by deriving Gateway shutdown proof from the LaunchAgent timeout, atomically replacing the plist, restoring the prior deployment after failure, and recording restart milestones.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

Keep this PR open. Current main still has the fixed 10-second native stopped-proof loop, while this branch adds the needed launchd-aware replacement and rollback transaction; no discrete patch defect was established in direct source review. It is maintainer-labeled and authored by a repository member, so it needs the normal exact-head CI completion and explicit maintainer merge decision rather than automated cleanup.

Priority: P1
Reviewed head: eac016a572cc37619d6fd7f0d17336f10bd39c93
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch has a coherent owner-boundary repair and focused coverage; it is ready for a normal maintainer decision once final exact-head CI completes.
Proof confidence 🌊 off-meta tidepool Not applicable: This member-authored PR is not subject to the external-contributor proof gate; its PR body nevertheless provides native macOS launchd benchmark evidence and exact-head Testbox results for maintainer review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This member-authored PR is not subject to the external-contributor proof gate; its PR body nevertheless provides native macOS launchd benchmark evidence and exact-head Testbox results for maintainer review.
Evidence reviewed 5 items Current-main behavior remains vulnerable: Current main still uses 100 stopped-proof attempts with a 100 ms delay, yielding a fixed 10-second window before the updater gives up on a native Gateway teardown.
Transaction repair is covered by focused regression cases: The final branch adds focused cases for bounded ExitTimeOut handling, slow teardown beyond the old window, system LaunchDaemon conflicts, readiness milestones, and restoration of the prior LaunchAgent after a failed replacement.
Final branch integrates adjacent updater repair: The merge commit for the related managed health-probe fix is an ancestor of the final PR head, so the final updater includes that separate correction without making it the canonical fix for this timing issue.
Findings None None.
Security None None.

How this fits together

The live updater maintains a macOS LaunchAgent that runs the Gateway. During an update it prepares a replacement, stops the old service, publishes the new plist, bootstraps the Gateway, and verifies readiness before scheduled maintenance continues.

flowchart LR
  A[Managed Gateway LaunchAgent] --> B[Updater preflight]
  B --> C[Stop old launchd service]
  C --> D[Publish replacement plist]
  D --> E[Bootstrap new Gateway]
  E --> F[Readiness and channel checks]
  F --> G[Update result and timing log]
Loading

Decision needed

Question Recommendation
Should this PR land after final exact-head CI, accepting a bounded maintenance window of the managed LaunchAgent ExitTimeOut plus 15 seconds in exchange for avoiding premature replacement failure and preserving rollback? Land after exact-head CI: Accept the bounded stop-proof and rollback evidence documented in the PR, then merge when the final head’s required checks are successful.

Why: The implementation changes the operator-visible recovery envelope for a managed Gateway update. The PR comments record a proposed evidence boundary, but the maintainer label and member authorship require a human merge judgment.

Before merge

  • Resolve merge risk (P0) - This patch changes the managed Gateway’s outage and recovery sequence; the final exact head still has required CI in progress, so merge should wait for those checks to complete.
  • Resolve merge risk (P0) - The bounded stopped-proof window intentionally permits a longer maintenance outage when a configured LaunchAgent needs its full ExitTimeOut; the contributor’s comments record acceptance, but the protected maintainer item still needs the explicit merge decision.
  • Resolve merge risk (P1) - The repository’s structured autoreview helper could not run because this environment lacks TruffleHog; no source-backed correctness finding resulted from direct review.
Agent review details

Security

None.

PR surface

Tests +559, Other +738. Total +1297 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 2 563 4 +559
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 822 84 +738
Total 3 1385 88 +1297

Review metrics

None.

Root-cause cluster

Relationship: canonical
Canonical: #117030
Summary: This PR is the canonical remaining work for launchd stopped-proof timing and reversible replacement. The related merged updater PR repaired a separate health-probe regression and is incorporated into this branch.

Members:

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

Merge-risk options

Maintainer options:

  1. Complete final-head validation (recommended)
    Merge only after the exact final head has green required checks, preserving the tested rollback and bounded stopped-proof behavior.
  2. Request an additional native failure transcript
    If the maintainer wants stronger operational evidence, require a disposable macOS launchd rollback transcript before landing.

Technical review

Best possible solution:

Land the final exact head after required CI is green, retaining the bounded launchd stop window and the rollback-to-prior-deployment behavior tested by the focused suite and demonstrated by the PR’s native benchmark evidence.

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

Yes—source-reproducible. Current main’s fixed 100-by-100 ms stopped-proof loop is visible in the updater, and the PR adds a focused slow-teardown regression case; no local execution was performed because this review checkout is read-only.

Is this the best way to solve the issue?

Yes, provisionally. The PR repairs the updater transaction at its owner boundary—preflight, native stop proof, atomic publication, restart verification, and rollback—rather than masking the failure with a downstream retry; final CI and maintainer acceptance remain the merge gate.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 383363e36233.

Labels

Label justifications:

  • P1: A failed managed Gateway replacement can interrupt an operator’s running service until rollback or manual recovery succeeds.
  • merge-risk: 🚨 availability: The PR changes shutdown timing, plist publication, bootstrap, and rollback for the managed Gateway.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This member-authored PR is not subject to the external-contributor proof gate; its PR body nevertheless provides native macOS launchd benchmark evidence and exact-head Testbox results for maintainer review.

Evidence

What I checked:

Likely related people:

  • steipete: Authored recent merged repairs to the same live-updater path, including the adjacent managed health-probe and readiness behavior. (role: recent updater contributor; confidence: high; commits: 21fba83254a8, d66b514a7e75; files: .agents/skills/openclaw-live-updater/scripts/update-main.mjs)
  • fuller-stack-dev: Authored the proposed timing and recovery transaction plus its focused regression coverage; this is a routing signal in addition to the member-authored protected-item rule. (role: current updater repair author; confidence: high; commits: 1d78a91ccd5c, 42c400393db3; files: .agents/skills/openclaw-live-updater/scripts/update-main.mjs, test/scripts/openclaw-live-updater.test.ts)

Rank-up moves

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

  • Wait for the in-progress exact-head required checks before merging.

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-07-31T20:01:38.210Z sha 1d78a91 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-31T20:41:40.093Z sha 1d78a91 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-31T21:09:18.767Z sha f20363b :: needs maintainer review before merge. :: none
  • reviewed 2026-07-31T21:25:13.990Z sha f20363b :: needs maintainer review before merge. :: none

@fuller-stack-dev fuller-stack-dev self-assigned this Jul 31, 2026
@clawsweeper clawsweeper Bot added status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jul 31, 2026
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jul 31, 2026
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Landing evidence decision for the latest ClawSweeper rank-up move:

  • Applied: the exact-head native slow-teardown benchmark harness and all raw before/after trial records are retained in the PR-linked evidence bundle.
  • Skipped: a native post-bootstrap rollback transcript. Deliberately faulting the production managed ai.openclaw.gateway was not justified for landing; the rollback transaction is instead covered by exact-head focused tests that assert partial-replacement stop, original-plist restoration, prior bootstrap, readiness proof, and primary-error preservation. The disposable native benchmark proves the launchd timing path but does not impersonate the updater's managed production label.

Maintainer direction is to land with that evidence boundary. The four new main commits since the reviewed base touch TUI, gateway media descriptors, OpenCode externalization, and onboarding only; none touch the updater, its declarations, tests, or assumptions.

@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Maintainer landing decision for the July 31, 2026 ClawSweeper review:

  • Accept the bounded maintenance-window tradeoff: malformed or absent ExitTimeOut uses the launchd-compatible 20-second default plus the bounded teardown margin, rather than aborting a healthy native teardown at the old fixed ceiling.
  • Accept the rollback evidence boundary: exact-head tests cover partial replacement stop, CAS-protected original-plist restoration, prior bootstrap, /readyz proof, and primary-error preservation; the disposable native benchmark covers real launchd stop/replacement timing without faulting the production managed label.
  • Skip refreshing the PR head solely for current-main drift. The reviewed delta through e4568f6bdddf touches TUI, gateway media descriptors/UI observer lifecycle, OpenCode externalization, and onboarding; it does not touch the updater, its declarations/tests, or the launchd assumptions. Exact-head PR CI and focused proof remain green. The deterministic merge wrapper will recheck drift and conflicts immediately before landing.

This explicitly resolves the two operational merge-risk choices and records why the optional current-main refresh is not being applied.

…ming-hardening

# Conflicts:
#	.agents/skills/openclaw-live-updater/scripts/update-main.mjs
#	test/external-script-modules.d.ts
#	test/scripts/openclaw-live-updater.test.ts
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Final-head refresh applied. The branch now contains current main at 383363e3623374db34c2b855f52f244caa688998; the overlapping updater change from #117038 was integrated by retaining its injected-port health probe while preserving this PR's structured JSON timing and channel milestones.

Exact final head: eac016a572cc37619d6fd7f0d17336f10bd39c93. Focused updater proof is 65/65 locally and 65/65 on Blacksmith Testbox tbx_01kyx1wthf8jxmgkw6nttvtsjj (Actions run 30667359322). The subsequent upstream cron-only merge did not alter the updater, declarations, or updater tests. Maintainer acceptance of the bounded stop-proof window and test-backed rollback boundary remains recorded above. Fresh exact-head PR CI is required before merge.

@fuller-stack-dev
fuller-stack-dev merged commit ae27d79 into openclaw:main Jul 31, 2026
94 of 97 checks passed
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Merged via squash.

@fuller-stack-dev
fuller-stack-dev deleted the codex/live-updater-timing-hardening branch July 31, 2026 22:02
vincentkoc added a commit that referenced this pull request Jul 31, 2026
…odels-20260729

* origin/main:
  fix(tui): canonical terminal outcomes, cancellation, and error privacy (#117044)
  fix(cron): avoid phantom message tool guidance (#116908)
  fix(test): avoid macOS release gate deadlocks (#116972)
  fix(openai): canonical Chat cache-hit and billing accounting (#117043)
  fix(memory-wiki): salvage human Notes before pruning imported source pages (#102294)
  fix(memory): suggest reindex, not --fix, for a missing qmd index (#116958)
  chore(msteams): add private Gateway QA adapter
  fix(ui): make session controls and failures accessible (#117019)
  docs: fix tilde paths in CLI output examples (#114595)
  fix(plugins): canonical discovery diagnostics and deterministic lifecycles (#117025)
  fix(ui): honor Gateway readiness abort and subscription ownership (#117048)
  fix(updater): harden launchd replacement timing (#117030)
  fix(gateway): preserve static asset HEAD representation metadata (#117049)
  fix(gateway): abort embeddings when clients disconnect (#116146)
  fix(googlechat): retain fallback thread continuity (#117053)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant