Repository navigation
Conversation
After the gateway exited, find_gateway_daemon_pid could return any process with "openclaw" in its command line: gateway helper workers, agent CLI children, scripts under /config/.openclaw. The supervisor then polled that PID and did not relaunch the gateway until it exited, which for a long-running script can take hours. - Tier 2 matches the process title exactly (pgrep -fx openclaw-gateway). - Tier 3 accepts only the gateway entrypoint ([node] .../openclaw gateway run). - An adopted PID must own the gateway port within 300 s, otherwise it is dropped and never adopted again, and the supervisor relaunches.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #194.
Problem
After the gateway exits (OOM kill, crash), the supervisor loop calls
find_gateway_daemon_pidto look for a self-restarted daemon. Tier 3 returns the first process withopenclawanywhere in its command line, and tier 2 (pgrep -f openclaw-gateway) also matches any shell containing that string. The loop then polls that PID and does not relaunch the gateway until it exits.Seen on a Raspberry Pi 4 (add-on 0.5.95, OpenClaw 2026.10.4) on 19 Oct 2026: the gateway was OOM-killed twice, and both times the supervisor logged
OpenClaw runtime active (PID …); monitoring.for an unrelated process: a scheduled shell job (cd /config/.openclaw/workspace/..., runs up to ~100 min), and once a monitoring loop that hadopenclaw-gatewayin its command line. Nothing listened on the gateway port; the ingress watchdog stayed green.While the gateway was healthy, the old tier 3 would have adopted 4 processes on that system, including the gateway's own helper workers (
.../openclaw/dist/process/spawn-broker/worker.js,.../infra/sqlite-readonly-location.worker.js), which can outlive a killed gateway.Change
Implements points 1 and 2 of the fix proposed in #194:
pgrep -fx openclaw-gateway(exact process title), skipping known and rejected PIDs.is_gateway_entrypoint_pidaccepts only the titleopenclaw-gatewayor argv[node] <path>/openclaw[.mjs|.js] gateway run [...]. Anything that merely mentionsopenclawis ignored. The/proccmdline is NUL-padded afterprocess.titleis set, so empty fields are skipped.GATEWAY_INTERNAL_PORTwithinGW_ADOPT_PORT_DEADLINE(300 s). If not, it is logged, added toGW_REJECTED_PIDS(never adopted again) and the supervisor relaunches. If the port turns out to be owned by a different PID, the loop switches to that PID. Remote mode is unchanged.gateway_port_owner_pidso the loop can reuse it.Why 300 s and not the 120 s suggested in the issue: on the Pi 4 above, a cold start of 2026.10.4 took ~260 s before the port was bound (
startup phase: ready … total=258127ms). With 120 s a slow but real gateway would be dropped and relaunched.Point 3 of #194 (pointing the add-on watchdog at the gateway) is left out to keep this change small.
Testing
bash -n openclaw_assistant/run.shis_gateway_entrypoint_pidopenclaw-gateway)sh -c 'cd /config/.openclaw/workspace; sleep 40'sh -c 'sleep 40; echo openclaw gateway run'node /tmp/fk/openclaw gateway statusnode /tmp/fk/openclaw gateway runfind_gateway_daemon_pidwith an unused port andGW_PIDset to the live gateway returned nothing (the old tier 3 returned one of 7 candidates). With a fakegateway runprocess it returned that PID, and nothing once that PID was inGW_REJECTED_PIDS. With the real port, tier 1 returned the gateway PID.sslookup as tier 1.