OpenClaw 对话无响应问题深度排查分析
摘要:本文详细记录了OpenClaw对话功能失效问题的系统性排查过程。通过检查服务状态、测试API连接、分析会话记录和网络请求,最终发现是Node.js无法验证API服务器SSL证书导致HTTPS请求失败。解决方案包括修改Gateway配置文件添加SSL环境变量并重启服务。文章还提供了验证修复的方法、预防措施、快速修复指南以及从该问题中总结的经验教训,强调系统性排查和技术环境差异的重要性,为类似问
完整全文:https://www.toutiao.com/article/7612834342615794218/
问题背景
近期在使用 OpenClaw 时遇到了一个棘手问题:界面可以正常访问,但对话功能完全无响应,无论输入什么内容都得不到 AI 的回复。刚开始怀疑是模型的问题,先后试了智谱和小米都是同样的问题。所以这是一个典型的 “界面正常但功能失效” 的场景,需要系统性地排查才能找到根本原因。
系统性排查过程
第一步:服务状态检查
首先,我们需要确认 OpenClaw Gateway 服务是否正常运行:
# 检查进程是否运行
ps aux | grep openclaw-gateway
# 检查端口是否监听
lsof -i :18789
结果:Gateway 服务正常运行,端口 18789 正常监听。这排除了服务未启动的可能性。
第二步:API 连接测试
直接测试小米 API 是否正常工作:
# 直接测试 Xiaomi API
curl -X POST 'https://api.xiaomimimo.com/anthropic/v1/messages' \
-H 'x-api-key: YOUR_API_KEY' \
-H 'anthropic-version: 2023-06-01' \
-H 'content-type: application/json' \
-d '{"model":"mimo-v2-flash","max_tokens":100,"messages":[{"role":"user","content":"你好"}]}'
结果:API 测试成功,能正常返回响应。这说明 API 本身是可用的。
第三步:会话记录分析
查看会话文件,发现所有消息都显示错误:
# 查看会话文件
tail -50 ~/.openclaw/agents/main/sessions/*.jsonl
关键发现:所有消息都显示 "stopReason":"error" 和 "errorMessage":"Connection error."
第四步:网络请求分析
使用浏览器开发者工具捕获的请求和响应:
请求:
{
"type":"req",
"method":"chat.send",
"params":{"sessionKey":"agent:main:main","message":"helloworld"}
}
响应:
{
"type":"res",
"ok":true,
"payload":{"runId":"...","status":"started"}
}
分析:请求成功发送到 Gateway,agent 开始运行,但最终返回错误。
第五步:Node.js SSL 连接测试
创建测试文件测试 Node.js 环境下的 SSL 连接:
// 创建测试文件 test_node_api.js
const https = require('https');
const options = {
hostname: 'api.xiaomimimo.com',
port: 443,
path: '/anthropic/v1/messages',
method: 'POST',
headers: {
'x-api-key': 'YOUR_API_KEY',
'anthropic-version': '2023-06-01',
'content-type': 'application/json'
}
};
const req = https.request(options, (res) => {
let data = '';
res.on('data', (chunk) => { data += chunk; });
res.on('end', () => { console.log('Response:', data); });
});
req.on('error', (e) => {
console.error('Error:', e.message);
});
req.write(JSON.stringify({
model: 'mimo-v2-flash',
max_tokens: 100,
messages: [{ role: 'user', content: '你好' }]
}));
req.end();
node test_node_api.js
关键错误:
Error: unable to get local issuer certificate
根本原因分析
经过五步系统性排查,我们找到了问题的根本原因:
Node.js 无法验证 API 服务器的 SSL 证书
虽然 curl 能够成功调用 API(因为 curl 使用系统的证书存储),但 OpenClaw Gateway 运行在 Node.js 环境中,无法验证 Xiaomi API 服务器的 SSL 证书,导致所有 HTTPS 请求都失败。
这是一个典型的环境差异问题:不同工具链对 SSL 证书的处理方式不同,导致在 curl 中正常的请求在 Node.js 中失败。
解决方案
步骤 1:编辑服务配置文件
修改 Gateway 服务配置文件,添加 SSL/TLS 相关的环境变量:
# 查看配置文件
cat ~/Library/LaunchAgents/ai.openclaw.gateway.plist
在 EnvironmentVariables 部分添加:
<key>NODE_TLS_REJECT_UNAUTHORIZED</key>
<string>0</string>
<key>NODE_EXTRA_CA_CERTS</key>
<string>/etc/ssl/cert.pem</string>
步骤 2:重新加载并重启 Gateway 服务
# 停止服务
launchctl unload ~/Library/LaunchAgents/ai.openclaw.gateway.plist
# 启动服务
launchctl load ~/Library/LaunchAgents/ai.openclaw.gateway.plist
# 验证服务运行
ps aux | grep openclaw-gateway
步骤 3:测试对话功能
# 打开 Dashboard
openclaw dashboard
在打开的页面中输入消息,应该能正常收到 AI 回复。
验证修复成功
检查日志
# 查看最新的 Gateway 日志
tail -f ~/.openclaw/logs/gateway.log
# 查看会话记录
tail -f ~/.openclaw/agents/main/sessions/*.jsonl
正常情况下,您应该看到:
- WebSocket 连接成功
- Agent 运行完成
- 没有 “Connection error” 错误
检查会话文件
会话文件中应该包含正常的响应:
{
"type": "message",
"role": "assistant",
"content": [{"type": "text", "text": "AI 的回复内容..."}],
"stopReason": "end_turn"
}
而不是:
{
"stopReason": "error",
"errorMessage": "Connection error."
}
预防措施和最佳实践
1. 定期检查配置
# 运行诊断工具
openclaw doctor
# 检查配置文件
cat ~/.openclaw/openclaw.json | jq .
2. 监控日志
# 实时查看日志
tail -f ~/.openclaw/logs/gateway.log
tail -f ~/.openclaw/logs/gateway.err.log
3. 测试 API 连接
定期测试 API 提供商的连接状态:
# Xiaomi API
curl -X POST 'https://api.xiaomimimo.com/anthropic/v1/messages' \
-H "x-api-key: $XIAOMI_API_KEY" \
-H 'anthropic-version: 2023-06-01' \
-H 'content-type: application/json' \
-d '{"model":"mimo-v2-flash","max_tokens":10,"messages":[{"role":"user","content":"hi"}]}'
4. 保存重要信息
- Dashboard URL(包含 token)
- API 密钥安全存储位置
- 服务配置文件路径
快速修复指南
对于遇到相同问题的用户,以下是快速修复步骤:
修复 1:解决 SSL 证书问题(90% 的情况)
编辑文件:~/Library/LaunchAgents/ai.openclaw.gateway.plist
在 <key>EnvironmentVariables</key> 部分添加:
<key>NODE_TLS_REJECT_UNAUTHORIZED</key>
<string>0</string>
<key>NODE_EXTRA_CA_CERTS</key>
<string>/etc/ssl/cert.pem</string>
然后重启:
launchctl unload ~/Library/LaunchAgents/ai.openclaw.gateway.plist
launchctl load ~/Library/LaunchAgents/ai.openclaw.gateway.plist
修复2:使用正确的 URL
# 打开正确的 Dashboard(包含 token)
openclaw dashboard
经验教训
- 系统性排查:从服务状态、日志、配置、认证、网络层层递进,不要跳过任何步骤。
- 工具链差异:curl 成功不代表应用层也能成功,要注意运行环境差异。
- F12 调试:浏览器开发者工具可以提供关键的请求/响应信息。
- 日志分析:会话文件(.jsonl)记录了详细的对话历史和错误信息。
- 环境变量配置:对于 Node.js 应用,正确配置 SSL 相关的环境变量至关重要。
结语
OpenClaw 对话无响应问题的排查过程展示了如何通过系统性的方法定位和解决复杂的技术问题。从表面现象到根本原因,每一步都需要细致的分析和验证。
通过本文的排查思路和解决方案,希望能帮助遇到类似问题的用户快速定位并解决问题,同时也为大家提供一种系统性排查技术问题的方法参考。
更多推荐

所有评论(0)