Skip to content

[PR] fix: reject unknown billing root fields when prices is present - #7265

Open
Afloat16 wants to merge 1 commit into
ranxianglei:masterfrom
Afloat16:2026-11-19_reject-billing-root-fields
Open

Afloat16 wants to merge 1 commit into
ranxianglei:masterfrom
Afloat16:2026-11-19_reject-billing-root-fields

Conversation

@Afloat16

Copy link
Copy Markdown
Contributor

Fixes #7263

Problem and change

parseBillingSettings checks unknown root fields only when prices is absent. Adding an empty or populated prices map therefore makes a misplaced field such as billing.cacheRead, or a misspelling such as billing.price, silently disappear. Startup loading and both web config-save paths share this parser, so they accept a block that violates its documented whole-block rejection contract.

Move the existing root-key validation before the optional-prices branch. The accepted root key remains prices; price-value validation and price resolution use their existing paths.

The regression coverage checks:

  • Unknown fields with absent, empty, and populated prices.
  • Startup warning, removal of stale overrides, availability of other settings, and byte-for-byte preservation of the configuration file.
  • Structured and whole-file saves returning HTTP 400 before changing either the file or the active price table, for both empty and populated prices.

Existing valid full, partial, and empty shapes, successful saves, and clearing the price table remain covered by the same suites.

Config surface

No supported configuration fields are added, renamed, or given new meanings. This restores the documented rejection of unknown fields at the billing root when prices is present. Previously tolerated misspelled or misplaced root fields now cause saves to return HTTP 400. Loading an existing malformed block warns and falls back to registry prices without rewriting the file. Correct such fields by moving price values into billing.prices[model] or removing unsupported keys.

This is the shared configuration path for both compression modes. No request-wire, compression-kernel, price-calculation, or persistence-format change is involved.

Validation

Base: current master at 04ecbb42dd38543e9c407bd40eb773ae5ec8b60b (billion-context 0.1.216).

  • Baseline: 19 existing billing tests passed; npm run typecheck passed.
  • Before the production change: all three new regressions failed, with the original 19 tests still passing.
  • After the change: 22/22 tests passed, with no skips, using the repository's two test preloads and tsx:
node --import ./tests/preload-storage-baseline.mjs --import ./tests/preload-test-env.mjs --import tsx --test tests/billing-prices.test.ts tests/billing-web.test.ts
  • npm run typecheck: passed.
  • npm run build: passed, including kernel and pi-subagents builds and the dist import/external-dependency checks.
  • git diff --check: passed.

Local runs used a writable task-specific TMPDIR. The authoritative full-suite verdict remains the remote CI result on the pushed head, per the repository workflow.

Prior work checked

#4916 introduced the billing feature; #5042 fixed null prices. Neither fixes the conditional root-key check. Existing issues, all-state PRs, the contributor's prior PRs, and billing branches were screened for overlapping work before this change.

@ranxianglei ranxianglei changed the title fix: reject unknown billing root fields when prices is present [PR] fix: reject unknown billing root fields when prices is present Nov 19, 2026
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 (ai: opencode/qwen3.8-27b)

Duplicate screening: this PR is not a duplicate of any issue — but there is a parallel PR #7266 fixing the same issue #7263 with the same fix. #7265 was opened 07:10:16Z, #7266 at 07:10:58Z (a 42-second race). Per first-come-first-served and the repo rule against replacing external contributions (#1765), #7265 is canonical. I labeled the #7266 thread duplicate; the worker on that thread already posted a supersede comment asking the owner to close it. Agents cannot close PRs — that call is yours.

Review of #7265 — verified, mergeable (human merge required: config-behavior change, §7.4 "must stay human").

