Skip to content

fix(daemon): prevent duplicate systemd gateway ownership - #116162

Merged
vincentkoc merged 1 commit into
mainfrom
fix/systemd-user-install-ownership
Jul 30, 2026
Merged

vincentkoc merged 1 commit into
mainfrom
fix/systemd-user-install-ownership

Conversation

@vincentkoc

Copy link
Copy Markdown
Member

Fixes #116129

Additional instructions

MUST: Keep Allow edits from maintainers enabled for this PR so maintainers
can help update the branch when needed.

What Problem This Solves

Fixes an issue where Linux operators could install the same OpenClaw gateway unit in both system and user systemd scopes, leaving two supervisors competing over one gateway and causing restart loops or unreliable message delivery.

Why This Change Was Made

Gateway install, stage, start, and restart now fail closed when the system manager owns the exact canonical unit name. The check uses the running system manager's unit search path, is repeated around publication and activation to close races, and cannot be bypassed with --force.

OpenClaw does not mutate system-scope units automatically. Differently named and profile-specific units remain independent, while user-unit and environment-file publication is atomic and rolls back exact prior contents and permissions if ownership changes mid-install.

User Impact

Linux operators get an actionable error before OpenClaw creates or activates a conflicting user gateway. Existing system units remain untouched, custom differently named services continue to work, and failed publication does not leave partial user-scope files behind.

Evidence

  • Blacksmith Testbox focused proof: 145/145 tests passed across src/daemon/systemd-system.test.ts, src/daemon/systemd.test.ts, and src/cli/daemon-cli/install.integration.test.ts.
  • Blacksmith Testbox changed gate passed formatting, dead-code, boundary, core/core-test typecheck, lint, schema, storage, and import-cycle checks.
  • Live Linux proof created an ephemeral same-name unit in /run/systemd/system, confirmed install failed with SYSTEM_SYSTEMD_OWNERSHIP, confirmed a differently named unit passed, and verified no user unit or gateway environment file was published.
  • Regression coverage includes system-only normal and forced install, pre-existing duel, /etc, /run, /usr/local, generator/package guidance, uncheckable ownership, root/non-root recovery, profile names, publication and activation races, symlink refusal, rollback, and zero-valued permission preservation.
  • Fresh autoreview: clean, no accepted/actionable findings.

Agent Transcript

Redacted Codex session transcript
source: local Codex session
redaction: local paths, runner identities, raw tool output, secrets, and unrelated PR work omitted

[assistant]
Issue policy is explicit: user-scope install must fail closed when the canonical system unit exists, including --force, and must never mutate the system unit.

[assistant]
The launchd comparison confirms the right boundary: an exact-name system owner is a hard ownership conflict, not a cleanup opportunity.

[assistant]
The live Linux proof is clean: a real system-manager unit blocked the user install before publication, while a different name passed; cleanup removed the ephemeral proof unit and reloaded systemd.

[assistant]
Autoreview found and drove fixes for missing-bus classification, environment-file rollback, complete systemd unit paths, symlink safety, recovery guidance, and exact permission preservation.

[assistant]
Final proof is green: 145 focused tests, the scoped changed gate, live systemd ownership proof, and a clean fresh autoreview.

@vincentkoc vincentkoc self-assigned this Jul 30, 2026
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime cli CLI command changes size: L maintainer Maintainer-authored PR labels Jul 30, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review July 30, 2026 01:37
@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. 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 30, 2026
@clawsweeper

clawsweeper Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 29, 2026, 9:42 PM ET / July 30, 2026, 01:42 UTC.

ClawSweeper review

What this changes

