Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/notice-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ export const PCK_NOTICE_ID = "pck-default-off";
// #5403 watermark fastpath experimental-grey intro (owner ruling 2026-11-02):
// own id so dismissal stays independent of pck's.
export const WM_FASTPATH_INTRO_ID = "wm-fastpath-intro";
// Owner report 2026-11-09: dsh's iot-thinking plugin fires one extra
// compress/rewrite request after every model reply, occupying the SAME
// session's proxy lane serially — the step keeps waiting seconds to tens of
// seconds after its first byte. Own id so its dismissal is independent.
export const IOT_INCOMPAT_NOTICE_ID = "iot-incompat";

const UPGRADE_NOTICE_IDS: ReadonlySet<string> = new Set([PCK_NOTICE_ID, WM_FASTPATH_INTRO_ID]);
const UPGRADE_NOTICE_IDS: ReadonlySet<string> = new Set([PCK_NOTICE_ID, WM_FASTPATH_INTRO_ID, IOT_INCOMPAT_NOTICE_ID]);
// #5548 P2: local announcements dismiss as `<id>@<content-hash16>` so edited
// content re-nags exactly once; the hash shape is the only dynamic form the
// store accepts (raw local ids never enter it — those use instance/always).
Expand Down
57 changes: 56 additions & 1 deletion src/notices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
// other file touches per-notice code again. Display semantics (tone color,
// action words) come from the web layer; activity predicates live HERE so the
// server-side judgment never scatters back into route handlers.
import fs from "node:fs";
import path from "node:path";
import { effectivePromptCacheRouting, loadConfigFile } from "./config.js";
import { resolveDshHome } from "./client-config.js";
import { dshProfileDirs } from "./dsh-channel.js";
import { featureOverrideAbsent } from "./rollout.js";
import { PCK_NOTICE_ID, dismissedUpgradeNotices, pckNoticeActive, WM_FASTPATH_INTRO_ID } from "./pck-notice.js";
import { IOT_INCOMPAT_NOTICE_ID, PCK_NOTICE_ID, dismissedUpgradeNotices, pckNoticeActive, WM_FASTPATH_INTRO_ID } from "./pck-notice.js";

interface NoticeEntry {
readonly id: string;
Expand Down Expand Up @@ -36,8 +40,59 @@ export const NOTICES: readonly NoticeEntry[] = [
!dismissedUpgradeNotices(process.env).has(WM_FASTPATH_INTRO_ID) &&
featureOverrideAbsent("pluginFullResendWatermark", loadConfigFile().rollout),
},
// Owner report 2026-11-09: dsh's iot-thinking plugin rewrites/hides the
// thinking channel through a SECOND, self-issued model call after every
// reply. Both calls share one session lane, so the step keeps waiting
// after its first byte — the measured gap tracked that rewrite call's own
// latency (p50 ~7s per step) and the extra requests vanished when the
// plugin was disabled (44% of one session's requests were that shape).
// Installed AND not switched off in its own config ⇒ warn (owner ruling
// 2026-11-09: disabling the plugin removes the extra wait, so the notice
// must go away with it and only reappear when it is turned back on).
{
id: IOT_INCOMPAT_NOTICE_ID,
tone: "warn",
keys: { on: "iotcompat.on", desc: "iotcompat.desc", hint: "iotcompat.hint", dismiss: "iotcompat.dismiss_btn" },
active: () =>
!dismissedUpgradeNotices(process.env).has(IOT_INCOMPAT_NOTICE_ID) &&
dshIotThinkingActive(process.env),
},
];

/** Uncached: does ANY dsh profile carry the iot-thinking plugin? Never throws
* (no profiles / unreadable home ⇒ false — an advisory must not fail a page). */
export function probeDshIotThinking(env: NodeJS.ProcessEnv = process.env): boolean {
let dirs: string[];
try {
dirs = dshProfileDirs(env);
} catch {
return false;
}
for (const dir of dirs) {
try {
if (fs.existsSync(path.join(dir, "node_modules", "dsh-plugin-iot-thinking", "package.json"))) return true;
} catch {
// unreadable profile: keep scanning the rest
}
}
return false;
}

/** Installed AND effective-enabled. The plugin's own default is enabled
* (its config-store seeds enabled: true), so a missing/unreadable config
* keeps the warning; only an explicit enabled: false silences it. */
export function dshIotThinkingActive(env: NodeJS.ProcessEnv = process.env): boolean {
if (!probeDshIotThinking(env)) return false;
try {
const raw = fs.readFileSync(path.join(resolveDshHome(env), "plugin-data", "iot-thinking", "config.json"), "utf8");
const doc: unknown = JSON.parse(raw);
if (doc !== null && typeof doc === "object" && (doc as { enabled?: unknown }).enabled === false) return false;
} catch {
// absent/broken config ⇒ plugin runs on its default (enabled)
}
return true;
}

