Skip to content

[PR] fix(dsh): read the config hook's fiber argument instead of this (#7112) - #7115

Open
resec wants to merge 4 commits into
ranxianglei:masterfrom
resec:2026-11-18_dsh-config-hook-fiber
Open

resec wants to merge 4 commits into
ranxianglei:masterfrom
resec:2026-11-18_dsh-config-hook-fiber

Conversation

@resec

@resec resec commented Nov 18, 2026

Copy link
Copy Markdown

Closes #7112.

What & why

registerCompactionDisable's internal/config middleware read the entry name from this:

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

cordis dispatches that waterfall as waterfall('internal/config', fiber, next) (vendor/cordis/src/fiber.ts:678) — the first argument is the event name, so events.ts:163 resolves thisArg = null and the listener receives (fiber, next). Measured in a real host during one boot: internal/config called 163 times, this === null 163 times, while fiber.entry.options was readable 163 times.

Consequences of the dead accessor:

The rewrite itself is name-independent since #4147 (structural match), so disabling native compaction kept working — this is a diagnostics-and-branching defect, not a compression regression.

Fix

Read the name from the first argument, and expose it as the single entry point for future name-keyed code:

export function entryNameOf(fiber: unknown): string | undefined {
    const name = (fiber as MiddlewareSelf | undefined)?.entry?.options?.name;
    return typeof name === "string" && name.length > 0 ? name : undefined;
}

The middleware signature loses one parameter (_raw was already the fiber; keeping three would shift next).

Tests

tests/issue7112-config-hook-fiber.test.ts dispatches through a real @deepseek-ai/cordis Context — the existing mock hosts call the captured middleware directly, which is exactly why this defect stayed green.

  • binding: this is null and entryNameOf(fiber) still yields the name;
  • factory preset: telemetry records @deepseek-ai/dsh-agent-preset and sawFactoryPreset === true;
  • custom preset: records its own name, sawFactoryPreset === false (positive + negative, per the gate discipline);
  • absent/empty names fall back to undefined;
  • the gate service is still published when the host cannot bind a name.

Negative control (reverting only the accessor line, keeping the helper): the two telemetry tests fail, the other three pass.

Pre-flight

check result
npm run typecheck clean
targeted node --import tsx --test (issue7112 + issue3354 + issue3662) 19/19 pass
npm run build success (dist-import-annotations: OK, dist-external: OK)

Merge order vs #5994

Both touch the same middleware. If this lands first, #5994 needs a one-line rebase onto entryNameOf(fiber) for its added branch; if #5994 lands first, this PR is the supplement that makes its branch reachable. Either order leaves the other correct once rebased — I noted this on #5994 as well.

Not in scope

No config surface change, no version bump, no docs change (the mechanism is unchanged; only the accessor is).

…nxianglei#7112)

cordis dispatches internal/config as waterfall('internal/config', fiber, next): the first argument is the event name, so no this is bound (thisArg null) and the listener receives (fiber, next). Reading this.entry always yielded undefined, so every covered entry was recorded as unnamed-entry, sawFactoryPreset never latched, and PR ranxianglei#5994's ranxianglei#5248 restore could never fire.

