openclaw - 💡(How to fix) Fix [Bug]: Gateway killed on every `exec` tool invocation [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#60087Fetched 2026-04-08 02:36:33
View on GitHub
Comments
0
Participants
1
Timeline
2
Reactions
0
Participants
Timeline (top)
labeled ×2

Every exec tool invocation causes the gateway to receive SIGTERM and restart due to login shell sourcing ~/.profile which unconditionally calls openclaw gateway start.

Root Cause

Root cause: Non-idempotent openclaw gateway start command. When sourced via login shell in exec tool, it unconditionally calls systemctl --user restart.

Fix Action

Fix / Workaround

User workaround:

if ! systemctl --user is-active --quiet openclaw-gateway.service; then
    openclaw gateway start
fi

Code Example

Gateway logs showing SIGTERM:
20:53:47 [agent] tool=exec completed successfully
20:53:50 [gateway] signal SIGTERM received
20:53:50 [gateway] shutting down
20:53:50 [ws] close code=1012 reason=service restart

Signal trace confirmed sender: `/usr/lib/systemd/systemd --user` (PID 1642)

Trigger chain: exec tool runs `bash -l -c env -0` → sources ~/.profile → calls `openclaw gateway start` → systemctl detects active service → `systemctl --user restart openclaw-gateway.service`SIGTERM sent.

---

if ! systemctl --user is-active --quiet openclaw-gateway.service; then
    openclaw gateway start
fi
RAW_BUFFERClick to expand / collapse

Bug type

Crash (process/app exits or hangs)

Beta release blocker

No

Summary

Every exec tool invocation causes the gateway to receive SIGTERM and restart due to login shell sourcing ~/.profile which unconditionally calls openclaw gateway start.

Steps to reproduce

  1. Ensure ~/.profile contains openclaw gateway start (default after install).
  2. Start OpenClaw with openclaw gateway start or systemd service.
  3. Trigger any exec tool invocation (e.g., agent runs echo hello).
  4. Observe gateway receives SIGTERM ~3 seconds after exec completes and restarts.

Expected behavior

Exec tool completes and gateway remains running without restart.

Actual behavior

Exec tool completes successfully, then gateway receives SIGTERM from systemd (~3 sec delay) and restarts. WebSocket connections drop with code 1012 (service restart). Signal trace confirms SIGTERM from systemd (PID 1642).

OpenClaw version

v2026.4.2 (d74a122)

Operating system

Ubuntu (systemd 255, Node.js v22.22.1)

Install method

systemd user service (openclaw-gateway.service)

Model

anthropic/opus4-6/sonnet4-5/openaiGPT5-4

Provider / routing chain

not model-specific (opus-4-6

Additional provider/model setup details

No response

Logs, screenshots, and evidence

Gateway logs showing SIGTERM:
20:53:47 [agent] tool=exec completed successfully
20:53:50 [gateway] signal SIGTERM received
20:53:50 [gateway] shutting down
20:53:50 [ws] close code=1012 reason=service restart

Signal trace confirmed sender: `/usr/lib/systemd/systemd --user` (PID 1642)

Trigger chain: exec tool runs `bash -l -c env -0` → sources ~/.profile → calls `openclaw gateway start` → systemctl detects active service`systemctl --user restart openclaw-gateway.service` → SIGTERM sent.

Impact and severity

Affected: Any user with openclaw gateway start in ~/.profile Severity: High (breaks long-running sessions, drops websocket connections) Frequency: Always (occurs on every exec invocation) Consequence: Gateway restarts repeatedly, breaking agent workflows that use exec tool, dropped websocket connections

Additional information

Root cause: Non-idempotent openclaw gateway start command. When sourced via login shell in exec tool, it unconditionally calls systemctl --user restart.

User workaround:

if ! systemctl --user is-active --quiet openclaw-gateway.service; then
    openclaw gateway start
fi

Suggested fixes:

  1. Make openclaw gateway start idempotent — check if service is already active before restart
  2. Prevent exec tool from triggering shell init — use bash -c instead of bash -l -c, or set OPENCLAW_SKIP_AUTOSTART=1 environment variable

Last known good: versions prior to any setup guide adding openclaw gateway start to ~/.profile First known bad: Affected any version after the auto-start was added to shell init files

extent analysis

TL;DR

To fix the issue, make the openclaw gateway start command idempotent by checking if the service is already active before attempting to start it.

Guidance

  • Modify the openclaw gateway start command to check if the service is already active using systemctl --user is-active --quiet openclaw-gateway.service before starting it.
  • As a workaround, users can add a conditional statement to their ~/.profile to only start the gateway service if it's not already active, using the provided bash snippet.
  • Consider preventing the exec tool from triggering shell init by using bash -c instead of bash -l -c, or by setting the OPENCLAW_SKIP_AUTOSTART=1 environment variable.
  • Verify the fix by triggering an exec tool invocation and checking if the gateway receives a SIGTERM and restarts.

Example

if ! systemctl --user is-active --quiet openclaw-gateway.service; then
    openclaw gateway start
fi

Notes

The provided fix assumes that the issue is caused by the non-idempotent openclaw gateway start command. If the issue persists after applying the fix, further investigation may be necessary.

Recommendation

Apply the workaround by adding the conditional statement to the ~/.profile file, as it provides a safe and effective way to prevent the gateway from restarting unnecessarily. This workaround can be used until a permanent fix is implemented.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

Exec tool completes and gateway remains running without restart.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING