Skip to content

feat: side-lane regression hardening — pure lane gates, truth tables, canaries, CI lane guard (#2170) - #2175

Merged
ranxianglei merged 5 commits into
masterfrom
2026-10-05_dsh-regression-hardening
Oct 5, 2026
Merged

ranxianglei merged 5 commits into
masterfrom
2026-10-05_dsh-regression-hardening

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Implements #2170 (measures 1, 2, 4, 5 in full; measure 3's e2e lane ships, its recorded golden fixture stays the follow-up noted in the issue).

Why

The #2156 → #2157 → #2164 chain showed the side-lane decision (the #388 passthrough) is regression-critical but only guarded by behavior tests that happened to exist. #2157 shipped a fork-child pollution regression with every existing suite green — the fork-child title shape simply wasn't tested. This PR makes each layer of that failure mechanically harder to repeat.

Measure 1 — pure lane gates (src/server/side-request.ts)

  • demoteGate(signals) — the seven cheap conjuncts of the heuristic demotion (was an inline conjunction in src/server.ts).
  • resolveSideLane(signals) → {lane, demoted, reason} — the #388 lane decision + the three reason shapes.
  • src/server.ts wires them; the two request-body effects (detectAcpArtifacts full-history re-encode, stripLeakedBiliTools mutation) stay in the caller and stay lazily short-circuited behind demoteGate — no hot-path behavior change.
  • Structural pin of the fix: side requests under public-fork children ride the #388 passthrough (#2157 follow-up) #2164 fix: resolveSideLane has no fork input — intent-certain side requests ride the lane under a fork receipt because there is no fork field to consult. demoteGate keeps the deliberate !publicForkPrefix veto (early fork-child mainline turns false-positive the leak-shape heuristic).

Measure 2 — truth tables + invariants (tests/)

Measure 4 — runtime canaries

  • Post-lane SIDE-EFFECT LEAK canary in src/server.ts: today unreachable; any side-shaped request that reaches the full pipeline increments session.metadata.sideEffectLeaks and logs loudly.
  • splitSessionWarnings() in src/session.ts (the #2165 failure shape: one conversation live under both the raw id and a |sub: fork). Surfaced as a new splitSessions key on /__bili/status (additive JSON) plus one rate-limited log line per base.

Measure 5 — CI lane guard (.github/workflows/ci.yml)

New lane-guard job (PR-only, kernel-guard mechanics): lane logic changed (src/server/side-request.ts, or lane-symbol lines in src/server.ts) without touching a dedicated side-lane suite → red with an explanatory message.

Measure 3 — dedicated dsh e2e lane (.github/workflows/ci-e2e-dsh.yml)

e2e-dsh-plugin-lane: runs the 12 fork/side/dsh-shaped suites sequentially in one named check (paths-filtered). Follow-up recorded in #2170: capture a real dsh transcript as a golden fixture.

Verification

  • tsc --noEmit clean.
  • New suites: 7 + 3 pass.
  • Lane-touching suites re-run: 110/110 green (truth-table, invariants, fork-side-request-lane, side-request-isolation 22, fix-1075-side-request 6, dsh-persona-fingerprint 7, plugin-fork 43, fork-adoption 2, fork-nudge-trigger 3, truncation-fork 8, fork-ccr-adoption 6, preflight-fork-estimate 2).
  • /__bili/status consumers re-run green (advisory-panel, opencode-acp-command, acp-status, update-notes).
  • Both workflow files YAML-validated.

Closes #2170 (fixture follow-up tracked there).

… runtime canaries, CI lane guard (#2170)

Measures 1/2/4/5 from #2170 (measure 3's recorded golden fixture stays a
follow-up; the e2e lane itself ships here):
- demoteGate()/resolveSideLane() extracted into src/server/side-request.ts
  as pure functions; server.ts wires them with the detect/strip effects
  still lazily short-circuited. resolveSideLane takes no fork input (the
  #2164 structural guarantee); demoteGate keeps the !publicForkPrefix veto.
- tests/side-lane-truth-table.test.ts: exhaustive tables pinning both gates
  and the reason strings.
- tests/side-lane-invariants.test.ts: observation-transparency, seeded
  ordering-fuzz vs main-only baseline, splitSessionWarnings unit.
- Runtime canaries: post-lane SIDE-EFFECT LEAK counter on the session +
  /__bili/status splitSessions warnings (the #2165 shape).
- ci.yml lane-guard job; new ci-e2e-dsh.yml dedicated dsh plugin lane.
@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-05_dsh-regression-hardening (695f5c7)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.2237-pr.2175.f757558

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-pr2175.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] 🏷 PR #2175 review 结论(对应原 issue #2170,五项加固措施)

验证了什么(不止读 diff):

  • 拉取分支做 rebase dry-run:当前落后 master 12 个提交(含 fix: bound web admin session loading (paged list, summary index, lazy detail) #1939 web-sessions-index,同样触碰 src/server.ts)——rebase 干净无冲突,与 fix: bound web admin session loading (paged list, summary index, lazy detail) #1939 改动区域(web 会话索引/persist 分页 vs 本 PR 的 lane 区域/sendStatus)无语义交互。
  • 本地定向跑新套件 + 相关既有套件:truth-table 7 + invariants 3 + dsh-persona-fingerprint 7 = 17/17 绿(全量回归交给 CI)。
  • CI:head 876b556 上 23/23 checks 全绿(含 lane-guard、kernel-guard、ubuntu/windows 双平台测试矩阵、registry e2e、image billing、新的 dsh plugin lane 命名 check),mergeable_state=clean。
  • 写了一个最小复现脚本验证 measure 4 的 split canary 与 dsh 设计内 persona fork 的交互(见下方发现 A)。

结构化七问

  1. 是什么问题:side-lane(标题生成等侧请求污染主会话状态:prepareAnthropic 缺 isTitleGen 守卫、快照无条件覆盖、survivedCount 每请求空转 #388 passthrough)决策是一个散落在 src/server.ts 里的复合布尔判断,[bug] dsh:side request 先到会抢走 persona 锚点,主会话被 fork 到 |sub:<fp>,原生 compress 永久失败 #2156→fix: side requests must not claim the persona namespace anchor (#2156) #2157→fix: side requests under public-fork children ride the #388 passthrough (#2157 follow-up) #2164 链条证明该决策面可以在全套件全绿的情况下放出回归(fix: side requests must not claim the persona namespace anchor (#2156) #2157 实际发生了)。本 PR 按 dsh 回归防护:泳道判定真值表 + 侧请求不变量 + dsh e2e lane + 运行时金丝雀 + lane-guard(5 项) #2170 的五项措施把每一层机械化地变难复发。
  2. 什么原因导致:lane 决策是「会话种类 × 请求种类 × 到达顺序」的组合空间,此前只有恰好存在的行为测试覆盖,没有穷举 pin、没有顺序无关性不变量测试、没有运行时哨兵、CI 也没有强制「改 lane 必须动测试」的配对。fix: side requests must not claim the persona namespace anchor (#2156) #2157 改 gate 时恰好漏掉 fork-child + 全历史重放 cell。
  3. 怎么修复的:measure 1 把两个 gate 抽成纯函数(demoteGate / resolveSideLane,后者结构性地没有 fork 输入——fix: side requests under public-fork children ride the #388 passthrough (#2157 follow-up) #2164 的性质变成「没有字段可查」);measure 2 用逐 cell 对照旧内联表达式的穷举真值表 + 真服务器上的观察透明性/顺序收敛不变量(deterministic LCG 交错);measure 4 两个运行时 canary(side-effect leak 计数 + splitSessionWarnings → /__bili/status.splitSessions);measure 5 lane-guard CI job(lane-symbol 变更 ⇔ 专用套件变更);measure 3 的 e2e 命名 lane(12 个 dsh/fork/side 套件,golden fixture 按作者声明留在 dsh 回归防护:泳道判定真值表 + 侧请求不变量 + dsh e2e lane + 运行时金丝雀 + lane-guard(5 项) #2170 跟踪)。
  4. 是否有回归问题:逐项审了触碰路径的既有行为——
  5. 是否破坏缓存:不涉及。prefix cache / 重试 / 增量游标 / 去重键均未触碰;side lane 保持 kernel-no-touch(invariant 测试 A 把 usage baseline / snapshot 内容钉到 bit-for-bit);canary 只写内存 metadata,不触发任何持久化失效策略。
  6. 是否改了设计方向:没有。纯函数抽取 + 观测面 + CI 纪律,架构/边界/数据流未转向;无 kernel/ 改动(kernel-guard 绿);install-lane/update-ownership 契约不受影响。
  7. 是否引入新配置:没有。无新 env/config key/CLI flag;SPLIT_CANARY_FRESH_MS(10 min)是内部常量而非用户旋钮;splitSessions 是增量 JSON 输出字段,不是配置。

测试有效性:真值表是对旧内联表达式逐字拷贝的参考公式做穷举对照——任何 conjunct/veto/reason 改动必翻 cell,断言有牙(唯一固有弱点:函数与拷贝的参考公式被同步修改时表仍会通过,已由 lane-guard 配对 + 人审缓解,可接受)。invariants (A)/(B) 是真服务器 + mock upstream,deterministic LCG(失败可从 seed 复现)、listen(0) 取端口(无环境运气,#360 纪律),断言的正是 #2156/#2157 类回归会破坏的量(requests / parentRevision / usage baseline / contextTokens / snapshot 内容)。(C) 的单元表带负例(idle twin / stale twin / 无关 base)。缺口:没有任何测试覆盖 persona fork 共存场景——与发现 A 是新发现一致,不意外。lane-guard 的 symbol-list grep 与 kernel-guard 同脆弱性等级(符号改名/搬家会静默失效),over-demanding 方向(注释里提到 "side request" 也强制动套件)可接受。

diff 整洁度:7 文件 +501/−7,单一线性提交,每一行都服务于本 PR 目的,无 lockfile/version/空白噪音,分支命名合规,version 未动。


判定:可合。 措施 1/2/4/5 忠实实现 #2170 规格,equivalence 有穷举证明,CI 23/23 绿,rebase 干净。发现 A/B 都是 measure 4 canary 语义层面的跟进项(措辞/一行收紧级别),不阻塞本 PR;若 owner 认可,我可以直接在本分支补一个标注清楚的小 commit(措辞调整 + leak canary 收紧),或在 #2170 线程记为 follow-up。measure 3 的 golden fixture 按作者声明留在 #2170 跟踪。请 @ranxianglei 择机合并:#2175

…a forks; leak canary lane-eligible only

Finding A (ework review): dsh auto-review classifyRisk forks onto |sub:<fp> BY
DESIGN (#1916/#1307/#1314) and rides the child's main pipeline, so every
healthy Auto-tier dsh conversation tripped splitSessionWarnings — the canary's
most common production trigger would have been the designed state. Fix:
requests deliberately namespaced onto a |sub: key (#970 claude subagents,
#1916 dsh persona reviews, codex/claude-over-Responses instructions personas)
stamp session.metadata.personaNamespace at resolution time; splitSessionWarnings
skips marked sessions. Also widened detection to the #2165-reported shape
itself (traffic-less raw twin + live fork now warns); only stale or fully idle
groups stay silent.

Finding B: the SIDE-EFFECT LEAK canary counted count_tokens / /responses/compact
/ session-less requests that legitimately route past the #388 lane — false
diagnostic signal. Now fires only for lane-eligible side-shaped requests,
making it a true structural assertion (unreachable by construction).

Tests: unit table gains persona-marked / mixed-sibling / #2165-shape cases;
new (D) integration proves a design persona fork stamps the child and keeps
/__bili/status splitSessions clean. 16 suites, 134/134 green.
@ranxianglei

Copy link
Copy Markdown
Owner Author

Review findings A and B both confirmed by code reading and repro, fixed in the latest push:

A (split canary vs design persona forks) — real. dshPersonaFingerprintApplies + subagentNamespace (src/server.ts identity resolution) forks review traffic onto |sub:<fp> by design and it rides the child's main pipeline (requests++), so every healthy Auto-tier dsh conversation warned. Fix: requests that were deliberately namespaced (#970 claude subagents, #1916 dsh persona reviews, codex/claude-over-Responses instructions personas) stamp session.metadata.personaNamespace = true at resolution time; splitSessionWarnings skips marked sessions. While re-deriving the semantics I also widened detection to the actual #2165-reported shape (traffic-less raw twin + live fork — the old all-requests>0 rule would have missed it); only stale or fully idle groups stay silent. New integration test (D): a design dsh persona fork lands on a stamped child, /__bili/status.splitSessions stays [].

B (leak canary false positives) — real. count_tokens / /responses/compact / session-less requests legitimately route past the #388 lane but still matched sideIntent || demotedSide. Canary now requires lane-eligible (!countTokens && !responsesCompact && protocol !== null) — with the pure resolveSideLane() this is unreachable by construction, which is the assertion it was always meant to be.

16 suites 134/134 green locally (incl. new negative/positive canary cases + mixed-sibling case: a marked sibling must not hide a drifting twin). Chose provenance stamping over rewording because the mark also future-proofs #970 codex/claude persona splits, which share the shape.

…ons dir

Found while reviewing #2175: all four test-matrix jobs went red on this PR's
merge commit with 'not ok - #2152 ... /__bili/overview answers 200' (got 500).
Master itself (4af31e0) is red on the same jobs — pre-existing, not caused
by this PR.

Root cause: /__bili/overview walks the disk session store, and a missing
sessions dir rejects loudly by design (#1937 pins 'no prior snapshot → reject,
never silent empty'). The parity test never isolated BILI_SESSIONS_DIR, so on
a fresh CI runner — where the ambient default state dir has never existed —
the overview 500s. Dev machines always have the dir, which is why it only
failed in CI. Reproduced locally by running the suite with HOME/XDG_DATA_HOME
pointed at empty dirs: ENOENT scandir + 500 before the fix, green after.

Fix: pin BILI_SESSIONS_DIR to a mkdtemp'd dir for the test's lifetime
(restore + rmrf in finally). Test-only; no production behavior touched — the
#1937 missing-dir contract stays exactly as pinned.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 第 2 轮 review(A/B 修复验证 + 新发现 C)

A、B 两处修复已在代码级逐条核对并本地验证,结论:修法成立。另外本轮发现 CI 四个 test-matrix job 全红,排查后确认是 master 侧既有问题,非本 PR 引入,已按「小问题直接修」在 PR 分支补了一个 test-only commit(695f5c727),详见第 3 问。

1. 是什么问题
本 PR 落地 #2170 的五项回归加固(纯 lane 函数、真值表、canary、CI lane guard、dsh e2e lane)。第 1 轮提出两个发现:A(split canary 对设计内的 dsh persona fork 误报)、B(leak canary 条件过宽)。本轮验证作者对 A/B 的修复;同时定位本 PR CI 全红的真实根因(C)。

2. 什么原因导致的

3. 怎么修复的

4. 是否有回归问题
审过的既有行为:lane 决策语义(真值表对 pre-#2170 内联表达式穷举比对,无漂移)、热路径惰性短路顺序、restoreOutputBudget skip、/__bili/status 纯增量键、#1937 契约(我回退生产改动后 web-sessions 14/14 绿,含 "reject loudly")——全部保持。一处可接受残差(一句话):dshPersona keying 分支会给它 fork 出的任何会话打标,因此未来若有回归导致 MAIN turns 被路由进同一分支 fork,会被打上标而对 split canary 不可见(仅限 dsh lane)——这是 provenance-stamping 方案的固有取舍(第 1 轮已提示,你知情选择),其余守卫层(真值表/invariants/fork-side 套件)不受影响。

5. 是否破坏缓存
不涉及——未触碰缓存、重试、增量游标或去重键。

6. 是否改了设计方向
否。lane 决策仍是纯函数 + caller 保留副作用;canary 仍只观察(log + status 字段,不采取行动);无 kernel/ 变更。

7. 是否引入了新的配置
无新 env/config/CLI flag。内部运行时元数据字段 personaNamespace(非用户配置);/__bili/status.splitSessions 为 v1 已有的增量 JSON 键(消费者套件重跑绿)。

行为变更披露(旧→新):

验证证据:定向套件 41/41 绿(e615575 上:truth-table、invariants、dsh-persona-fingerprint、fork-side-request-lane、side-request-isolation)+ web-sessions 14/14 + parity 在干净 HOME/XDG 下通过(即 CI 失败模式)+ tsc --noEmit 干净;e615575c 的 CI 为 19 成功/4 失败(4 个失败全是 #2152 那一个测试,根因即 C)。

判定:可合(待 695f5c727 的 CI 转绿,合并由人操作)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 CI 跟进(695f5c7):23/23 全绿 ✅

最终判定:可合。 合并由人操作:#2175

@ranxianglei
ranxianglei merged commit d5dfb37 into master Oct 5, 2026
31 of 32 checks passed
@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.50-master.d5dfb37 (rolling master tag).

npm install -g billion-context@0.0.50-master.d5dfb37  # 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.

dsh 回归防护:泳道判定真值表 + 侧请求不变量 + dsh e2e lane + 运行时金丝雀 + lane-guard(5 项)

1 participant