Tests dispatch through a real cordis Context; the existing mock hosts call the captured middleware directly, which is why the defect stayed green.
@ranxianglei ranxianglei changed the title fix(dsh): read the config hook's fiber argument instead of this (#7112) [PR] fix(dsh): read the config hook's fiber argument instead of this (#7112) Nov 18, 2026
These three files invoked the captured internal/config middleware as mw.call(entryLike, null, next), passing the entry name as `this`. That is not how cordis dispatches (thisArg is null, the fiber is the first argument), so the mocks were asserting a binding the host never produces — which is why ranxianglei#7112 shipped green. Move the entry-like object to the first parameter; the assertions themselves are unchanged.
@resec

resec commented Nov 18, 2026 •

Copy link
Copy Markdown
Author

CI 修复(8461f55b):issue3354 / issue3662 / issue4147 用 mw.call(entryLike, null, next) 把 entry 名当作 this 传,而 cordis 实际派发是 (fiber, next) —— 这三个 mock 断言的绑定宿主从来不会产生,这也是 #7112 一直绿的原因。已改成把 entry-like 对象放在第一个形参,断言本身未改。

本地:typecheck ✅ / 24 用例 ✅ / build ✅ / unused-exports ✅。

…missed (ranxianglei#7112)

8461f55 moved the entry-like object to the first parameter in most
mock calls but left two issue3662 sites still passing it as `this`
(mw.call(PRESET_SELF, null, next)) — they only stay green because their
assertions are name-independent, so the broken binding survives exactly
where a future name-keyed branch (e.g. ranxianglei#5994's ranxianglei#5248 restore) would be
exercised. Move those two calls to the real binding and rename the
identifiers that now lie (PRESET_SELF/self/raw → the fiber they carry),
so the mocks cannot silently drift back to the pre-ranxianglei#7112 convention.
@resec

resec commented Nov 18, 2026

Copy link
Copy Markdown
Author

本 PR 已被 #5994 覆盖,独有价值只剩测试约定修复

#5994 的 head 675ebb70 已经按同一诊断改了两行(读第一个形参、去掉 this: 注解),与这里的 3792c0b6 等价。所以运行时修复出现了两份实现,保留一份即可。

本 PR 仍有 #5994 目前缺的部分:tests/issue3354-dsh-compaction-disable.test.ts(4 处)与 tests/issue4147-dsh-overlay-structural.test.ts(8 处)仍按 mw.call(entryLike, null, next) 派发——即把 entry 名当 this 传。修复一生效,这三条断言就会红,这也是 #5994 现在 4 个 shard 红的原因。

那 14 处改动已经写进 #5994 的评论里(含逐行 diff),可以照抄:

#5994 (comment)

建议

如果更希望保留本 PR 作为测试修复的载体(例如 #5994 想只做运行时那一行),说一声,我把运行时那两行从这个分支撤掉,只留测试改动。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

查重:不重复。在途同属 dsh 车道的 [PR] 7116(#7113 compaction-basic override 告警)、7117(#7111 post-load reconcile)、5994(GitHub #5994 #5248 restore)目标各不相同;其中 #5994 与本 PR 触碰同一个 middleware,存在合入顺序交互(见下)。

标签:bug、p1(接手时已有)、dsh、scope/wiring(我补)。

八问

  1. 是什么问题:registerCompactionDisable 的 internal/config 中间件从 this 读 entry 名,但 cordis 实际派发是 (fiber, next) 且 this === null,于是名字恒为 undefined → 覆盖记录全写成 unnamed-entry、sawFactoryPreset 永不 latch、任何按名字分叉的逻辑(含 [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 restore)全部失效。

  2. 什么原因导致的:cordis waterfall('internal/config', fiber, next)(vendor/cordis/src/fiber.ts:678)把事件名当第一参传入,events.ts:163 的 _resolve 见第一参是字符串就把 thisArg 置 null,监听器收到的是 (fiber, next)。被 vendor 的插件是按"绑定 this 可读 this.entry.options.name"的旧约定写的,和真实派发对不上。

  3. 影响范围与严重程度:只到诊断面 + 卡住一个未来修复。当前 master 的 transform 自 [Bug][dsh] #3354 Native compression disabled: overlay does not override custom preset → native auto-compression remains | [Bug][dsh] #3354 原生压缩关闭 overlay 不覆盖自定义 preset → 原生自动压缩仍武装 → 压缩基底被毁(被迫换新会话)/上下文溢出循环 #4147 起是结构匹配(按行名、与 entry 名无关),所以禁用原生压缩本身仍工作,不是压缩回归;真正受影响的是 ① 启动 note 永远说错 preset 是否被覆盖、② 遥测 entry 名恒为 unnamed-entry、③ [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 restore 分支(尚未合入)按现状写是死的。按口径属 p2(能用但诊断明显错),非 p1(无可用性破坏、无缓存泄露)。

  4. 怎么修复的:名字改从第一参 fiber 读,抽成单一入口 entryNameOf(fiber) 供未来按名分叉的代码复用;中间件签名去掉已无用的 _raw(它本来就是 fiber)。

  5. 是否有回归问题:无。transform 结构匹配不变;entry 名唯一的按名用途是遥测 + sawFactoryPreset latch(均诊断面),从"恒 unnamed-entry / 永不 latch"变为"真实名 / 正确 latch"正是本修复目的。安全降级:若真实宿主 fiber 没有 .entry.options.name,entryNameOf 走可选链返回 undefined → 回退 unnamed-entry(与现状逐字节相同),严格优于现状或不变。与新 master(4b77eab409)无文件重叠。

  6. 是否破坏缓存:不涉及。

  7. 是否改了设计方向:不涉及。机制(结构 transform、gate service)不变,只修 accessor;entryNameOf 是新增的小导出 helper,非方向变更。

  8. 是否引入了新的配置:不涉及。无 config surface / env / 默认值变更。

我的验证

一个要留意的点(非阻塞)

新增用例用真实 cordis Context 派发,验证了绑定(fiber 是第一参、this===null)这一修复核心;但用例里的 fiber 形状 {entry:{options:{name}}} 是构造的——npm 上的 cordis 4.1.0 Fiber 类根本没有 entry 属性(grep 源码 + 编译产物 0 命中),真实 dsh 宿主必然 bundle 了另一份 cordis。所以"真实宿主 fiber 确实带 .entry.options.name"这一点只靠作者的一次启动实测(163/163)背书。因修复安全降级(形状缺失 → 回退 unnamed-entry),不构成阻塞;但该实测是本修复"确实解决真机症状"的承重证据,建议保留在 issue 里备查。

判定

可合(合并动作仍归人工)。修复正确、安全、测试有牙;CI 待全绿(目前无失败);唯一保留项(fiber 形状)属验证关切而非正确性阻塞,且安全降级。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

🔶 需要决策

背景一句话:#5994(owner 分支)head 675ebb70 已并入与本 PR 等价的运行时修复,两份实现并存;本 PR 独有的只剩 entryNameOf helper、issue7112 回归测试、以及 issue3354/issue4147 的测试约定修复——而 #5994 正因缺后者红了 4 个 shard。

我已独立核实(live,非转述作者):

两 PR 的实质差异(不止"两份运行时修复"):

待决问题:运行时修复两份并存,由谁承载、本 PR 如何收场?

选项(各带代价):

我的推荐:C。理由:#7115 已绿且自洽,helper 设计比 #5994 的两处内联更干净;#7112(绑定修复)与 #5248(restore)本就是两件事,分 PR 各自可审;#5994 rebase 后其 4 个红 shard 会因测试约定已修而转绿。若 owner 更想要"单 PR 收敛、不折腾 rebase",则选 A。

不决定的默认行为:两 PR 都保持 open、重叠不消解;#5994 继续红 4 shard,本 PR 继续绿——谁先合都要求另一个 rebase/去重。

边界:关闭 PR 是 owner 动作(agent 不关单);向 #5994(owner 分支)push 任何改动也需 owner 明确点头。我不动任何分支,等 owner 拍板方向——选 C 则无需我动手(#7115 已就绪,#5994 由 owner rebase);选 A 且授权后,我可把 14 处测试改动 + issue7112 测试整理成可直接合入 #5994 的 patch。

@resec

resec commented Nov 18, 2026

Copy link
Copy Markdown
Author

回答「C 还是 A」,并更正你 C 方案的一个前提

结论:我按 C 走,C 我同意。 但 C 的成本描述已经过时——#5994 不再红 4 个 shard。

事实更正:#5994 的测试约定缺口已被补上

你 05:44 的核对(「#5994 文件清单不含 issue3354/4147,正因缺其而红 4 shard」)在当时成立,现在不成立了:你的 eb949ef8 已补齐 14 处派发。实测 run 44246844710(head eb949ef8):

所以 C 的代价「#5994 需一次 rebase 去重」还在,但「#5994 rebase 后 4 红转绿」这个收益已经不是收益——那 4 红已经没人了。

本 PR 侧事实

  • head 现在是 412ea386:我把 upstream/master(548e3960,含 3186e54a)合了进来,无冲突,代码未改。
  • CI:run 44249210808 success,含 windows-22/5。也就是说 C 需要的「本 PR 已绿」成立,且是带最新 master 的绿。
  • 本地门禁:typecheck / unused-exports / test-import-graph / build 全绿。

两个选项的现状(都由你拍)

边界:关 PR、动 #5994 分支都是 owner 动作。我不投票替你做决定,只把成本对齐。

ranxianglei pushed a commit that referenced this pull request Nov 18, 2026
…ads (#7196)

#7115 changed the internal/config listener to read the entry name from the
fiber argument (cordis dispatches waterfall('internal/config', fiber, next)
with this=null), but this pre-existing #6770 fixture still passed the entry
as `this` — so entryNameOf(null) degraded to "unnamed-entry" and the
assertion failed on every OS/Node. Pass the entry object as the first
argument, matching how cordis actually dispatches (and how
tests/issue7112-config-hook-fiber drives it).

This branch has not been deployed

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

Projects

None yet

2 participants