Skip to content

refactor(daemon): centralize managed service lifecycle ownership - #119647

Merged
steipete merged 1 commit into
mainfrom
codex/loc-0805-infra-dmvazq
Aug 5, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/loc-0805-infra-dmvazq

Conversation

@steipete

@steipete steipete commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Managed gateway and node services repeated lifecycle-ownership checks, portable environment-key normalization, inline secret/proxy auditing, and native service identity in separate implementation paths. That duplication made launchd, systemd, and Windows Scheduled Task behavior harder to keep aligned while maintaining service-account, secret, and mutation safety.

Why This Change Was Made

This maintainer-requested refactor establishes one canonical node-service identity, managed service environment-key/source policy, guarded gateway mutation flow, and scope-aware systemd action dispatcher. It removes 104 production lines (98 additions and 202 deletions across nine daemon files) while preserving ambient and explicit supervision checks, future-config guards, portable case-insensitive key validation, exact platform identities, system/root ownership authorization, reset-failed ordering, mutation notifications, operator output, rollback behavior, PATH sanitization, symlink safety, and 0600 secret-file permissions.

User Impact

No intended user-visible, configuration, default, public API, or service-management behavior changes. Gateway and node install, repair, start, stop, restart, status, and environment auditing retain their existing behavior on macOS launchd, Linux user/system systemd scopes, and Windows Scheduled Tasks.

Evidence

  • Trusted Blacksmith Testbox tbx_01kz93h6y9kazx4ycmy32f8c1h: https://github.com/openclaw/openclaw/actions/runs/31012882109. The single owned lease was stopped and verified completed.

  • Focused existing coverage: 574 tests passed across 13 files, with 24 existing platform-specific skips. Command: pnpm test src/daemon/constants.test.ts src/daemon/service.test.ts src/daemon/service-env.test.ts src/daemon/service-audit.test.ts src/daemon/systemd.test.ts src/daemon/systemd-system.test.ts src/daemon/launchd-system.test.ts src/daemon/launchd.test.ts src/daemon/schtasks.install.test.ts src/infra/host-env-security.test.ts src/infra/gateway-supervision.test.ts src/commands/daemon-install-helpers.test.ts src/commands/node-daemon-install-helpers.test.ts.

  • Unmodified full pnpm check:changed passed, including production/full-tree/script dead-export scans, core and core-test tsgo, changed-file lint, formatting, plugin boundaries, import cycles, dependency/security guards, and native schema safeguards.

  • 207 baseline-versus-refactor source differential comparisons covered invalid/mixed-case keys, managed secrets, inline/file proxy sources, exact node identities on all three platforms, all six mutation guards and their failures, and system/user systemd ownership, reset, action, callback, output, and failure ordering.

  • Fresh independent .agents/skills/autoreview/scripts/autoreview --mode local --engine codex --model gpt-5.6-sol --thinking xhigh: clean; zero actionable findings; confidence 0.97.

  • Production LOC: -104; test LOC: 0. AI-assisted, maintainer-requested owner-boundary cleanup; no operator gateway or service action was executed.

  • Controlled committed-production Linux service lifecycle: Executed the actual stageSystemdService, readSystemdServiceExecStart, startSystemdService, stopSystemdService, and restartSystemdService production owners against real isolated temporary service/config artifacts and a real spawned, fail-closed synthetic systemctl executable. The production system-scope ownership guard also executed against that synthetic manager. No native operator service manager, gateway, real credentials, tracked source, or PR head was touched; temporary artifacts were removed afterward.

