Files
youlu-openclaw-workspace/memory/2026-03-24.md

69 lines
2.0 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 2026-03-24 — 修复工作区备份 Cron 任务
## 问题发现
小鹿问"昨天晚上的工作区备份执行了吗",检查发现:
- Cron 日志显示"执行成功"
- 但 git log 最后一次备份是 3月23日 10:02
- 工作区有未提交的变更calendars/*.ics, memory/*.md
## 根本原因
备份任务配置为 `agentTurn` 类型:
```json
{
"kind": "agentTurn",
"message": "cd ... && git add -A && git commit ...",
"lightContext": true
}
```
这意味着 shell 命令被当作**文本提示**发给 kimi-k2.5LLM 只是"理解"了命令的含义,然后编造了"备份完成"的回复,**根本没有调用工具执行 git**。
对比邮件处理器 digest 任务(工作正常):
```json
{
"kind": "systemEvent",
"text": "exec:cd ... && ./email-processor.sh digest"
}
```
## 修复过程
### 1. 切换到 systemEvent
```bash
openclaw cron edit 53c0b2a6-e3b3-4a1d-b2a8-66e216fad753 \
--session main \
--system-event 'exec:cd /home/lyx/.openclaw/workspace && git add -A && git diff --cached --quiet || (git commit -m "Daily backup $(date +"%Y-%m-%d %H:%M:%S")" && git push origin main)'
```
关键改动:
- `agentTurn``systemEvent`(直接执行,不走 LLM
- `isolated``main`(在主会话通过 heartbeat 执行)
- `exec:` 前缀确保 shell 直接执行
### 2. 日期转义问题
最初尝试时 `$(date +%Y-%m-%d %H:%M:%S)` 报错,因为 `%` 被 shell 特殊处理。
解决方案:外层单引号 + 内层双引号:
```
'... "$(date +"%Y-%m-%d %H:%M:%S")" ...'
```
### 3. 验证成功
手动触发测试后git log 显示:
```
33f0dac Daily backup
...(后续提交)
df7cdff Daily backup 2026-03-24 10:02:50
```
备份现在真正工作了。
## 教训记录
- 确定性任务shell 命令)必须用 `systemEvent`,不能依赖 LLM 解释执行
- kimi-k2.5 的工具使用能力较弱,容易产生幻觉
- 日期/特殊字符在 cron 命令中需要正确转义
## 更新文件
- MEMORY.md — 更新备份任务配置
- TOOLS.md — 添加 OpenClaw Cron 章节记录经验教训