OpenClaw Gateway Crash: Auto-Repair Without SSH

You can set up your OpenClaw bot to auto-repair a crashed gateway without any manual intervention. This guide covers the full repair sequence โ€” from simple systemd restarts to config corruption recovery โ€” and how to make it completely hands-off.

What happens when the gateway crashes

When OpenClaw's gateway process dies, your bot stops responding immediately. The crash looks different depending on the cause:

Symptoms by crash type

  • ECONNREFUSED in Telegram โ€” gateway socket closed cleanly (memory/crash)
  • SyntaxError: Unexpected token in logs โ€” config file is corrupted
  • ENOSPC errors โ€” disk full, gateway can't write logs
  • 401 Unauthorized from LLM โ€” API key expired
  • Gateway starts but Telegram silent โ€” provider not initialized (check token)

Manual repair (the SSH approach)

If you're already SSHed in, here's the fastest path to a working gateway:

1

Check what actually died

Terminal
journalctl -u openclaw-gateway -n 50 --no-pager
# or: openclaw logs --tail 50
2

Check config file health

Terminal
# Validate JSON
node -e "require(fs.readFileSync(process.env.HOME + '/.openclaw/workspace/openclaw.json', 'utf8'))"
# Better: use openclaw's built-in check
openclaw doctor
3

Repair config without losing tokens

Terminal โ€” safe repair (preserves botToken)
# Backup first
cp ~/.openclaw/workspace/openclaw.json ~/.openclaw/workspace/openclaw.json.bak

# Auto-repair
openclaw doctor --fix

# Verify token is still there
grep -c "botToken" ~/.openclaw/workspace/openclaw.json
Critical

Never delete and recreate the config file โ€” you'll lose your Telegram bot token and need to re-pair everything.

4

Restart and verify

Terminal
openclaw gateway restart
sleep 5
openclaw gateway status
# Should show: running (PID: XXXXX)

Automated repair: no SSH required

The DIY approach requires you to be awake, have SSH access, and know which fix to apply. That's fine for your own machine during business hours. It's a problem at 3am from your phone.

There are two approaches to full automation:

Approach A: systemd with auto-restart

For simple crashes (not config corruption), systemd can restart automatically:

Enable auto-restart in systemd unit
# /etc/systemd/system/openclaw-gateway.service
[Service]
Restart=on-failure
RestartSec=10
StartLimitBurst=5
StartLimitInterval=300

Works for: clean crashes, OOM kills, SIGTERM. Fails for: config corruption (gateway will fail to start and systemd eventually gives up).

Approach B: repair agent (handles all failure modes)

Mechanic Bot runs a repair loop that handles every failure mode in order:

What Mechanic does on gateway down
Phase 1: Try systemd restart
  โ†’ Success: notify + log. Done.
  
Phase 2: Config check
  โ†’ If broken: backup โ†’ deep-merge repair โ†’ restart
  โ†’ Config repair preserves: botToken, API keys, channel settings
  
Phase 3: Environment check
  โ†’ Check disk space: if >90%, clear logs + npm cache first
  โ†’ Check Node version: if incompatible, re-link nvm version
  
Phase 4: Hard reset
  โ†’ pkill -9 gateway process
  โ†’ Start fresh
  
Phase 5: Escalate
  โ†’ All above failed โ†’ Telegram + email alert to operator
  โ†’ Detailed diagnostics included in alert

The critical difference in Phase 2: config repair uses a deep-merge, not a full overwrite. Your Telegram bot token stays intact.

Setting up automated repair

Mechanic Bot installs a lightweight agent that handles all of this automatically:

Linux/VPS
curl -fsSL https://mechanicbot.io/onboard.sh | sudo bash -s -- \
  --token YOUR_INSTALL_TOKEN
Mac
curl -fsSL https://mechanicbot.io/onboard-mac.sh | bash -s -- \
  --token YOUR_INSTALL_TOKEN
How to get a token

Start a free 14-day trial at mechanicbot.io/plans.html. The setup page gives you your install command with token pre-filled.

What you see when a crash happens

With Mechanic running, the typical experience after a gateway crash:

You don't need to do anything. You find out it happened, not that it needs fixing.

Automate your gateway repair.

Mechanic Bot handles gateway crashes, config corruption, disk issues, and more โ€” automatically, without SSH.

Start free trial โ†’ Bot broken now?