xiaowei-system/skills/devops/hermes-debug/references/main-feishu-debug-20260709.md

3.1 KiB
Raw Blame History

主体飞书无响应调试记录 (2026-07-09)

问题

重启电脑后主体飞书App ID cli_a95d7ff06b789bb4)不通,分身正常。

诊断路径

Step 1: 确认连接状态

journalctl --user -u hermes-gateway --no-pager --since "22:00" | grep -E "feishu|lark|connect"

结果Lark connected但无 Inbound dm 日志 → 消息根本没进来。

Step 2: 确认 gateway 是否在跑对应 profile

for pid in $(pgrep -f "hermes_cli.main gateway"); do
  echo "PID $pid: $(cat /proc/$pid/environ | tr '\0' '\n' | grep HERMES_HOME)"
done

结果:主体 ~/.hermes/ 没有 gateway 在跑,所有进程都是 HERMES_HOME=/home/muc/.hermes-prof-b

Step 3: 找根因 — systemd service 指向错误

systemctl --user cat hermes-gateway.service | grep HERMES_HOME
# 输出HERMES_HOME=/home/muc/.hermes-prof-b

hermes-gateway.service 是分身用的,不是主体。

Step 4: 检查 config.yaml 是否有语法错误

飞书配置在 config.yamlplatforms.feishu 段,但文件有两处 platforms: 声明:

  • Line 280: platforms: {}(空覆盖)
  • Line 599: platforms: { feishu: {...} }

YAML 解析时 line 280 的空对象覆盖了后面真实配置 → 飞书配置从未生效。

Step 5: YAML 修复过程(踩坑)

sed -i 删除 platforms: {} 行时不小心多删了嵌套缩进,导致 YAML 损坏。 正确做法:用 Python yaml 库读写文件,避免 sed 的行操作破坏嵌套结构。

修复操作记录

修复 1: config.yaml 语法

import yaml
with open('/home/muc/.hermes/config.yaml', 'r') as f:
    lines = f.readlines()
# 在正确位置插入 runtime_footer: 块,删除错误的 platforms: {}
# 保存后验证 yaml.safe_load() 通过

修复 2: 创建主体专用 systemd service

给主体新建 hermes-gateway-main.service(不要改 hermes-gateway.service,那是分身的):

[Unit]
Description=Hermes Agent Gateway - Main Body
[Service]
ExecStart=/home/muc/.hermes/hermes-agent/.venv/bin/python -m hermes_cli.main gateway run
WorkingDirectory=/home/muc/.hermes
Environment="HERMES_HOME=/home/muc/.hermes"
Restart=always

修复 3: daemon-reload

改了 systemd service 文件后必须执行:

systemctl --user daemon-reload

否则 systemd 用的还是旧配置。

关键教训

  1. systemd service 文件改了不等于生效 — 必须 daemon-reload
  2. 从 gateway 内部无法控制自己Blocked: cannot restart/stop the gateway from inside the gateway process,所有控制操作必须在另一个终端执行
  3. YAML 配置优先用 Python 读写 — 嵌套缩进文件用 sed 行操作极容易坏
  4. hermes gateway run --force — 跳过 systemd 直接起主体 gateway用于临时修复
  5. 区分两个 profile 的进程 — 用 cat /proc/PID/environ | grep HERMES_HOME 确认

当前架构(修复后)

进程 profile 管理方式
PID 10982 ~/.hermes/ (主体) systemd hermes-gateway-main.service
PID 9721 ~/.hermes-prof-b/ (分身) systemd hermes-gateway-prof-b.service