Skip to content

fix(gateway): recognize system-scope systemd ownership in status and maintenance checks - #149055

Merged
steipete merged 4 commits into
mainfrom
upd/systemd-scope-ownership-149009
Sep 16, 2026
Merged

steipete merged 4 commits into
mainfrom
upd/systemd-scope-ownership-149009

Conversation

@steipete

@steipete steipete commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #149009

What Problem This Solves

Fixes system-scope Gateway installations being labeled as user services, offered destructive cleanup advice, and rejected during offline Doctor maintenance because effective command and loaded-runtime inspection queried the user manager.

Reported by @cookywook (#149009).

User Impact

Installed system units are inspected at their actual scope. Status names the observed manager, excludes the observed unit from extra-service warnings, and shows the existing competing-supervisor diagnosis when both scopes are installed. Linux discovery offers inspection commands instead of unconditional disable/remove commands.

After the system service owner stops the Gateway, Doctor can verify its offline state from the service's non-root account. System-owned definitions remain sealed; this does not grant service-control privileges or create a user unit.

Release-note context: system-scope installations on 2026.9.2–2026.9.4 could receive false user/extra-service diagnostics and blocked offline doctor --fix checks. Valid Control UI config writes do not directly use this gate; repairing invalid configuration through Doctor can unblock their prerequisite.

Why This Change Was Made

The shared service reader now carries the existing scope discovery result through command, runtime, and definition-capability inspection. System-manager reads verify the native manager UID separately from the Gateway's User= account and preserve the existing non-activating admission rules. A missing unit at the queried scope is no longer described as a stopped service.

Scope discovery remains limited to the existing installed-unit and marker paths. Runtime/generated-only and fileless transient units are not newly supported. Automatic managed-update handoff for system units retains its existing manual-update requirement.

Evidence

  • 920 focused tests passed, including the real service-adapter-to-maintenance boundary, user/system/neither/competing-scope cases, status, cleanup guidance, and service-definition protection.
  • Regressions were run with the production fix reversed: the maintenance path failed with the user-session-bus error, the system reader queried the wrong manager, missing-at-scope was reported stopped, and status emitted disable/remove advice. The same tests pass with the fix.
  • Real Linux baseline on systemd 255: published 2026.9.4 reported a healthy system unit as systemd user, then doctor --fix exited 1 with the reported ownership/shutdown refusal after the unit was stopped. Testbox run.
  • On the same Testbox, the candidate completed offline Doctor repair with the system unit byte-for-byte unchanged and no user unit created. After restarting through the system owner, status reported systemd system, scope: system, RPC success, and zero extra services. The user-unit sibling installation/start also passed with systemd user, scope: user, and RPC success.
  • node scripts/check-changed.mjs passed, including production/test typechecking, lint, schema and ownership guards, and zero runtime import cycles. The final reader refactor also passed 325 focused tests.
  • CI exposed a host-dependent mock label in the status timeout test. The fixture now selects its label explicitly, and the timeout test runs under both Linux and macOS settings with its assertions unchanged: 109 status-gather tests and scoped changed-file checks passed. Production code is unchanged from the live proof.
  • Earlier-head CI infrastructure gap: actionlint job exited 124 while fetching trusted audit configuration from refs/heads/main; workflow linting never ran. This PR changes no workflow or guard scripts. Cancelled dependency/security guard jobs were rerun once and passed.
  • Landing refresh: rebased all three reviewed commits onto current main at d363685cab9fd6c6202998216cf945c46a195904, which contains the upstream fix for the attribution test fixture at 273b6c5e114. git range-diff contains only identical commit mappings, with no patch differences and no other branch changes. Rebased head before the warning follow-up: 325cd67dab198d44a12b6f8e0ae5f660b9e25176. CI for that rebased head passed with 147 successful checks and 42 skipped checks.
  • No configuration option, dependency, database schema, or persistent recovery format changed.

ClawSweeper review

Applied the P2 finding: the status renderer no longer independently derives a competing-supervisor warning from service metadata. The gatherer owns the target-aware verdict; managed-service status prints its warning once, while unrelated explicit --url and --port targets print none.

Regression proof: node scripts/run-vitest.mjs src/cli/daemon-cli/status.print.test.ts -t 'renders the gathered supervisor warning once' failed before the deletion in all three cases (managed expected 1 warning, received 2; URL and port expected 0, received 1). With the same assertions and the 11-line production deletion, node scripts/run-vitest.mjs src/cli/daemon-cli/status.print.test.ts src/cli/daemon-cli/status.gather.test.ts passed: 176 tests passed, one platform-specific skip. The gather-to-print coverage now checks both stdout and stderr.

node scripts/check-changed.mjs -- src/cli/daemon-cli/status.print.ts src/cli/daemon-cli/status.print.test.ts src/cli/daemon-cli/status.gather.test.ts passed, including production/test typechecking, lint, and ownership guards. Independent branch review at P1 is scoped-clean (confidence 0.85) for follow-up head 00a4b5e35906f362d6faefd7b94df5baea743de3. The earlier CI run failed on an unrelated duplicate-case lint error in the base/merge context; ClawSweeper revision 9, reviewed at 2026-09-15 20:12 UTC on this exact head, confirms the P2 and its rank-up request are resolved and reports no remaining correctness or security findings. No other production behavior changed. The archived-log access concern reflects the review environment; the recorded real Linux observations cover system/user status, offline Doctor, unchanged system definitions, and no competing user unit. The generic data-model flag is not applicable: no schema, stored format, retention, or recovery format changes. A full published-driver-to-candidate update was not run; automatic system-unit update handoff retains its existing manual-update requirement.

Latest landing refresh

Rebased onto main d3930e1641997f9f5c5c9f53cda7cfd0bbe5c595, which contains the trusted-sibling alias-wrapper fix. Current head: cbaac7e6aa880bc361dea817373ab467e8027360. All four patches are unchanged: git range-diff reports four identical mappings. The P1 scoped-clean review and ClawSweeper revision 9 cover these unchanged patches. Fresh exact-head CI passed. The standard exact-head watcher reported GREEN with zero pending checks and five superseded contexts; no rerun was needed on this head.

@clawsweeper

clawsweeper Bot commented Sep 15, 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.

@steipete
steipete marked this pull request as ready for review September 15, 2026 11:56
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime cli CLI command changes commands Command implementations size: XL maintainer Maintainer-authored PR labels Sep 15, 2026
@steipete
steipete force-pushed the upd/systemd-scope-ownership-149009 branch from bc7b9f0 to 233f0c9 Compare September 15, 2026 12:56
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 15, 2026
@clawsweeper

clawsweeper Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 15, 2026, 9:36 PM ET / September 16, 2026, 01:36 UTC (Revision 13).

ClawSweeper review

What this changes

The PR makes Gateway status and Doctor inspect the installed systemd scope, preserve system-owned definitions, and offer inspection commands instead of unverified removal advice.

Merge readiness

⛔ Blocked before merge - 3 items remain

This remains a useful fix absent from inspected main. The previous duplicate-warning finding is resolved, and no additional blocking code defect was established.

Priority: P2
Reviewed head: cbaac7e6aa880bc361dea817373ab467e8027360

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent repair with meaningful Linux proof and resolved review findings; upgrade compatibility still needs validation.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Recorded systemd 255 observations exercise the changed service readers through real status and offline Doctor: scope labels and RPC succeed, system definitions remain unchanged, and no competing user unit appears. This proves the central repair, while complete updater compatibility remains separately unproven.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Recorded systemd 255 observations exercise the changed service readers through real status and offline Doctor: scope labels and RPC succeed, system definitions remain unchanged, and no competing user unit appears. This proves the central repair, while complete updater compatibility remains separately unproven.
Evidence reviewed 7 items Pinned introduction and current-main necessity: The host pins introduction to d3930e1..cbaac7e. Independent comparison with fetched main still shows the scope propagation and corrected service label as branch changes.
Published behavior: The v2026.9.4 service adapter labels Linux services systemd user and does not propagate a selected system-scope read target. The release file was inspected through GitHub after local historical-blob retrieval failed.
Upgrade-sensitive refusal: The introduced guard rejects strict inspection when the same unit name exists in both scopes. Doctor and update call this reader with both strict flags; the maintenance caller converts ordinary errors into its generic inspection refusal. This establishes the compatibility surface behind the prior upgrade-proof request, without proving loss of the previous Gateway.
Findings None None.
Security None None.

How this fits together

Gateway service inspection reads Linux service definitions and manager state for status, Doctor, and update maintenance. Its results determine diagnostic output and whether maintenance can safely proceed.

flowchart TD
  A[Installed service definitions] --> B[Scope discovery]
  B --> C[User or system manager]
  C --> D[Verified command and runtime]
  D --> E[Status and inspection guidance]
  D --> F[Doctor and update admission]
  F --> G[Maintenance or ownership refusal]
Loading

Before merge

  • Resolve merge risk (P1) - Existing installations with the same unit in both scopes now encounter strict maintenance refusal. Complete published-updater compatibility, actionable recovery, and preservation or restoration of the previous Gateway remain unverified.
  • Complete next step (P2) - Provide published v2026.9.4 updater-to-candidate evidence for competing scopes, including actionable refusal or recovery and confirmation that the previous Gateway remains running or is restored.
  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +146, Tests +594, Docs +8. Total +748 across 29 files.

View PR surface stats
Area Files Added Removed Net
Source 17 273 127 +146
Tests 11 734 140 +594
Docs 1 8 0 +8
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 29 1015 267 +748

Review metrics

Metric Value Why it matters
Production versus regression coverage production +146 net lines; tests +594 net lines Production growth extends existing service readers, while most growth protects scope selection, maintenance admission, and diagnostic behavior.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/commands/doctor-format.ts, migration/backfill/repair: src/daemon/service.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #149009
Summary: This PR is the explicit candidate fix for the open system-scope diagnostic and maintenance report.

Members:

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

Merge-risk options

Maintainer options:

  1. Verify the published update path (recommended)
    Supply published-driver-to-candidate evidence showing how competing scopes are diagnosed and recovered without leaving the previous Gateway unavailable.

Technical review

Best possible solution:

Keep scope-aware inspection under the existing service owner, with demonstrated upgrade recovery and system-owned definitions left intact.

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

Yes: current-main service readers still omit system-scope propagation, and the PR records a matching real Linux baseline failure. This read-only review did not execute target code.

Is this the best way to solve the issue?

Yes: extending the existing scope detector and service readers avoids a competing implementation; complete update compatibility remains the outstanding validation gate.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This repairs misleading Linux service diagnostics and blocked offline maintenance for a bounded deployment shape.
  • merge-risk: 🚨 compatibility: The new competing-scope refusal changes maintenance admission for existing installations without complete published-updater recovery evidence.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): Recorded systemd 255 observations exercise the changed service readers through real status and offline Doctor: scope labels and RPC succeed, system definitions remain unchanged, and no competing user unit appears. This proves the central repair, while complete updater compatibility remains separately unproven.
  • proof: sufficient: Contributor real behavior proof is sufficient. Recorded systemd 255 observations exercise the changed service readers through real status and offline Doctor: scope labels and RPC succeed, system definitions remain unchanged, and no competing user unit appears. This proves the central repair, while complete updater compatibility remains separately unproven.

