Skip to content

fix(doctor): resolve legacy systemd unit for the target profile (#119648) - #119685

Closed
licheer-zte wants to merge 1 commit into
openclaw:mainfrom
licheer-zte:doctor-legacy-systemd-profile-119648
Closed

licheer-zte wants to merge 1 commit into
openclaw:mainfrom
licheer-zte:doctor-legacy-systemd-profile-119648

Conversation

@licheer-zte

@licheer-zte licheer-zte commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

openclaw --profile <name> doctor misreported a stopped agent's gateway as running and recommended restarting an unrelated agent's service. Reproduction: host runs several per-profile gateway services; openclaw-lisa.service (legacy naming, pre-openclaw-gateway- rename) is stopped while openclaw-darlene.service runs. Doctor resolved the target installation by scanning every openclaw-* system unit and picking the first marker-owned one — Darlene's — then reported that PID as Lisa's runtime and suggested sudo systemctl restart openclaw-darlene.service. Following that advice takes an unrelated agent offline during an outage.

Why

findSystemSystemdGatewayScope (src/daemon/systemd.ts) tried only the canonical unit name (openclaw-gateway-<profile>.service) and then fell back to findMarkerOwnedSystemSystemdUnit(), a system-wide scan with no profile filter. On multi-agent hosts that scan legitimately returns other agents' units, and the first match was treated as the target's installation. Two compounding gaps: (1) the legacy openclaw-<profile> naming convention was never tried, and (2) the marker fallback never verified the unit belongs to the target profile.

User Impact

Doctor now reports the truth in the outage scenario: a legacy-named unit is resolved as the target's own service (so Runtime: stopped is shown with the correct unit), and when the target's unit genuinely cannot be located, doctor refuses to guess instead of borrowing another agent's running unit. It can no longer recommend restarting a different agent's service.

Evidence

  • [AI-assisted] src/daemon/constants.ts: added resolveLegacyGatewaySystemdServiceName(profile) → openclaw-<profile> (named profiles) / openclaw (default), matching the pre-rename convention from the report.
  • [AI-assisted] src/daemon/systemd.ts:
    • findSystemSystemdGatewayScope now tries the canonical name, then the legacy name for the same profile (skipped when OPENCLAW_SYSTEMD_UNIT overrides the unit), before any scan;
    • the marker-owned fallback now only accepts a unit whose name matches the target profile's canonical or legacy name (isSystemdGatewayUnitNameForProfile); unrelated units (e.g. openclaw-darlene.service for profile lisa) are rejected and resolution returns null — doctor then reports stopped/not-found instead of guessing. The intentional "separate gateway with a different name" case (issue Upgrade leaves stale user-level systemd unit, dueling services kill each other on Linux #79375 dueling test) is preserved.
  • Tests (src/daemon/systemd.test.ts, src/daemon/constants.test.ts):
    • legacy openclaw-<profile> system unit resolves for a named profile;
    • unrelated marker-owned unit is refused for the target profile;
    • marker-owned unit matching the profile's legacy name is accepted;
    • readSystemdServiceRuntime reads the legacy unit's own systemctl show (inactive → stopped, unit openclaw-lisa.service);
    • legacy-name resolver unit tests (default/named/"default" normalization).
  • pnpm vitest run src/daemon/systemd.test.ts → 145 passed; src/daemon/constants.test.ts → 24 passed; tsgo core typecheck clean.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. and removed triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Aug 5, 2026
@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. 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 5, 2026
@clawsweeper

clawsweeper Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 5, 2026, 1:49 PM ET / 17:49 UTC.

ClawSweeper review

What this changes

The PR makes Doctor resolve same-profile legacy systemd unit names before scanning host-wide units and rejects scanned units whose names do not match the selected profile.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Blocked until real behavior proof from a real setup is added - 7 items remain

Keep this PR open: it repairs the profile-blind fallback at the right owner boundary, but a P1 path still ignores an explicit systemd-unit override and can target a different service. It also needs after-fix real systemd behavior proof before merge.

Priority: P1
Reviewed head: a7767a4f5b3999ac74bcbaffdeab290928249a7b

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The root-boundary direction is sound, but the explicit-override regression and absent real behavior proof leave the PR not ready to merge.
Proof confidence 🧂 unranked krab (1/6) Needs real behavior proof before merge: The PR lists unit tests and typechecking, but no after-fix execution against a real systemd setup or redacted terminal artifact; add one before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The PR lists unit tests and typechecking, but no after-fix execution against a real systemd setup or redacted terminal artifact; add one before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 5 items Current defect owner path: Current main's marker-owned system-unit scan returns the first OpenClaw-marked unit without a profile constraint, and that scope is treated as the selected installation.
Operator-visible consumers: The resolved scope feeds both systemd restart advice and runtime reporting, so an incorrectly adopted unit can direct an operator to restart a different gateway.
Override regression in the patch: The direct legacy probe skips an explicit override, but the new marker fallback still accepts the same profile's legacy name; a missing custom override can therefore adopt openclaw-lisa.service.
Findings 1 actionable finding [P1] Honor explicit systemd unit overrides in marker fallback
Security None None.

How this fits together

Doctor maps a selected OpenClaw profile to its systemd gateway unit, then uses that unit for runtime status and restart guidance. The resolver must preserve profile and explicit-unit identity so an outage diagnosis never acts on another gateway.

flowchart LR
A[Doctor profile request] --> B[Profile and unit override]
B --> C[Systemd unit resolver]
C --> D{Matching target unit?}
D -->|yes| E[Runtime status and restart guidance]
D -->|no| F[Report unit not found]
E --> G[Operator action]
Loading

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The PR lists unit tests and typechecking, but no after-fix execution against a real systemd setup or redacted terminal artifact; add one before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Honor explicit systemd unit overrides in marker fallback (P1) - With OPENCLAW_SYSTEMD_UNIT=custom-lisa, a missing custom unit and scanned openclaw-lisa.service still reach this fallback and become the target. Runtime and restart guidance then act on that substituted service despite the explicit identity. Disable marker adoption when an override is present and add this regression case.
  • Resolve merge risk (P2) - With OPENCLAW_SYSTEMD_UNIT set to a missing custom unit, the new marker fallback can still adopt a same-profile legacy unit and send runtime/restart actions to the wrong configured service.
  • Resolve merge risk (P1) - The PR body provides mocked tests and typechecking only; no after-fix systemd terminal trace or equivalent real behavior artifact is available.
  • Complete next step (P2) - A narrow changed-line repair and regression test can remove the remaining explicit-override misrouting path; contributor-supplied real behavior proof remains required afterward.
  • Improve patch quality - Honor OPENCLAW_SYSTEMD_UNIT during marker fallback and add the focused regression test.
  • Improve patch quality - Attach a redacted terminal trace from a multi-profile or equivalent systemd setup showing the intended unit alone is selected.

Findings

  • [P1] Honor explicit systemd unit overrides in marker fallback — src/daemon/systemd.ts:242-251
Agent review details

Security

None.

PR surface

Source +65, Tests +92. Total +157 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 69 4 +65
Tests 2 92 0 +92
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 161 4 +157

Review metrics

Metric Value Why it matters
Production vs test LOC production +69/-4; tests +92/-0 The production growth is justified by profile-safe legacy unit resolution, but the remaining override path needs correction before that safety claim holds.

Merge-risk options

Maintainer options:

  1. Preserve explicit unit identity (recommended)
    Prevent marker fallback when OPENCLAW_SYSTEMD_UNIT is set, add the missing override regression, and provide an after-fix systemd trace before merge.
  2. Pause the change
    Hold the PR if preserving an explicit override while its unit is absent is not the intended Doctor contract.

Technical review

Best possible solution:

Make an explicit OPENCLAW_SYSTEMD_UNIT disable marker-based adoption, add the override regression, and attach a redacted terminal trace showing Doctor selects only the intended unit.

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

Yes, from source: configure a missing custom OPENCLAW_SYSTEMD_UNIT and expose a scanned matching legacy unit; the new fallback adopts that legacy unit despite the override.

Is this the best way to solve the issue?

No. Canonical then same-profile legacy lookup is the right repair, but the marker fallback must honor an explicit unit override rather than substituting a discovered unit.

Full review comments:

  • [P1] Honor explicit systemd unit overrides in marker fallback — src/daemon/systemd.ts:242-251
    With OPENCLAW_SYSTEMD_UNIT=custom-lisa, a missing custom unit and scanned openclaw-lisa.service still reach this fallback and become the target. Runtime and restart guidance then act on that substituted service despite the explicit identity. Disable marker adoption when an override is present and add this regression case.
    Confidence: 0.97

Overall correctness: patch is incorrect
Overall confidence: 0.95

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add merge-risk: 🚨 availability: A wrongly adopted service can produce restart guidance that disrupts an unrelated running gateway.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🧂 unranked krab, so this older rating label is no longer current.

Label justifications:

  • P1: Doctor can still direct an operator to act on the wrong gateway during an outage when an explicit unit override is unresolved.
  • merge-risk: 🚨 compatibility: The patch changes legacy systemd discovery around the existing OPENCLAW_SYSTEMD_UNIT operator setting.
  • merge-risk: 🚨 availability: A wrongly adopted service can produce restart guidance that disrupts an unrelated running gateway.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR lists unit tests and typechecking, but no after-fix execution against a real systemd setup or redacted terminal artifact; add one before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs src/daemon/systemd.test.ts.
  • [P1] node scripts/run-vitest.mjs src/daemon/constants.test.ts.
  • [P1] Run Doctor against a redacted systemd setup with an explicit missing custom unit and a scanned legacy unit; confirm it refuses substitution.

What I checked:

  • Current defect owner path: Current main's marker-owned system-unit scan returns the first OpenClaw-marked unit without a profile constraint, and that scope is treated as the selected installation. (src/daemon/systemd.ts:117, e17bc5887707)
  • Operator-visible consumers: The resolved scope feeds both systemd restart advice and runtime reporting, so an incorrectly adopted unit can direct an operator to restart a different gateway. (src/daemon/systemd.ts:1590, e17bc5887707)
  • Override regression in the patch: The direct legacy probe skips an explicit override, but the new marker fallback still accepts the same profile's legacy name; a missing custom override can therefore adopt openclaw-lisa.service. (src/daemon/systemd.ts:242, a7767a4f5b39)
  • Existing identity contract: Gateway CLI documentation supports an explicit systemd-unit identity, which must take precedence over discovery fallback. Public docs: docs/cli/gateway.md. (docs/cli/gateway.md:152, e17bc5887707)
  • Recent area ownership: Recent daemon lifecycle consolidation is in the PR base commit, making its author the strongest available routing signal; deeper blame history could not be materialized from this partial clone. (src/daemon/systemd.ts:189, 36554c282008)

Likely related people:

  • steipete: Recent daemon lifecycle consolidation at the PR base is the strongest available history signal for this resolver path. (role: recent daemon lifecycle contributor; confidence: medium; commits: 36554c282008; files: src/daemon/systemd.ts, src/daemon/constants.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-05T17:16:45.578Z sha a7767a4 :: needs real behavior proof before merge. :: [P2] Scan beyond an unrelated marker-owned unit

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 5, 2026
@vincentkoc vincentkoc added close:duplicate Closed as duplicate dedupe:child Duplicate issue/PR child in dedupe cluster labels Aug 5, 2026
@vincentkoc vincentkoc self-assigned this Aug 5, 2026
@vincentkoc

Copy link
Copy Markdown
Member

Closing this as a duplicate repair lane of #119674, not as fixed.

Both PRs target #119648 at the same owner boundary: current/legacy profile candidates in src/daemon/constants.ts, installed unit selection in src/daemon/systemd.ts, and regression coverage in src/daemon/systemd.test.ts. #119674 opened first and now contains the broader contract work: it preserves explicit OPENCLAW_SYSTEMD_UNIT identity across user/system discovery and rejects unrelated marker-owned units. This branch overlaps that repair but still allows a missing explicit override to fall through to a same-profile legacy unit, so it is not the safer branch to continue.

#119674 is still blocked. Its current head must preserve the documented default-profile custom-unit discovery contract and add real multi-unit Linux Doctor/systemctl proof before merge. Closing this PR does not approve or merge #119674; it keeps one repair lane for the remaining work.

Thanks @licheer-zte for the focused legacy-name analysis and regression tests. This PR and commit remain linked for credit; if code from this branch is reused, we must preserve commit authorship.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

close:duplicate Closed as duplicate dedupe:child Duplicate issue/PR child in dedupe cluster gateway Gateway runtime 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: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants