Repository navigation
fix(gateway): surface systemd start-limit exhaustion - #98291
Conversation
|
Codex review: needs maintainer review before merge. Reviewed July 1, 2026, 12:45 AM ET / 04:45 UTC. Summary PR surface: Source +112, Tests +328. Total +440 across 8 files. Reproducibility: yes. at source level: current main does not read Result/NRestarts/StartLimitBurst and both status and doctor always use the generic stopped-service hint. I did not run a live current-main crash-loop repro in this read-only checkout. Review metrics: 1 noteworthy metric.
Stored data model Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Next step before merge
Security Review detailsBest possible solution: Land this focused systemd runtime and restart recovery fix through normal maintainer merge gates, leaving broader crash-recovery policy outside this PR. Do we have a high-confidence way to reproduce the issue? Yes, at source level: current main does not read Result/NRestarts/StartLimitBurst and both status and doctor always use the generic stopped-service hint. I did not run a live current-main crash-loop repro in this read-only checkout. Is this the best way to solve the issue? Yes. The fix stays in the systemd runtime/control owner boundary, shares one classifier between status and doctor, and clears the systemd failed latch in the existing restart action without adding config or a parallel recovery controller. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against d68ba5edc598. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +112, Tests +328. Total +440 across 8 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
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. How this review workflow works
|
* fix(gateway): surface systemd start-limit exhaustion * fix(gateway): avoid start-limit false positive for exit 78
* fix(gateway): surface systemd start-limit exhaustion * fix(gateway): avoid start-limit false positive for exit 78
* fix(gateway): surface systemd start-limit exhaustion * fix(gateway): avoid start-limit false positive for exit 78 (cherry picked from commit 76f9b6d)
* fix(gateway): surface systemd start-limit exhaustion * fix(gateway): avoid start-limit false positive for exit 78 (cherry picked from commit 76f9b6d)
What Problem This Solves
The managed gateway's systemd unit ships
Restart=alwayswithStartLimitBurst=5/StartLimitIntervalSec=60. When the gateway crashes faster than that allows, systemd latches theunit into
failedand stops auto-restarting it entirely. OpenClaw collapses that terminal stateinto a generic
status: "stopped", soopenclaw gateway statusandopenclaw doctoronly report"Service is loaded but not running (likely exited immediately)." — there is no signal that systemd
has given up, and nothing ever clears the failed latch, so on systemd versions that refuse a start in
that state the gateway cannot be recovered with
openclaw gateway restart.Why This Change Was Made
A crash-looped, given-up service is a distinct, actionable state (the systemd analogue of a
Kubernetes CrashLoopBackOff), not an ordinary stop. Surfacing it and making the existing restart
command recover it turns a silent dead end into a one-command fix, using state systemd already exposes.
The change is two small parts:
readSystemdServiceRuntimenow also readsResult,NRestarts, andStartLimitBurst. Detection isstate === "failed" && (Result === "start-limit-hit" || (lastExitStatus !== 78 && StartLimitBurst > 0 && NRestarts >= StartLimitBurst)). The counter pathis the important one: once the gateway process has actually run and exited non-zero, systemd keeps
Result = exit-codeand never overwrites it withstart-limit-hit, soResultalone misses realcrash loops. The counter path excludes the deliberate no-restart exit: the unit pins
RestartPreventExitStatus=78, so a last exit of78(the gateway's config-error / duplicate-lockEX_CONFIGcode) means systemd stopped on purpose — a leftoverNRestartsfrom earlier crashes isstale and must keep the ordinary stopped/config diagnostic instead of restart guidance. The explicit
Result === "start-limit-hit"signal stays authoritative regardless of exit status. While a unit isstill inside its restart cycle its state is
activating, notfailed, so the check only fires atthe terminal give-up.
openclaw gateway restartnow runssystemctl reset-failed <unit>beforerestart. It is idempotent (a no-op on a healthy unit) and clears the failed/start-limit latch so acrash-looped gateway comes back up.
Presentation changes are confined to the existing
stoppedbranch ofopenclaw gateway statusandopenclaw doctor; all other wording, health computation, the generated unit, and non-systemd backendsare untouched.
User Impact
after repeated crashes; run
openclaw gateway restartor inspect logs." — instead of themisleading "exited immediately."
openclaw gateway restartreliably recovers a unit that systemd has stopped restarting."likely exited immediately" hint.
Evidence
Unit tests (
pnpm test):service-runtime.test.ts+doctor-format.test.ts(18, incl. theexit-78 no-restart guard on the counter path),
systemd.test.ts(92, incl. parse fixtures, runtimeclassification, and
reset-failed-before-restartordering across user/sudo/machine-fallback/systemscopes),
status.print.test.ts(19).oxfmt --checkclean;tsgocore + test-types green;pnpm buildclean.Patched-OpenClaw production-path proof on real systemd 249. The real patched functions were
invoked (via
tsx) against a throwaway systemd user unitopenclaw-gateway-slproof.service,targeted through
OPENCLAW_PROFILE=slproof(which namespaces the unit name, so the real managedgateway unit is never referenced or touched). It is labeled as a production-path invocation rather
than a full
openclaw gateway restartCLI run because the CLI restart path also waits on a gatewayhealth probe that a throwaway
/bin/false-style unit cannot satisfy. Paths below redacted (~).StartLimitBurst:readSystemdServiceRuntimereads the give-up state, and the predicate fires:openclaw doctorrender (buildGatewayRuntimeHints):openclaw gateway statusrender (printDaemonStatus):Service is loaded but not running (likely exited immediately).line.restartSystemdService) — systemctl call ordering, captured via a PATH shim:reset-failedruns beforerestart.The throwaway unit was removed afterward (
stop+reset-failed+ unit-file delete +daemon-reload).