Skip to content

fix(daemon): legacy systemd unit removal reloads the user manager and stops masking failures - #120027

Merged
steipete merged 3 commits into
mainfrom
steipete/systemd-uninstall-reload
Aug 7, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/systemd-uninstall-reload

Conversation

@steipete

@steipete steipete commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where uninstalling legacy systemd gateway units left the unit startable: uninstallLegacySystemdUnits deleted the unit file but never ran systemctl --user daemon-reload, so the user manager kept the deleted unit's definition loaded — systemctl start still worked while the detector reported the unit gone. Unlink failures other than "file already gone" were also swallowed, reporting successful removal that never happened.

Why This Change Was Made

The sibling path uninstallUserSystemdGatewayUnit already documented and handled this manager-reload invariant; legacy-unit removal now follows the same contract. The already-missing/inactive detection that uninstallSystemdService had inline is extracted into a shared disableSystemdUserUnitForRemoval helper used by all three uninstall paths, non-ENOENT unlink errors propagate instead of printing "not found", and one daemon-reload runs after any unit file was actually removed.

User Impact

openclaw doctor/uninstall flows on Linux leave no ghost systemd units behind, and real removal failures surface instead of being reported as success.

Evidence

  • node scripts/run-vitest.mjs src/daemon/systemd.test.ts — passes, with new regression tests for the reload-after-removal contract, ENOENT tolerance, non-ENOENT propagation, and the shared disable helper's already-missing matching.
  • Codex autoreview (gpt-5.6-sol, high) over the change bundle: clean, no actionable findings.

uninstallLegacySystemdUnits removed unit files without a daemon-reload, so the
user manager kept the deleted unit definitions loaded and startable until an
unrelated reload. Legacy-unit removal now reuses the shared
disable-or-tolerate-missing helper, surfaces non-ENOENT unlink failures instead
of swallowing them, and reloads the user manager once after any unit file was
removed (matching uninstallUserSystemdGatewayUnit).
@steipete
steipete marked this pull request as ready for review August 6, 2026 19:00
@steipete steipete closed this Aug 6, 2026
@steipete steipete reopened this Aug 6, 2026
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S maintainer Maintainer-authored PR labels Aug 6, 2026
@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. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Aug 6, 2026
@clawsweeper

clawsweeper Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed August 7, 2026, 3:38 AM ET / 07:38 UTC.

ClawSweeper review

What this changes

The branch centralizes systemd user-unit disable handling, surfaces legacy removal failures, and reloads the user manager after legacy unit deletion.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

This PR remains necessary but is incorrect: it fixes the reload invariant for legacy and doctor cleanup while leaving the canonical Linux uninstall path without a post-delete manager reload.

Priority: P1
Reviewed head: 24aee85775db1311f31fa69bb3d2c4a05caf144b

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The refactor is focused and partially correct, but the unresolved P1 leaves the central removal invariant incomplete.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored daemon PR is not subject to the external-contributor proof gate; its cited focused Vitest result is supplemental rather than live behavior proof.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored daemon PR is not subject to the external-contributor proof gate; its cited focused Vitest result is supplemental rather than live behavior proof.
Evidence reviewed 5 items Canonical path remains incomplete: At the PR head, canonical uninstall deletes the unit then only cleans environment state and writes output; it never reloads the user manager.
User-facing caller: The Linux service registry routes the normal uninstall operation to the incomplete canonical systemd removal function.
Sibling invariant: The branch reloads after legacy deletion, and the existing doctor user-unit path documents and implements the same post-delete reload invariant.
Findings 1 actionable finding [P1] Reload the manager after canonical-unit removal
Security None None.

How this fits together

OpenClaw’s daemon service layer maps Linux uninstall and Doctor cleanup operations to systemd user units. Those flows disable a unit, remove its file, and must reload the user manager so its loaded definition matches disk state.

flowchart LR
A[Linux uninstall or Doctor] --> B[Service registry]
B --> C[Systemd unit removal]
C --> D[Disable active unit]
D --> E[Delete unit file]
E --> F[Reload user manager]
F --> G[Accurate service state]
Loading

Before merge

  • Reload the manager after canonical-unit removal (P1) - After the canonical unit is unlinked, this path only removes generated environment state and reports success. openclaw uninstall --service routes here, so systemd can retain the deleted definition just as the legacy path did; invoke the reload helper after a successful unlink and cover the ordered call plus reload failure.
  • Resolve merge risk (P1) - Merging as-is leaves normal Linux service uninstall able to report removal while systemd retains the deleted unit definition until a later reload.
  • Complete next step (P2) - A narrow mechanical completion is clear: repair the missing canonical post-delete reload and its regression coverage.

