Skip to content

fix(systemd): clear start-limit latch before gateway start - #116178

Merged
vincentkoc merged 4 commits into
openclaw:mainfrom
miorbnli:fix/systemd-start-limit-latch
Jul 30, 2026
Merged

vincentkoc merged 4 commits into
openclaw:mainfrom
miorbnli:fix/systemd-start-limit-latch

Conversation

@miorbnli

@miorbnli miorbnli commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where operators running openclaw gateway start could not recover
a systemd-managed gateway after repeated crashes tripped systemd's start-limit
latch. restart already cleared that latch, but start did not.

Fixes #116177.

Why This Change Was Made

Run systemctl reset-failed before both start and restart, while leaving
stop unchanged. The change stays in the shared systemd service-action owner,
after the existing system-unit ownership guard for user services. No config,
protocol, or new command surface is added.

User Impact

openclaw gateway start now recovers a crash-looped systemd gateway instead of
returning a start-limit failure that requires an undocumented manual
systemctl reset-failed.

Evidence

Real managed-gateway CLI recovery

Validated on Linux with systemd 255 running as PID 1, using the built OpenClaw
CLI and a real OpenClaw-managed user gateway:

  1. openclaw gateway install --json installed and enabled
    openclaw-gateway.service.
  2. A controlled crashing gateway process forced three rapid restarts. The unit
    reached failed, with NRestarts=3.
  3. Raw systemctl --user start openclaw-gateway.service returned nonzero;
    systemctl status reported Start request repeated too quickly.
  4. After switching the gateway process healthy,
    openclaw gateway start --json succeeded and the unit reached
    ActiveState=active.
  5. strace captured this ordering from the real CLI:
systemctl --user reset-failed openclaw-gateway.service
systemctl --user start openclaw-gateway.service

Lifecycle controls on the same managed gateway:

  • Starting an already-active healthy gateway returned already-running, kept
    the same main PID, and issued no reset-failed.
  • openclaw gateway stop --force --json reached inactive and issued stop
    without reset-failed.
  • Starting the clean inactive gateway reached active with
    reset-before-start ordering.

Hosted build and Linux proof:
https://github.com/openclaw/openclaw/actions/runs/30511918775

Focused tests

node scripts/run-vitest.mjs src/daemon/systemd.test.ts passed 129/129.

Coverage includes:

  • system-scope start issues reset-failed before start;
  • user-scope start issues reset-failed before start;
  • start still proceeds when reset-failed cannot resolve an unloaded unit;
  • stop issues only stop;
  • existing restart ordering and ownership-guard coverage remain green.

Targeted formatting and git diff --check passed.

Autoreview

Structured Codex autoreview on final head 49c4237bcb4 found no
accepted/actionable findings. TruffleHog and git diff --check were clean.

Remaining proof boundary

The real managed user-scope CLI path is fully exercised. A separate synthetic
system-scope CLI control could not complete because the isolated Testbox root
environment was rejected by OpenClaw's canonical service-target guard. The
system-scope command ordering is covered by the focused unit test and uses the
same runSystemdServiceAction implementation.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: XS labels Jul 30, 2026
@miorbnli
miorbnli force-pushed the fix/systemd-start-limit-latch branch from 924d6c7 to 0fea36c Compare July 30, 2026 02:26
@miorbnli
miorbnli marked this pull request as ready for review July 30, 2026 02:26
@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: 🚨 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 30, 2026, 12:26 AM ET / 04:26 UTC.

ClawSweeper review

What this changes

Updates gateway systemd start handling so a managed user or system unit has its failed/start-limit latch cleared before start, matching the existing restart recovery behavior while leaving stop unchanged.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep this PR open for normal maintainer review. It addresses the linked systemd recovery bug with focused service-action changes, supplied real Linux/systemd proof, and targeted coverage; no concrete patch defect is established, but the availability-sensitive start-path behavior should be accepted on the current head rather than auto-closed or auto-repaired.

Priority: P1
Reviewed head: a75ac9eb0f01dfaf690296d527c75ea3ac8f5168

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Focused implementation, regression coverage, and real CLI proof make this a solid availability repair awaiting ordinary maintainer acceptance.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The PR body provides after-fix real systemd gateway recovery evidence from the built CLI, including command ordering and an observed active service result.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body provides after-fix real systemd gateway recovery evidence from the built CLI, including command ordering and an observed active service result.
Evidence reviewed 4 items Changed service-action behavior: The PR changes both system-scope and user-scope service actions from clearing the latch only for restart to clearing it for every non-stop action, after the user-scope ownership guard.
Focused regression coverage: The branch adds tests for system-scope reset-before-start ordering, user-scope ordering, reset-failed failure tolerance, and stop remaining free of reset-failed.
Real behavior proof supplied: The PR body records a real systemd 255 user-service recovery: a crash-looped unit rejected raw start, then the built OpenClaw CLI reset the latch before start and reached active state; the supplied strace records the command ordering.
Findings None None.
Security None None.

