docs: eng monitor — 用 ScheduleWakeup 替代伪代码轮询循环
Claude Code CLI 提供 ScheduleWakeup 工具,每 5 分钟唤醒 Agent 执行一轮 monitor。 后台 Worker 完成时 <task-notification> 自动推送,不需轮询。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -100,37 +100,34 @@ dispatch 返回 `{waveId, taskIds, dispatchPath}`。**然后按以下步骤操
|
||||
|
||||
### monitor
|
||||
|
||||
spawn Worker 之后**必须进入轮询循环**。CLI 的 `monitor_engine()` 只执行一次检测——你需要循环调用它。
|
||||
spawn Worker 后,**不自己循环**。用 `ScheduleWakeup` 让系统每 5 分钟唤醒你一次。
|
||||
|
||||
```bash
|
||||
python scripts/airplan.py --mode eng --project . --sub monitor
|
||||
```
|
||||
1. 所有 Worker 以 Agent(run_in_background: true) 启动后,立即返回当前波次状态给用户
|
||||
2. 调用 ScheduleWakeup(delaySeconds: 300, prompt: "检查 Worker 状态并处理")
|
||||
3. 系统 5 分钟后唤醒你,唤醒时执行:
|
||||
a. 运行 `python scripts/airplan.py --mode eng --project . --sub monitor`
|
||||
b. 如果 readyToMergeCount > 0: 对每个完成的 Worker 运行 merge
|
||||
c. 如果 stalledCount > 0: 检查 interventions,action=upgraded-to-airdbg 则启动 Dbg
|
||||
d. 如果 activeWorkerCount > 0: 再次 ScheduleWakeup(300, ...)
|
||||
e. 如果 activeWorkerCount == 0: 检查是否需要下一波 dispatch,不需要则结束
|
||||
4. 后台 Worker 完成时系统会自动 <task-notification> 推送——收到后也可以立即处理 merge,不一定要等 5 分钟
|
||||
```
|
||||
|
||||
monitor 返回 `{activeWorkerCount, readyToMergeCount, stalledCount, interventionCount, nextAction}`。
|
||||
|
||||
**轮询循环(伪代码,每轮执行)**:
|
||||
**ScheduleWakeup 调用格式**:
|
||||
```
|
||||
while 有活跃 Worker (activeWorkerCount > 0):
|
||||
1. 等待 60-300 秒(根据 Worker 阶段自适应)
|
||||
2. 运行 monitor 命令
|
||||
3. 如果 readyToMergeCount > 0:
|
||||
a. 找到完成的 Worker(读 state.json activeWorkers 中 status=done 的)
|
||||
b. 对每个完成的 Worker 运行 merge 命令
|
||||
4. 如果 stalledCount > 0:
|
||||
a. 检查 interventions 列表
|
||||
b. action="upgraded-to-airdbg" → 启动 Dbg 会话
|
||||
c. action="terminate-and-block" → 标记任务 blocked
|
||||
5. 如果 activeWorkerCount == 0:
|
||||
退出循环,检查是否需要下一波 dispatch
|
||||
ScheduleWakeup(
|
||||
delaySeconds: 300,
|
||||
reason: "Eng monitor: 检查 {n} 个活跃 Worker 状态",
|
||||
prompt: "/eng monitor"
|
||||
)
|
||||
```
|
||||
|
||||
**停滞检测逻辑**(代码自动执行,Agent 只需读结果):
|
||||
**停滞检测**(monitor_engine 代码自动执行):
|
||||
- Worker state 文件 mtime > 5 分钟未更新 → 标记 stalled
|
||||
- Worker 存活时间 > 2 小时 → 标记 wall-time-exceeded
|
||||
- 资源压力(loadavg > 2× CPU 数)→ 暂停派发
|
||||
|
||||
**注意**:Agent 没有内置时钟——你必须主动循环调用 monitor,不能等。
|
||||
|
||||
### merge
|
||||
|
||||
```bash
|
||||
|
||||
Reference in New Issue
Block a user