The PR blocks user-scope systemd gateway installation and lifecycle actions when a same-named system-scope unit owns—or cannot be reliably checked for—the canonical gateway service name, while adding rollback and regression coverage.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep this PR open for explicit maintainer review. It addresses the linked dual-supervisor failure, but it deliberately chooses fail-closed installation over the linked issue's proposed automatic opposite-scope retirement; the author is a MEMBER and the PR carries the protected maintainer label, so this workflow must not close or auto-resolve it.

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

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch has a focused ownership boundary, regression coverage, and stated live Linux validation; its remaining blocker is the maintainer policy choice about fail-closed upgrade behavior.
Proof confidence 🌊 off-meta tidepool Not applicable: The contributor is a repository MEMBER, so the external-contributor proof gate does not apply; the PR body nevertheless reports a live Linux systemd check plus focused test proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The contributor is a repository MEMBER, so the external-contributor proof gate does not apply; the PR body nevertheless reports a live Linux systemd check plus focused test proof.
Evidence reviewed 5 items Linked problem and candidate fix: The PR body formally links the open canonical issue, which describes dual user/system systemd gateway units causing restart loops and unreliable delivery; this branch is a candidate implementation rather than a completed resolution.
Ownership boundary implementation: The branch adds a dedicated system-manager ownership check and returns conflict or unverifiable outcomes before a user-scope gateway service is mutated.
Lifecycle integration: The branch imports the ownership assertion into the Linux user-systemd service implementation and calls it before writing the managed unit, making the policy part of the daemon installer boundary rather than a CLI-only message.
Findings None None.
Security None None.

How this fits together

OpenClaw's daemon CLI publishes and controls a user-level systemd gateway service. This change inserts a system-scope ownership decision before user-unit publication or activation so two supervisors cannot manage the same canonical gateway name and compete for the gateway process.

flowchart LR
  A[Daemon CLI request] --> B[User systemd service lifecycle]
  B --> C[Resolve canonical gateway unit name]
  C --> D[Check system systemd manager]
  D -->|Same name or unverifiable| E[Actionable ownership error]
  D -->|No owner found| F[Publish user unit and environment]
  F --> G[Enable or restart user gateway]
  E --> H[No user files changed]
Loading

Decision needed

Question Recommendation
Should OpenClaw reject a same-named user-scope gateway operation whenever system ownership is present or unverifiable, or should installation instead retire the opposite-scope unit as proposed in the linked issue? Adopt fail-closed ownership: Keep this PR's exact-name conflict rule so OpenClaw never automatically alters a system-scope unit and instead gives the operator recovery guidance.

Why: Both approaches prevent the dual-supervisor failure, but they differ materially in operator control, upgrade behavior, and whether OpenClaw automatically changes a system-managed service.

Before merge

  • Resolve merge risk (P1) - This intentionally makes a previously permitted user-systemd install fail when a same-named system unit exists or the system manager cannot be verified; maintainers need to confirm that fail-closed behavior is the desired upgrade policy rather than retiring the conflicting opposite-scope unit.
  • Resolve merge risk (P1) - The change affects daemon installation, stage, start, and restart behavior on Linux, so an operator with an existing system-managed unit may need to follow the new recovery guidance before a user-scope workflow can proceed.
Agent review details

Security

None.

PR surface

Source +331, Tests +488, Docs +1. Total +820 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 2 371 40 +331
Tests 3 488 0 +488
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 860 40 +820

Review metrics

None.

Stored data model

Persistent data-model change detected: serialized state: src/daemon/systemd.test.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #116129
Summary: This PR explicitly targets the open canonical report about preventing dual user/system systemd gateway registration.

Members:

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

Merge-risk options

Maintainer options:

  1. Confirm the fail-closed upgrade rule (recommended)
    Approve the exact-name fail-closed policy only after confirming that existing Linux operators should resolve system ownership manually rather than having OpenClaw modify a system unit.
  2. Implement managed cross-scope retirement
    Replace the fail-closed branch with a bounded, ownership-verified migration that retires only the conflicting canonical unit and proves rollback behavior.
  3. Pause for daemon ownership policy
    Hold the PR if maintainers have not chosen whether system-scope units are operator-owned or installer-managed during upgrades.

Technical review

Best possible solution:

Adopt one explicit cross-scope ownership policy for canonical gateway units—prefer the proposed fail-closed rule if maintainers want to preserve system units untouched—and ensure the resulting recovery path remains actionable for existing Linux operators.

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

No high-confidence independent reproduction was run in this read-only review. The linked issue and the added test paths make the dual-owner condition source-reproducible, and the PR body reports a live Linux reproduction with a transient /run/systemd/system unit.

