Skip to content

fix(mac): preserve LaunchAgent bytes and permissions on rollback - #152195

Merged
steipete merged 1 commit into
mainfrom
codex/launchagent-rollback-snapshot
Sep 19, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/launchagent-rollback-snapshot

Conversation

@steipete

@steipete steipete commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Related: #150153

What Problem This Solves

A failed macOS LaunchAgent replacement can make the previous plist more readable or corrupt its binary contents during rollback.

User Impact

Rollback restores the previous plist's exact bytes and permission bits, preserving the service definition that existed before the failed replacement.

Why This Change Was Made

Capture contents and mode from one open file, then restore both through the existing publication transaction. Set the restored mode before renaming the file into place and retain binary data without text conversion. Normal new-install permissions stay unchanged.

Evidence

Real temporary-file regressions reproduce private 0600 and 0640 plists becoming 0644, plus binary contents changing during failed install rollback. All 212 focused tests pass after the fix, including exact bytes and modes before rename and file-handle cleanup. Native commands and ownership observations were mocked in those fault-injection tests.

The unmodified published 2026.9.4 updater also passed a real macOS 26.5 arm64 upgrade to the exact canonical package at 054e5f70a6895e70e89fb24e76c6abe981cd08c8. The ordinary CLI update completed in 131.408 seconds with exit 0 and status ok. Native process identity changed, HTTP readiness returned 200, the authenticated WebSocket handshake reported the candidate build, and the durable update ledger finished successfully with all verification flags true and no remaining custody rows. Processes, listeners, service definition, profile, runtime files and the verified empty control root were cleaned up. The custody backup is retained; normal launchd enable overrides remain for disposal of the task-owned clone. No operator Gateway was restarted.

The live cell covers the ordinary upgrade path; rollback faults are covered by the filesystem regressions above. Optional WebSocket diagnostic reads lacked operator.read both before and after, so this is handshake/build evidence rather than unrestricted RPC-health coverage. Earlier transport and harness setup failures remain recorded; product assertions and timeouts were unchanged, and only one actual update ran.

Full selected checks, fresh independent P0–P2 autoreview and exact-head CI pass. The canonical package build and artifact checks also passed. This isolated prerequisite adds 21 production lines; the replacement series' final production reduction remains an aggregate requirement.

Capture prior plist bytes and permission bits from one open descriptor and
restore them before atomic rollback publication. Failed activation no
longer re-encodes binary plists or widens private plist permissions.

Adapt the read-only service audit caller and cover actual filesystem
restoration, staged modes, and descriptor cleanup.
@clawsweeper

clawsweeper Bot commented Sep 18, 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 docs Improvements or additions to documentation gateway Gateway runtime size: M maintainer Maintainer-authored PR labels Sep 18, 2026
@steipete
steipete marked this pull request as ready for review September 18, 2026 22:08
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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. labels Sep 18, 2026
@clawsweeper

clawsweeper Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 18, 2026, 8:39 PM ET / September 19, 2026, 00:39 UTC (Revision 2).

ClawSweeper review

What this changes

Preserves the original macOS LaunchAgent service definition’s bytes and permission bits when replacement fails, with filesystem regression coverage and documentation.

Merge readiness

✅ Ready for maintainer review

The fix remains necessary: current main still loses plist permissions and converts binary rollback contents to text. No introduced blocking defect was found, and the updated published-updater evidence addresses the previous review’s upgrade-proof request.

Priority: P2
Reviewed head: 054e5f70a6895e70e89fb24e76c6abe981cd08c8

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with meaningful filesystem regressions, reported native upgrade evidence, and no blocking findings.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: The supplied repository context identifies a maintainer-authored PR, so the external-contributor gate does not apply. Its reported exact-head macOS published-driver upgrade addresses compatibility; rollback bytes and permissions are covered by real-filesystem tests with mocked native commands, not a live rollback demonstration.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied repository context identifies a maintainer-authored PR, so the external-contributor gate does not apply. Its reported exact-head macOS published-driver upgrade addresses compatibility; rollback bytes and permissions are covered by real-filesystem tests with mocked native commands, not a live rollback demonstration.
Evidence reviewed 9 items Rollback implementation: The snapshot reads bytes and mode through one descriptor and closes it in finally. Both explicit restoration and post-publication rollback set captured permissions before rename; ordinary publication retains its existing default.
Install and caller cutover: Install rollback passes the captured Buffer and mode to the existing publisher, and restores auxiliary file contents without UTF-8 conversion. The read-only audit consumes snapshot.contents; the caller search found no remaining production consumer expecting the old Buffer return shape.
Current main still needs the repair: Fetched main still snapshots only contents and restores publication failures with the default plist mode; install rollback still calls toString("utf8") on the captured plist.
Findings None None.
Security None None.

How this fits together

OpenClaw’s macOS service installer publishes LaunchAgent files and asks launchd to activate the Gateway. Failed publication or activation restores the previous files and supervision state.

flowchart TD
 A[Gateway service installation] --> B[Capture existing bytes and permissions]
 B --> C[Publish replacement files]
 C --> D{Publication and activation succeed?}
 D -->|Yes| E[Gateway service running]
 D -->|No| F[Restore captured files]
 F --> G[Restore prior supervision or report failure]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +21, Tests +204, Docs +1. Total +226 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 3 46 25 +21
Tests 3 215 11 +204
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 262 36 +226

Review metrics

Metric Value Why it matters
Rollback coverage 2 permission modes × 2 failure paths The filesystem regressions check binary contents and permissions before restored files become visible.

