Skip to content

[PR] fix: dsh compaction gate covers runtime-registered agentPresets (#7169) - #7179

Open
ranxianglei wants to merge 4 commits into
masterfrom
2026-11-18_dsh-runtime-preset-gate
Open

ranxianglei wants to merge 4 commits into
masterfrom
2026-11-18_dsh-runtime-preset-gate

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Nov 18, 2026 •

Copy link
Copy Markdown
Owner

Problem

The #3354 load-time overlay only hooked internal/config, which fires for plugin entries resolved via waterfall. Presets registered at runtime via ctx.agentPresets.register(definition) (dsh 0.2.2-rc.3+) bypass the hook entirely, so their compaction rows stay armed. Two failure modes:

Root Cause

registerCompactionDisable in src/agent/dsh-compaction-disable.ts registers a middleware on internal/config. This hook fires only for plugin entries (bundles) resolved via cordis waterfall. Agent presets registered at runtime via ctx.agentPresets.register(definition) do not go through this path — their plugins tree is never seen by the gate. Standard presets (preset-standard/ptc/minimal/cordis) have been covered by the structural matcher since #4147; only runtime-registered presets slipped through.

Fix

Extends the existing disable verdict to the single birth point of runtime presets: the gate wraps agentPresets.register() (via cordis inject) and, when the verdict is active and the definition's plugins tree carries compaction rows, rewrites them in place to disabled: true before passing through. Reuses #4147's disableBasicCompaction pure function and the same telemetry channel (the coverage text gains a runtime dimension). The #1729 wire guard is kept as the backstop for older dsh versions.

The wrapper is:

  • Idempotent — disableBasicCompaction is a no-op on already-disabled rows; the re-entry marker sits on the replacement function so a re-fired inject callback does not double-wrap (0204e41)
  • Async-preserving — returns the same Promise as the original register()
  • Fail-safe — skipped when inject or the agentPresets service is absent; an absent inject is deliberately NOT a boot-alarm gap, because the loader-path overlay still latches without it (717b88f)

Changes

  1. src/agent/dsh-compaction-disable.ts:

  2. tests/issue3354-dsh-compaction-disable.test.ts:

    • 4 regression tests for the runtime preset register wrapper (incl. the double-wrap guard)
    • Pinned the gap semantics: missing inject is not a gap
  3. docs/configuration.md + docs/configuration.zh-CN.md:

Sticky dshCompactionRefusedBytes stop-bleed (tracked separately, does not block this PR)

The sticky dshCompactionRefusedBytes (src/server/handle.ts:2667-2668) is write-only by design (#2490). The follow-up reset work is already tracked: PR #5364 (owner-approved — the ledger floor follows the authored snapshot instead of the envelope peak; open, in flight) plus related #6551. Not touched here. Note: "clear after successful bili fold" (the wording in #7190's out-of-scope list) is a mismatched trigger — bili folds never shrink dsh's raw ledger; the correct reset trigger is a landed checkpoint, which is exactly what #5364 implements.

Test Plan

  • Targeted tests: tests/issue3354-dsh-compaction-disable.test.ts, tests/issue6770-compaction-coverage-text.test.ts, tests/issue4147-dsh-overlay-structural.test.ts, tests/issue3662-dsh-gate-fallback.test.ts, tests/dsh-native.test.ts — 104/104 pass
  • Typecheck: clean
  • Full suite: remote CI

Closes #7190, #7169, #7062, #7178

The #3354 load-time overlay only hooked internal/config, which fires for
plugin entries resolved via waterfall. Presets registered at runtime via
ctx.agentPresets.register(definition) (dsh 0.2.2-rc.3+) bypass the hook
entirely, so their compaction rows stay armed — with an active bili block
that means native compaction is answered 200 and silently wipes bili's
folds.

This commit adds an agentPresets.register() wrapper (via cordis inject)
that applies the same disableBasicCompaction rewrite to the definition's
plugins tree. The gate is an always-on entry loaded before any preset, so
the wrapper is in place before any register() call. The wrapper is
idempotent and preserves the async register() semantics.

Also extends the gate telemetry with a runtimePresetHookInstalled flag
and adds a no-preset-register-hook gap to detectCompactionOverlayGap.

Fixes #7169
Related: #7062
@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-11-18_dsh-runtime-preset-gate (0204e41)

Latest build — install this exact version

npm install -g billion-context@0.0.10862-pr.7179.6c7fa67

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Recent builds (commit → version)

commit version build
0204e41 billion-context@0.0.10862-pr.7179.6c7fa67 build
2e8e7c7 billion-context@0.0.10824-pr.7179.f388550 build

Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr7179.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 closes #7169(gate 漏掉运行时注册的 preset)。Related #7062(用户报 dsh-multitask 运行时 preset 的 compaction-basic 60/60 全 422 dsh_compaction_refused)与 #7169 同一机制(gate 看不到运行时注册的 preset),仅可见症状不同(422 刷屏 vs 静默 200 抹 fold);本修复同时覆盖两者,PR 正确以 Related 引用。

标签: 已齐 — PR #7179: bug p1 dsh scope/wiring;源 issue #7169: bug p1 马上合并 dsh scope/wiring。无需新增。

Verification (live, head 2e8e7c7)

Mechanism — checked against the real dsh/cordis packages (downloaded dsh 0.2.0-rc.2 + 0.2.2-rc.3, dsh-agent-preset for both, cordis 4.0.4 + 4.1.0):

  • ctx.agentPresets.register(definition) exists in both dsh versions; PresetDefinition = { id: string (required), name?, description?, order?, plugins: any[] (required) } — the wrapper's definition.id / definition.plugins access matches the real schema.
  • register is async (definition) => Promise<() => Promise<void>> (returns a disposer) — the wrapper returns the original's Promise, disposer semantics preserved.
  • ctx.inject(deps, callback) exists in cordis 4.0.4 and 4.1.0 (same signature; callback gets a child context carrying the injected service, re-runs on service change). ⇒ the new no-preset-register-hook gap is unreachable in real dsh builds — defensive only, no false-positive boot alarm.
  • Factory presets (dsh-agent-preset package) also flow through agentPresets.register() in 0.2.2-rc.3 — the wrapper is an idempotent no-op for rows the config hook already disabled. No double-processing.

Tests/typecheck (local, targeted): 23/23 pass across tests/issue3354-dsh-compaction-disable.test.ts (13), tests/issue4147-dsh-overlay-structural.test.ts (5), tests/issue3662-dsh-gate-fallback.test.ts (5); npm run typecheck clean.

CI (live): the first full run on this commit (run 44325026030, 14:30–14:38Z) is fully green (17/17 jobs + all e2e workflows incl. e2e-native-dsh, e2e-dsh-plugin-lane). The very first run (44324821132) had 3 flaky test-shard failures (ubuntu-24/1, windows-22/1, ubuntu-22/1) that went green on the re-run of the same sha — flaky/environmental, not code. ⚠️ Note: four further CI runs re-triggered at 14:46–14:55Z with no new push are stuck (jobs in_progress/queued ~8h, zero progress since 15:02Z; the e2e workflows in the same batch all completed green) — a runner/queue infrastructure stall, reported to #4599. The green run above is the valid CI verdict for this commit; if you want a fresh green check before merging, cancel the stuck runs and re-run.

Regression review: the original internal/config middleware path is untouched; the wrapper is a pure pass-through unless bili compaction is active AND the definition carries compaction rows; no wire/config/persistence/kernel changes. dshCompactionRefusedBytes confirmed write-only high-water (src/server/handle.ts:2667-2668, #2490 comment at :2689) — the PR's "Product Decision Needed" section is accurate; no code change made for it, as it should be.

Non-blocking notes:

  1. Hot-file contention — PRs [PR] fix(dsh): keep the host agentPresets dependency in the preset gate inject rows (#6456) #6470 (fixes [Bug][dsh] 0.2.2-rc.2: preset inject replaced by [biliBasicCompactionPolicy], overriding agentPresets → session list sho | [Bug][dsh] 0.2.2-rc.2: preset inject 被替换成 [biliBasicCompactionPolicy] 顶掉 agentPresets → 会话列表「暂无会话」、标题回退 session id、点一个少一个 #6456) and [PR] fix(dsh): replace the fail-closed preset gate with a post-load reconcile (#7111) #7117 (fixes [Bug][dsh] preset gate latch is fail-closed: a missing gate service permanently bricks session creation (root cause of #6456, not fixed by #6470) #7111) both modify src/agent/dsh-compaction-disable.ts + the same test files; [PR] fix(dsh): replace the fail-closed preset gate with a post-load reconcile (#7111) #7117 rewrites the gate latch (+87 -24, fail-closed → post-load reconcile) and can semantically interact with this wrapper. Merge sequencing matters: whichever of the three lands second/third needs a rebase + re-verify.
  2. Cosmetic: PR body claims "issue4147 (10/10)" — the file carries 5 tests (all pass). The __biliCompactionDisableWrapped flag sits on the original function; a same-instance re-injection would double-wrap — idempotent and telemetry-deduped, harmless.
  3. Product decision (not blocking this PR): sticky dshCompactionRefusedBytes — clear-after-bili-compression or keep sticky. My recommendation: keep sticky — bili's fold doesn't shrink dsh's raw ledger, and clearing would hide the known-bad state the mark exists to surface. Owner's call; can be decided separately.

八问

  1. 是什么问题:dsh 压缩门(See how to integrate the plugin that automatically disables dsh compression. | 自动关闭 dsh 压缩的插件看如何集成 #3354)只挂了 internal/config 中间件,只能拦住走 waterfall 解析的插件条目;运行时通过 ctx.agentPresets.register() 注册的 preset(dsh 0.2.2-rc.3+,如 dsh-multitask)完全绕过门,其 compaction-basic 行保持 armed——bili 激活时 dsh 原生压缩要么被 200 应答、静默抹掉 bili 的 fold,要么 422 拒答刷屏(dsh-compaction-gate doesn't cover runtime-registered presets: dsh-multitask's compaction-basic keeps hitting 422 dsh_com | dsh-compaction-gate 覆盖不到运行期注册的 preset:dsh-multitask 的 compaction-basic 持续撞 422 dsh_compaction_refused #7062)。
  2. 什么原因导致的:registerCompactionDisable 的覆盖面假设"所有 preset 都经过 config 解析",对运行时注册的 preset 不成立——它们的 plugins 树从不出现在 config 中间件面前。
  3. 影响范围与严重程度:跑带 agentPresets 服务的 dsh(≥0.2.2-rc.3)+ 运行时注册 preset + 活跃 bili block 的用户。p1:静默 200 = bili fold 被原生压缩抹掉(数据丢失类);或 422 刷屏(dsh-compaction-gate doesn't cover runtime-registered presets: dsh-multitask's compaction-basic keeps hitting 422 dsh_com | dsh-compaction-gate 覆盖不到运行期注册的 preset:dsh-multitask 的 compaction-basic 持续撞 422 dsh_compaction_refused #7062 实测 60/60 全拒)。
  4. 怎么修复的:在同一个常驻 gate 入口里用 ctx.inject(["agentPresets"], …) 包一层 register():bili 压缩激活且 definition 带压缩行时,先用现成的 disableBasicCompaction 重写 plugins 树再调原 register()。幂等(已禁用行 no-op)、保异步(返回原 Promise,disposer 语义不变)、fail-safe(inject/agentPresets/register 任一缺失即跳过)。遥测加 runtimePresetHookInstalled 标志 + 按 preset 记覆盖;no-preset-register-hook gap 仅防御用(真实 dsh 构建不可达)。
  5. 是否有回归问题:逐项审过既有行为——① 原 config 中间件路径未动,插件条目行为不变;② wrapper 仅在 bili 激活 + definition 有压缩行时改写,否则纯透传;③ register() 签名/返回值保持(Promise);④ 新 gap 检查经 cordis 4.0.4/4.1.0 源码核实为防御性,真实构建不会误报 boot alarm;⑤ 0.2.2-rc.3 的工厂 preset 也走 agentPresets.register,wrapper 对已禁用行幂等 no-op,无双重处理;⑥ 无 wire/配置/持久化/kernel 变更。未发现回归。
  6. 是否破坏缓存:不涉及——未触碰缓存/重试/增量游标/去重逻辑。
  7. 是否改了设计方向:没有——把既有 See how to integrate the plugin that automatically disables dsh compression. | 自动关闭 dsh 压缩的插件看如何集成 #3354 门扩展到第二条注册路径,复用同一重写函数与同一遥测,无架构变化。
  8. 是否引入了新的配置:没有新 env/config/默认值(runtimePresetHookInstalled 是内部遥测字段,非配置面)。

判定:可合并 — 机制经真实 dsh/cordis 源码核实,定向测试 + typecheck 本地过,该 commit 最后一次完整 CI 全绿,未发现回归。合并是 owner 权限(issue 已带"马上合并"标签);注意与 #6470/#7117 的合并顺序——后合者需 rebase + 复验。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

🔶 需要决策

CI state (live, mirror cache, head 2e8e7c7912): 3 red shards — test(ubuntu-22,1), test(windows-22,1), test(ubuntu-24,1) — all the same single test: #1772 apply(): web-profile compaction caveat warns once in the durable log (tests/dsh-native.test.ts:1142, failing assertion at :1229, 0 !== 1). Everything else green. Not an inherited red — the test passes on master; the failure is introduced by this PR.

Root cause (traced, not guessed):

Why this is a decision, not a mechanical fix: Runtime-registered presets are a dsh 0.2.2-rc.3+ feature (per the PR's own docs/configuration.md:2550 and the #7169 report env table). On dsh builds that predate ctx.inject there are no runtime-registered presets — the waterfall internal/config hook (which the overlay already covers) is the only preset path, so the overlay is fully latched there. The new "likely ARMED" alarm on those builds is a false positive: it tells old-dsh web-profile users compaction is armed and tells them to apply a manual override they don't need. Every other ctx.inject consumer in dsh-native.ts treats absence as best-effort degradation, not a latch failure. Whether to alarm on no-inject hosts is a user-visible behavior call on the dsh lane (over-alarm vs. under-alarm), and it hinges on dsh version history I can't fully verify from this repo.

Options:

Recommendation: B — the alarm is a false positive on exactly the builds that lack inject, and the PR's real fix (the agentPresets.register() wrapper) is unaffected either way.
Default if undecided: A — unblocks CI with the minimal test-only change and flags the behavior for your review; if you then pick B/C it's a small follow-up.

Nothing was pushed this run; the branch head is unchanged (2e8e7c7912). needs-decision label applied.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[ework] CI fix verified green ✓

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[ework] CI fix verified green ✓

ci-check added 2 commits November 19, 2026 01:07
… overlay still latches

The #7169 runtime-preset wrapper needs ctx.inject, but a host without
it still latches the loader-path internal/config hook, so the
no-preset-register-hook gap value made detectCompactionOverlayGap
alarm "could not latch / likely ARMED" for hosts where the overlay
actually did latch — a boot-time behavior change (passive note ->
ARMED alarm) that the pinned #1772 bare-host test caught.

Revert the gap detector to its two capability checks; the wrapper
state stays observable through the runtimePresetHookInstalled
telemetry flag and the coverage text. Hosts predating inject also
predate the runtime agentPresets.register() surface; the #1729 wire
guard remains their backstop.
…he replacement

The register() wrapper set __biliCompactionDisableWrapped on the
ORIGINAL register function before replacing it, so a re-fired inject
callback (host re-provisioning the agentPresets service) saw no marker
on the function now at registry.register and wrapped the wrapper —
double telemetry notes and a redundant rewrite pass per register call.
Marker now sits on the replacement itself; regression test pins the
skip-on-re-entry behavior.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

🔶 需要决策

New situation since the last escalation: master merged a parallel fix for the same problem — PR #7190 (merged as #7242, commit ee909fc6d4d "fix: dsh runtime-registered presets — extend the compaction-disable verdict to agentPresets.register"). This PR (#7179) is now superseded.

Master's #7190 fix (already merged):

  • Wraps agentPresets.register() via installRuntimePresetCoverage(ctx) — gets the registry from ctx.agentPresets or ctx.get("agentPresets") (no inject).
  • Per-entry runtime telemetry (runtime[] array with entry+rows) + runtimeWrapped boolean.
  • Symbol.for idempotency mark (survives the bundle/host realm split).
  • detectCompactionOverlayGap unchanged (only on + reflect.provide) — it never had the "absent inject is a gap" false-alarm I escalated last run.

This PR (#7179), branch head 0204e416a86:

  • Wraps agentPresets.register() via ctx.inject(["agentPresets"], …) — a different mechanism.
  • Boolean-only telemetry (runtimePresetHookInstalled).
  • String-property idempotency mark (__biliCompactionDisableWrapped).
  • Two follow-up commits: 717b88ffb94 (removed the inject check from gap detection = my option B, fixing the red test) and 0204e416a86 (idempotency-marker fix).

The conflict is semantic, not textual. Both sides rewrite src/agent/dsh-compaction-disable.ts, docs/configuration.md, and docs/configuration.zh-CN.md with different implementations. A rebase would require choosing which implementation to keep — and keeping this PR's would mean reverting a merged, more complete fix. This PR's branch-specific test additions (tests/issue3354-dsh-compaction-disable.test.ts, +169 lines) would then test an implementation that no longer exists.

Options:

Recommendation: A — close this PR as superseded by #7190.
Default if undecided: A — master's fix is already merged and is a superset; this PR is redundant.

Nothing was pushed this run; the branch head is unchanged (0204e416a86). The needs-decision label is already applied.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[ework] CI fix verified green ✓

1 similar comment
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[ework] CI fix verified green ✓

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

🔶 需要决策

State unchanged since floor 12 (re-verified live this run): branch head 0204e416a86, master now at 6453feeeb, PR still in a semantic conflict with master, no owner response to the floor-12 escalation yet.

The full A/B/C analysis is in floor 12 — the short version: this PR is superseded by #7190 (already merged into master; a superset: per-entry runtime[] telemetry, Symbol.for idempotency mark, ctx.get fallback, and it never had the inject-gap false-alarm). Re-basing would require choosing which implementation to keep — and keeping this PR's would mean reverting a merged, more complete fix, while this PR's +169-line test additions (tests/issue3354-dsh-compaction-disable.test.ts) would then test an implementation that no longer exists.

Recommendation: A — close this PR as superseded by #7190. Default if undecided: A (close). Options B (revert master's #7190) and C (merge both → double-wrap) are not recommended — see floor 12.

Nothing was pushed this run; the branch head is unchanged (0204e416a86). The needs-decision label is already applied. Waiting on the owner's close decision.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[ework] CI fix verified green ✓

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

🔶 需要决策

4th wake for the same blocker; state completely unchanged (re-verified live this run): branch head 0204e416a86, master 6453feeeb, no owner response to the three prior escalations (floors 6, 12, 17).

Recommendation (unchanged): close this PR as superseded by #7190 — already merged into master as a superset (per-entry runtime[] telemetry, Symbol.for idempotency mark, ctx.get fallback; it never had the inject-gap false-alarm). Re-basing would require reverting that merged fix, and this PR's +169-line test additions would then test an implementation that no longer exists. Full A/B/C analysis: floor 12. Default if undecided: close.

Nothing was pushed; the branch head is unchanged (0204e416a86). The needs-decision label is already applied. The owner's close decision is the only unblocking action — I have nothing new to add on this wake and will not re-post the full escalation while the state stays unchanged.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[ework] CI fix verified green ✓

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[ework] CI fix verified green ✓

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

🔶 需要决策

5th wake; state unchanged (re-verified live + against the actual code this run): branch head 0204e416a86, master now b10c1a0d4ee, no owner response to the four prior escalations (floors 6, 12, 17, 21), check state clean (0 failed).

Re-confirmed against the source: master's #7190 fix (installRuntimePresetCoverage, registry via ctx.agentPresets/ctx.get) is already merged and is the official implementation; this PR's ctx.inject(["agentPresets"], …) variant is redundant. Re-basing would require reverting that merged fix, and this PR's +169-line test additions would then test an implementation that no longer exists.

Recommendation (unchanged): close this PR as superseded by #7190. Default: close. Full A/B/C: floor 12. Nothing pushed; branch head unchanged. The owner's close decision is the only unblocking action.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[ework] CI fix verified green ✓

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

🔶 需要决策

6th and final auto-fix attempt (1/6); state unchanged (re-verified live this run): branch head 0204e416a86, master b10c1a0d4ee, check state clean (0 failed), no owner response to the five prior escalations (floors 6, 12, 17, 21, and the 5th-wake note).

Final recommendation: close this PR as superseded by #7190 — already merged into master as a superset (per-entry runtime[] telemetry, Symbol.for idempotency mark, ctx.get fallback; it never had the inject-gap false-alarm). Re-basing would require reverting that merged fix, and this PR's +169-line test additions would then test an implementation that no longer exists. Full A/B/C: floor 12. Default: close.

Nothing was pushed; the branch head is unchanged (0204e416a86). The needs-decision label is applied. The auto-fix lane for this blocker is now exhausted — the owner's close decision is the only unblocking action, and it is human-only.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[ework] CI fix verified green ✓

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