Is this the best way to solve the issue?

Unclear. The branch is a coherent way to prevent duplicate ownership, but its fail-closed policy differs from the linked issue's automatic-retirement proposal and needs an explicit maintainer choice before it can be called the best fix.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P1: The linked issue describes a real Linux gateway failure mode involving restart loops and unreliable message delivery when duplicate supervisors own the canonical service.
  • add merge-risk: 🚨 compatibility: The PR changes existing Linux user-systemd install and lifecycle behavior by rejecting operations that previously could proceed.
  • add merge-risk: 🚨 availability: A deliberate or unverifiable system-ownership result now blocks gateway publication or activation until the operator resolves the condition.
  • 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: The contributor is a repository MEMBER, so the external-contributor proof gate does not apply; the PR body nevertheless reports a live Linux systemd check plus focused test proof.

Label justifications:

  • P1: The linked issue describes a real Linux gateway failure mode involving restart loops and unreliable message delivery when duplicate supervisors own the canonical service.
  • merge-risk: 🚨 compatibility: The PR changes existing Linux user-systemd install and lifecycle behavior by rejecting operations that previously could proceed.
  • merge-risk: 🚨 availability: A deliberate or unverifiable system-ownership result now blocks gateway publication or activation until the operator resolves the condition.
  • 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: The contributor is a repository MEMBER, so the external-contributor proof gate does not apply; the PR body nevertheless reports a live Linux systemd check plus focused test proof.

Evidence

What I checked:

  • Linked problem and candidate fix: The PR body formally links the open canonical issue, which describes dual user/system systemd gateway units causing restart loops and unreliable delivery; this branch is a candidate implementation rather than a completed resolution. (8c57a15c2f76)
  • Ownership boundary implementation: The branch adds a dedicated system-manager ownership check and returns conflict or unverifiable outcomes before a user-scope gateway service is mutated. (src/daemon/systemd-system.ts:1, 8c57a15c2f76)
  • Lifecycle integration: The branch imports the ownership assertion into the Linux user-systemd service implementation and calls it before writing the managed unit, making the policy part of the daemon installer boundary rather than a CLI-only message. (src/daemon/systemd.ts:518, 8c57a15c2f76)
  • Regression coverage: The branch adds coverage for forced installs, publication races, rollback, system unit search paths, and ownership failures, including the integration assertion that --force cannot bypass a system owner. (src/cli/daemon-cli/install.integration.test.ts:140, 8c57a15c2f76)
  • Maintainer-controlled decision: The supplied PR context identifies the author as a repository MEMBER and the PR has the protected maintainer label; repository review policy requires the item to remain open for explicit maintainer handling.

Likely related people:

  • vincentkoc: The supplied PR context identifies this MEMBER as the author of the implementation commit and as the assignee on the PR; they are the clearest available routing point for the chosen ownership policy. (role: current daemon-change author and linked-issue assignee; confidence: medium; commits: 8c57a15c2f76; files: src/daemon/systemd.ts, src/daemon/systemd-system.ts, src/daemon/systemd.test.ts)

Rank-up moves

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

  • Obtain explicit maintainer confirmation that system-scope ownership should block rather than be automatically retired.
  • Refresh the final merge review after the policy choice, including the current head's required checks.

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.

@vincentkoc

Copy link
Copy Markdown
Member Author

Maintainer decision: adopt the fail-closed ownership rule in this PR. A same-named system-scope unit is operator-owned; user-scope install/start/restart must stop with recovery guidance, and --force must not bypass that boundary. OpenClaw must not automatically disable or delete the system unit.

This matches the existing launchd ownership policy and keeps cross-scope retirement out of unattended install/update paths. The live /run/systemd/system proof, rollback coverage, and exact-head hosted checks are the merge gates.

@vincentkoc
vincentkoc merged commit d5e3c68 into main Jul 30, 2026
187 of 198 checks passed
@vincentkoc
vincentkoc deleted the fix/systemd-user-install-ownership branch July 30, 2026 01:53
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 30, 2026
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: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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.

Prevent dual-scope systemd gateway registration at install time

1 participant