From e154f787fff167ef57ec9bda2a660efc6965ccd3 Mon Sep 17 00:00:00 2001 From: Louie0806 Date: Sat, 31 Oct 2026 18:27:13 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix(ci):=20clear=20the=20three=20master-red?= =?UTF-8?q?=20gates=20=E2=80=94=20two=20unused=20exports=20+=20the=20lost?= =?UTF-8?q?=20config-docs=20seed=20(#5317,=20#5319)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The master branch has carried three inherited required-check failures: 1. unused-exports: INTERNAL_ONLY src/codex-models.ts CodexWindowSource (#5305 added the type with only same-file uses). 2. unused-exports: INTERNAL_ONLY src/pack-install.ts PackInstallOptions (#5340 added the param-type interface; installPackFromNpm is the only consumer and it lives in the same file). 3. docs-sync: #5319 shipped a 'chat' prompt pack and hand-edited CONFIGURATION.md/.zh-CN.md, but never updated the generator seed at website/config-reference/compress.yaml. The generator therefore rewrote the docs back to the pre-#5319 text on every run. Both type demotions are behavior-neutral (the gate classifies them INTERNAL_ONLY: no cross-file import exists). The seed row now carries the 'chat' builtin and the 'shipped pack' resolution tier, matching the code in src/chat-settings.ts and src/compress-settings.ts. Verified: unused-exports clean (6 waived), docs-sync generate is a fixed point (no diff after commit), config-surface-guard / lifecycle-ledger-guard / test-import-graph all exit 0, tsc --noEmit clean, npm run build OK. --- src/codex-models.ts | 2 +- src/pack-install.ts | 2 +- website/config-reference/compress.yaml | 10 +++++----- website/docs/index.html | 2 +- website/main.js | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/codex-models.ts b/src/codex-models.ts index 45ee8b588e..02d49f1ab2 100644 --- a/src/codex-models.ts +++ b/src/codex-models.ts @@ -89,7 +89,7 @@ function positiveWindow(value: unknown): number | undefined { /** #5243: which surface produced a codex-aligned window — named in the clamp * log so "window clamped" stops claiming client metadata when no client * metadata existed. */ -export type CodexWindowSource = +type CodexWindowSource = | "client-metadata" | "codex-catalog" | "codex-models-cache" diff --git a/src/pack-install.ts b/src/pack-install.ts index a70844c1a8..dad6facaf3 100644 --- a/src/pack-install.ts +++ b/src/pack-install.ts @@ -31,7 +31,7 @@ export const PACK_ENTRY_FILE = "bili-pack.json"; const NPM_TIMEOUT_MS = 120_000; -export interface PackInstallOptions { +interface PackInstallOptions { /** Target `./.billion-context/packs/` instead of the user-dir default. */ project?: boolean; /** Replace an existing pack file (refused otherwise). */ diff --git a/website/config-reference/compress.yaml b/website/config-reference/compress.yaml index 25a7896f63..44a5e627db 100644 --- a/website/config-reference/compress.yaml +++ b/website/config-reference/compress.yaml @@ -164,15 +164,15 @@ entries: site_en: "\"off\" | \"warn\" | \"repair\" (default repair): reconcile folded state when the client rewinds or rewrites history between turns." site_zh: "\"off\" | \"warn\" | \"repair\"(默认 repair):客户端在轮次之间回退或改写历史时校准已折叠状态。" - key: compress.promptPack - type: "string (builtin: \"default\", \"lean\")" + type: "string (builtin: \"default\", \"lean\", \"chat\")" default: "builtin \"default\"" group: compress id: cw.ppk render: compress-row - desc_en: "Compression prompt pack, resolved project pack → user pack → builtin; not gated by acknowledgePromptsRisk." - desc_zh: "压缩提示词包,按 项目包 → 用户包 → 内置 解析;不受 acknowledgePromptsRisk 门控。" - site_en: "Compression prompt pack, resolved project pack → user pack → builtin. Builtins: \"default\" and \"lean\" (one-line tool descriptions). Not gated by acknowledgePromptsRisk." - site_zh: "压缩提示词包,按 项目包 → 用户包 → 内置 解析。内置:\"default\" 与 \"lean\"(单行工具描述)。不受 acknowledgePromptsRisk 门控。" + desc_en: "Compression prompt pack, resolved project pack → user pack → shipped pack → builtin; not gated by acknowledgePromptsRisk." + desc_zh: "压缩提示词包,按 项目包 → 用户包 → 随包附带(chat)→ 内置 解析;不受 acknowledgePromptsRisk 门控。" + site_en: "Compression prompt pack, resolved project pack → user pack → shipped pack → builtin. Builtins: \"default\" and \"lean\" (one-line tool descriptions); hosts may also ship a \"chat\" pack (#5319). Not gated by acknowledgePromptsRisk." + site_zh: "压缩提示词包,按 项目包 → 用户包 → 随包附带 → 内置 解析。内置:\"default\" 与 \"lean\"(单行工具描述);宿主可另附 \"chat\" 包(#5319)。不受 acknowledgePromptsRisk 门控。" - key: compress.tiers type: boolean default: "true" diff --git a/website/docs/index.html b/website/docs/index.html index cfbe6e24b1..0b8460df05 100644 --- a/website/docs/index.html +++ b/website/docs/index.html @@ -195,7 +195,7 @@

compress — every knob

maxSummaryLengthnumberHard cap, in characters, on one generated summary (kernel default 20000): longer replies are rejected whole by the kernel check or the external-summary executor. External summarizers receive this exact cap in their instructions (#3635); 0 disables the cap. minSummaryLengthnumberFloor, in characters, for generated summaries (kernel default 50): shorter replies are rejected whole; 0 disables the floor. External summarizers are held to the same floor (#3635). reconcile"off" | "warn" | "repair""off" | "warn" | "repair" (default repair): reconcile folded state when the client rewinds or rewrites history between turns. - promptPackstring (builtin: "default", "lean")Compression prompt pack, resolved project pack → user pack → builtin. Builtins: "default" and "lean" (one-line tool descriptions). Not gated by acknowledgePromptsRisk. + promptPackstring (builtin: "default", "lean", "chat")Compression prompt pack, resolved project pack → user pack → shipped pack → builtin. Builtins: "default" and "lean" (one-line tool descriptions); hosts may also ship a "chat" pack (#5319). Not gated by acknowledgePromptsRisk. tiersbooleanOn by default: tiered T1→T3 distillation spreads folding cost across generations. protectedToolsstring[]Hard exclusion across all history: results of listed tools never fold (use with care). protectedLatestToolsstring[]Protects only the LATEST instance of cumulative-snapshot tools whose newest result supersedes older ones (e.g. todo lists). diff --git a/website/main.js b/website/main.js index 86222cd284..51eed44329 100644 --- a/website/main.js +++ b/website/main.js @@ -77,7 +77,7 @@ "cw.msl": "Hard cap, in characters, on one generated summary (kernel default 20000): longer replies are rejected whole by the kernel check or the external-summary executor. External summarizers receive this exact cap in their instructions (#3635); 0 disables the cap.", "cw.mnl": "Floor, in characters, for generated summaries (kernel default 50): shorter replies are rejected whole; 0 disables the floor. External summarizers are held to the same floor (#3635).", "cw.rec": "\"off\" | \"warn\" | \"repair\" (default repair): reconcile folded state when the client rewinds or rewrites history between turns.", - "cw.ppk": "Compression prompt pack, resolved project pack → user pack → builtin. Builtins: \"default\" and \"lean\" (one-line tool descriptions). Not gated by acknowledgePromptsRisk.", + "cw.ppk": "Compression prompt pack, resolved project pack → user pack → shipped pack → builtin. Builtins: \"default\" and \"lean\" (one-line tool descriptions); hosts may also ship a \"chat\" pack (#5319). Not gated by acknowledgePromptsRisk.", "cw.tiers": "On by default: tiered T1→T3 distillation spreads folding cost across generations.", "ct.pt": "Hard exclusion across all history: results of listed tools never fold (use with care).", "ct.plt": "Protects only the LATEST instance of cumulative-snapshot tools whose newest result supersedes older ones (e.g. todo lists).", @@ -325,7 +325,7 @@ "cw.msl": "单条生成摘要的硬上限,单位为字符(内核默认 20000):超长的回复由内核检查或外部摘要执行器整段拒绝。外部摘要模型的指令中会写明这个确切上限(#3635);0 禁用上限。", "cw.mnl": "生成摘要的下限,单位为字符(内核默认 50):过短的回复被整段拒绝;0 禁下限。外部摘要模型受同一下限约束(#3635)。", "cw.rec": "\"off\" | \"warn\" | \"repair\"(默认 repair):客户端在轮次之间回退或改写历史时校准已折叠状态。", - "cw.ppk": "压缩提示词包,按 项目包 → 用户包 → 内置 解析。内置:\"default\" 与 \"lean\"(单行工具描述)。不受 acknowledgePromptsRisk 门控。", + "cw.ppk": "压缩提示词包,按 项目包 → 用户包 → 随包附带 → 内置 解析。内置:\"default\" 与 \"lean\"(单行工具描述);宿主可另附 \"chat\" 包(#5319)。不受 acknowledgePromptsRisk 门控。", "cw.tiers": "默认开:T1→T3 分级蒸馏,把折叠成本摊到多代。", "ct.pt": "全历史硬排除:列出工具的结果永不折叠(慎用)。", "ct.plt": "只保护累积快照类工具的「最新一次」实例(新结果覆盖旧结果的工具,如 todo 列表)。", From f5ddd362b69d392edaee13da5a5216f85996fe5b Mon Sep 17 00:00:00 2001 From: Louie0806 Date: Sat, 31 Oct 2026 19:23:12 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix(ci):=20clear=20the=20two=20remaining=20?= =?UTF-8?q?master-red=20test=20shards=20=E2=80=94=20windows=20npm=20shim?= =?UTF-8?q?=20+=20a=20stale=20#5103=20assertion=20(#5340,=20#4125)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two required-check failures reproduce on pristine master 485c5eaff (and pass on dc10c2d0b), so they are inherited, not introduced by the #5175 branches. Both are fixed here, each with a negative control. 1. `family gate: no raw negative string slices outside the allowlist` (tests/text-safe.test.ts) — the gate is red because src/pack-install.ts spawns `npm` with a bare `execFileSync("npm", …)`. On Windows `npm` is `npm.cmd`, which CreateProcess cannot execute, so every Windows shard reported `npm was not found on PATH` and the whole pack-install suite failed there (`not ok 1547`, `not ok 1548`). Route it through `planDshSpawn`, the same cmd.exe /d /s /c planner the launcher, pi and dsh lanes already use. Verified: win32 -> `cmd.exe /d /s /c "npm …"` with windowsVerbatimArguments; linux -> unchanged bare `npm`. 2. That `.slice(-3)` is an ARRAY receiver (`split("\n")`), so it was never the #816/#1615 family bug — the gate only inspects the receiver text. Allowlist the exact expression rather than loosening the gate. 3. `#5103: explicit attachUrl target found but build-incompatible — refusal named with reason and remedy` pinned the literal remedy sentence "...converges to the same version". #4125 (fc53fd466) reworded it because a strictly newer same-lane holder is now adopted rather than deadlocked around, dropping "to the same version". Pin the stable fragment ("restart the host once its copy converges") so the assertion tracks the remedy instead of its old prose. Negative controls: restoring the old `execFileSync` line / the old assertion string makes the two suites red again (17/1 and 4/1); with the fixes they are 18/0 and 5/0. Battery: pack-install 6, text-safe 18, issue5103 5, dsh-native 71, dsh-refresh 19, win-cmd-argv 28 = 147 pass / 0 fail; `npx tsc --noEmit` clean; the four static gates exit 0. --- src/pack-install.ts | 25 ++++++++++++++++--- ...ue5103-startup-recovery-visibility.test.ts | 5 +++- tests/text-safe.test.ts | 1 + 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/pack-install.ts b/src/pack-install.ts index dad6facaf3..978b761fe6 100644 --- a/src/pack-install.ts +++ b/src/pack-install.ts @@ -17,13 +17,14 @@ // overwrite of user config). Writes go through the temp-file+rename // pattern shared with every other writer here. -import { execFileSync } from "node:child_process"; +import { spawnSync } from "node:child_process"; import { closeSync, existsSync, fsyncSync, mkdirSync, mkdtempSync, openSync, readFileSync, readdirSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync } from "node:fs"; import os from "node:os"; import path from "node:path"; import { randomUUID } from "node:crypto"; import { isValidPackName, sanitizePackSurface, type PromptPackFile } from "acp-kernel"; import { configDir } from "./paths.js"; +import { planDshSpawn } from "./dsh-channel.js"; import { packSurfaceHasContent } from "./web/api.js"; /** The file an npm package must ship to be installable as a pack. */ @@ -107,9 +108,25 @@ export function installPackFromNpm(spec: string, options: PackInstallOptions = { try { let stderr = ""; try { - execFileSync("npm", [ - "install", "--prefix", tmp, "--no-save", "--no-audit", "--no-fund", trimmed, - ], { timeout: NPM_TIMEOUT_MS, stdio: ["ignore", "pipe", "pipe"] }); + // #5340: `npm` is `npm.cmd` on Windows, which CreateProcess cannot + // execute directly — a bare execFileSync("npm", …) fails there with + // ENOENT ("npm was not found on PATH"). planDshSpawn applies the same + // cmd.exe /d /s /c wrap the launcher/pi/dsh lanes already use. + const npmArgs = ["install", "--prefix", tmp, "--no-save", "--no-audit", "--no-fund", trimmed]; + const plan = planDshSpawn("npm", npmArgs); + const res = spawnSync(plan.command, plan.args, { + timeout: NPM_TIMEOUT_MS, + stdio: ["ignore", "pipe", "pipe"], + windowsVerbatimArguments: plan.windowsVerbatimArguments, + windowsHide: true, + }); + if (res.error) throw res.error; + if (res.status !== 0 && res.status !== null) { + const err = new Error(`exit ${res.status}`); + Object.assign(err, { status: res.status, stderr: typeof res.stderr === "string" ? res.stderr : "" }); + throw err; + } + stderr = typeof res.stderr === "string" ? res.stderr : ""; } catch (error) { const err = error as { stderr?: unknown; message?: string }; stderr = typeof err.stderr === "string" ? err.stderr : ""; diff --git a/tests/issue5103-startup-recovery-visibility.test.ts b/tests/issue5103-startup-recovery-visibility.test.ts index 2f59fc183b..13120aeaee 100644 --- a/tests/issue5103-startup-recovery-visibility.test.ts +++ b/tests/issue5103-startup-recovery-visibility.test.ts @@ -102,7 +102,10 @@ test("#5103: explicit attachUrl target found but build-incompatible — refusal const notice = stderrLines.find((l) => l.includes(`explicit attach target ${ORIGIN}`)); assert.ok(notice, "the visible channel must name the refused explicit target"); assert.ok(notice!.includes("code-fingerprint-mismatch"), notice); - assert.ok(notice!.includes("restart the host once its copy converges to the same version"), notice); + // #4125 rewrote this remedy: a strictly newer same-lane holder is now adopted + // rather than deadlocked around, so the wording no longer promises "the same + // version" — pin the stable remedy fragment instead of the old sentence. + assert.ok(notice!.includes("restart the host once its copy converges"), notice); assert.ok(diags.some((d) => d.includes(`explicit attach target ${ORIGIN}`)), "the durable log gets the same line"); }); diff --git a/tests/text-safe.test.ts b/tests/text-safe.test.ts index 7d729446c9..d0e5ebb773 100644 --- a/tests/text-safe.test.ts +++ b/tests/text-safe.test.ts @@ -176,6 +176,7 @@ test("family gate: no raw negative string slices outside the allowlist", () => { ["src/conflict-watch.ts", [/events\.slice\(-10\)/]], // array receiver ["src/web/client.ts", [/conflicts\.slice\(-10\)/]], // array receiver (#2102 session-detail card) ["src/web/report.ts", [/lines\.slice\(-12\)/, /folds\.slice\(-15\)/]], // array receiver (#3099 session-report tables) + ["src/pack-install.ts", [/stderr\.trim\(\)\.split\("\\n"\)\.slice\(-3\)/]], // array receiver (#5340): keeps the last 3 STDERR LINES, not a string suffix ["src/text-safe.ts", [/\.slice\(/]], // the clamped implementation itself ]); const srcDir = path.join(import.meta.dirname, "..", "src"); From b75cde50ec4fd860227dead705841cd5bb91f51e Mon Sep 17 00:00:00 2001 From: Louie0806 Date: Sat, 31 Oct 2026 20:04:25 +0800 Subject: [PATCH 3/3] fix(#4788): a discharged content-store proxy must not turn the next turn into a hard failure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two defects in the #4788 phase-2 discharge path, both surfaced by the CI matrix running under the `legacy` storage baseline: 1. `contentStoreLanded()` proved "the next touch will find data" with `existsSync(p)` alone. A PATH is not a COPY: a directory (or socket) sitting at the sidecar name satisfies existsSync, so the store was folded away while nothing readable was left behind. Require a regular file — that is exactly what `readContentStoreLys` can read back, so the proof now implies the reload instead of merely implying a name. 2. `adoptContentStore` read `prev.byRef` to compute the delta. When `prev` is a discharged lazy Proxy whose copy vanished, that read triggers `ensure()` and throws "could not be re-materialized from the store — refusing the thinned view" — a stale path turning an ordinary turn into a hard failure. Adoption is append-only and the incoming store already carries every ref (kernel processTurn re-ingests history), so a thinned prev is not a source of truth: treat it as absent. Repro (deterministic, CI parity): the matrix preload pins `BILIE_STORAGE_UNIFIED=legacy` (tests/preload-storage-baseline.mjs:16) and `tests/store.test.ts` flips the sidecar file into a DIRECTORY right before the second adopt. Pre-fix: BILI_STORAGE_UNIFIED=legacy ... --test tests/store.test.ts not ok 10 - flushAll retries a dirty content store after a transient write failure error: '[persist] resident content store for ccr-flushall-* could not be re-materialized from the store — refusing the thinned view' Post-fix: 29/29 in all three modes (legacy, shadow, full). Negative controls: revert (1) alone -> 28/1 reproduced; revert (2) alone -> 28/1 reproduced; both present -> 29/0. `BILI_SESSION_CONTENT_STORE_PIN=1` also masks the symptom, which is why this stayed invisible on machines that set it. Battery (legacy baseline, CI parity): store 29, memory-contentstore-lazy 8, persist-lazy-narrow-reads 9, issue4788-resident-minimal 4, persist-tail 7, persist-stats-roundtrip 1, proxy-persist 23, storage-ccr 3 = 84 pass / 0 fail. `npx tsc --noEmit` clean; the four static gates exit 0. --- src/persist.ts | 8 +++++++- src/store.ts | 14 +++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/persist.ts b/src/persist.ts index 3537509881..9b28155d44 100644 --- a/src/persist.ts +++ b/src/persist.ts @@ -3239,7 +3239,13 @@ export class SessionStore { contentStoreRelPathFor(id, meta?.protocol, meta?.upstreamOrigin), contentStoreRelPathFor(id), ])) { - try { if (existsSync(p)) return true; } catch { /* probe only */ } + // A PATH is not a COPY: existsSync alone accepts a directory or a + // socket sitting at the sidecar name, and folding on that proof makes + // the next touch throw ("could not be re-materialized … refusing the + // thinned view") where a resident set was still in hand. Require a + // regular file — this mirrors what readContentStoreRels can actually + // read back, so the drop only happens when the reload is guaranteed. + try { if (statSync(p).isFile()) return true; } catch { /* probe only */ } } return false; } diff --git a/src/store.ts b/src/store.ts index 9e24628e6b..06520a3a85 100644 --- a/src/store.ts +++ b/src/store.ts @@ -19,7 +19,7 @@ import { stateDir } from "./paths.js"; import { getStore } from "./persist.js"; import type { CompressSettings } from "./config.js"; import { ccrRetrievalTtlMs as knobCcrRetrievalTtlMs } from "./knobs.js"; -import type { PendingRetrieval, Session } from "./session.js"; +import { isDroppedContentStore, type PendingRetrieval, type Session } from "./session.js"; import { toolFail, toolOk, type ProxyToolResult } from "./proxy-tool-result.js"; export type CcrSettings = NonNullable; @@ -134,8 +134,16 @@ export function contentStoreOf(session: Session): MessageContentStore { * only when new entries appeared, so a no-growth turn costs nothing. */ export function adoptContentStore(session: Session, store: MessageContentStore): void { const prev = session.contentStore; - const added = prev - ? Object.entries(store.byRef).filter(([ref]) => !(ref in prev.byRef)) + // #4788 phase 2: a discharged (lazy) resident store is a Proxy that throws + // on first touch when its on-disk copy vanished under it (e.g. the sidecar + // was replaced by a directory, or the user deleted the sessions dir after + // the drop). Adoption is append-only and the incoming store already carries + // every ref (kernel processTurn re-ingests the history), so a THINNED prev + // is not a source of truth: treat it as absent instead of letting one stale + // path turn a normal turn into a hard failure. + const usablePrev = prev && !isDroppedContentStore(prev) ? prev : undefined; + const added = usablePrev + ? Object.entries(store.byRef).filter(([ref]) => !(ref in usablePrev.byRef)) : Object.entries(store.byRef); session.contentStore = store; if (added.length === 0) return;