# OpenClaw Gateway Closed (1006 Abnormal Closure) - Fix

Fix OpenClaw Gateway Closed (1006 Abnormal Closure) by checking gateway status, port 18789, WebSocket proxy settings, tokens, and logs. For fewer gateway issues, run OpenClaw on Ampere.sh with managed hosting.

## What Does OpenClaw Gateway Closed 1006 Mean?

The 1006 Abnormal Closure error is usually a WebSocket connection issue. OpenClaw expected the gateway connection to stay open, but the connection closed without a normal close response.

You may see errors like:
```
gateway closed (1006 abnormal closure)
RPC probe failed: ws://127.0.0.1:18789 gateway closed (1006 abnormal closure)
Health check failed: gateway closed (1006 abnormal closure)
ECONNREFUSED 127.0.0.1:18789
```

The error does not always mean OpenClaw itself is broken. It usually means the gateway connection path is broken somewhere - OpenClaw gateway, local machine, browser extension, port 18789, firewall, VPS network rules, reverse proxy, WebSocket config, token/auth settings, or runtime stability.

## Quick Fix Summary

| Problem | What to Check |
|---------|---------------|
| Gateway is stopped | Start the OpenClaw gateway |
| Gateway keeps closing | Check gateway logs |
| Port issue | Check port 18789 |
| Works locally but not remotely | Check gateway URL, VPS firewall, and domain |
| Browser extension shows 1006 | Check saved gateway URL and token |
| Domain/proxy setup fails | Fix WebSocket proxy settings |
| Token issue | Match gateway auth and remote token |
| Windows issue | Check OpenClaw Gateway Scheduled Task |
| Still unstable | Use managed OpenClaw hosting |

## Why This Error Happens

1. The OpenClaw gateway is not running
2. The gateway crashed after startup
3. Port 18789 is already used by another process
4. The browser or extension is using the wrong gateway URL
5. `127.0.0.1` is being used incorrectly for a remote VPS
6. A firewall or VPS security rule is blocking access
7. Nginx, Caddy, Cloudflare, or another proxy is blocking WebSocket traffic
8. Gateway token/auth config does not match
9. Windows Scheduled Task is missing or stopped
10. The laptop, VPS, or server restarted or went to sleep
11. OpenClaw is running in a terminal and stops after SSH closes

## Step 1: Check OpenClaw Gateway Status

```bash
openclaw gateway status
```

If stopped:
```bash
openclaw gateway start
```

If running but failing:
```bash
openclaw gateway stop
openclaw gateway start
openclaw gateway logs --tail 50
```

## Step 2: Run a Full OpenClaw Health Check

```bash
openclaw status --all
openclaw gateway status
openclaw models status
openclaw channels status --probe
```

| Command | What It Checks |
|---------|----------------|
| `openclaw status --all` | Full OpenClaw health |
| `openclaw gateway status` | Gateway status |
| `openclaw models status` | Model and API key setup |
| `openclaw channels status --probe` | Telegram, WhatsApp, Discord, Slack status |

## Step 3: Check Port 18789

macOS or Linux:
```bash
lsof -i :18789
```

Windows PowerShell:
```powershell
Get-NetTCPConnection -LocalPort 18789
```

| Result | Meaning |
|--------|---------|
| No process found | Gateway may not be running |
| OpenClaw process found | Gateway is listening |
| Another app found | Port conflict |
| Multiple OpenClaw processes found | Duplicate gateway process |

## Step 4: Check Localhost vs Remote Gateway URL

If OpenClaw is running on your own laptop: `ws://127.0.0.1:18789`

But if OpenClaw is running on a VPS, your laptop browser cannot use `127.0.0.1:18789` to reach that VPS.

| Setup | Correct Gateway Target |
|-------|------------------------|
| OpenClaw runs on your laptop | `ws://127.0.0.1:18789` |
| OpenClaw runs on VPS | VPS IP or domain |
| OpenClaw runs behind HTTPS | `wss://your-domain.com` |
| OpenClaw runs behind proxy | Proxy must support WebSocket |

## Step 5: Check Firewall and VPS Rules

```bash
sudo ufw status
sudo ufw allow 18789/tcp
```

Also check VPS provider firewall, cloud security group, Docker network rules, reverse proxy routing, domain DNS, HTTPS certificate setup.

## Step 6: Fix WebSocket Proxy Issues

For Nginx, make sure WebSocket upgrade headers are passed:

```nginx
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
```

Use `wss://` when the site uses HTTPS. Confirm upstream port. Increase proxy timeout.

## Step 7: Check Gateway Token or Auth Mismatch

```bash
openclaw config get gateway.auth.token
openclaw config get gateway.remote.token
```

Fix:
```bash
openclaw config set gateway.remote.token "your-exact-token-here"
openclaw config apply
openclaw gateway stop
openclaw gateway start
```

## Step 8: Fix Browser Extension Connection Issues

1. Confirm the gateway URL
2. Confirm the token
3. Remove old saved connection details
4. Reconnect the extension
5. Test another browser profile
6. Check the browser console for WebSocket errors