/** Currently-visible notices, in registry order. Never throws. */
export function visibleNotices(): Array<{ id: string; tone: "ok" | "warn"; keys: NoticeEntry["keys"] }> {
const out: Array<{ id: string; tone: "ok" | "warn"; keys: NoticeEntry["keys"] }> = [];
Expand Down
4 changes: 2 additions & 2 deletions src/pck-notice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import {
persistDismissedKey,
unifiedReceiptsActive,
} from "./notice-store.js";
import { PCK_NOTICE_ID, WM_FASTPATH_INTRO_ID } from "./notice-store.js";
import { IOT_INCOMPAT_NOTICE_ID, PCK_NOTICE_ID, WM_FASTPATH_INTRO_ID } from "./notice-store.js";

export { PCK_NOTICE_ID, WM_FASTPATH_INTRO_ID };
export { IOT_INCOMPAT_NOTICE_ID, PCK_NOTICE_ID, WM_FASTPATH_INTRO_ID };

const DISMISS_FILE = "upgrade-notices.json";

Expand Down
3 changes: 3 additions & 0 deletions src/web/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1682,6 +1682,9 @@ function changelogCatOf(rawLine) {
if (!n || typeof n !== "object" || typeof n.id !== "string") continue;
const el = document.createElement("div");
el.className = "banner " + (n.tone === "ok" ? "ok" : n.tone === "warn" ? "warn" : "");
// .banner is display:none until .show — #5548's loop never added it,
// so every merged notice (builtin + file + feed) rendered invisibly.
el.classList.add("show");
el.dataset.id = n.id;
nr.appendChild(el);
if (n.source !== "builtin") {
Expand Down
8 changes: 8 additions & 0 deletions src/web/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ export const MESSAGES: Record<Locale, Record<string, string>> = {
"wmfast.desc": "长会话每轮都要把整个历史重新发给代理解析一遍,现在改为增量解析:只解析本轮新增的那部分,优化长会话的解析性能(发给模型的内容不变;有任何疑点,当轮自动回退老路径并重新对齐)。当前版本对约 5% 的安装灰度开启,属实验性功能。",
"wmfast.hint": "开关在「配置」页快速配置(大上下文增量解析),也可在 billion-context.json 写 rollout.features.pluginFullResendWatermark: true/false,或设环境变量 BILI_ROLLOUT_PLUGIN_FULL_RESEND_WATERMARK=1/0。",
"wmfast.dismiss_btn": "我知道了",
"iotcompat.on": "检测到不兼容插件:dsh 的 iot-thinking(会造成额外等待)",
"iotcompat.desc": "该插件在每次模型回复后额外发起一轮自己的压缩/改写请求,占用同一会话的代理通道并串行执行——表现为首字已经回来,这一步还要再等数秒到十几秒;开启压缩时会话内排队更明显。",
"iotcompat.hint": "建议在 dsh 侧关闭或卸载 dsh-plugin-iot-thinking(其 config.json 里 enabled=false,或 dsh plugin --profile <name> remove dsh-plugin-iot-thinking);关闭后本提示会自动消失,bili 侧无需改动。",
"iotcompat.dismiss_btn": "我知道了",
"notices.dismissed": "已关闭该提示",
"notices.dismiss_btn": "我知道了",
"ses.title": "会话",
Expand Down Expand Up @@ -1043,6 +1047,10 @@ export const MESSAGES: Record<Locale, Record<string, string>> = {
"pckoff.desc": "Since this version bili no longer adds OpenAI's prompt_cache_key field to requests on its own (previously on by default). If your upstream routes prefix cache by this key (relays such as workbuddy panel/hub, account pools), turn the switch back on — otherwise traffic may route randomly and miss the prefix cache.",
"pckoff.hint": "Switch: Configuration page → quick config (promptCache.routing: disabled/auto/enabled), or edit billion-context.json directly; direct official-API users can ignore this notice.",
"pckoff.dismiss_btn": "Got it",
"iotcompat.on": "Incompatible plugin detected: dsh's iot-thinking (adds extra waiting)",
"iotcompat.desc": "After every model reply this plugin issues its own extra compress/rewrite request through the SAME session lane, serially — the step keeps waiting for seconds to tens of seconds after its first byte has arrived; the queueing is more visible while compression is active.",
"iotcompat.hint": "Disable or uninstall dsh-plugin-iot-thinking on the dsh side (set enabled=false in its config.json, or run dsh plugin --profile <name> remove dsh-plugin-iot-thinking); this notice disappears once it is off. Nothing needs to change in bili.",
"iotcompat.dismiss_btn": "Got it",
"wmfast.on": "New: incremental parsing for large contexts (incremental-compression bridge feature, experimental)",
"wmfast.desc": "Long conversations used to re-send their entire history for parsing on every turn. Now only the new part of each turn is parsed — faster parsing on long sessions (the request sent to the model is unchanged; any doubt falls back to the old path for that turn and re-aligns). This release rolls it out to roughly 5% of installs; it is marked experimental.",
"wmfast.hint": "Switch: Configuration page → quick config (incremental parsing for large contexts), or write rollout.features.pluginFullResendWatermark: true/false in billion-context.json, or set BILI_ROLLOUT_PLUGIN_FULL_RESEND_WATERMARK=1/0.",
Expand Down
69 changes: 69 additions & 0 deletions tests/iot-incompat-notice.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";

// Owner report 2026-11-09: dsh's iot-thinking plugin issues one extra
// compress/rewrite call after every reply; both calls share one session lane,
// so the step waits seconds after its first byte. The registry exposes that as
// a warn notice, gated on "installed AND still enabled" (disabling the plugin
// removes the wait, so the notice must go away with it).
// Hermetic: fresh DSH_HOME (no profiles), state and config isolated.

const home = fs.mkdtempSync(path.join(os.tmpdir(), "iot-incompat-home-"));
process.env.DSH_HOME = home;
process.env.XDG_STATE_HOME = fs.mkdtempSync(path.join(os.tmpdir(), "iot-incompat-state-"));
process.env.BILI_CONFIG_FILE = path.join(fs.mkdtempSync(path.join(os.tmpdir(), "iot-incompat-cfg-")), "absent.json");

const { NOTICES, probeDshIotThinking, dshIotThinkingActive } = await import("../src/notices.ts");
const { IOT_INCOMPAT_NOTICE_ID, dismissUpgradeNotice } = await import("../src/pck-notice.ts");

const entry = () => {
const found = NOTICES.find((n) => n.id === IOT_INCOMPAT_NOTICE_ID);
assert.ok(found, "registry carries the iot-incompat entry");
return found;
};
const writeConfig = (doc: unknown): void => {
const dir = path.join(home, "plugin-data", "iot-thinking");
fs.mkdirSync(dir, { recursive: true });
fs.writeFileSync(path.join(dir, "config.json"), JSON.stringify(doc));
};

test("no dsh profiles ⇒ not detected, notice inactive", () => {
assert.equal(probeDshIotThinking(process.env), false);
assert.equal(dshIotThinkingActive(process.env), false);
assert.equal(entry().active(), false);
});

test("installed with no config yet ⇒ active (plugin default is enabled)", () => {
const pkg = path.join(home, "profiles", "web", "node_modules", "dsh-plugin-iot-thinking");
fs.mkdirSync(pkg, { recursive: true });
fs.writeFileSync(path.join(pkg, "package.json"), JSON.stringify({ name: "dsh-plugin-iot-thinking", version: "0.2.0" }));
assert.equal(probeDshIotThinking(process.env), true);
assert.equal(dshIotThinkingActive(process.env), true);
assert.equal(entry().active(), true);
});

test("explicit enabled:false ⇒ installed but silent", () => {
writeConfig({ enabled: false });
assert.equal(probeDshIotThinking(process.env), true);
assert.equal(dshIotThinkingActive(process.env), false);
assert.equal(entry().active(), false);
});

test("turning it back on ⇒ notice returns", () => {
writeConfig({ enabled: true });
assert.equal(dshIotThinkingActive(process.env), true);
assert.equal(entry().active(), true);
});

test("dismissal hides the notice for later polls", () => {
assert.equal(dismissUpgradeNotice(IOT_INCOMPAT_NOTICE_ID, process.env), true);
assert.equal(entry().active(), false);
});

test("a different dsh home without profiles probes clean", () => {
const other = fs.mkdtempSync(path.join(os.tmpdir(), "iot-incompat-home2-"));
assert.equal(probeDshIotThinking({ ...process.env, DSH_HOME: other }), false);
});
13 changes: 10 additions & 3 deletions tests/notice-registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@ import path from "node:path";

const stateDir = fs.mkdtempSync(path.join(os.tmpdir(), "notice-reg-state-"));
const cfgPath = path.join(fs.mkdtempSync(path.join(os.tmpdir(), "notice-reg-cfg-")), "absent.json");
// Hermetic dsh home too: the iot-thinking probe must see NO profiles here, or
// a developer machine that has the plugin installed changes the expectations.
process.env.DSH_HOME = fs.mkdtempSync(path.join(os.tmpdir(), "notice-reg-dsh-"));
process.env.XDG_STATE_HOME = stateDir;
process.env.BILI_CONFIG_FILE = cfgPath;

const { NOTICES, visibleNotices } = await import("../src/notices.ts");
const { PCK_NOTICE_ID, WM_FASTPATH_INTRO_ID, dismissUpgradeNotice } = await import("../src/pck-notice.ts");
const { IOT_INCOMPAT_NOTICE_ID, PCK_NOTICE_ID, WM_FASTPATH_INTRO_ID, dismissUpgradeNotice } = await import("../src/pck-notice.ts");
const { MESSAGES, LOCALES } = await import("../src/web/i18n.ts");

test("registry: unique ids, valid tones, every key resolves in both locales", () => {
const ids = NOTICES.map((n) => n.id);
assert.equal(new Set(ids).size, ids.length, "ids must be unique");
assert.deepEqual([...ids].sort(), [PCK_NOTICE_ID, WM_FASTPATH_INTRO_ID].sort());
assert.deepEqual([...ids].sort(), [IOT_INCOMPAT_NOTICE_ID, PCK_NOTICE_ID, WM_FASTPATH_INTRO_ID].sort());
for (const n of NOTICES) {
assert.ok(n.tone === "ok" || n.tone === "warn", `${n.id} tone`);
for (const locale of LOCALES) {
Expand All @@ -34,12 +37,16 @@ test("registry: unique ids, valid tones, every key resolves in both locales", ()
}
});

test("visibleNotices: fresh install sees both, registry order", () => {
test("visibleNotices: fresh install sees both, registry order (iot absent ⇒ hidden)", () => {
const v = visibleNotices();
assert.deepEqual(v.map((n) => n.id), [PCK_NOTICE_ID, WM_FASTPATH_INTRO_ID]);
assert.deepEqual(v.map((n) => n.tone), ["warn", "ok"]);
});

test("iot notice id is a dismissible builtin (no 400 on close)", () => {
assert.equal(dismissUpgradeNotice(IOT_INCOMPAT_NOTICE_ID, process.env), true);
});

test("visibleNotices: dismissing one hides only that one", () => {
assert.equal(dismissUpgradeNotice(WM_FASTPATH_INTRO_ID, process.env), true);
const v = visibleNotices();
Expand Down
12 changes: 10 additions & 2 deletions tests/web-i18n.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,18 @@ function collectRefs(): Set<string> {
// #5345: the pack editor builds its <option> labels through a pair-array
// (t(pair[1])), so those catalog keys are only referenced via bare quoted
// strings — accept any dot-qualified identifier that appears verbatim in
// the sources as a live reference too.
// the sources as a live reference too. Filenames share the dotted shape
// (package.json / config.json in notices.ts) but are not keys: drop tokens
// whose final segment is a file extension. Segments already proven to be
// key suffixes (summary.key, det.log) stay out of the exclusion, and those
// keys are referenced through the explicit t()/data-i18n rules above anyway.
const fileExt = new Set(["json", "jsonl", "js", "mjs", "cjs", "ts", "tsx", "map", "db", "sqlite", "sqlite3", "pem", "crt", "cert", "txt", "md", "yml", "yaml", "toml", "lock", "html", "css", "sh", "bat", "ps1", "png", "jpg", "jpeg", "gif", "svg", "ico", "woff", "woff2", "ttf"]);
for (const src of [pageSrc, clientSrc, reportSrc, noticesSrc]) {
for (const m of src.matchAll(/"([a-z][\w]*\.[\w.]+)"/g)) {
if (/^[a-z][\w]*(\.[\w]+)+$/.test(m[1]) && !m[1].includes("..")) refs.add(m[1]);
const token = m[1];
if (!/^[a-z][\w]*(\.[\w]+)+$/.test(token) || token.includes("..")) continue;
if (fileExt.has(token.slice(token.lastIndexOf(".") + 1))) continue;
refs.add(token);
}
}
return refs;
Expand Down
Loading