Skip to content

refactor(daemon): split launchd into concept modules - #121929

Merged
steipete merged 3 commits into
mainfrom
steipete/split-launchd
Aug 11, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/split-launchd

Conversation

@steipete

@steipete steipete commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

src/daemon/launchd.ts had grown to 2,013 lines and required a grandfathered max-lines suppression, making macOS managed-gateway lifecycle code difficult to navigate safely.

Why This Change Was Made

This behavior-neutral refactor follows the file's independently evolved concept seams: service-file generation/publication, stale updater jobs, launchctl runtime inspection, transactional install/rollback, stop/maintenance parking, and start/restart recovery. The original module remains a pure public re-export facade so existing callers and test mocks retain the same import surface.

New module line counts:

  • launchd-service-files.ts: 439
  • launchd-install.ts: 423
  • launchd-lifecycle.ts: 404
  • launchd-runtime.ts: 366
  • launchd-update-jobs.ts: 264
  • launchd-stop.ts: 209
  • launchd.ts facade: 30

The max-lines suppression and config/max-lines-baseline.txt entry are removed.

User Impact

None. Generated plist bytes, environment-wrapper content, launchctl command strings, lifecycle ordering, and error text are unchanged.

Evidence

  • node scripts/run-vitest.mjs src/daemon — 54 files passed; 1,575 tests passed, 10 skipped before the stale-base rebase; post-rebase daemon proof passed 20 files and 737 tests with 5 skipped.
  • Importer suites — 456 tests passed across CLI update, daemon status/recovery, gateway CLI, doctor flow, and install-helper owners.
  • node --import tsx scripts/check-export-name-collisions.mts — passed.
  • node --import tsx scripts/check-wrapper-shadowing.mts — passed without baseline growth.
  • node --import tsx scripts/check-import-cycles.ts — 0 runtime value cycles.
  • node --import tsx scripts/check-max-lines-ratchet.mts --base origin/main — passed; baseline shrank by one.
  • node --import tsx scripts/check-deadcode-exports.mts — passed with 0 unused exports.
  • Targeted oxlint and git diff --check — passed.
  • Autoreview (--mode branch --base origin/main) — clean, no accepted/actionable findings.
  • Exact-head CI run 31473576360 — all 69 jobs passed, including build artifacts and macOS launchd coverage.

Raw numstat is +2,132/-2,011. Discounting pure moves and module import scaffolding, behavior-bearing production LOC is net -1 (the removed suppression); tests and production importers are unchanged.

@clawsweeper

clawsweeper Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete
steipete marked this pull request as ready for review August 11, 2026 07:45
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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 11, 2026
@clawsweeper

clawsweeper Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 11, 2026, 4:03 AM ET / 08:03 UTC.

ClawSweeper review

What this changes

The PR splits macOS LaunchAgent installation, runtime inspection, lifecycle, stop, updater-job, and plist work into focused daemon modules while retaining the existing launchd import facade.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep this maintainer-authored, maintainer-labeled refactor open for normal merge review. The exact-head facade preserves the existing launchd import surface and the split follows current lifecycle ownership; no concrete patch defect was found.

Priority: P3
Reviewed head: b4322caec47cb5c3297ef0dafad6c64b6dbe353e

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The module boundaries and compatibility facade are coherent, with the remaining merge gate being exact-head CI.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored refactor is not subject to the external-contributor proof gate; exact-head CI remains pending.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored refactor is not subject to the external-contributor proof gate; exact-head CI remains pending.
Evidence reviewed 5 items Public import compatibility: The PR-head facade re-exports the existing install, lifecycle, runtime, plist, stop, and updater APIs instead of changing callers’ launchd import path.
Caller and test boundary: The service registry imports the LaunchAgent operations through the facade, and the focused launchd suite imports the same public operations from that facade.
Existing lifecycle coverage: Current tests cover install rollback, start/restart recovery, stop port-release confirmation, maintenance parking, runtime parsing, and updater-job handling.
Findings None None.
Security None None.

How this fits together

OpenClaw’s daemon service layer translates Gateway CLI lifecycle operations into LaunchAgent plist and launchctl work on macOS. Service callers consume the launchd facade, which then installs, inspects, starts, stops, and recovers the managed Gateway.

flowchart LR
  A[Gateway CLI] --> B[Daemon service registry]
  B --> C[LaunchAgent facade]
  C --> D[Service-file module]
  C --> E[Runtime and lifecycle modules]
  E --> F[launchctl]
  D --> G[LaunchAgent plist and environment files]
  F --> H[Managed Gateway]
Loading

Before merge

  • Resolve merge risk (P1) - The local partial clone could not retrieve one historical blob for a full local diff/check; require the in-progress exact-head CI before merge.
  • Complete next step (P2) - No repair lane is needed: no actionable source defect was found, and the maintainer label requires normal human merge handling.