How this fits together

The gateway CLI delegates start, restart, and stop requests to the shared systemd service-control helper. That helper checks service ownership, invokes systemctl for the selected scope, and reports the resulting gateway lifecycle outcome to the operator.

flowchart LR
  A[Operator runs gateway start] --> B[Gateway service control]
  B --> C[Check unit scope and ownership]
  C --> D[Clear failed start-limit latch]
  D --> E[Run systemctl start]
  E --> F[Gateway becomes active or reports failure]
Loading

Before merge

  • Resolve merge risk (P1) - This changes every systemd start path to perform an additional lifecycle command; maintainers should accept that recovery-oriented availability behavior on the exact merge head after the required checks complete.
Agent review details

Security

None.

PR surface

Source -2, Tests +56. Total +54 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 5 7 -2
Tests 1 56 0 +56
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 61 7 +54

Review metrics

None.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #116177
Summary: This PR is the focused candidate fix for the linked report about systemd start-limit recovery.

Members:

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

Merge-risk options

Maintainer options:

  1. Accept the recovery-first start behavior (recommended)
    Merge after confirming the exact head retains the tested non-blocking reset-failed handling, because this deliberately changes the availability path used by every systemd gateway start.

Technical review

Best possible solution:

Land the narrow shared-helper fix if the current merge head preserves reset-before-start ordering, ownership guards, reset-failure tolerance, and stop isolation across both system and user scopes.

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

Yes. The PR supplies a concrete Linux systemd 255 path that drives a managed gateway into start-limit failure, observes raw start rejection, then demonstrates successful OpenClaw CLI recovery after the process becomes healthy.

Is this the best way to solve the issue?

Yes. Extending the existing shared systemd action owner preserves the established restart recovery contract for start without adding configuration, a parallel workflow, or a new command surface.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: A systemd-managed gateway that has tripped its start limit cannot recover through the natural gateway start command without this repair.
  • merge-risk: 🚨 availability: The patch adds a systemctl operation before every systemd start, so an incorrect failure-handling or ordering change could block gateway recovery.
  • 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 (terminal): The PR body provides after-fix real systemd gateway recovery evidence from the built CLI, including command ordering and an observed active service result.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides after-fix real systemd gateway recovery evidence from the built CLI, including command ordering and an observed active service result.

Evidence

What I checked:

  • Changed service-action behavior: The PR changes both system-scope and user-scope service actions from clearing the latch only for restart to clearing it for every non-stop action, after the user-scope ownership guard. (src/daemon/systemd.ts:1593, a75ac9eb0f01)
  • Focused regression coverage: The branch adds tests for system-scope reset-before-start ordering, user-scope ordering, reset-failed failure tolerance, and stop remaining free of reset-failed. (src/daemon/systemd.test.ts:862, a75ac9eb0f01)
  • Real behavior proof supplied: The PR body records a real systemd 255 user-service recovery: a crash-looped unit rejected raw start, then the built OpenClaw CLI reset the latch before start and reached active state; the supplied strace records the command ordering. (a75ac9eb0f01)
  • Related bug remains the canonical problem report: The linked issue describes the same start-limit recovery failure and remains open while this unmerged PR is its candidate fix. (src/daemon/systemd.ts:1611, a75ac9eb0f01)

Likely related people:

  • vincentkoc: Assigned to this PR and authored the final branch commit that extends the systemd tests for reset failure and stop controls. (role: recent reviewer and test contributor; confidence: medium; commits: a75ac9eb0f01; files: src/daemon/systemd.test.ts)

Rank-up moves

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

  • Confirm the required checks and exact merge head still preserve the tested reset-failed failure tolerance.

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 (7 earlier review cycles)
  • reviewed 2026-07-30T02:30:13.365Z sha 0fea36c197855b3f278206060bf4fcbb37720b93 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-30T03:01:51.825Z sha 7e8b7dcb3dd888946663cd998fe968ebc20ca409 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-30T03:13:45.773Z sha 7e8b7dcb3dd888946663cd998fe968ebc20ca409 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-30T03:20:38.127Z sha d60e73a8fbf7487ca4550565ead39d5d99099e73 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-30T03:40:20.984Z sha d60e73a8fbf7487ca4550565ead39d5d99099e73 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-30T04:01:56.096Z sha 49c4237bcb4ac52ff2b68322f1e26963601b1c0b :: needs maintainer review before merge. :: none
  • reviewed 2026-07-30T04:12:03.319Z sha a75ac9e :: needs maintainer review before merge. :: none

@vincentkoc vincentkoc self-assigned this Jul 30, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Jul 30, 2026
@vincentkoc

