From 40416cf5684ad5af49e580c385c886f7dae020ac Mon Sep 17 00:00:00 2001 From: awork Date: Fri, 16 Oct 2026 00:42:03 +0800 Subject: [PATCH] fix: narrow dsh-context host-plugin notice to segment composition/timeline (#3303) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #3303 measured (real session, same-instant three-way comparison) that dsh-context's headline "current context" size equals bili's contextTokens — it is anchored on provider usage, not the lossless local log. Only its per-segment composition / timeline derives from the local store, so under active compression the SPLIT (not the headline size) is the pre-compression distribution. The #2865 notice claimed every displayed figure was inaccurate, making users chase a size deviation that does not exist. Scope the notice text plus the module/entry comments to what actually holds: the segment composition / timeline is a pre-compression estimate, the headline tracks the real sent volume, authoritative size via /acp or contextTokens. Add a regression test pinning the narrowed scope. --- src/host-plugin-notice.ts | 28 +++++++++++++--------- src/web/i18n.ts | 4 ++-- tests/issue2861-host-plugin-notice.test.ts | 9 +++++++ 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/host-plugin-notice.ts b/src/host-plugin-notice.ts index a5c985f1be..4ecdada57a 100644 --- a/src/host-plugin-notice.ts +++ b/src/host-plugin-notice.ts @@ -1,12 +1,16 @@ -// #2861: known third-party host-side plugins whose context meter reads the -// host's LOCAL session store. While bili compresses the wire, that store -// diverges from what the model actually sees: dsh's durable log stays lossless -// by architectural invariant, so a meter computed from it reports the unfolded -// local surface (~full history) even though every request carries far fewer -// tokens. This module detects such plugins conservatively from the client's own -// registry (best-effort, read-only, cached) so the web UI tells users their -// figures are pre-compression instead of letting them read "~1M" as a stuck -// compressor. Every fs access is guarded — detection must NEVER fail a request +// #2861: known third-party host-side plugins whose context BREAKDOWN derives +// from the host's LOCAL session store. While bili compresses the wire, that +// store diverges from what the model actually sees: dsh's durable log stays +// lossless by architectural invariant and folds happen outside the host event +// stream (storage: shadow), so the per-category composition / timeline a meter +// computes from it is the PRE-COMPRESSION distribution even though every +// request carries far fewer tokens. (dsh-context's headline size is anchored on +// provider usage and tracks the effective volume — only its split is stale; +// #3303 measured the two equal within one sampling phase.) This module detects +// such plugins conservatively from the client's own registry (best-effort, +// read-only, cached) so the web UI tells users their segment composition is +// pre-compression instead of letting them read a stale split as the model's +// view. Every fs access is guarded — detection must NEVER fail a request // or a page load. // // Detection keys off the dsh profile manifest (package.json): a bundle plugin @@ -45,8 +49,10 @@ interface HostPluginEntry { // One row per known host-side metering plugin — adding the next one adds one // entry here. const KNOWN_HOST_PLUGINS: readonly HostPluginEntry[] = [ - // #2837: dsh-context meters dsh's durable (lossless) session log, so under - // active compression its figures are the pre-compression local surface. + // #2837/#3303: dsh-context's segment composition / timeline derive from + // dsh's durable (lossless) session log, so under active compression they are + // the pre-compression distribution; its headline size is provider-usage- + // anchored and tracks the effective volume. { client: "dsh", id: "dsh-context", depName: "dsh-context", loaderId: "dsh-context", requiresBiliLane: true }, ]; diff --git a/src/web/i18n.ts b/src/web/i18n.ts index 9483f54eba..b49c5d8ee7 100644 --- a/src/web/i18n.ts +++ b/src/web/i18n.ts @@ -170,7 +170,7 @@ export const MESSAGES: Record> = { "advisory.restartDesc": ":安全版本已安装到磁盘,但当前进程仍在运行受影响版本。原因:", "advisory.restartHint": "。重启 bili 后生效。", "hostplug.on": "检测到宿主侧插件", - "hostplug.desc": "它显示/记录的上下文为压缩前的本地口径(本地日志按 dsh 架构要求保持无损),数值不准确;显示有效尺寸需其对 billion-context 做适配。", + "hostplug.desc": "它的分段构成/时间线按压缩前的本地口径估算(本地日志按 dsh 架构要求保持无损),各段比例可能与实际发送内容不符;头部上下文尺寸跟随实际发送量。", "hostplug.hint": "当前有效上下文以 /acp 或 GET /__bili/plugin/status → contextTokens 为准。", "hostplug.dismiss_btn": "关闭", "hostplug.dismissed": "已关闭该提示", @@ -646,7 +646,7 @@ export const MESSAGES: Record> = { "advisory.restartDesc": ": the safe version is installed on disk, but this process is still running the affected version. Reason:", "advisory.restartHint": ". Restart bili to activate it.", "hostplug.on": "Host-side plugin detected", - "hostplug.desc": "Its displayed/recorded context figures are the pre-compression local meter (the durable log stays lossless by dsh architecture requirements), so they are not accurate while compression is active; showing the effective size needs a billion-context adaptation.", + "hostplug.desc": "Its segment composition / timeline is estimated from the pre-compression local meter (the durable log stays lossless by dsh architecture requirements), so the per-segment proportions may not match what is actually sent; the headline context size tracks the real sent volume.", "hostplug.hint": "Authoritative effective context: /acp or GET /__bili/plugin/status → contextTokens.", "hostplug.dismiss_btn": "Dismiss", "hostplug.dismissed": "Notice dismissed", diff --git a/tests/issue2861-host-plugin-notice.test.ts b/tests/issue2861-host-plugin-notice.test.ts index fda89d77dd..6173b429b2 100644 --- a/tests/issue2861-host-plugin-notice.test.ts +++ b/tests/issue2861-host-plugin-notice.test.ts @@ -232,3 +232,12 @@ test("#2861: i18n — hostplug.* key sets are identical across locales and non-e assert.ok(MESSAGES["zh-CN"][k]?.length > 0 && MESSAGES["en"][k]?.length > 0, `${k} non-empty in both locales`); } }); + +test("#3303: notice scopes the pre-compression claim to segment composition/timeline, not the headline size", () => { + const zh = MESSAGES["zh-CN"]["hostplug.desc"] ?? ""; + const en = MESSAGES["en"]["hostplug.desc"] ?? ""; + assert.ok(!zh.includes("数值不准确"), "zh desc must not re-assert the headline numbers are inaccurate (the #3303 false alarm)"); + assert.ok(zh.includes("分段") || zh.includes("构成"), "zh desc must scope the pre-compression claim to segment composition"); + assert.ok(!/not\s+accurate|inaccurate/i.test(en), "en desc must not re-assert the headline figures are inaccurate (the #3303 false alarm)"); + assert.ok(/composition|segment|timeline/i.test(en), "en desc must scope the pre-compression claim to segment composition / timeline"); +});