Skip to content

feat: per-install rollout gating (registry, bucketing, nested cohorts) - #3104

Merged
ranxianglei merged 5 commits into
masterfrom
2026-10-13_rollout-gating
Oct 14, 2026
Merged

ranxianglei merged 5 commits into
masterfrom
2026-10-13_rollout-gating

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Fixes #3062

What

New src/rollout.ts — a per-install gradual-rollout engine:

  • ROLLOUT_FEATURES registry (ships EMPTY — zero behavior change in this PR; feature adopters add entries in their own PRs with the percent/salt/base they want).
  • Per-install identity: UUID persisted at stateDir()/rollout-id.json (machine-global state, stable across releases; pinnable via rollout.installId; heals corrupt files in place; derived fallback when state dir is unwritable). Empty registry ⇒ the id file is never even created — strictly zero observable change.
  • Bucketing: sha256(salt + "\n" + id) → readUInt32BE(0) % 10000 basis points (BP_MAX=10000). Monotonic: enabled-at-X% stays enabled at every Y>X.
  • Nested cohorts (the A→B / C→D pattern from feat: 灰度发布机制 —— 新特性按安装维度百分比放量(支持嵌套灰度 A→B) #3062): base re-scopes a feature's bucketing to its parent's cohort, with visited-set cycle guards (cycles fail closed).
  • Precedence: env (BILI_ROLLOUT_<FEATURE>, 0/false=off else on) > config enabled > config/registry percent > OFF (unknown features fail closed).
  • Startup log: one [rollout] install <id8> — feature=on/off(source, bucket b/10000 vs Nbp[, base X]) line per feature when the registry is non-empty; warnInertRolloutEntries() warns on config entries that can't resolve (建议:compress.stripImages 默认开启——否则带图消息不可压缩会形成只升不降的输入地板撑爆上下文 #2607 discipline).

Config surface

  • Added: top-level rollout block — rollout.installId, rollout.features.<name>.{enabled,percent,salt,base} — plus the BILI_ROLLOUT_<FEATURE> env family (dynamic name, documented in the seeds with the expected check-coverage notice).
  • Why the existing surface cannot express it: src/knobs.ts is scalar env>file>default only (no nesting, no registry, no per-install identity); providers/compress are provider/model-scoped, not feature-boolean gating; nothing anywhere provides a stable per-machine install identity (native session ids are per-conversation by design).
  • Compat/migration: purely additive. rollout added to FileConfig + KNOWN_TOP_LEVEL_KEYS (no unknown-key warning noise); seeds added to website/config-reference/rollout.yaml so both doc gates pass; CONFIGURATION.md/CONFIGURATION.zh-CN.md/website regenerated via tools/gen-config-docs.mjs.

Testing

  • tests/rollout.test.ts — 21 tests: determinism/range, monotonicity, ~10% distribution over 4000 ids, salt reshuffle, precedence ladder (env>enabled>percent>registry), invalid-percent fall-through, nested cohorts (incl. 25%×50%≈12.5%, config base re-scope), cycle guards (self/x↔y) without hanging, deep chains, install-id persistence/pre-existing-file-wins/corrupt-heal/unwritable-fallback/config pin, inert-entry warnings.
  • Rebased onto current master (6887bbd), clean rebase; on the rebased head: npm run typecheck ✓, rollout suite 21/21 ✓, npm run build ✓, check:unused-exports ✓, gen-config-docs check-coverage + config-surface-guard ✓.
  • Full suite delegated to CI per owner instruction — the local full-suite attempt was invalidated by a concurrent-suite interference (two full npm test trees on one machine; documented as tests: two concurrent full-suite runs on one machine corrupt each other — need a per-machine suite lock (fail-fast) #3103).

Not in scope

#3062)

Adds src/rollout.ts: ROLLOUT_FEATURES registry (ships EMPTY — zero behavior
change until adopters add entries), sha256 bucketing on a per-install UUID
(persisted at stateDir()/rollout-id.json, config-pinnable), env>file>registry
precedence, and nested base cohorts (A->B patterned rollouts) with cycle
guards. New `rollout` config block + BILI_ROLLOUT_<FEATURE> env family,
docs regenerated (en+zh), seeds for both doc gates, 21-test suite.

Fixes #3062
@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-13_rollout-gating (46cd18d)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.3566-pr.3104.97860a2

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-pr3104.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] 🏷 (ai: vllm-qwen/qwen3.8-27b)

收到,开始按 PR Review 规范独立审核:方向对照 #3062 设计、回归清单(重点看 src/config.ts / src/server.ts 两处既有路径的增量)、代码与测试有效性、diff 整洁度。纯增量 670 行,先通读全部改动再下结论,稍后给结构化八问回复。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

#3104 审核完成,结论:可合并(详见末尾 CI 判定)。八问:

  1. 是什么问题:功能实现(feat: 灰度发布机制 —— 新特性按安装维度百分比放量(支持嵌套灰度 A→B) #3062)而非缺陷——给 bili 加「按安装实例灰度」引擎:稳定的机器级 install id + 确定性分桶,让后续功能可按百分比逐步放量。
  2. 什么原因导致的:现有配置面表达不了这个需求——knobs.ts 是标量 env>file>default(无嵌套/注册表/实例身份),providers/compress 是 provider/model 维度,全仓没有任何跨版本稳定的机器身份。PR 正文的 config-surface 论证成立。
  3. 影响范围与严重程度:注册表为空,合入即零行为变化——不创建 id 文件、不打日志、不改任何请求路径;首个真实 feature 条目另开 PR 时才生效。无用户面风险。
  4. 怎么修复的(设计判定):逐条对照 feat: 灰度发布机制 —— 新特性按安装维度百分比放量(支持嵌套灰度 A→B) #3062 规格独立核验——sha256(salt+"\n"+id)%10000bp 单调分桶、空注册表零足迹、base 嵌套队列 + visited 环保护(fail closed)、env>enabled>percent>OFF 优先级链、installId 钉扎、启动可观测行、warnInertRolloutEntries(建议:compress.stripImages 默认开启——否则带图消息不可压缩会形成只升不降的输入地板撑爆上下文 #2607 纪律),全部与规格一致;递归/竞态(wx 独占创建、损坏自愈、不可写降级)路径我逐条追过,不是照抄 PR 描述。
  5. 是否有回归问题:审过的既有行为及结论——config 解析与 unknown-key 警告:rollout 进 KNOWN_TOP_LEVEL_KEYS,不再误报(有意);server 启动路径:空注册表时除 warnInertRolloutEntries 的空返回外无任何新动作,保持;持久化格式:只新增独立文件 rollout-id.json,不动 sessions.json,保持;wire/请求路径:完全不触碰,保持;文档门:en/zh 同步、seed 驱动表格再生成,通过。无意回归:零。唯一可见变化 = rollout 不再被当未知顶层键告警(有意兼容,已披露)。
  6. 是否破坏缓存:不涉及——消息重建、前缀缓存输入、重试/游标/去重键均未触碰。
  7. 是否改了设计方向:不涉及架构转向;新增模块单向依赖(server→rollout→config/paths/logger),无循环导入,空注册表为后续条目留了干净扩展点。
  8. 是否引入了新的配置:是,且已按 owner-gated 规则给出 config-surface 段:rollout.installId、rollout.features.<name>.{enabled,percent,salt,base}、env 族 BILI_ROLLOUT_<FEATURE>(动态名,种子文档已注明 check-coverage 预期);纯增量、默认全 OFF、无需迁移。

CI 判定:head 3c4510f 共 35 项检查——31 绿(全部静态门 + 全部真客户端 e2e lane;codex lane 的一次 ETIMEDOUT 是 Windows runner 基础设施抖动,同 lane 在 master 上绿,我已触发重跑并转绿)。剩 4 红 = test ubuntu×2/windows×2,失败的全部是与 PR 无关的既有问题:storage-render 四个 golden 在 master 裸树上本就红(我在 master 上复现出相同 digest)。根因分层:#3093 把 biliVersion 变成 metadata 首个插入键(值无变化,A/B dump 逐字段比对证实),撞上 golden 摘要按插入顺序序列化的键序敏感——已立 #3113 跟踪,修复 PR #3119 在途(harness 侧深排对象键,跨提交 digest 一致性已验证)。

收工判定:PR 自身表面全绿、零回归、规格符合性逐条通过;4 红 lane 属 master 既有缺陷(#3113/#3119)。建议直接合并;若想等全绿,先合 #3119 再 rebase 本 PR 即可。

Three user-facing traps found in review, all fixed:

1. Shorthand overrides were silently dropped: overrideFor only read
   objects, so "simhashV2": true (force on) or "simhashV2": 20
   (percent) — the shapes users naturally write first — became {}, the
   config force silently vanished and the bucket kept deciding. The
   shorthand forms are now accepted and equivalent to {enabled}/{percent}.
2. Wrong-typed fields ("enabled": "true", "percent": "100") failed
   strict equality / percentBp and fell back to the bucket with zero
   feedback. The startup warn now names every such entry (and non-object
   entries, and unknown features) instead of only inert objects.
3. The derived-id fallback (unwritable state dir) hashed process.env
   HOSTNAME — a bash-ism absent on Windows, so every affected Windows
   box collided on one shared id and moved through cohorts in lockstep.
   It now derives from os.hostname() + OS home (USERPROFILE) + user
   name via the exported derivedInstallId().

Type widened honestly (features accepts boolean|number shorthands);
docs regenerated; 4 new tests (25/25 green), tsc clean.
@ranxianglei

Copy link
Copy Markdown
Owner Author

Review 追加:三处"用户配置被静默吞掉"的陷阱 + Windows 修复(f582d4d)

对 #3062 机制逐行 review 后发现:判定逻辑(优先级/单调性/嵌套/环)没有硬 bug,但存在用户以为打开了、实际静默没生效的三条路径,已直接修在本分支:

① 布尔/数字缩写被静默丢弃(最常见写法)

用户自然写法 "simhashV2": true(强制开)或 "simhashV2": 20(比例),旧 overrideFor() 只认对象 → 返回 {} → 配置力场消失、桶继续决定,且无任何告警。现在缩写与 {enabled:true} / {percent:20} 等价。

② 类型写错静默降级

"enabled": "true"、"percent": "100"(字符串)不命中严格全等/数值校验 → 落回桶计算;原 inert 告警因为"字段存在"反而不点名。现在启动警告逐条点名(非对象条目、类型错误字段、未知特性各自有专属提示),warn-once 去重。

③ Windows 派生 id 全员撞车(state dir 不可写时的兜底路径)

旧兜底哈希 process.env.HOSTNAME——bash 专属变量,Windows 上恒为 undefined,所有踩到兜底的 Windows 机器共享同一个派生 id、同进同出灰度组。现改用 os.hostname() + OS home(USERPROFILE)+ 用户名,导出为 derivedInstallId()。

类型与文档

  • RolloutFileConfig.features 诚实放宽为 RolloutFeatureOverride | boolean | number(缩写合法);
  • config-reference YAML + CONFIGURATION.md en/zh 已重生成,check-coverage 通过。

验证

  • 本地:tsc 0 错,tests/rollout.test.ts 25/25(原 21 + 新 4:缩写生效/缩写压过注册表 percent/错类型忽略且警告点名/派生 id 区分主机),build 通过;
  • Windows 10 真机(VM, node v22.23.2):25/25 测试全绿;真机行为脚本 9/9 PASS——os.hostname()=DESKTOP-… 非空而 process.env.HOSTNAME=undefined(实锤旧 bug 输入)、state-dir 不可写 → derived- id 稳定且不同主机不同、真配置文件端到端 sh:true 强制开、"enabled":"true" 不强制且警告点名。

CI 全绿后可合;合入即修复上述三条,注册表仍为空、无行为变化。

ework-agent added 2 commits October 14, 2026 13:08
…3104 review)

Review follow-up on f582d4d: a number shorthand outside 0-100 (e.g.
"x": 200) was accepted by overrideFor, rejected by percentBp, and skipped
by the warn loop's blanket number bypass - silently OFF for unknown
features, silent fall-back to the baked-in plan for registered ones, with
zero feedback. Same silent-no-op class this commit set out to kill.

warnRolloutConfigProblems now range-checks numeric shorthands and names
them like every other ignored entry; tests pin the resolver fall-through
(no cohort widening) and both warn/no-warn cases.
 review)

Review follow-up on f582d4d: os.userInfo() throws when the running uid
has no passwd entry (common in containers) and os.hostname() can fail
with ENOSYS on minimal hosts - both called inline inside the
persist-failure catch, so an exception there escapes rolloutInstallId
and takes the proxy down at boot. The whole point of the fallback is to
never crash; degrade each lookup independently to "" instead.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

f582d4d 逐行审完并独立验证。结论:三处修复方向与实现都正确,但我在同一条路径上找到两个残留漏洞,已直接修在本分支(两个独立小 commit:48b1df3c、46cd18d4,均已 push)。

对你三处修复的独立验证

  1. 缩写等价 — 正确。true/false 走严格全等 → {enabled}(强制语义),数字走 Number.isFinite → {percent}(比例语义)。你测了 false 压过注册表 percent-100,钉住了「强制而非重缩放」;NaN 被排除(JSON 也带不出 NaN),无误伤面。
  2. 启动警告点名 — 四类点名齐全(非对象条目/未知特性/错类型 enabled/错类型 percent),warn-once 去重正确。但漏了一类:越界数字缩写("x": 200)——overrideFor 收下、percentBp 拒绝、而警告循环「数字一律跳过」让它溜过 → 未知特性静默 OFF、已注册特性静默落回内置 percent,零反馈。这正是本 commit 要消灭的「静默吞掉」类,我已补上范围校验与点名(见下)。
  3. Windows 派生 id — 根因定位准确(HOSTNAME 是 bash 专属变量,Windows 恒 undefined),os.hostname() + USERPROFILE + username 的修法正确,\n 字段分隔防拼接歧义;真机证据(HOSTNAME undefined vs os.hostname 非空)扎实。但它引入一个新风险:os.userInfo() 在 uid 无 passwd 条目时抛异常(容器里很常见)、os.hostname() 在精简系统可 ENOSYS——两者原来内联在 persist-failure 的 catch 块里,任一抛错都会逃出 rolloutInstallId,代理启动即崩。兜底路径的全部意义就是「任何情况下都不崩」,我已把两个查询各自包 try/catch 降级为空串(第二个 commit)。此分支无法单测:node:os 是 ESM namespace 对象不可 monkey-patch,属 exotic host 才触发的防御代码,靠审查保证。

回归清点(本轮 diff 触碰的既有行为,逐项)

  • features 类型放宽(| boolean | number):纯加性,旧配置解析结果不变;
  • 缩写从「静默丢弃」变「生效」:有意变更(即本修复目的),已披露;
  • warnInertRolloutEntries → warnRolloutConfigProblems:模块内改名,全仓 grep 零残留引用,unused-exports 门禁干净;
  • Windows 派生 id:旧=全员共享同一 id(同进同出灰度组)→ 新=按主机区分;有意变更,已披露;
  • 我的警告改动:越界数字缩写会多一行警告(加性日志输出),正常配置不受影响;
  • wire/缓存/时序/持久化格式:未触碰。注册表仍为空 ⇒ 发布构建对用户零可见变化。

验证(均在 46cd18d 由我实跑):rollout 套件 25/25 ✓(含我新增的越界断言:resolver 不扩 cohort + 警告点名/范围内不点名)、typecheck ✓、build ✓、unused-exports ✓。全量交给 CI——push 后 17 个 check-runs 已开跑,出结果我再补一句。

八问

  1. 是什么问题:用户以为打开的 rollout 开关在三种写法下被静默忽略(缩写、类型写错、Windows 兜底 id 撞车)。
  2. 什么原因导致的:overrideFor 只认对象一种形态;警告逻辑对数字有盲区;兜底哈希用了 bash 专属的 HOSTNAME 变量。
  3. 影响范围与严重程度:只影响已写 rollout 配置的用户(注册表当前为空,发布构建零影响);严重度为体验陷阱 + Windows 兜底路径完全失效。
  4. 怎么修复的:缩写与正式对象等价且强制/比例语义分清;启动警告对每条被忽略的配置点名;派生 id 改用 OS 原生 hostname/home/用户名。
  5. 是否有回归问题:无(逐项清单见上;两处有意变更均已披露旧值→新值)。
  6. 是否破坏缓存:不涉及。
  7. 是否改了设计方向:没有——只是把 feat: 灰度发布机制 —— 新特性按安装维度百分比放量(支持嵌套灰度 A→B) #3062 机制的失败路径补齐,架构不变。
  8. 是否引入新配置:没有——仅放宽既有 rollout.features.<name> 的值类型以接受缩写(纯加性)。

判定:可合——机制主体与你这三处修复经独立验证成立,我又顺手堵了同路径的两个洞(越界数字静默吞掉、exotic host 启动崩溃)。CI 全绿后合并即可。

@ranxianglei
ranxianglei merged commit 6c78389 into master Oct 14, 2026
35 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.402-master.6c78389 (rolling master tag).

npm install -g billion-context@0.0.402-master.6c78389  # this exact build
npm install -g billion-context@master  # always the newest merged build

npm view billion-context@master prints the current version at any time.

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.

feat: 灰度发布机制 —— 新特性按安装维度百分比放量(支持嵌套灰度 A→B)

1 participant