Copy link
Copy Markdown
Member

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 30, 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 repository_dispatch).
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 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. and removed proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 30, 2026
miorbnli and others added 4 commits July 30, 2026 12:07
systemd latches a unit into failed/start-limit-hit after a crash loop,
then refuses systemctl start until reset-failed clears the latch. The
reset-failed step only ran for the restart action, so the natural
recovery command `openclaw gateway start` failed on a crash-looped
gateway while `openclaw gateway restart` recovered it.

Run reset-failed before both start and restart (stop is unchanged),
mirroring launchd's startLaunchAgent which calls launchctl enable before
kickstart. reset-failed is idempotent and a no-op on a healthy unit.
Mirrors the existing system-scope restart test: when startSystemdService
targets a system unit as root, it must emit reset-failed before start so
a crash-looped gateway recovers via `openclaw gateway start` too.
reset-failed is idempotent on a non-failed unit (systemd returns success
without changing unit state), so prepending it to start cannot regress a
healthy gateway. Covers the merge-risk concern that every start now
depends on an extra reset-failed call.
@miorbnli
miorbnli force-pushed the fix/systemd-start-limit-latch branch from 49c4237 to a75ac9e Compare July 30, 2026 04:08
@vincentkoc

Copy link
Copy Markdown
Member

Maintainer review complete. ClawSweeper’s current-head validation move is satisfied by exact-head CI on a75ac9eb0f01 (including the isolated media-shard retry); structured autoreview and the focused systemd suite are clean.

I am not rebasing again solely because main advanced after the contributor’s patch-identical rebase: the PR remains mergeable, the systemd diff is byte-identical, and the native merge wrapper verifies relevance-aware mainline drift against the merge result. Chasing a continuously moving main would only restart the same validated checks.

@vincentkoc
vincentkoc merged commit 5e1e70e into openclaw:main Jul 30, 2026
189 of 191 checks passed
@vincentkoc

Copy link
Copy Markdown
Member

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 30, 2026
…116178)

* fix(systemd): clear start-limit latch before gateway start

systemd latches a unit into failed/start-limit-hit after a crash loop,
then refuses systemctl start until reset-failed clears the latch. The
reset-failed step only ran for the restart action, so the natural
recovery command `openclaw gateway start` failed on a crash-looped
gateway while `openclaw gateway restart` recovered it.

Run reset-failed before both start and restart (stop is unchanged),
mirroring launchd's startLaunchAgent which calls launchctl enable before
kickstart. reset-failed is idempotent and a no-op on a healthy unit.

* test(systemd): cover start-limit latch clearing on system-scope start

Mirrors the existing system-scope restart test: when startSystemdService
targets a system unit as root, it must emit reset-failed before start so
a crash-looped gateway recovers via `openclaw gateway start` too.

* test(systemd): assert healthy start tolerates reset-failed no-op

reset-failed is idempotent on a non-failed unit (systemd returns success
without changing unit state), so prepending it to start cannot regress a
healthy gateway. Covers the merge-risk concern that every start now
depends on an extra reset-failed call.

* test(systemd): cover reset failure and stop controls

---------

Co-authored-by: Vincent Koc <[email protected]>
vincentkoc added a commit to Hackerismydream/openclaw that referenced this pull request Jul 30, 2026
* origin/main: (24 commits)
  fix(e2e): apply default service identity per flow (openclaw#116265)
  chore(android): record 2026.7.4 Play metadata
  fix(ci): accept one verified Telegram SUT launch (openclaw#116267)
  chore(android): prepare 2026.7.4 Play release
  fix(e2e): align service account state (openclaw#116254)
  refactor(qa): remove live-channel scenario registries and wrappers (openclaw#115752)
  fix(ci): let trusted Telegram QA stage runtime (openclaw#116252)
  fix(plugins): plugin install survives pnpm-only overrides (openclaw#116245)
  test(qa): recognize internal image completions (openclaw#116234)
  fix(test): review Codex runtime scan chunks (openclaw#116212)
  fix(systemd): clear start-limit latch before gateway start (openclaw#116178)
  fix(security): expose every executable call in plugin scans (openclaw#116222)
  chore(sdk): repin the API baseline after the resolver signature change
  test(e2e): delay the draft-proof final answer past the start gate
  fix(channels): resolve tool progress against the caller's stream mode
  fix(ci): satisfy docs formatting, lint, and the SDK API baseline
  test(e2e): add a progress-draft scenario to the mock provider
  docs(telegram): call out the changed default preview on upgrade
  refactor(channels): render the progress label as a block, not a line
  fix(channels): show tool lines under the progress status headline
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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.

[Bug]: openclaw gateway start cannot recover a crash-looped systemd gateway (start-limit latch not cleared)

2 participants