Evidence

What I checked:

  • Pinned introduction and current-main necessity: The host pins introduction to d3930e1..cbaac7e. Independent comparison with fetched main still shows the scope propagation and corrected service label as branch changes. (src/daemon/service.ts:225, cbaac7e6aa88)
  • Published behavior: The v2026.9.4 service adapter labels Linux services systemd user and does not propagate a selected system-scope read target. The release file was inspected through GitHub after local historical-blob retrieval failed. (src/daemon/service.ts:415, 3a9d69db306c)
  • Upgrade-sensitive refusal: The introduced guard rejects strict inspection when the same unit name exists in both scopes. Doctor and update call this reader with both strict flags; the maintenance caller converts ordinary errors into its generic inspection refusal. This establishes the compatibility surface behind the prior upgrade-proof request, without proving loss of the previous Gateway. (src/daemon/service.ts:233, cbaac7e6aa88)
  • Resolved previous finding: The printer consumes the gathered warning once; the gatherer limits its diagnosis to the native service target. Added coverage checks managed, explicit-URL, and explicit-port warning counts. The previous completed review used this same head, and comparison confirms no subsequent changes to these paths. (src/cli/daemon-cli/status.print.ts:279, cbaac7e6aa88)
  • Recorded real Linux proof and explicit coverage boundary: The fully supplied PR body records systemd 255 baseline failure on published 2026.9.4, successful candidate offline Doctor repair, unchanged system-unit bytes, no user unit created, and successful system/user status and RPC checks. It explicitly says a complete published-driver-to-candidate update was not run. The linked Testbox run is https://github.com/openclaw/openclaw/actions/runs/34963238113; its cancelled workflow status neither proves nor disproves the recorded interactive observations. Archived-log retrieval was blocked by the review environment's storage-host allowlist. Captured context sourceRevision: 29d2d1a5b16d63e45f8758cff2709df0579615432551c58e2335124766a8100d.
  • Authority remains separated from inspection: System command inspection verifies manager UID 0 and the service account; loaded-runtime inspection compares manager identity and native transitions. System definitions return a sealed capability, while the existing lifecycle owner independently requires root before system service control. No new dependency, workflow, schema, or persisted authority format is introduced. (src/daemon/systemd-service-files.ts:220, cbaac7e6aa88)