Agent review details

Security

None.

PR surface

Source +122, Other -1. Total +121 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 7 2132 2010 +122
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 0 1 -1
Total 8 2132 2011 +121

Review metrics

Metric Value Why it matters
Production versus test delta source raw +122 after moving 2,010 prior source lines; tests 0 The increase is module-boundary scaffolding for a behavior-neutral split, while the existing launchd test surface remains unchanged.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Land the focused module split only after exact-head CI is green, retaining the facade and existing lifecycle test coverage as the compatibility boundary.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Land the focused module split only after exact-head CI is green, retaining the facade and existing lifecycle test coverage as the compatibility boundary.

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

Not applicable: this is a structural refactor; preservation is assessed through the facade, existing daemon tests, and exact-head CI rather than a new bug reproduction.

Is this the best way to solve the issue?

Yes: splitting by plist ownership, runtime inspection, lifecycle, stopping, installation, and updater cleanup keeps the public facade while aligning code with the existing operational boundaries.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored refactor is not subject to the external-contributor proof gate; exact-head CI remains pending.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P3: This is a behavior-neutral maintainability refactor with no reported user-facing regression.
  • 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 maintainer-authored refactor is not subject to the external-contributor proof gate; exact-head CI remains pending.

Evidence

What I checked:

  • Public import compatibility: The PR-head facade re-exports the existing install, lifecycle, runtime, plist, stop, and updater APIs instead of changing callers’ launchd import path. (src/daemon/launchd.ts:2, b4322caec47c)
  • Caller and test boundary: The service registry imports the LaunchAgent operations through the facade, and the focused launchd suite imports the same public operations from that facade. (src/daemon/service.ts:10, a8839a89239a)
  • Existing lifecycle coverage: Current tests cover install rollback, start/restart recovery, stop port-release confirmation, maintenance parking, runtime parsing, and updater-job handling. (src/daemon/launchd.test.ts:1619, a8839a89239a)
  • History and ownership: Recent launchd work is concentrated in Peter Steinberger’s history, with restart recovery also contributed by Chris Allbritton. (src/daemon/launchd.ts:1, c5b7b8e33c99)
  • Review-environment limitation: The PR-head blobs were readable directly, but the partial clone could not fetch one parent blob for a full local diff/check because github.com DNS was unavailable; exact-head CI remains the appropriate final verification.

Likely related people:

  • steipete: Current launchd history is heavily authored by Peter Steinberger, including the immediate pre-refactor state and this refactor branch. (role: recent area contributor; confidence: high; commits: c5b7b8e33c99, b4322caec47c; files: src/daemon/launchd.ts, src/daemon/launchd-install.ts)
  • Chris Allbritton: Recent launchd history records a focused macOS gateway restart-recovery repair in this owner surface. (role: restart-recovery contributor; confidence: medium; commits: 7d039fb424d9; 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 (1 earlier review cycle)
  • reviewed 2026-08-11T07:55:22.150Z sha 12a6768 :: needs real behavior proof before merge. :: none

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: XL maintainer Maintainer-authored PR labels Aug 11, 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: 🦪 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 11, 2026
@steipete
steipete force-pushed the steipete/split-launchd branch from df355d0 to 5663df3 Compare August 11, 2026 08:31
@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready proof:

  • Exact head: 5663df3a501f693eca4226621a8406da42d21178
  • CI: run 31473576360, all 69 jobs green, including build artifacts, macOS launchd tests, max-lines ratchet, production/test types, lint, import cycles, export collisions, wrapper shadowing, and dead-code exports.
  • Local focused proof: node scripts/run-vitest.mjs src/daemon (1,575 passed, 10 skipped before rebase); importer suites (456 passed); post-rebase daemon + unit-fast inventory proof (849 passed, 5 skipped).
  • Local guards: export-name collisions, wrapper shadowing, import cycles, max-lines ratchet, dead-code exports, targeted oxlint, and git diff --check all passed.
  • Autoreview: --mode branch --base origin/main clean with no accepted/actionable findings.

ClawSweeper rank-up moves are addressed: exact-head CI is green and this is proceeding through normal maintainer review/landing. No behavior, config, protocol, storage, or public import contract changed.

Proof gap: no separate local Testbox run ID. The local wrapper stopped before allocation because the checked Crabbox binary could not be safely rebuilt from its unrelated dirty checkout; exact-head hosted CI supplied the required build and macOS proof instead.

@steipete
steipete merged commit 3d707a9 into main Aug 11, 2026
125 checks passed
@steipete
steipete deleted the steipete/split-launchd branch August 11, 2026 08:49
@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

gateway Gateway runtime maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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