What I verified (executed, not just read):

  • Bug is real on master 04ecbb42dd3: in parseBillingSettings (src/billing.ts:59-62) the root-key loop only runs inside the root["prices"] === undefined branch, so { prices: {...}, cacheRead: 0.3 } parses with the misplaced field silently dropped — violating the function's own documented "ANY shape violation → undefined" contract (src/billing.ts:52-54) and the documented schema (docs/configuration.md:95).
  • Fix is at the root cause: the loop moves ahead of the branch. I enumerated every input shape: the ONLY behavior delta is "root has prices + ≥1 other key": accepted-before (field dropped) → rejected-now. All other shapes ({}, { prices: {} }, valid/invalid prices, prices: null) behave byte-identically to before.
  • All three consumers checked: startup load (src/config.ts:1666-1670) warns + clears overrides and never rewrites the file; whole-file save (src/web/api.ts:343) and structured save (src/web/api.ts:450-452) return 400 before any write. The web editor (src/web/client.ts:5899) only ever PUTs { billing: { prices } }, so no self-inflicted 400s.
  • Tests are real regressions, not tautologies: on the PR base the 3 new Billing root fields are silently ignored when prices is present #7263 tests FAIL (19 original pass); on the PR head 22/22 pass. Assertions have teeth: byte-for-byte file preservation, active-override table state, HTTP status, warning text. npm run typecheck clean; git diff --check clean; single commit, 3 files, +42/−1, every line on-topic.
  • CI on head 35e06e88595: 36 success / 12 skipped / 0 failed (fetched live).

Behavior change (disclosed in the PR's Config surface section, which I confirm accurate): billing: { prices: {...}, <unknownRootKey> } — old: loaded, unknown key silently dropped, prices applied; new: whole block rejected (startup warns + registry fallback; saves 400). No shipped writer emits such a block, so this restores the documented contract rather than breaking anyone.

One small note: parallel PR #7266 carries a 4-line "why" comment on the moved check that #7265 lacks. I attempted to add it as an additive commit but the fork rejects pushes from this account (permission denied), so it stays a suggestion — the text is in #7266's diff if you want it in the merged code.

Labels: #7263 (source issue) and this thread → bug + p2 + scope/other (config silently ineffective; workaround exists, no data loss/cache leak, so not p1); #7266 → duplicate (parallel PR, 42s later, same fix).

Recommendation: merge #7265, close #7266 (owner action).


八问结论(供人工 reviewer):

  1. 是什么问题: billing 配置块的解析器只在 prices 缺席时才校验未知根字段——一旦带任何 prices 映射,错放/拼错的根字段(如 billing.cacheRead)被静默丢弃,配置看似有效实则不生效。
  2. 什么原因导致的: 根字段校验循环被写在了 prices === undefined 分支内部(src/billing.ts:59-62),「prices 存在」的路径整体跳过了校验——分支摆放缺陷,不是数据问题。
  3. 影响范围与严重程度: 任何手改 billing 多写了根字段(或第三方工具写出)的用户;web 编辑器自身不会。p2——配置静默失效但有绕行(把值移进 billing.prices[model] 或删掉该键);无数据丢失、无缓存泄露、不影响可用性。
  4. 怎么修复的: 把既有的根字段校验移到可选 prices 分支之前,使文档声明的整块 loud-reject 契约(src/billing.ts:52-54)对所有形状成立;接受的 schema 不变。
  5. 是否有回归问题: 逐形状枚举过——唯一行为差集就是有意的那一处(未知根字段 + prices 存在:从接受变拒绝);既有 19 个 billing 测试在 PR head 上原样通过;启动/保存三条消费路径逐一核过调用点;不碰 wire/kernel/持久化。
  6. 是否破坏缓存: 不涉及——纯配置解析,不触碰缓存/重试/游标/去重键。
  7. 是否改了设计方向: 否——是把解析器拉回它文档承诺的契约,无新机制。
  8. 是否引入了新的配置: 否——无新字段/env/默认值;文档 schema 不变,原先被容忍的非法形状现在被正确拒绝(已在 PR 的 Config surface 一节披露)。

判定: 可合(§7.4 要求人工合并——配置行为变更),合后请关闭 #7266。

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working p2 scope/other

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Billing root fields are silently ignored when prices is present

2 participants