cost-federation
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCost Federation
成本联邦
ADR-097 Phase 3 specifies a event bus that publishes one event per completion: . Cost-tracker is the declared consumer — it aggregates per-peer rolling windows (1h / 24h / 7d) and the federation breaker queries that aggregate to suspend peers exceeding the configured threshold.
federation_spendfederation_send{peerId, taskId, tokensUsed, usdSpent, ts}Phase 3 isn't landed upstream yet. This skill is the consumer-side wiring; it activates the moment upstream publishes events to the namespace. Until then it reports cleanly with a "no events found" notice.
federation-spendADR-097第三阶段指定了一个事件总线,每次完成时发布一个事件:。Cost-tracker是指定的消费端——它聚合基于节点的滚动窗口(1小时/24小时/7天)数据,联邦断路器会查询该聚合数据,以暂停超过配置阈值的节点。
federation_spendfederation_send{peerId, taskId, tokensUsed, usdSpent, ts}第三阶段尚未合并到上游代码库。 本Skill是消费端的适配逻辑;一旦上游开始向命名空间发布事件,它就会激活。在此之前,它会清晰返回“未找到事件”的提示。
federation-spendWhen to use
使用场景
- Before opening federation traffic to a new peer — establish baseline.
- Periodically (e.g. ) to monitor per-peer spend across windows.
/loop 5m - After ADR-097 Phase 2/3 lands — to verify breaker suspension reasoning.
- 在向新节点开放联邦流量之前——建立基准数据。
- 定期执行(例如)——监控各节点在不同窗口内的支出情况。
/loop 5m - ADR-097第二/三阶段落地后——验证断路器暂停节点的依据。
Steps
操作步骤
-
Run the script:bash
node plugins/ruflo-cost-tracker/scripts/federation.mjsOptional env:- — JSON instead of markdown
FED_FORMAT=json - — override target namespace
FED_NAMESPACE=federation-spend - — breaker threshold (ADR-097 default)
FED_SUSPEND_THRESHOLD_USD=5.0
-
Inspect — per-peer 1h/24h/7d windows of count + USD spent, plus a "Suspension threshold check" block flagging peers over the breaker line.
-
运行脚本:bash
node plugins/ruflo-cost-tracker/scripts/federation.mjs可选环境变量:- —— 输出JSON格式而非Markdown
FED_FORMAT=json - —— 覆盖目标命名空间
FED_NAMESPACE=federation-spend - —— 断路器阈值(ADR-097默认值)
FED_SUSPEND_THRESHOLD_USD=5.0
-
查看结果——各节点1小时/24小时/7天窗口内的事件数量+美元支出数据,以及一个“暂停阈值检查”模块,标记超出断路器阈值的节点。
Storage contract (consumer side)
消费端存储约定
When Phase 3 lands, events should be persisted to namespace with key prefix and JSON value matching:
federation-spendfed-spend-json
{
"peerId": "<peer-uuid>",
"taskId": "<task-uuid>",
"tokensUsed": 12345,
"usdSpent": 0.0287,
"ts": "2026-05-05T..."
}The script reads any record matching that prefix, regardless of how upstream produces them. Multiple events per peer accumulate cleanly into the rolling-window sums.
当第三阶段落地后,事件应持久化到命名空间,键前缀为,JSON值格式如下:
federation-spendfed-spend-json
{
"peerId": "<peer-uuid>",
"taskId": "<task-uuid>",
"tokensUsed": 12345,
"usdSpent": 0.0287,
"ts": "2026-05-05T..."
}脚本会读取所有匹配该前缀的记录,无论上游如何生成这些记录。同一节点的多个事件会被干净地累积到滚动窗口的总和中。
Cross-references
交叉引用
- ADR-097: Federation budget circuit breaker — the complete spec
- — same data, different lens (cost-report focuses on local agent spend; this skill on per-peer federated spend)
cost-report - plugin — the producer side (when Phase 3 lands)
ruflo-federation
- ADR-097: 联邦预算断路器 —— 完整规范
- —— 相同数据,不同视角(cost-report聚焦本地Agent支出;本Skill聚焦各节点的联邦支出)
cost-report - 插件 —— 生产端逻辑(第三阶段落地后)
ruflo-federation