head=5cf860d274bd2dd0afe0c6e737b319bd4944cd86
entrypoints=stageSystemdService,startSystemdService,stopSystemdService,restartSystemdService,readSystemdServiceExecStart
isolation=real temporary HOME/state/unit/env files; real child-process synthetic systemctl; no native manager/operator credentials
gateway.unit=openclaw-gateway-proof.service
gateway.marker=openclaw/gateway
gateway.environmentFile.mode=600
gateway.environmentFile.token=[redacted]; source=file; inlineUnitLeak=false
node.identity=ai.openclaw.node | openclaw-node | OpenClaw Node
systemOwnership.probes=10
start: inactive -> active
stop: active -> inactive
restart: inactive -> active (completed)
commands=--user reset-failed openclaw-gateway-proof.service ; --user start openclaw-gateway-proof.service ; --user stop openclaw-gateway-proof.service ; --user reset-failed openclaw-gateway-proof.service ; --user restart openclaw-gateway-proof.service
mutationCallbacks=systemctl-start,systemctl-stop,systemctl-restart
operatorOutput=Staged systemd service: <isolated>/home/.config/systemd/user/openclaw-gateway-proof.service
operatorOutput=Started systemd service: openclaw-gateway-proof.service
operatorOutput=Stopped systemd service: openclaw-gateway-proof.service
operatorOutput=Restarted systemd service: openclaw-gateway-proof.service
result=PASS

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: M maintainer Maintainer-authored PR labels Aug 5, 2026
@steipete
steipete marked this pull request as ready for review August 5, 2026 14:24
@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. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Aug 5, 2026
@clawsweeper

clawsweeper Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 5, 2026, 11:21 AM ET / 15:21 UTC.

ClawSweeper review

What this changes

The PR consolidates managed gateway and node-service identity, environment handling, mutation guards, and systemd lifecycle dispatch without intended behavior changes.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep this maintainer-owned PR open: current main does not contain the refactor, the prior proof request is now met by a controlled production-owner trace, and no actionable correctness finding was found.

Priority: P3
Reviewed head: 5cf860d274bd2dd0afe0c6e737b319bd4944cd86

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused, net-negative owner-boundary refactor with exact-head controlled lifecycle proof and no supported correctness finding.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): The PR body includes an exact-head controlled trace through the production systemd lifecycle owners and child-process boundary, with recorded after-fix lifecycle recovery and redacted secret-file checks.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (logs): The PR body includes an exact-head controlled trace through the production systemd lifecycle owners and child-process boundary, with recorded after-fix lifecycle recovery and redacted secret-file checks.
Evidence reviewed 4 items Canonical mutation guard: The centralized wrapper applies both lifecycle ownership checks and the future-config guard before each native service mutation, preserving the former per-method contract.
Systemd behavior preservation: The shared dispatcher retains scope selection, reset-failed ordering, callbacks, operator output, and error handling; existing tests cover root/user scope and lifecycle ordering.
Current-main comparison: Current main has no daemon-path changes since the PR base, and a three-way merge is clean, so main has not superseded this work.
Findings None None.
Security None None.

How this fits together

Daemon service code converts gateway and node settings into launchd, systemd, or Scheduled Task definitions, then performs guarded lifecycle actions. It protects ownership, config-version, environment-source, and secret-file rules before reaching each platform manager.

flowchart LR
  Config[Gateway and node settings] --> Env[Managed environment policy]
  Env --> Definition[Platform service definition]
  Definition --> Guards[Ownership and config guards]
  Guards --> Actions[Lifecycle actions]
  Actions --> Platforms[launchd, systemd, Task Scheduler]
Loading

Before merge

  • Complete next step (P2) - No repair is indicated; this remains a normal maintainer-owned PR review path.
Agent review details

Security

None.

PR surface

Source -104. Total -104 across 9 files.

View PR surface stats
Area Files Added Removed Net
Source 9 98 202 -104
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 98 202 -104

Review metrics

Metric Value Why it matters
Production versus test LOC production -104, tests 0 The refactor removes duplicated production policy without expanding the test surface.

Technical review

Best possible solution:

Retain the single canonical daemon-policy owners and merge this behavior-preserving cleanup after normal maintainer review.

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

Not applicable: this PR refactors existing service-management behavior rather than fixing a separately reported failure; its controlled trace verifies preserved lifecycle behavior on the exact head.

Is this the best way to solve the issue?

Yes. Centralizing the repeated identity, normalization, guard, and dispatch policy at their existing daemon owners removes duplicate behavior without adding a parallel path.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes an exact-head controlled trace through the production systemd lifecycle owners and child-process boundary, with recorded after-fix lifecycle recovery and redacted secret-file checks.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (logs): The PR body includes an exact-head controlled trace through the production systemd lifecycle owners and child-process boundary, with recorded after-fix lifecycle recovery and redacted secret-file checks.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.
  • remove merge-risk: 🚨 availability: Current PR review selected no merge-risk labels.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P3: This is a maintainer-requested behavior-preserving cleanup rather than a user-facing outage or feature.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (logs): The PR body includes an exact-head controlled trace through the production systemd lifecycle owners and child-process boundary, with recorded after-fix lifecycle recovery and redacted secret-file checks.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes an exact-head controlled trace through the production systemd lifecycle owners and child-process boundary, with recorded after-fix lifecycle recovery and redacted secret-file checks.

