---
name: cron-delivery-debug
description: Cron 任务推送失效的排查与修复流程
---

# Cron 任务投递失效排查

## 触发条件
- 定时 cron 任务执行成功（`last_status: ok`）
- 内容已生成（查看 `/root/.hermes/cron/output/<job_id>/`）
- 但用户反映未收到推送

## 排查步骤

### 1. 确认任务是否真正执行
```bash
grep "<job_id>" /root/.hermes/logs/agent.log | tail -20
```

### 2. 确认 cron 执行时间
```bash
crontab -l | grep <job_id>
# 或
hermes cron list
```

### 3. 查看生成的内容（验证内容已产出）
```bash
cat /root/.hermes/cron/output/<job_id>/<latest_date>.md
```

### 4. 确认网关是否投递（关键！）
```bash
grep "17:3" /root/.hermes/logs/agent.log | grep "response ready\|Sending response\|weixin"
# 或查看具体任务
grep "<job_id>.*deliver\|deliver.*<job_id>" /root/.hermes/logs/agent.log
```

### 5. 检查 gateway 日志
```bash
ls -la /root/.hermes/logs/gateway.log
# 如果不存在 → gateway 未运行或不记录该平台日志
```

### 6. 进程检查（确认 gateway 在跑）
```bash
ps aux | grep "hermes\|gateway" | grep -v grep
```

## 根因
- cron 任务的 `deliver` 字段指定的 WeChat 投递**静默失败**
- gateway 日志不存在（gateway 未向文件记录 weixin 投递）
- 任务在 4 月 24 日之后开始失效

## 临时解法：手动 send_message 强制投递
```python
from tools.send_message_tool import send_message_tool
chat_id = 'o9cq801Q4BDVa20m46H0KTKRUOjo@im.wechat'
r = send_message_tool({'action':'send', 'message': content, 'target': f'weixin:{chat_id}'})
```

## 长期解法
- 修复 cron deliver 机制或 gateway weixin 投递
- 调查为何 gateway.log 未记录 weixin 投递

## 相关文件
- cron output: `/root/.hermes/cron/output/<job_id>/`
- agent log: `/root/.hermes/logs/agent.log`
- cron jobs: `hermes cron list`