Skip to content

fix: #2976 跟进(部分):canonFp lane gate (#2973) + dsh-lane atomic/case (#2972 M1/L3) - #2978

Merged
ranxianglei merged 4 commits into
masterfrom
wt-2976-ework-daemon
Oct 13, 2026
Merged

ranxianglei merged 4 commits into
masterfrom
wt-2976-ework-daemon

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Part of #2976(release v0.1.196 非阻塞跟进伞)。本 PR 处理其中自包含、低风险、诊断/约定类的三项;其余三项按性质分别延后/阻塞,均仍在 #2976 追踪(见「不在本 PR」)。分支从 v0.1.196(origin/master d64139f9c)切出并 rebase 到当前 master,非陈旧基。

本 PR 修复(3 项,2 commit)

#2973(C-F1)— cache-ledger canonicalSysFp 跨 wire 残留

settleUsageReport 对所有 lane 无条件读 METADATA_CANONICAL_SYS_FP 并传给 recordCacheSample,但该槽的唯一写入点是 prepare-responses(仅 responses lane)。metadata 跨 turn/lane 持久,会话从 responses 切到 anthropic/openai/google 后槽里残留最后一次 responses 请求的 fp,把投影记账算进错误桶,削弱 #2867 的 host-rewrite vs proxy-projection 归因。修法:在唯一读取点(settle)按当前请求 wire(protocol === "responses")门控,抽成纯函数 canonicalSysFpForSettle 便于 off-Windows 单测。

  • 行为变更(披露):此前「曾跑过 responses 的会话」在非 responses settle 时也会携带陈旧的 responses canonFp;现在非 responses 样本不再携带。仅影响诊断归因面,不影响压缩行为本身。

#2972-M1 — dsh profile manifest 非原子写

syncDshProfileManifestSpec 用裸 writeFileSync 直写宿主(dsh)拥有的 package.json,写一半崩溃/断电 → 清单永久 malformed 且无自愈路径。改为 tmp sibling + rename(与 persist.ts #2674 同一纪律)。成功路径无可见变化,仅增强崩溃安全。

#2972-L3 — isDshDesktopBiliCopy 大小写敏感(继承自 0.1.195)

前缀匹配用字节级 startsWith;Windows 上 DSH_HOME 大小写与解析出的安装目录不一致时会静默跳过 #2894 manifest 同步并误判为 pnpm-owned。win32 下改为大小写不敏感比较(抽成纯谓词 dshDesktopCopyPathMatches 可单测);POSIX 保持字节精确不变。

  • 行为变更(披露):仅 Windows——此前大小写不一致会漏同步(bug),现在正确同步;POSIX 无变化。

不在本 PR(按性质分流,均在 #2976 追踪)

验证

  • npm run typecheck 干净(kernel + pi-subagents 预构建通过,tsc --noEmit 无错)。
  • 定向测试:tests/cache-ledger.test.ts + tests/update-desktop-inplace.test.ts 全绿(47 pass,含 3 个新增回归用例)。全量回归交 CI。

配置面(八问第 8 项)

未新增任何 env/config/CLI flag —— 不涉及。

@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: wt-2976-ework-daemon (4fe8732)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.3374-pr.2978.cafb9dc

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-pr2978.tgz
npm install -g package

Install instructions are refreshed on each push.

ework-agent added 4 commits October 13, 2026 12:31
#2973)

settleUsageReport read METADATA_CANONICAL_SYS_FP unconditionally and passed it to recordCacheSample on every lane, but its sole writer is prepare-responses. Session metadata persists across turns AND lanes, so after a session switched responses->anthropic/openai/google the slot still held the last responses request's fp, mis-bucketing the #2867 host-rewrite-vs-proxy-projection attribution on every subsequent sample. Gate the read on the current request's wire (protocol === 'responses') via a pure helper; this settle path is the only reader of the slot. Regression test pins the lane gate off-Windows.
…profile match (#2972)

M1: syncDshProfileManifestSpec wrote the host-owned dsh profile package.json with a bare writeFileSync - a crash/power-loss mid-write could leave a torn manifest with no self-heal path. Write atomically (tmp sibling + rename, same discipline as persist.ts #2674).\n\nL3: isDshDesktopBiliCopy matched the DSH_HOME anchor with a byte-exact startsWith; on Windows a DSH_HOME spelled with different casing than the resolved install dir silently skipped the #2894 manifest sync and misread the copy as pnpm-owned. Compare case-insensitively on win32 via an extracted pure predicate (unit-testable off-Windows).
…ire too (#2973)

Same stale-slot family as the canon fp gate in c9cb878: the mode stamp's
sole writer is prepare-responses, but settle read it for every lane, so a
session that switched off the responses wire kept stamping its inert pm line
field with the last responses request's label. The existing comment already
documented the intent ('responses lane only; other lanes omit both') — this
makes the code match it. pm has no consumers; diagnostic-only change.
…ane gate

The suite's turn() helper defaulted to proto='openai' while modeling the
Responses self-heal degrade — pre-gate that worked because settle read the
canon slot unconditionally; post-gate 7 of 9 scenarios lost their canon fp
and degraded to 'prompt' attribution (CI red on all four test jobs).

- helper default proto -> 'responses' (the lane these scenarios model);
  the sparseness test's non-responses part now passes 'anthropic' explicitly
- 'projection flip outranks a co-occurring wire switch': the old
  openai->anthropic shape is unreachable under the gate (a flip can only fire
  ON the responses lane) — reshaped as baseline-on-responses -> one-round
  anthropic detour -> return-to-responses co-firing the mode flip; the
  priority pin survives and the detour now books its own (zero-token, warm)
  wire event
- new regression: stale canon + mode slots must not leak into a
  non-responses settle — a host edit on the anthropic wire after a
  responses history books 'prompt', never 'projection', and pm stays empty
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

Review 完成。结论先行:三项修复方向都对,但 CI 是红的 —— lane gate 打破了 7 个既有 #2867 回归测试。已定位根因、当场修复(2 个标注 commit 推到分支,并 rebase 到最新 master),等 CI 转绿。

CI 红因(以及为何本地「全绿」没抓到)

  • 7 个失败全在 tests/cache-ledger-projection-switch.test.ts —— 不是 PR 正文列的 cache-ledger.test.ts;定向测试漏了这个兄弟文件(四个 test job 同挂,即这 7 个)。
  • 该文件 turn() helper 默认 proto="openai",而场景建模的是 Responses self-heal degrade(文件头注释明说)。gate 之前 settle 无条件读 canon 槽,openai 也能工作,gate 之后 canonFp 只在 responses wire 透传 → projFlip 永不触发 → cause 从 projection 退化成 prompt(断言 actual: 'prompt', expected: 'projection')。
  • gate 生产侧语义已核实正确,不动:槽的唯一写入点是 prepare-responses(两条返回路径都 stamp protocol:"responses");三个 settle 调用点(loop core / relay 非流式 / plugin applyUsageSample)全部携带当前请求的 wire —— 没有任何真实 responses 样本会丢 canonFp。所以修法是测试侧对齐:让测试建模它声称建模的 lane。

我推的改动(原 2 commit 之上 +2,rebase 到含 #2971/#2979 的最新 master,零文件重叠、干净)

  1. fix(cache-ledger): gate the lastResponsesMode slot on the responses wire too (#2973) —— mode 槽与 canonFp 属同一机制族(唯一写入者同为 prepare-responses,metadata 同样跨 turn/lane 持久),且原注释本就写着 "(responses lane only; other lanes omit both)",代码此前只 omit 了一半。补上 gate;pm 字段零消费者(grep 全仓核实),纯诊断面。
  2. test(cache-ledger): align the #2867 projection suite with the #2973 lane gate:
    • helper 默认 proto → "responses";sparseness 用例显式传 "anthropic"(与其「非 responses lane」本意一致);
    • 「projection outranks wire」用例重写:旧 openai→anthropic 形状在新 gate 下不可达(flip 只能发生在 responses lane 上),改为「responses 基线 → 一轮 anthropic 绕行 → 回 responses 同时翻 mode」——优先级 pin 保留,绕行轮照常记自己那个零 token(warm)wire 事件;
    • 新增 settle 级回归:切出 responses 后,陈旧 canon+mode 槽不得泄漏进非 responses settle(host 在 anthropic wire 上改 system → 记 prompt,永不 projection,pm 保持空)。这一条钉住的是 [cache-ledger] settleUsageReport 无条件读 canonicalSysFp 槽:responses→其他 wire 切换后投影记账错位(#2867) #2973 的用户可见后果(诊断误归因),比纯函数单测更靠下一层。

本地验证:typecheck 干净;定向三文件(cache-ledger / projection-switch / update-desktop-inplace)57/57 绿,含原先红的 7 个。全量回归交 CI,等新 head 4fe873283。

结构化八问

  1. 是什么问题:两层 —— (a) PR 自身的 gate 打破 7 个既有 [Bug] Responses self-heal 切换投影规则后,提示词指纹变化被误归因为宿主改写 #2867 回归测试(CI 红);(b) gate 只修了机制族的一半,lastResponsesMode 槽仍在跨 lane 读取。
  2. 什么原因导致的:(a) 测试 helper 用 openai wire 建模 responses-lane 场景,gate 前的无条件读取恰好掩盖了错配;(b) [cache-ledger] settleUsageReport 无条件读 canonicalSysFp 槽:responses→其他 wire 切换后投影记账错位(#2867) #2973 修法落在唯一读取点时,相邻同源读取点未被一并处理。
  3. 影响范围与严重程度:仅诊断归因面(/acp-cache 的 projection/prompt 分桶 + 无消费者的 pm 字段),不影响压缩行为与计费。gate 前严重度:「跑过 responses 再切 lane」的会话会把宿主 system 编辑误归因为 bili 自己的 projection switch —— 正是本 PR 要修的问题本身。
  4. 怎么修复的:测试侧对齐到正确 lane(生产语义核实无误、不改)+ 同一读取点补齐 mode 槽 gate + 新增 stale-slot settle 级回归用例。
  5. 是否有回归问题:逐项清点过 —— responses lane settle 的 canonFp/mode 透传不变(三个调用点均带当前 wire);off-lane 样本不推进 lastKnownCanon(仅 defined 时推进),回 responses 后 flip 检测不受影响;manifest 写成功路径字节级不变、仅增强崩溃安全;dshDesktopCopyPathMatches POSIX 字节精确保持、仅 win32 大小写不敏感。未发现破坏项。
  6. 是否破坏缓存:不涉及 —— 未触碰前缀缓存/重试/增量游标/去重键;ledger 行是诊断记录而非缓存。
  7. 是否改了设计方向:不涉及。
  8. 是否引入新配置:不涉及。

行为变更披露(补充 PR 正文):非 responses ledger 行的 pm 字段今后不再携带陈旧的 responses mode 标签(旧值:最后一次 responses 请求的标签残留;新值:缺省)—— pm 零消费者,纯诊断面,无外部影响。

判定:方向、diff 整洁度、测试有效性均通过;唯一余项是新 head 的 CI 结果。转绿后即可由 owner 合并(agent 不代合)。

@ranxianglei
ranxianglei merged commit 7ad3c1f into master Oct 13, 2026
22 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.360-master.7ad3c1f (rolling master tag).

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

1 participant