Skip to content

fix(#1815): warn on unknown top-level config keys with compress-placement hint - #1817

Merged
ranxianglei merged 1 commit into
masterfrom
2026-10-01_unknown-top-level-keys-warn
Oct 1, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-10-01_unknown-top-level-keys-warn

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What & why

loadConfigFile() (src/config.ts) casts the parsed JSON straight to FileConfig — TypeScript types are erased at runtime, so any top-level key the loader does not consume was dropped with zero feedback. The issue's repro (root-level "promptPack") is exactly that: the user's intent vanished silently, violating the §7.3 "never silently clobber or drop user config" rule.

The fix adds runtime key validation at the single chokepoint every file-based config read passes through (loadConfigFile, used by loadOptions/loadRoutes/all resolvers):

  • Unknown top-level keys are collected and logged as ONE warn per unique key set per process (signature-deduped, same pattern as seenAbsorbDivergenceWarnings): repeated config reads within one startup don't spam; if the user fixes some keys while running, the new remainder re-warns.
  • Any unknown key matching a known compress field gets a targeted hint — this covers the whole misplaced-compress-key class named in the issue (promptPack, nudgeGrowthTokens, …), not just promptPack.

Example log line (the issue's exact repro):

[warn] [acp-config] ignoring unknown top-level config key(s): promptPack — "promptPack" belongs under "compress" (did you mean "compress.promptPack"?)

Behavior change (explicit)

  • Old: unknown/misplaced top-level keys were ignored silently — no log output at all.
  • New: one warn line per process per distinct unknown-key set. Log-only: the keys are still ignored exactly as before (no parsing change, no rejection, no file mutation), so nothing that worked before changes behavior.

Config surface

None. No config field, env var, or CLI flag added/renamed/re-semantics'd — this change only adds a diagnostic log for existing invalid input.

Scope note

Top-level only, per the issue's suggested fix. Deeper levels (compress block typos, provider route-entry typos) have the same silent-drop class; left as-is here to keep the diff scoped. Same root cause, so no separate issue filed — owner decides whether a follow-up wants the same treatment one level down.

Tests

New tests/issue1815-unknown-top-level-keys.test.ts (4 tests):

  1. direct unit: warns once per unique key set, repeat suppressed, compress-placement hint present only for compress fields;
  2. the issue's exact repro through the real load path (BILI_CONFIG_FILE + loadRoutes()): exactly one warn across two loads, known keys never flagged, routes parse identically;
  3. multiple unknowns list together; fixing some re-warns about the rest;
  4. false-positive guard: the full documented 31-key top-level surface produces zero warnings.

Pre-flight

  • npm run typecheck — clean
  • npm test — 3248 tests, 3236 pass, 0 fail, 12 skipped (all env-conditional pre-existing skips, e.g. live-E2E gates / non-loopback-address checks; the new file has none)
  • npm run build — success

Fixes #1815

@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-01_unknown-top-level-keys-warn (42fb56d)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.1798-pr.1817.a44db96

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr1817.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review started — 方向审核通过(修复打在 loadConfigFile 唯一漏斗点、纯日志不改解析语义、无配置面变更、与 #1469 的 provider 级 dead-field guard 分层互补不重叠)。发现一个必须处理的问题,正在分支上直接修:

Stale base → 误报回归:PR base 是 8d3d1bfc(v0.1.172 时代),当前 master 已到 v0.1.178。期间 master 给 FileConfig 新增了顶层字段 chainEgressStamp(#1683/#1690,chain-egress-stamp-off)——它不在本 PR 的 KNOWN_TOP_LEVEL_KEYS(33 keys,与 base 的 FileConfig 完全一致)里。若按现状合并,任何在 config 里写了 "chainEgressStamp": true 的用户会收到一条虚假告警 ignoring unknown top-level config key(s): chainEgressStamp——恰好是这类告警最不能犯的错误。

处理中:rebase 到当前 master + 把 chainEgressStamp 补进 KNOWN_TOP_LEVEL_KEYS 与测试 4 的防误报清单(该测试同时是两个集合的漂移探测器);另顺手把测试 teardown 从裸 fs.rmSync 换成 tests/tmp-rm.ts 的 rmrf(retry 选项,#1646 起的全仓约定,CI 负载下裸 rmSync 有 ENOTEMPTY flake 史)。rebase 后重跑 typecheck + 全量测试 + build,验证完贴七问结论。

@ranxianglei
ranxianglei force-pushed the 2026-10-01_unknown-top-level-keys-warn branch from 4c0526d to 42fb56d Compare October 1, 2026 03:47
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review 完成 — 已修好可直接合并。 分支已 rebase 到当前 master(bdc170b5,含评审期间刚合入的 #1784 web quick-config,该 PR 只动 src/web/*,与本 PR 无交集),单 commit 42fb56d9,--force-with-lease 推送完毕。CI 全绿(12/12)。

评审中发现并直接修掉的问题(2 处):

  1. Stale base → 误报回归(拦下):原分支基于 v0.1.172 时代,KNOWN_TOP_LEVEL_KEYS(33 keys)与当时 FileConfig 完全一致,但 master 其后新增了顶层字段 chainEgressStamp([Bug]Chain-integrity checkpoint tag <bili-chain …/> is injected as a visible trailing user-role message — models read it as phantom user input and burn tokens commenting on it #1683/fix: make chain-integrity recognition header-only by default (#1683) #1690)。按原状合并的话,任何在 config 里写了 "chainEgressStamp": true 的用户会收到虚假告警——对「告警必须零误报」这类功能是最不可接受的错误。已把 chainEgressStamp 补进集合(src/config.ts:1246)并同步进测试 4 的防误报清单(该测试同时是两个集合的漂移探测器:今后 FileConfig 加字段而忘记同步集合时,它会红)。
  2. 测试 teardown 不合规(顺手修):withConfigFile 用裸 fs.rmSync(dir, {recursive, force}),缺 test: teardown rmSync ENOTEMPTY race — most test cleanups lack retry options (CI ubuntu-latest Node 22 flake) #1646 起全仓约定的 retry 选项(CI 负载下 ENOTEMPTY flake 史,见 tests/tmp-rm.ts)。已换成 rmrf(dir)。

既有行为清点(回归审查结论:无回归):

  • 合法配置解析不变:当前 master 全部 34 个顶层 key 零误报,测试钉死;
  • 未知 key 仍照旧被忽略——无新增拒绝/失败路径,fail-fast 语义未变;
  • COMPRESS_SETTING_FIELDS(30 字段)与当前 master parseCompressSettings 实际接受的顶层 compress 字段逐一核对一致,无漏提示(debugLog/contextThresholdPct 等是 absorb/ccr/search 嵌套子字段,正确地不在其中);
  • 与 One-shot: named providers as real lanes — bind + compactionOptIn + agent-side switch, landing in a single PR (replaces #1466 staging) #1469 的 provider 级 inert-routing-field guard 分层互补:一个管顶层、一个管 named-provider entry,同套签名去重模式,无语义重叠;
  • Web UI raw whole-file PUT 本来保留磁盘未知键,与新告警不冲突;
  • 高危模式逐项过:无阈值/时序/输出格式漂移,无错误处理语义变化,无缓存/重试/去重键触碰。

测试有效性:4 个测试断言有牙——精确计数(两次加载恰好一条 warn)、消息内容逐字匹配、走真实 BILI_CONFIG_FILE→loadRoutes() 路径而非 mock、部分修复后重告警、全表面防误报。bug 回归时抓得住。

diff 整洁度:单 commit,仅 src/config.ts(+51)与 tests/issue1815-unknown-top-level-keys.test.ts(+130),每行都与本 PR 目的相关。

验证(rebased head 42fb56d9):本地 typecheck clean;全量 3480 tests / 3461 pass / 0 fail / 19 skipped(环境条件性 skip,新文件 4/4 pass);build 成功。CI 12/12 green:ubuntu/windows × Node 22/24 矩阵、4 条 zero-token E2E lane(opencode/codex/dsh/pi)、hermetic registry e2e、version-guard、codex MCP 注册。

结构化七问:

  1. 是什么问题:config 文件里 loader 不消费的顶层 key(典型:root 级 promptPack)被静默丢弃、零反馈,用户意图无声消失。
  2. 什么原因导致的:loadConfigFile() 把解析后的 JSON 直 cast 为 FileConfig,类型擦除后未知 key 无运行时校验、无人认领。
  3. 怎么修复的:在文件读取唯一漏斗点加未知顶层 key 检测;每进程按唯一 key 集合签名单条 warn(重复读配置不刷屏,运行中修掉部分 key 后剩余项重新告警);匹配已知 compress 字段的 key 附 did you mean compress.K? 定向 hint。纯日志:不改解析、不拒绝、不改写文件。
  4. 是否有回归问题:无。上述既有行为逐项审过;评审中拦截了一处潜在误报回归(stale base 下的 chainEgressStamp),已在分支上修复并验证。
  5. 是否破坏缓存:不涉及(进程内 Set 仅为日志去重状态,与请求缓存无关)。
  6. 是否改了设计方向:不涉及——纯诊断补充,架构/边界/数据流无转向。
  7. 是否引入新配置:不涉及——无新字段/env/CLI flag。

行为变更披露(旧→新):旧 = 顶层未知/错位 key 零日志静默丢弃;新 = 每进程每个不同未知 key 集合一条 warn。仅日志层面,key 仍照旧被忽略,此前能正常工作的配置零影响。

小注:PR 描述里的「31-key」与 pre-flight 数字(3248 tests)是原 base 时的口径;rebase 后实际为 34-key 表面、3480 tests(以本条为准)。Scope note 维持原判:深层 silent-drop(compress 块内/provider route entry 内)同根因未拆 issue,是否下沉一级由你定。

判定:可合并(合并操作留给你)。

@ranxianglei
ranxianglei merged commit bc21e6f into master Oct 1, 2026
12 checks passed
@ranxianglei
ranxianglei deleted the 2026-10-01_unknown-top-level-keys-warn branch October 15, 2026 05:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[config] misplaced/unknown top-level keys are silently ignored — root-level promptPack does nothing without any warning

1 participant