From 3ef918a87a5f79063a305069a950143955ae493e Mon Sep 17 00:00:00 2001 From: root Date: Tue, 20 Oct 2026 22:05:19 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=9B=9E=E6=B5=81=20m?= =?UTF-8?q?ain=20=E6=97=B6=E6=AE=8B=E7=95=99=E7=9A=84=E5=86=B2=E7=AA=81?= =?UTF-8?q?=E6=A0=87=E8=AE=B0=EF=BC=88billing.lua=20/=20billing=5Ftest.go?= =?UTF-8?q?=20=E5=8F=96=20release/v2.0.x=20=E5=B9=B2=E5=87=80=E7=89=88?= =?UTF-8?q?=E6=9C=AC=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/lua/billing_test.go | 3 --- internal/lua/plugins/billing.lua | 12 +++++------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/internal/lua/billing_test.go b/internal/lua/billing_test.go index aecefb5..6edabe5 100644 --- a/internal/lua/billing_test.go +++ b/internal/lua/billing_test.go @@ -1236,8 +1236,6 @@ func TestLongContextComposesWithCacheDiscount(t *testing.T) { // total = 0.2325 approx(t, "step composes with cache discount", got, 0.2325) } -<<<<<<< HEAD -======= // ---- 源层零价覆盖模型价(issue #1)--------------------------------------- // @@ -1371,4 +1369,3 @@ func TestBillingProfileDefaultPolicy(t *testing.T) { } } } ->>>>>>> 7941b41 (refactor(billing)!: 计费全部沉入插件,内核零 billing 代码;规则由插件自持) diff --git a/internal/lua/plugins/billing.lua b/internal/lua/plugins/billing.lua index 62be325..2c4f41a 100644 --- a/internal/lua/plugins/billing.lua +++ b/internal/lua/plugins/billing.lua @@ -72,8 +72,6 @@ local DEFAULT_PRICES = { } plugin.prices = DEFAULT_PRICES -<<<<<<< HEAD -======= -- ===== 规则 → 价格表编译(全部在插件内) ============================== -- -- billing 没有任何内核逻辑(issue #1 的方向):规则文件、编译、计价、账目、 @@ -479,7 +477,6 @@ plugin.http = { -- 测试/运维直调导出(/api/plugins/billing/call/...);不是内核接口。 plugin.exports = { "rules_get", "rules_put", "rules_add", "rules_delete" } ->>>>>>> 7941b41 (refactor(billing)!: 计费全部沉入插件,内核零 billing 代码;规则由插件自持) -- Default prompt-cache discount. 0.1 = a cache read costs a tenth of a fresh -- token, which is what DeepSeek/Qwen/Kimi and most others charge. It can be -- overridden per price entry (prices.models..cache_discount) or globally by @@ -597,7 +594,11 @@ local function priceFor(payload) -- look the same: an unpriced model silently costing 0 is the most dangerous -- failure mode a cost plugin has, because the bill still adds up and just -- quietly under-reports. It is counted separately and surfaced in the UI. - out = { + -- ★ local 是必须的:此前写的是全局 `out = {`,而 priceFor 每个请求都会调用, + -- 于是这个表挂在 VM 级全局变量上跨请求残留/泄漏(GitCode issue #1 顺带发现)。 + -- 功能上因为每次整体重建而侥幸正确,但它是共享可变状态,任何提前 return 或 + -- 后续分支忘了重建都会让上一单的价格漏到下一单 —— 计费错误不会报错。 + local out = { prompt = d.prompt or 0, completion = d.completion or 0, per_request = 0, cache_discount = d.cache_discount, peak = d.peak, -- nil = bill reasoning at the completion rate, which is what every @@ -644,8 +645,6 @@ local function priceFor(payload) if kp.cache_discount ~= nil then out.cache_discount = kp.cache_discount end if kp.peak ~= nil then out.peak = kp.peak end end -<<<<<<< HEAD -======= -- profile 级 default 策略(编译期写入 prices.default_mode)在这里落地: -- `free` = 运营声明"没有单独规则的源一律免费" ⇒ 计为已定价(不进 unpriced 统计); @@ -656,7 +655,6 @@ local function priceFor(payload) out.priced = true end end ->>>>>>> 7941b41 (refactor(billing)!: 计费全部沉入插件,内核零 billing 代码;规则由插件自持) return out end