Stored data model

Persistent data-model change detected: serialized state: src/daemon/launchd-install.ts, serialized state: src/daemon/launchd-service-files.ts, unknown-data-model-change: src/daemon/launchd-install.ts, unknown-data-model-change: src/daemon/launchd-service-files.ts. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Technical review

Best possible solution:

Keep byte-preserving restoration in the existing publication owner, restoring captured plist permissions before publication while retaining normal installation defaults.

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

Yes, from source: replacing a private or binary plist and then failing publication or activation reaches current-main rollback code that resets its mode or converts its bytes to UTF-8; this review did not execute that path.

Is this the best way to solve the issue?

Yes. Capturing bytes and permissions together and restoring them through the existing publisher is a narrow repair, and all production consumers of the changed snapshot shape were adapted.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This repairs a bounded macOS failed-replacement path that can corrupt the previous service definition or widen its permissions.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied repository context identifies a maintainer-authored PR, so the external-contributor gate does not apply. Its reported exact-head macOS published-driver upgrade addresses compatibility; rollback bytes and permissions are covered by real-filesystem tests with mocked native commands, not a live rollback demonstration.

Evidence

What I checked:

  • Rollback implementation: The snapshot reads bytes and mode through one descriptor and closes it in finally. Both explicit restoration and post-publication rollback set captured permissions before rename; ordinary publication retains its existing default. (src/daemon/launchd-service-files.ts:212, 054e5f70a689)
  • Install and caller cutover: Install rollback passes the captured Buffer and mode to the existing publisher, and restores auxiliary file contents without UTF-8 conversion. The read-only audit consumes snapshot.contents; the caller search found no remaining production consumer expecting the old Buffer return shape. (src/daemon/launchd-install.ts:221, 054e5f70a689)
  • Current main still needs the repair: Fetched main still snapshots only contents and restores publication failures with the default plist mode; install rollback still calls toString("utf8") on the captured plist. (src/daemon/launchd-install.ts:223, 732f5fe0a772)
  • Latest release comparison: GitHub’s v2026.9.4 source likewise restores publication rollback using the default mode. Its install source also retains the lossy UTF-8 conversion. Local release blobs were unavailable, so these files were inspected through the read-only contents API. (src/daemon/launchd-service-files.ts, 3a9d69db306c)
  • Regression coverage: The new tests exercise real temporary files with binary plist bytes, 0600 and 0640 permissions, both rollback triggers, pre-rename permissions, path replacement during capture, and descriptor closure. Native ownership checks and launchctl are mocked. Existing tests cover fresh installation and loaded-service recovery. Tests were inspected, not executed during this read-only review. (src/daemon/launchd-service-files.test.ts:108, 054e5f70a689)
  • Updated upgrade evidence and review continuity: The supplied complete PR body, captured under sourceRevision c2cdf4b3647333aa194b26780a84527618a3d24c64fcdc972f0900b4990556fc, reports the unmodified 2026.9.4 updater upgrading macOS 26.5 arm64 to this exact head in 131.408 seconds: exit 0, readiness HTTP 200, candidate identity in the authenticated WebSocket handshake, and successful durable verification. This addresses the previous review’s upgrade-proof request. The body explicitly limits live coverage to ordinary upgrade and identifies rollback fault coverage as filesystem tests. (054e5f70a689)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)

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 (1 earlier review cycle)
  • reviewed 2026-09-18T22:14:03.914Z sha 054e5f7 :: blocked before merge. :: none

@steipete
steipete merged commit e4f603b into main Sep 19, 2026
292 of 293 checks passed
@steipete
steipete deleted the codex/launchagent-rollback-snapshot branch September 19, 2026 00:53
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Sep 19, 2026
* commit '912b21b98581c0be3baad87fe3686b64d69fffeb': (191 commits)
  perf(process): reduce allocation while processing command output (#152261)
  fix(ui): collapse duplicate previews when a page opens in multiple tabs (#152281)
  fix(test): run local Gateway tests behind protected exec egress (#152318)
  fix(node-host): avoid blocking configuration reads (#151411)
  fix(qa-lab): prevent Evidence Archive filters from overflowing (#152123)
  test: stabilize Docker scheduler signal fixtures on macOS (#152301)
  fix(ui): close stuck submenus when moving between menu rows (#152317)
  fix(ui): preserve question drafts and pending submissions (#152096)
  fix(release): recognize 7.34 fs-safe contract (#152326)
  chore: retire CLAUDE.md files
  fix(ui): release queued input after completed chat runs (#152299)
  improve(tooling): reduce commit formatting resource use (#152297)
  feat: show mentioned sessions in Involving me (#152083)
  perf(tasks): reuse prepared audit summaries (#152294)
  fix(daemon): preserve LaunchAgent rollback bytes and modes (#152195)
  fix: stop chat layout changes from loading extra history (#151726)
  perf(gateway): streamline config reload comparison (#152279)
  fix(xai): reject invalid UTF-8 OAuth responses (#111737)
  fix(release): accept waived advisory performance evidence for stable publication (#152290)
  fix: deliver watcher results while other sessions are busy (#152287)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 19, 2026
…152195)

Capture prior plist bytes and permission bits from one open descriptor and
restore them before atomic rollback publication. Failed activation no
longer re-encodes binary plists or widens private plist permissions.

Adapt the read-only service audit caller and cover actual filesystem
restoration, staged modes, and descriptor cleanup.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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