## Step 9: Fix Windows Gateway Scheduled Task Issues

```bash
openclaw gateway install
```

```powershell
Get-ScheduledTask -TaskName "OpenClaw Gateway"
Start-ScheduledTask -TaskName "OpenClaw Gateway"
```

## Step 10: Check Model and Provider Status

```bash
openclaw models status
openclaw models test <model-name>
```

## Step 11: Check Channel Status

```bash
openclaw channels status --probe
openclaw logs --follow
```

| What Happens | Likely Cause |
|--------------|--------------|
| Nothing appears in logs | Channel receiver issue |
| Message appears but is blocked | Pairing or allowlist issue |
| Message appears then model error | Model/API issue |
| Message appears then gateway closes | Gateway/runtime issue |

## Step 12: Check Runtime Stability

Common causes: VPS memory too low, server restarted, laptop slept, SSH session closed, process not a service, disk full, logs too large, runtime crashed, multiple OpenClaw versions conflict.

## Step 13: Read Gateway Logs Properly

```bash
openclaw gateway logs --tail 100
openclaw logs --follow
DEBUG=* openclaw gateway start
```

| Log / Symptom | Likely Cause |
|---------------|--------------|
| `ECONNREFUSED` | Gateway not running or port blocked |
| `1006 abnormal closure` | Gateway crashed or WebSocket path failed |
| `1008 unauthorized` | Token/auth mismatch |
| `port already in use` | Port conflict |
| `health check failed` | Gateway unreachable |
| `model error` | API key, model, or provider issue |

## Step 14: Emergency Reset

macOS or Linux:
```bash
openclaw gateway stop
rm -rf ~/.openclaw/gateway-state/
openclaw gateway start
```

Windows PowerShell:
```powershell
openclaw gateway stop
Remove-Item -Recurse -Force $env:USERPROFILE\.openclaw\gateway-state\
openclaw gateway start
```

Warning: do not delete config, API keys, workspace files, or project data.

## Best Fix Order

1. Run `openclaw gateway status`
2. Start or restart the gateway
3. Check `openclaw gateway logs --tail 50`
4. Check port 18789
5. Confirm localhost vs remote gateway URL
6. Check firewall and VPS rules
7. Fix WebSocket proxy settings
8. Check gateway token/auth config
9. Reconnect the browser extension
10. Check Windows Scheduled Task if using Windows
11. Check model status
12. Check channel status
13. Review full logs
14. Use emergency reset only if needed

## Easiest Fix: Run OpenClaw on Ampere.sh

Ampere.sh helps you run OpenClaw with managed hosting, easier deployment, model setup, uptime handling, and fewer gateway-level problems.

[Run OpenClaw on Ampere.sh](https://www.ampere.sh/setup)

## Quick Commands

| Command | Purpose |
|---------|---------|
| `openclaw status --all` | Check full OpenClaw status |
| `openclaw gateway status` | Check gateway status |
| `openclaw gateway start` | Start gateway |
| `openclaw gateway stop` | Stop gateway |
| `openclaw gateway logs --tail 50` | View recent gateway logs |
| `openclaw logs --follow` | Watch live logs |
| `openclaw models status` | Check model setup |
| `openclaw models test <model-name>` | Test selected model |
| `openclaw channels status --probe` | Check channel connections |
| `lsof -i :18789` | Check port on macOS/Linux |
| `Get-NetTCPConnection -LocalPort 18789` | Check port on Windows |
| `sudo ufw status` | Check Ubuntu firewall |
| `openclaw gateway install` | Install Windows gateway task |

## FAQs

**What does OpenClaw Gateway Closed 1006 mean?**
It means the OpenClaw gateway WebSocket connection closed unexpectedly without a normal close response.

**Is 1006 Abnormal Closure always an OpenClaw bug?**
No. It can happen because the gateway stopped, crashed, lost network access, hit a token issue, or failed behind a proxy.

**How do I fix OpenClaw Gateway Closed 1006?**
Run `openclaw gateway status`, restart the gateway, check logs, confirm port 18789, verify the gateway URL, and check firewall, proxy, and token settings.

**Why does OpenClaw work locally but not remotely?**
Usually because `127.0.0.1` only works on the same machine. If OpenClaw runs on a VPS, your browser needs the VPS IP, domain, or a properly configured proxy.

**Can Nginx cause OpenClaw Gateway Closed 1006?**
Yes. If Nginx does not pass WebSocket upgrade headers correctly, the gateway connection can close with a 1006 error.

**Can Cloudflare cause OpenClaw WebSocket problems?**
Yes. Cloudflare SSL, proxy, timeout, or WebSocket settings can break the connection if configured incorrectly.

**Why does the OpenClaw browser extension show 1006?**
The extension may be using the wrong gateway URL, an old token, blocked WebSocket connection, or stale saved settings.

**What port does OpenClaw gateway use?**
OpenClaw gateway commonly uses port 18789 for the local gateway connection.

**Should I use managed hosting for OpenClaw?**
Use managed hosting if you want fewer setup problems and do not want to manually manage ports, proxies, gateway services, and uptime.