Likely related people:

  • fuller-stack-dev: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

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

  • Add published-driver-to-candidate upgrade evidence covering competing scopes, useful recovery guidance, and preservation or restoration of the previous Gateway.

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 (12 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-15T15:32:35.059Z sha 0e6221f :: blocked before merge. :: [P2] Keep competing-supervisor warnings tied to the native target
  • reviewed 2026-09-15T16:50:47.147Z sha 40dea55 :: blocked before merge. :: [P2] Keep competing-supervisor warnings tied to the native target
  • reviewed 2026-09-15T18:16:19.844Z sha 2bc6865f2c0184e3adb4f3a603c8ba0aa279f82d :: blocked before merge. :: [P2] Keep competing-supervisor warnings tied to the native target
  • reviewed 2026-09-15T18:43:22.661Z sha 325cd67 :: blocked before merge. :: [P2] Keep competing-supervisor warnings tied to the native target
  • reviewed 2026-09-15T20:12:34.616Z sha 00a4b5e35906f362d6faefd7b94df5baea743de3 :: blocked before merge. :: none
  • reviewed 2026-09-15T21:11:30.292Z sha ad81e89 :: blocked before merge. :: none
  • reviewed 2026-09-15T22:50:21.333Z sha cef00585458d25ec40ae0f4faff698fd78be13ec :: blocked before merge. :: none
  • reviewed 2026-09-16T01:00:31.986Z sha cbaac7e :: blocked before merge. :: none

@steipete
steipete force-pushed the upd/systemd-scope-ownership-149009 branch from d9d0b59 to 68ee3f0 Compare September 15, 2026 14:17
@clawsweeper clawsweeper Bot added 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. and removed 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 15, 2026
@steipete
steipete force-pushed the upd/systemd-scope-ownership-149009 branch 2 times, most recently from 0e6221f to 40dea55 Compare September 15, 2026 16:42
@steipete
steipete force-pushed the upd/systemd-scope-ownership-149009 branch 2 times, most recently from 2bc6865 to 325cd67 Compare September 15, 2026 18:27
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Addressed the P2 at head 00a4b5e35906f362d6faefd7b94df5baea743de3: removed the duplicate printer-owned supervisor diagnosis. The gatherer remains the sole owner; managed-service status emits its warning once and explicit URL/port targets emit none. All three cases failed before the deletion for the expected warning counts and pass after it. The full status printer/gatherer suites passed (176 tests, one platform-specific skip), as did changed-file checks. Details are in the PR body.

@clawsweeper

clawsweeper Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Sep 15, 2026
@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 15, 2026
@steipete
steipete force-pushed the upd/systemd-scope-ownership-149009 branch 2 times, most recently from ad81e89 to cef0058 Compare September 15, 2026 21:58
Carry the installed scope through effective command and loaded-runtime
inspection, verify the service account separately from the manager, and
preserve system-owned definitions during offline Doctor repair. Report the
observed scope and competing supervisors, and replace unverified Linux
cleanup commands with inspection guidance.

Reported by @cookywook (#149009). System-scope installs on 2026.9.2 through
2026.9.4 could receive misleading service diagnostics and fail offline
Doctor maintenance.
@steipete
steipete force-pushed the upd/systemd-scope-ownership-149009 branch from cef0058 to cbaac7e Compare September 16, 2026 00:53
@steipete
steipete merged commit 8afc393 into main Sep 16, 2026
199 of 200 checks passed
@steipete
steipete deleted the upd/systemd-scope-ownership-149009 branch September 16, 2026 01:37
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 16, 2026
…maintenance checks (openclaw#149055)

Inspect installed Gateway systemd units at their actual user or system scope. Carry the selected manager through command and runtime inspection, report its scope accurately, and avoid listing the owned unit as an extra service or suggesting its removal.

After the system service owner stops the Gateway, Doctor can verify offline maintenance from the service's User= account. System-owned definitions stay sealed, competing supervisors remain explicit, and unverifiable ownership still blocks maintenance. Automatic system-unit update handoff retains its existing manual-update requirement.

Fixes openclaw#149009.
Reported by @cookywook (openclaw#149009).

The status gatherer remains the sole owner of competing-supervisor warnings: managed-service status prints its warning once, while unrelated explicit URL/port targets print none.

Validation: the warning regression failed before the deletion in all three cases and passed after it. The full status printer/gatherer suites passed (176 tests, one platform-specific skip), changed-file checks passed, and independent branch review at P1 is scoped-clean. The PR records regression failure before the fix, passing focused and changed-file checks, and live Linux system/user service proof. Exact-head CI and the completed ClawSweeper review are linked in the PR body; the broader published-updater validation gap is recorded there.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes commands Command implementations docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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.

gateway status --deep false-positive service-ownership check on system-scope units; suggests commands that would kill the running service

1 participant