root
33cb2bdb06
fix(billing): 源层零价不再覆盖模型价(issue #1)+ default_mode 生效 + 文档/判据补齐
GitCode issue #1:任何按 `mode: token` 且 URL 非通配符的规则定价的源,计费恒为 0,
且 `unpriced_reqs` 也不增长 —— 完全静默。
## 真因
- `compile.go` 给这类规则写源条目 `{prompt:0, completion:0, per_request:0}`,
本意只是"标记该源已定价"(同源未列入价目表的模型不算 unpriced);
- `billing.lua` 的 priceFor() 源层在模型层之后、且 `sp.prompt ~= nil` 即覆盖;
- 两者叠加 ⇒ 模型价被清成 0,而 `out.priced` 仍为 true ⇒ 连未定价计数都不涨。
## 修法
1. `compile.go`:token 规则的源条目只写 `{per_request: 0}`(只是标记,不参与 token
计价)。`free` / `subscription` 保留全零(那里 0 本身就是语义)。
2. `billing.lua`:
- `priceFor()` 的 `out` 补 `local`(此前是 VM 级全局变量,跨请求残留);
- 实现 `profiles[].default` 的 `free|unpriced` 语义:`free` = 刻意免费(不进
unpriced),`unpriced`(默认)= 未定价债务。此前 compile.go 写 `default_mode`
但**无人读**,两种取值运行时完全等价。
3. `core.go`:应用 profile 时把 `unmatched_sources` 打进日志(WARNING 列出没有
规则命中的源)。该字段此前只写不读,是第二个静默少报点。
4. `docs/plugins.md`:token 价优先级改为与实际实现一致的
`keys > sources > models > default`,并写明"标记已定价只能用 per_request:0"。
## 判据(都先红后绿)
- `internal/billing`:token 规则的源条目**不含** prompt/completion;free/subscription
仍保留显式 0。
- `internal/lua`:同源同模型下旧形状 cost=0(缺陷本身)、新形状 cost=0.75 且
unpriced_reqs=0;未列入价目表的模型仍算"已定价";default_mode 三态。
- `internal/gateway`:`billing_rules_api_test` 的单位断言原本读
`cc["models"]`(恒 false,整块被跳过——从未执行过),改为 `prices["models"]`,
并新增"源条目不得带 token 价"断言。
## 顺带修掉一个"永不执行"的判据
`discover_mutate_test.go` 的变异锚点写成 6 个空格,而 `discover.go` 已是 2 个空格
⇒ 该变异每次都 `anchor not found`,变异 campaign 长期红着。修正锚点后,
"嵌套 metadata 不再读取"这条变异真的被执行并被测试 KILL。
2026-10-20 17:46:52 +08:00
..
2026-10-19 22:32:18 +08:00
2026-10-20 17:46:52 +08:00
2026-10-16 20:47:14 +08:00
2026-10-15 20:30:33 +08:00
2026-10-16 14:52:13 +08:00
2026-10-15 20:30:33 +08:00
2026-10-13 22:51:50 +08:00
2026-10-20 08:27:28 +08:00
2026-10-13 22:34:13 +08:00
2026-10-20 08:27:28 +08:00
2026-10-06 15:02:42 +08:00
2026-10-12 16:37:23 +08:00
2026-10-11 09:23:34 +08:00
2026-10-11 09:23:34 +08:00
2026-10-17 00:01:00 +08:00
2026-10-02 12:41:35 +08:00
2026-10-20 17:46:52 +08:00
2026-10-13 13:42:57 +08:00
2026-10-13 23:42:04 +08:00
2026-10-13 23:28:27 +08:00
2026-10-12 12:32:10 +08:00
2026-10-13 13:42:57 +08:00
2026-10-02 10:45:20 +08:00
2026-10-13 13:42:57 +08:00
2026-10-02 14:07:44 +08:00
2026-10-13 06:57:28 +08:00
2026-10-13 06:57:28 +08:00
2026-10-14 10:55:50 +08:00
2026-10-13 13:42:57 +08:00
2026-10-04 14:50:46 +08:00
2026-10-11 09:35:32 +08:00
2026-10-05 08:17:57 +08:00
2026-10-05 08:17:57 +08:00
2026-10-11 13:25:11 +08:00
2026-10-11 10:03:43 +08:00
2026-10-12 12:32:10 +08:00
2026-10-13 22:28:34 +08:00
2026-10-14 11:31:41 +08:00
2026-10-05 08:17:57 +08:00
2026-10-05 08:17:57 +08:00
2026-10-05 08:17:57 +08:00
2026-10-11 09:35:32 +08:00
2026-10-11 09:35:32 +08:00
2026-10-15 14:57:13 +08:00
2026-10-13 06:57:28 +08:00
2026-10-13 06:57:28 +08:00
2026-10-19 13:43:18 +08:00
2026-10-13 06:57:28 +08:00
2026-10-16 00:56:14 +08:00
2026-10-14 11:31:41 +08:00
2026-10-16 00:56:14 +08:00
2026-10-11 20:50:52 +08:00
2026-10-07 17:37:22 +08:00
2026-10-05 08:17:57 +08:00
2026-10-11 13:25:11 +08:00
2026-10-15 22:43:08 +08:00
2026-10-13 13:42:57 +08:00
2026-10-11 09:35:32 +08:00
2026-10-04 14:50:46 +08:00
2026-10-13 13:42:57 +08:00
2026-10-16 00:56:14 +08:00
2026-10-07 17:37:22 +08:00
2026-10-11 09:35:32 +08:00
2026-10-12 12:32:10 +08:00
2026-10-14 10:46:05 +08:00
2026-10-13 13:42:57 +08:00
2026-10-12 16:32:30 +08:00
2026-10-14 11:31:41 +08:00
2026-10-11 08:17:56 +08:00
2026-10-11 09:35:32 +08:00
2026-10-19 22:32:18 +08:00
2026-10-12 19:07:09 +08:00
2026-10-19 22:32:18 +08:00