Evidence

What I checked:

  • Canonical mutation guard: The centralized wrapper applies both lifecycle ownership checks and the future-config guard before each native service mutation, preserving the former per-method contract. (src/daemon/service.ts:383, 5cf860d274bd)
  • Systemd behavior preservation: The shared dispatcher retains scope selection, reset-failed ordering, callbacks, operator output, and error handling; existing tests cover root/user scope and lifecycle ordering. (src/daemon/systemd.ts:1582, 5cf860d274bd)
  • Current-main comparison: Current main has no daemon-path changes since the PR base, and a three-way merge is clean, so main has not superseded this work. (src/daemon/service.ts:383, 4511c9b71f78)
  • Exact-head provenance and proof: The head commit records the refactor; the PR body’s controlled trace exercises the production systemd stage/read/start/stop/restart owners through their child-process boundary and records after-fix state transitions, command ordering, callbacks, output, ownership probes, and 0600 environment-file handling. (src/daemon/exec-file.ts:7, 5cf860d274bd)

Likely related people:

  • steipete: Authored the exact-head refactor and is blamed for the newly centralized identity, guard, and dispatcher lines. (role: refactor author and recent daemon contributor; confidence: high; commits: 5cf860d274bd; files: src/daemon/constants.ts, src/daemon/service.ts, src/daemon/systemd.ts)
  • Vincent Koc: History around the retained systemd lifecycle and service-registry behavior attributes the surrounding implementation to this contributor. (role: pre-existing lifecycle-area contributor; confidence: medium; commits: db8e95f; files: src/daemon/service.ts, src/daemon/systemd.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-05T14:30:30.613Z sha 5cf860d :: needs real behavior proof before merge. :: none

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor 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. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Aug 5, 2026
@steipete
steipete merged commit 36554c2 into main Aug 5, 2026
206 checks passed
@steipete
steipete deleted the codex/loc-0805-infra-dmvazq branch August 5, 2026 16:49
@steipete

steipete commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit to VACInc/openclaw that referenced this pull request Aug 5, 2026
…cope

* origin/main: (70 commits)
  fix(clickclack): preserve MIME extension for unnamed uploads (openclaw#119646)
  fix(memory): keep post-ready RPCs responsive (openclaw#119710)
  fix(browser): preserve locale, timezone, and device overrides (openclaw#119695)
  fix(agents): stop messaging dedupe from dropping final replies that quote a short tool send (openclaw#118178)
  test(agents): batch code mode budget proof (openclaw#119699)
  fix(memory): keep gateway RPCs responsive during startup (openclaw#119676)
  improve(ui): trail transient session status beside row actions (openclaw#119560)
  refactor(msteams): consolidate channel action target resolution (openclaw#119632)
  fix: tail context answers the current user message (openclaw#117364)
  fix(whatsapp): exercise descriptor-safe credential persistence (openclaw#119621)
  fix(diagnostics-otel): route OTLP endpoints by signal (openclaw#101655)
  refactor(skills): consolidate workshop transcript and record normalization (openclaw#119643)
  fix(video): harden DashScope task and media lifecycle (openclaw#117303)
  refactor(transcripts): consolidate persistence and export ownership (openclaw#119634)
  fix: preserve ClickClack discussion state contracts (openclaw#118851)
  fix(matrix): retire shared E2EE clients safely (openclaw#119570)
  refactor(cron): unify catch-up persistence and payload encoding (openclaw#119636)
  refactor(ui): centralize composer attachment and capability controls (openclaw#119650)
  refactor(daemon): consolidate managed service lifecycle ownership (openclaw#119647)
  fix(browser): honor explicit navigation timeouts across browser drivers (openclaw#119654)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 6, 2026
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. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor 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