Findings

  • [P1] Reload the manager after canonical-unit removal — src/daemon/systemd.ts:1571
Agent review details

Security

None.

PR surface

Source +29, Tests +90. Total +119 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 48 19 +29
Tests 1 90 0 +90
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 138 19 +119

Review metrics

Metric Value Why it matters
Production versus test delta production +48/-19 (net +29), tests +90/-0 The helper consolidation is justified by a shared removal invariant only once the canonical uninstall path receives the same post-delete reload.

Stored data model

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

Merge-risk options

Maintainer options:

  1. Complete canonical uninstall reload (recommended)
    Call the existing user-manager reload helper after a successful canonical unit unlink and add matching success and reload-failure tests before merge.

Technical review

Best possible solution:

Complete one shared post-delete reload invariant for canonical, legacy, and doctor user-unit removal, with ordered success and reload-failure regression coverage.

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

Yes—source-reproducible with high confidence: successful canonical unlink has no subsequent reload, unlike both sibling removal paths; no live systemd run was executed in this read-only review.

Is this the best way to solve the issue?

No. The shared disable helper is appropriate, but the branch omits the canonical caller used by normal Linux uninstall, so it does not complete the stated invariant.

Full review comments:

  • [P1] Reload the manager after canonical-unit removal — src/daemon/systemd.ts:1571
    After the canonical unit is unlinked, this path only removes generated environment state and reports success. openclaw uninstall --service routes here, so systemd can retain the deleted definition just as the legacy path did; invoke the reload helper after a successful unlink and cover the ordered call plus reload failure.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.99

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: The normal Linux service-uninstall workflow still leaves a ghost unit definition after reporting successful removal.
  • merge-risk: 🚨 compatibility: This changes established uninstall behavior and must preserve accurate service-manager state for existing Linux installations.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer-authored daemon PR is not subject to the external-contributor proof gate; its cited focused Vitest result is supplemental rather than live behavior proof.

Evidence

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs src/daemon/systemd.test.ts.
  • [P1] git diff --check.

What I checked:

  • Canonical path remains incomplete: At the PR head, canonical uninstall deletes the unit then only cleans environment state and writes output; it never reloads the user manager. (src/daemon/systemd.ts:1576, 24aee85775db)
  • User-facing caller: The Linux service registry routes the normal uninstall operation to the incomplete canonical systemd removal function. (src/daemon/service.ts:359, ea4466e5dce5)
  • Sibling invariant: The branch reloads after legacy deletion, and the existing doctor user-unit path documents and implements the same post-delete reload invariant. (src/daemon/systemd.ts:1833, 24aee85775db)
  • Prior finding is unchanged: The two touched files have no changes between the prior reviewed head and the current head, so the previously raised canonical-reload blocker remains. (src/daemon/systemd.ts:1571, 24aee85775db)
  • Systemd contract: The installed systemctl help defines daemon-reload as reloading systemd manager configuration; a disable performed before unlink cannot refresh the later file deletion. (src/daemon/systemd.ts:1576, 24aee85775db)

Likely related people:

  • steipete: Current-main blame and the available systemd history show repeated ownership of the daemon service lifecycle, including the current user-unit cleanup path. (role: recent area contributor; confidence: high; commits: 48ea08918e3f, ae1ab269eb36; files: src/daemon/systemd.ts, src/daemon/systemd.test.ts)
  • Vincent Koc: Recent merged daemon work covers user-systemd failure handling and is adjacent to the removal invariant. (role: adjacent systemd contributor; confidence: medium; commits: 56ca4e2269df; files: src/daemon/systemd.ts)

Rank-up moves

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

  • Add post-unlink reload coverage for canonical uninstall, including reload-failure propagation.
  • Request an exact-head review after the repair and base refresh.

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-06T23:34:13.929Z sha 71c363d :: needs changes before merge. :: [P1] Reload the manager after canonical-unit removal

@steipete
steipete merged commit a672065 into main Aug 7, 2026
255 of 257 checks passed
@steipete
steipete deleted the steipete/systemd-uninstall-reload branch August 7, 2026 08:18
@steipete

steipete commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 8, 2026
… stops masking failures (openclaw#120027)

* fix(daemon): reload systemd user manager after removing legacy units

uninstallLegacySystemdUnits removed unit files without a daemon-reload, so the
user manager kept the deleted unit definitions loaded and startable until an
unrelated reload. Legacy-unit removal now reuses the shared
disable-or-tolerate-missing helper, surfaces non-ENOENT unlink failures instead
of swallowing them, and reloads the user manager once after any unit file was
removed (matching uninstallUserSystemdGatewayUnit).

* chore: re-fire CI

* chore: re-fire CI against fixed main baseline
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 merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant