Skip to content

[Bug][dsh] internal/config listener reads this (always null): coverage telemetry degenerates to unnamed-entry and every name-keyed transform is dead code #7112

Description

@resec

建议标签:p1 dsh scope/wiring(主题类别 F:dsh 车道)
关联:PR #5994(同一行代码,它的 #5248 修复因此永不生效)· #7111(同文件的另一个问题)· #5248

现象

src/agent/dsh-compaction-disable.ts 的 internal/config 中间件用 this 取 entry 名:

ctx.on("internal/config", function (this: MiddlewareSelf, _raw: unknown, next: () => unknown): unknown {
    ...
    const rawName = this?.entry?.options?.name;              // ← 恒为 undefined
    const entryName = typeof rawName === "string" ? rawName : "unnamed-entry";
    noteGateCoverage(entryName.slice(0, 120), compactionRows, entryName === DSH_AGENT_PRESET_PACKAGE);

在真实 cordis 里 this 恒为 null,于是:

  1. 覆盖遥测的每条记录 entry 名都是 unnamed-entry;
  2. isFactory 恒为 false → sawFactoryPreset 永远不会被置为 true;
  3. 任何按 entry 名匹配的逻辑都是死代码——包括 PR [PR] Restore dsh native auto-compaction when bili-native is disabled or absent (#5248) #5994 为 [PR] Four-lane shared startup lifecycle wrap-up: dsh adopts lane mutual exclusion guard, thick lifecycle retained in place (# | 四车道共享启动生命周期收尾:dsh 采用车道互斥守卫,厚生命周期保留原地(#5241 阶段 1 / PR-1d) #5248 新增的那段还原判断。

改写本身不依赖名字(#4147 起是结构性匹配),所以"禁用原生压缩"仍然生效;坏掉的是诊断可信度和所有按名字走的判断。

复现(bili master 0e475ceb · dsh 0.2.2-rc.4 · node 26.10.0 · web profile)

在宿主进程内挂一个探针(--patch 一条 loader entry,监听 internal/config),一次启动的统计:

internal/config calls: 163
this === null        : 163        ← 全部
fiber.entry.options  : 163 次可读  ← fiber 才是可用的参数

抽样两行(同一进程内相邻的两次调用):

{"n":1,"thisIsNull":true,"arg0IsFiber":true,"fiberEntryId":"preset-standard","fiberEntryName":"@deepseek-ai/dsh-agent-preset"}
{"n":18,"thisIsNull":true,"arg0IsFiber":true,"fiberEntryId":"compaction","fiberEntryName":"cordis:group"}

机制

cordis 的派发约定决定了 this 是 null:

步骤 代码(dsh dsh-v0.2.2-rc.4) 结论
1 vendor/cordis/src/fiber.ts:678 fiber.context.waterfall('internal/config', fiber, () => config) 第一个实参是事件名(字符串)
2 vendor/cordis/src/events.ts:163 const thisArg = typeof args[0] === 'object' || 'function' ? args.shift() : null 字符串 → thisArg = null,被 shift 的是事件名
3 vendor/cordis/src/events.ts:248-258 waterfall 弹末位作 next,其余作为监听器实参 监听器签名是 (fiber, next),this = null

宿主自己就是取第一个形参:vendor/loader/src/index.ts:104 用 (fiber, next) + fiber.entry。

影响

建议修复

-        ctx.on("internal/config", function (this: MiddlewareSelf, _raw: unknown, next: () => unknown): unknown {
+        ctx.on("internal/config", function (fiber: MiddlewareSelf, next: () => unknown): unknown {
             const resolved = next();
-            const rawName = this?.entry?.options?.name;
+            const rawName = fiber?.entry?.options?.name;

注意形参要少一个:现签名里的 _raw 实际收到的就是 fiber,next 才是链尾函数;保留三个形参会让 next 错位。

建议顺带抽一个 entryNameOf(fiber) 作为唯一入口,供 #5994 那类按名字判断的代码复用,避免同一坑再踩一次。

测试建议

现有 tests/issue3662-dsh-gate-fallback.test.ts 的 mock host 直接把捕获到的中间件拿来调用,this 不参与,所以测不出来。建议补一条真派发用例:用 devDeps 里已有的 @deepseek-ai/cordis 建 Context(tests/dsh-native.test.ts 有先例),派发一次 internal/config,断言"this 为 null,但 fiber.entry.options.name 取得到且遥测记录的不是 unnamed-entry"——正反两向(命中 preset 名 / 不命中)。

验证边界

以上是宿主内实测(探针 + 计数),不涉及模型往返;this 的绑定与业务无关,结论与上游模型无关。

Activity

  1. ranxianglei commented on Nov 18, 2026

    @ranxianglei
    Owner

    🤖 Powered by ework · qwen3.8-27b

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

    查重: 不重复。与 #5248 / PR #5994 / #7111 相关但机制独立——#5248/#5994 是「禁用 bili-native 后 host 平面 auto:false 不还原」的症状与修复;本 issue 是那个修复(以及所有按 entry 名走的判断)之所以是死代码的根因:this 绑定错误。#7111 是同文件的另一个问题。

    标签: p1, dsh, scope/wiring(已打;诊断误导 + 既有修复失效,且误导路径 #2474 更危险,维持 p1)

    审核结论(八问)

    1. 是什么问题:dsh 车道的 internal/config 中间件用 this 取 entry 名,但 cordis 真实派发下 this 恒为 null——覆盖遥测全部记成 unnamed-entry,sawFactoryPreset 永不置位,所有按名字走的分支(含 [PR] Restore dsh native auto-compaction when bili-native is disabled or absent (#5248) #5994 为 [PR] Four-lane shared startup lifecycle wrap-up: dsh adopts lane mutual exclusion guard, thick lifecycle retained in place (# | 四车道共享启动生命周期收尾:dsh 采用车道互斥守卫,厚生命周期保留原地(#5241 阶段 1 / PR-1d) #5248 加的还原判断)都是死代码。
    2. 什么原因导致的:cordis 派发约定——fiber.context.waterfall('internal/config', fiber, () => config)(fiber.ts:678)首参是事件名字符串,events.ts:163 因此 thisArg = null,监听器实参为 (fiber, next)(events.ts:246-258;cordis 自带监听器 events.ts:156 也是取第一形参)。原代码按 this: MiddlewareSelf 假设编写,与真实绑定不符。我在本机 cordis 4.1.0 源码逐行核对,与 issue 的机制表一致。
    3. 影响范围与严重程度:禁用原生压缩的改写本身不受影响([Bug][dsh] #3354 Native compression disabled: overlay does not override custom preset → native auto-compression remains | [Bug][dsh] #3354 原生压缩关闭 overlay 不覆盖自定义 preset → 原生自动压缩仍武装 → 压缩基底被毁(被迫换新会话)/上下文溢出循环 #4147 起结构性匹配,不依赖名字);坏的是 ① 诊断可信度——/acp 与 boot note 的「覆盖 preset」信息不可信,sawFactoryPreset 恒 false 会把人引向 fix(dsh): profile 层 patch 其实可以关掉 web profile 的原生自动压缩(#1772 结论修正)+ 一个会静默清空整个 preset 的写法坑 #2474 全量快照自救路径(写不全会静默清空 preset,更危险);② [PR] Restore dsh native auto-compaction when bili-native is disabled or absent (#5248) #5994 的 [PR] Four-lane shared startup lifecycle wrap-up: dsh adopts lane mutual exclusion guard, thick lifecycle retained in place (# | 四车道共享启动生命周期收尾:dsh 采用车道互斥守卫,厚生命周期保留原地(#5241 阶段 1 / PR-1d) #5248 修复永不生效——禁用 bili-native 后非 web profile 的 host 平面 auto:false 依旧不还原。核心功能可用但诊断误导 + 既有修复失效 → p1。
    4. 怎么修复的:中间件签名改为 (fiber, next) 取第一实参;抽 entryNameOf(fiber) 作为取名的唯一入口(空串 → undefined),[PR] Restore dsh native auto-compaction when bili-native is disabled or absent (#5248) #5994 类按名判断复用同一入口,避免同一坑再踩;测试补一条真 cordis Context 派发用例(断言 this === null 且遥测记录真实 preset 名,正反两向)。
    5. 是否有回归问题:审过既有行为——结构性匹配改写([Bug][dsh] #3354 Native compression disabled: overlay does not override custom preset → native auto-compression remains | [Bug][dsh] #3354 原生压缩关闭 overlay 不覆盖自定义 preset → 原生自动压缩仍武装 → 压缩基底被毁(被迫换新会话)/上下文溢出循环 #4147)不依赖名字,不受影响;noteGateCoverage 与 gate service 发布路径保留。但 PR 原 head 有一处测试层回归:tests/issue4147-dsh-overlay-structural.test.ts 的 mock 仍按旧绑定用 this 传名字,PR 原样合入会红(3/5 失败)——该回归已由作者并发推送的 8461f55bcf 修掉(且 this 显式传 null,比我的初版更忠实),我核验后在其上补齐了它漏掉的 issue3662 两处调用。
    6. 是否破坏缓存:不涉及。
    7. 是否改了设计方向:没有——对齐宿主真实派发约定,无新架构/数据流。
    8. 是否引入了新的配置:没有。

    交付

    合并判定:代码与测试已收敛,等主 CI 绿灯即可合(人工合入)。

  2. ranxianglei commented on Nov 18, 2026

    @ranxianglei
    Owner

    🤖 Powered by ework · qwen3.8-27b

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

    CI 结果补充(上一条承诺的跟进):PR #7115 head f7059d7ba8 全绿——主 CI(test 矩阵 ubuntu/windows × node 22/24 分片 + 全部 guard 车道)success,所有 e2e 车道 success(e2e-native-pi / e2e-native-opencode / e2e-native-dsh / e2e-local-registry / e2e-dsh-plugin-lane / e2e-codex-persona / E2E real codex / pi-codex-ws / codex overlay)。PR 状态 open、mergeable,仅 behind master(合并时 rebase 即可,非阻塞)。可以合了(人工合入)。

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions