heartbeat-governor
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseHeartbeat Governor
Heartbeat Governor
What it does
功能介绍
Cron skills run autonomously. A skill with a bug — an infinite retry, an unexpectedly large context, a model call inside a loop — can silently consume hundreds of dollars before you notice.
Heartbeat Governor tracks cumulative execution cost and wall-clock time per scheduled skill on a rolling 30-day basis. When a skill exceeds its budget, the governor pauses it and sends an alert. The skill won't fire again until you explicitly review and resume it.
It runs every hour to catch budget overruns within one cron cycle.
Cron skill会自动运行。存在bug的skill(比如无限重试、上下文意外过大、循环内调用模型)可能在你察觉之前就悄无声息地消耗掉数百美元。
Heartbeat Governor会以30天滚动周期为单位,追踪每个定时skill的累计执行成本和运行时长。当skill超出预算时,监管器会将其暂停并发送告警。在你明确审核并恢复它之前,该skill不会再次触发。
它每小时运行一次,可在一个cron周期内检测到预算超支情况。
When to invoke
触发场景
- Automatically, every hour (cron)
- Manually after noticing an unexpected API bill spike
- When a cron skill has been running unusually long
- 自动每小时触发(cron调度)
- 发现API账单意外飙升后手动触发
- 当某个cron skill运行时间异常过长时触发
Budget types
预算类型
| Budget type | Default | Configurable |
|---|---|---|
| $5.00 | Yes, per skill |
| $0.50 | Yes, per skill |
| 30 | Yes, per skill |
| 48 | Yes, per skill |
| 预算类型 | 默认值 | 是否支持配置 |
|---|---|---|
| $5.00 | 是,按skill配置 |
| $0.50 | 是,按skill配置 |
| 30 | 是,按skill配置 |
| 48 | 是,按skill配置 |
Actions on budget breach
预算超支处理动作
| Breach type | Action |
|---|---|
| Pause skill, log breach, alert |
| Abort current run, log breach |
| Abort current run, log breach |
| Skip remaining runs today, log |
| 超支类型 | 处理动作 |
|---|---|
| 暂停skill、记录超支日志、发送告警 |
| 终止当前运行、记录超支日志 |
| 终止当前运行、记录超支日志 |
| 跳过当日剩余运行计划、记录日志 |
How to use
使用方法
bash
python3 governor.py --status # Show all skills and budget utilisation
python3 governor.py --record <skill> --usd 0.12 --minutes 4 # Record a run
python3 governor.py --pause <skill> # Manually pause a skill
python3 governor.py --resume <skill> # Resume a paused skill after review
python3 governor.py --set-budget <skill> --monthly 10.00 # Override budget
python3 governor.py --check # Run hourly check (called by cron)
python3 governor.py --report # Full monthly spend report
python3 governor.py --format jsonbash
python3 governor.py --status # Show all skills and budget utilisation
python3 governor.py --record <skill> --usd 0.12 --minutes 4 # Record a run
python3 governor.py --pause <skill> # Manually pause a skill
python3 governor.py --resume <skill> # Resume a paused skill after review
python3 governor.py --set-budget <skill> --monthly 10.00 # Override budget
python3 governor.py --check # Run hourly check (called by cron)
python3 governor.py --report # Full monthly spend report
python3 governor.py --format jsonCron wakeup behaviour
Cron唤醒执行逻辑
Every hour the governor runs :
--check- Load all skill ledgers from state
- For each skill with :
paused: false- If 30-day rolling spend exceeds →
max_usd_monthly, logpaused: true - If runs today exceed → skip, log
max_runs_daily
- If 30-day rolling spend exceeds
- Print summary of paused skills and budget utilisation
- Save updated state
每小时监管器会运行命令:
--check- 从状态文件中加载所有skill的台账
- 遍历所有(未暂停)的skill:
paused: false- 如果30天滚动支出超出→ 设为
max_usd_monthly,记录日志paused: true - 如果当日运行次数超出→ 跳过运行,记录日志
max_runs_daily
- 如果30天滚动支出超出
- 打印已暂停skill和预算使用情况的汇总信息
- 保存更新后的状态
Procedure
使用流程
Step 1 — Set sensible budgets
After installing any new cron skill, set its monthly budget:
bash
python3 governor.py --set-budget daily-review --monthly 2.00
python3 governor.py --set-budget morning-briefing --monthly 3.00Defaults are conservative ($5/month) but explicit is better.
Step 2 — Monitor utilisation
bash
python3 governor.py --statusReview the utilisation column. Any skill above 80% monthly budget warrants investigation.
Step 3 — Respond to pause alerts
When the governor pauses a skill, investigate why it's over budget:
- Was there a one-time expensive run (large context)?
- Is there a bug causing repeated expensive calls?
- Does the budget simply need to be raised?
Resume after investigating:
bash
python3 governor.py --resume <skill>步骤1 — 设置合理预算
安装任何新的cron skill后,设置其月度预算:
bash
python3 governor.py --set-budget daily-review --monthly 2.00
python3 governor.py --set-budget morning-briefing --monthly 3.00默认值比较保守(每月5美元),但显式设置总归更好。
步骤2 — 监控使用情况
bash
python3 governor.py --status查看使用率列,任何月度预算使用率超过80%的skill都需要排查原因。
步骤3 — 响应暂停告警
当监管器暂停某个skill时,排查超支原因:
- 是否是单次运行成本过高(上下文过大)?
- 是否存在bug导致重复发起高成本调用?
- 是否只是需要提高预算额度?
排查完成后恢复运行:
bash
python3 governor.py --resume <skill>State
状态存储
Per-skill ledgers and pause flags stored in .
~/.openclaw/skill-state/heartbeat-governor/state.yamlFields: map, list, , .
skill_ledgerspaused_skillsbreach_logmonthly_summary单skill台账和暂停标记存储在。
~/.openclaw/skill-state/heartbeat-governor/state.yaml包含字段:映射表、列表、(超支日志)、(月度汇总)。
skill_ledgerspaused_skillsbreach_logmonthly_summary