| name | gateway-debugger |
| description | Troubleshooting gateway issues in ClosedClaw. Use when debugging gateway startup failures, port conflicts, lock file issues, WebSocket disconnections, or RPC errors. Covers log analysis, diagnostics, and recovery procedures. |
Gateway Debugger
This skill helps you diagnose and fix ClosedClaw gateway issues. The gateway is the control plane coordinating channels, sessions, tools, and agent execution via WebSocket/HTTP.
When to Use
- Gateway fails to start
- Port conflicts or "address already in use" errors
- Lock file errors preventing startup
- WebSocket connection issues
- RPC method failures
- Channel disconnections
- Config reload problems
- Performance debugging
Prerequisites
- Understanding of gateway architecture (
src/gateway/)
- Access to logs at
~/.closedclaw/logs/
- Familiarity with WebSocket protocol
Quick Diagnostics
Run Built-in Diagnostics
closedclaw doctor
closedclaw channels status
closedclaw channels status --probe
Check Gateway Status
ps aux | grep closedclaw | grep gateway
lsof -i :18789
netstat -tuln | grep 18789
cat ~/.closedclaw/gateway.lock
tail -f ~/.closedclaw/logs/gateway-$(date +%Y-%m-%d).log
Common Issues & Solutions
Issue 1: Port Already in Use
Symptoms:
- Error: "EADDRINUSE: address already in use :::18789"
- Gateway fails to start
- Cannot bind to port
Diagnosis:
lsof -i :18789
Solutions:
kill -9 12345
closedclaw gateway --port 18790
pkill -f closedclaw
sleep 2
closedclaw gateway --verbose
Prevention:
// ~/.closedclaw/config.json5
{
gateway: {
port: 18790, // Use non-default port
},
}
Issue 2: Stale Lock File
Symptoms:
- Error: "Gateway is already running"
- GatewayLockError thrown
- Lock file exists but no process running
Diagnosis:
cat ~/.closedclaw/gateway.lock
PID=$(cat ~/.closedclaw/gateway.lock 2>/dev/null)
ps -p $PID 2>/dev/null || echo "Process not running"
Solutions:
rm ~/.closedclaw/gateway.lock
closedclaw gateway --force
rm ~/.closedclaw/gateway.lock
pkill -f closedclaw
closedclaw gateway --verbose
Prevention:
- Always use Ctrl+C for graceful shutdown
- Avoid
kill -9 unless necessary
- Use daemon management (launchd/systemd)
Issue 3: Config Validation Errors
Symptoms:
- Gateway fails to start with config error
- "Unknown key" errors
- Schema validation failures
Diagnosis:
closedclaw doctor
cat ~/.closedclaw/config.json5 | json5
closedclaw config validate
Solutions:
closedclaw doctor | grep -i "unknown"
closedclaw config migrate
mv ~/.closedclaw/config.json5 ~/.closedclaw/config.json5.backup
closedclaw onboard
closedclaw gateway --dry-run
Common Config Issues:
- Unknown keys (strict validation)
- Missing required fields
- Invalid JSON5 syntax
- Circular
$include references
- Missing env var substitutions
Issue 4: WebSocket Connection Failures
Symptoms:
- Clients cannot connect
- "WebSocket connection failed"
- Auth failures
- Timeout errors
Diagnosis:
wscat -c ws://localhost:18789
echo $ClosedClaw_GATEWAY_TOKEN
curl -v http://localhost:18789/health
tail -f ~/.closedclaw/logs/gateway-*.log | grep -i websocket
Solutions:
cat ~/.closedclaw/config.json5 | grep -A5 "gateway"
export ClosedClaw_GATEWAY_TOKEN="your-token"
closedclaw gateway --verbose
{
"gateway": {
"auth": { "enabled": false }
}
}
sudo ufw allow 18789
sudo firewall-cmd --add-port=18789/tcp
Issue 5: Channel Disconnections
Symptoms:
- Channels show as disconnected in status
- Messages not being received
- Channel-specific errors
Diagnosis:
closedclaw channels status
closedclaw channels status --channel telegram --probe
tail -f ~/.closedclaw/logs/telegram-*.log
ls -la ~/.closedclaw/credentials/
Solutions:
closedclaw channels restart --channel telegram
closedclaw oauth signin --provider telegram
rm -rf ~/.closedclaw/sessions/telegram
closedclaw gateway restart
Issue 6: High Memory/CPU Usage
Symptoms:
- Gateway process using excessive resources
- Slow response times
- System lag
Diagnosis:
top -p $(pgrep -f "closedclaw.*gateway")
ps aux | grep closedclaw | grep gateway
node --max-old-space-size=4096 ...
node --prof dist/index.js gateway
node --prof-process isolate-*.log > processed.txt
Solutions:
closedclaw gateway --inspect
{
"sessions": {
"maxCacheSize": 100 // Reduce from default
}
}
{
"agents": {
"compaction": {
"enabled": true,
"minMessages": 50
}
}
}
Issue 7: Config Hot-Reload Failures
Symptoms:
- Changes to config.json5 not applied
- Gateway crashes on reload
- SIGUSR1 signal ignored
Diagnosis:
pgrep -f "closedclaw.*gateway"
kill -USR1 $(pgrep -f "closedclaw.*gateway")
tail -f ~/.closedclaw/logs/gateway-*.log | grep -i reload
Solutions:
closedclaw gateway restart
closedclaw doctor
kill -USR1 $(pgrep -f "closedclaw.*gateway")
closedclaw gateway reload
pnpm gateway:watch
Log Analysis
Log Locations
~/.closedclaw/logs/gateway-YYYY-MM-DD.log
~/.closedclaw/logs/telegram-YYYY-MM-DD.log
~/.closedclaw/logs/discord-YYYY-MM-DD.log
~/.closedclaw/logs/agent-main-YYYY-MM-DD.log
./scripts/clawlog.sh
log show --predicate 'subsystem == "ai.closedclaw"' --last 1h
Useful Log Patterns
grep -i error ~/.closedclaw/logs/gateway-*.log
grep -i warn ~/.closedclaw/logs/gateway-*.log
grep -i websocket ~/.closedclaw/logs/gateway-*.log
grep -i rpc ~/.closedclaw/logs/gateway-*.log
grep -i "channel:" ~/.closedclaw/logs/gateway-*.log
grep -i "uncaught\|unhandled" ~/.closedclaw/logs/gateway-*.log
grep -i "slow\|timeout" ~/.closedclaw/logs/gateway-*.log
tail -f ~/.closedclaw/logs/gateway-*.log | grep -E "error|warn|websocket"
Log Analysis Tools
grep -i error ~/.closedclaw/logs/gateway-*.log | cut -d' ' -f5- | sort | uniq -c | sort -rn
grep "2026-02-09 14:" ~/.closedclaw/logs/gateway-*.log
tar -czf closedclaw-logs-$(date +%Y%m%d).tar.gz ~/.closedclaw/logs/
cat ~/.closedclaw/logs/gateway-*.log | jq -r 'select(.level=="error") | .message'
Development Debugging
Hot-Reload Mode
pnpm gateway:watch
ClosedClaw_SKIP_CHANNELS=1 pnpm gateway:watch
pnpm closedclaw gateway --verbose
node --inspect dist/index.js gateway
Testing Gateway
pnpm test:e2e -- src/gateway
pnpm test -- src/gateway/server.test.ts
pnpm test -- src/gateway/server.test.ts --reporter=verbose
pnpm test:e2e -- src/gateway/server.e2e.test.ts
Debugging WebSocket/RPC
process.env.DEBUG = "closedclaw:gateway:*";
import { createTestGateway } from "../gateway/test-helpers.e2e.js";
const gateway = await createTestGateway({
port: 18790,
verbose: true,
});
Recovery Procedures
Full Reset (Nuclear Option)
pkill -f closedclaw
rm ~/.closedclaw/gateway.lock
cp ~/.closedclaw/config.json5 ~/config-backup.json5
rm -rf ~/.closedclaw/sessions/*
rm ~/.closedclaw/logs/*.log
closedclaw gateway --reset --verbose
Graceful Recovery
closedclaw gateway stop
sleep 5
rm -f ~/.closedclaw/gateway.lock
closedclaw gateway --verbose
closedclaw channels status
Daemon Recovery
launchctl stop ai.closedclaw.gateway
launchctl start ai.closedclaw.gateway
systemctl --user restart closedclaw-gateway
./scripts/restart-mac.sh
systemctl --user status closedclaw-gateway
Diagnostic Checklist
Prevention Best Practices
- Use daemon management: launchd/systemd for automatic restart
- Monitor logs: Set up log rotation and monitoring
- Regular health checks:
closedclaw doctor in cron
- Graceful shutdown: Always use Ctrl+C, not
kill -9
- Config validation: Test config changes before reload
- Backup config: Version control or regular backups
- Update regularly:
closedclaw update --channel stable
- Resource limits: Set memory/CPU limits in daemon config
- Rate limiting: Configure per-channel rate limits
- Error alerting: Set up notifications for critical errors
Related Files
src/gateway/boot.ts - Gateway startup logic
src/gateway/server.ts - WebSocket/HTTP server
src/infra/gateway-lock.ts - Lock file management
src/config/config-reload.ts - Hot-reload implementation
src/gateway/net.ts - Network configuration
docs/debugging.md - General debugging guide