From 16b8d9bc9b76d3d8da2d28b6771a2fc4fe819e65 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 13 Nov 2026 15:31:07 +0000 Subject: [PATCH 01/11] release v0.1.214 --- .agents/plugins/marketplace.json | 2 +- .claude-plugin/marketplace.json | 2 +- .claude-plugin/plugin.json | 2 +- package-lock.json | 4 ++-- package.json | 2 +- plugins/codex/.codex-plugin/plugin.json | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.agents/plugins/marketplace.json b/.agents/plugins/marketplace.json index e08731ba3c..9265730d36 100644 --- a/.agents/plugins/marketplace.json +++ b/.agents/plugins/marketplace.json @@ -6,7 +6,7 @@ "plugins": [ { "name": "billion-context", - "version": "0.1.213", + "version": "0.1.214", "source": { "source": "local", "path": "./plugins/codex" diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.json index 4b4a4100b1..147f989fb5 100644 --- a/.claude-plugin/marketplace.json +++ b/.claude-plugin/marketplace.json @@ -12,7 +12,7 @@ "name": "billion-context", "source": "./", "description": "Context-compression plugin for Claude Code · month-long single sessions (billions of tokens) · high compression quality even in small context windows (100K is enough) · 5× fewer tokens", - "version": "0.1.213", + "version": "0.1.214", "author": { "name": "ranxianglei" }, diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json index 49b4fd00c7..dbeb07d567 100644 --- a/.claude-plugin/plugin.json +++ b/.claude-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "billion-context", - "version": "0.1.213", + "version": "0.1.214", "description": "Context-compression plugin for Claude Code · month-long single sessions (billions of tokens) · high compression quality even in small context windows (100K is enough) · 5× fewer tokens", "author": { "name": "ranxianglei" diff --git a/package-lock.json b/package-lock.json index e2ff6fb483..534face6f1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "billion-context", - "version": "0.1.213", + "version": "0.1.214", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "billion-context", - "version": "0.1.213", + "version": "0.1.214", "license": "MIT", "dependencies": { "mysql2": "^3.15.3", diff --git a/package.json b/package.json index 13ff1da560..ca14494cd1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "billion-context", - "version": "0.1.213", + "version": "0.1.214", "description": "A context-compression plugin \u2014 small context windows (a 100K context is enough), 5x fewer tokens, month-long single sessions (billions of tokens), and compression quality \u2014 for all agents: pi, OpenCode, Codex, Claude Code, and more. billion-context is all you need.", "type": "module", "main": "dist/index.js", diff --git a/plugins/codex/.codex-plugin/plugin.json b/plugins/codex/.codex-plugin/plugin.json index c370655999..c15589b1e5 100644 --- a/plugins/codex/.codex-plugin/plugin.json +++ b/plugins/codex/.codex-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "billion-context", - "version": "0.1.213", + "version": "0.1.214", "description": "Context-compression plugin for Codex — small context windows (100K is enough), 5x fewer tokens, month-long single sessions (billions of tokens), and high compression quality.", "author": { "name": "ranxianglei" From 74a925db01dee317f580864f05d4731dd04f4764 Mon Sep 17 00:00:00 2001 From: ranxianglei Date: Sat, 14 Nov 2026 00:31:20 +0800 Subject: [PATCH 02/11] e2e: pin dual-write storage in client lanes + tolerate half-deleted install dir MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The pure-SQLite storage default (owner decision 2026-11-13, 5a80e2b8e) stopped writing JSONL session envelopes by default. Five hermetic client e2e lanes (native-pi / native-dsh / native-opencode / pi-codex-ws / subagent-sessions) assert those envelopes and were not updated with the default flip: they now fail with 'proxy must persist the session (got 0 sessions)' (reproduced locally with the CI-pinned pi-stable 0.83.6 and on the PR head). Pin BILI_STORAGE_JSON_WRITER=1 in the spawned-client env: these lanes cover proxy/session semantics, not the storage default — the pure-SQLite path stays covered by unit tests and the real-model gate. Also: the advisory-rollback waitFor probes crashed with ENOENT when the updater's uninstall->reinstall half-deletes the install dir (npm drops package.json before the directory; reproduced locally). New pkgVersionOrAbsent() helper treats that window as 'not there yet'; non-ENOENT errors still throw. This was the ubuntu flake behind the 'hermetic registry e2e' red on 16b8d9b (run 43454198949). --- tests/e2e/e2e-advisory-rollback.test.ts | 17 +++++++++++++++-- tests/e2e/e2e-native-dsh.test.ts | 4 ++++ tests/e2e/e2e-native-opencode.test.ts | 4 ++++ tests/e2e/e2e-native-pi.test.ts | 6 ++++++ tests/e2e/e2e-pi-codex-ws.test.ts | 4 ++++ tests/e2e/e2e-subagent-sessions.test.ts | 4 ++++ 6 files changed, 37 insertions(+), 2 deletions(-) diff --git a/tests/e2e/e2e-advisory-rollback.test.ts b/tests/e2e/e2e-advisory-rollback.test.ts index 0e7cf12fa2..f7082e2053 100644 --- a/tests/e2e/e2e-advisory-rollback.test.ts +++ b/tests/e2e/e2e-advisory-rollback.test.ts @@ -78,6 +78,19 @@ async function readPkgVersion(dir: string): Promise { return (JSON.parse(await fs.promises.readFile(path.join(dir, "package.json"), "utf8")) as { version: string }).version; } +// The updater's uninstall→reinstall half-deletes the install dir (npm drops +// package.json before the directory): readPkgVersion ENOENTs inside that +// window. waitFor probes must treat "gone for a moment" as "not there yet", +// not crash — anything other than ENOENT still throws. +async function pkgVersionOrAbsent(dir: string): Promise { + try { + return await readPkgVersion(dir); + } catch (err) { + if ((err as NodeJS.ErrnoException).code === "ENOENT") return null; + throw err; + } +} + function packTarball(stage: string, packs: string, home: string): string { const listing = npmRunSync(["pack", "--silent", "--pack-destination", packs], { cwd: stage, env: { PATH: process.env.PATH ?? "", ...npmHomeEnv(home) } }) .trim() @@ -262,14 +275,14 @@ test("e2e: rollback-form advisory (#1588) — forced rollback, no ping-pong, per await waitFor( `disk ${START} → ${LATEST} via normal self-update`, 90_000, - async () => (await readPkgVersion(installDir)) === LATEST && installedRe.test(readLog()), + async () => (await pkgVersionOrAbsent(installDir)) === LATEST && installedRe.test(readLog()), ); assert.match(readLog(), installedRe); }); await t.test("rollback-form advisory lands: forced install of the older target + persistent restart banner", async () => { await reg.publish(await makeAdvisoryTarball(work)); - await waitFor(`disk ${LATEST} → ${TARGET} via forced advisory install`, 60_000, async () => (await readPkgVersion(installDir)) === TARGET); + await waitFor(`disk ${LATEST} → ${TARGET} via forced advisory install`, 60_000, async () => (await pkgVersionOrAbsent(installDir)) === TARGET); const log = readLog(); assert.match(log, new RegExp(`forcing update to ${escapeRe(TARGET)}`)); // #1588-B: disk left the range but the RUNNING process is still on the diff --git a/tests/e2e/e2e-native-dsh.test.ts b/tests/e2e/e2e-native-dsh.test.ts index 7b7402356c..93d2521c7e 100644 --- a/tests/e2e/e2e-native-dsh.test.ts +++ b/tests/e2e/e2e-native-dsh.test.ts @@ -463,6 +463,10 @@ function dshRun( cwd: ctx.dshCwd, env: { ...cleanEnv(), + // Pure-SQLite is the default storage writer now (2026-11-13): this lane + // asserts the JSONL session envelopes — pin dual-write so coverage does + // not depend on the default (pure-SQLite path: unit tests + gate). + BILI_STORAGE_JSON_WRITER: "1", HOME: ctx.homeDir, TMPDIR: ctx.tmpDir, DSH_HOME: ctx.dshHome, diff --git a/tests/e2e/e2e-native-opencode.test.ts b/tests/e2e/e2e-native-opencode.test.ts index 8b5578020d..cf2200f2d2 100644 --- a/tests/e2e/e2e-native-opencode.test.ts +++ b/tests/e2e/e2e-native-opencode.test.ts @@ -421,6 +421,10 @@ async function ocRun( cwd: ctx.ocCwd, env: { ...cleanEnv(), + // Pure-SQLite is the default storage writer now (2026-11-13): this lane + // asserts the JSONL session envelopes — pin dual-write so coverage does + // not depend on the default (pure-SQLite path: unit tests + gate). + BILI_STORAGE_JSON_WRITER: "1", HOME: ctx.homeDir, TMPDIR: ctx.tmdir, XDG_CONFIG_HOME: ctx.xdg.config, diff --git a/tests/e2e/e2e-native-pi.test.ts b/tests/e2e/e2e-native-pi.test.ts index 7f0ee66eb3..7a4e55f660 100644 --- a/tests/e2e/e2e-native-pi.test.ts +++ b/tests/e2e/e2e-native-pi.test.ts @@ -468,6 +468,12 @@ function piRun( // (CI sentinel incident, #4599). Pin the legacy posture so this // coverage stays deterministic; inline posture is covered by // tests/pi-inline-ws.test.ts and tests/pi-native.test.ts. + // Pure-SQLite became the default storage writer (2026-11-13 owner + // decision): JSONL session envelopes stop being written unless + // dual-write is requested. This lane asserts the JSONL envelopes — + // pin dual-write so the coverage does not ride the default; the + // pure-SQLite path is covered by unit tests + the real-model gate. + BILI_STORAGE_JSON_WRITER: "1", BILI_PI_INLINE: "0", PI_CODING_AGENT_DIR: ctx.piAgentDir, XDG_CONFIG_HOME: ctx.xdg.config, diff --git a/tests/e2e/e2e-pi-codex-ws.test.ts b/tests/e2e/e2e-pi-codex-ws.test.ts index a8df48ae7c..bf4ea28acd 100644 --- a/tests/e2e/e2e-pi-codex-ws.test.ts +++ b/tests/e2e/e2e-pi-codex-ws.test.ts @@ -342,6 +342,10 @@ function piRun( cwd: ctx.piCwd, env: { ...cleanEnv(opts.extraEnv), + // Pure-SQLite is the default storage writer now (2026-11-13): + // this lane asserts the JSONL session envelopes — pin dual-write + // so coverage does not depend on the default. + BILI_STORAGE_JSON_WRITER: "1", PI_CODING_AGENT_DIR: ctx.piAgentDir, XDG_CONFIG_HOME: ctx.xdg.config, XDG_CACHE_HOME: ctx.xdg.cache, diff --git a/tests/e2e/e2e-subagent-sessions.test.ts b/tests/e2e/e2e-subagent-sessions.test.ts index af08050217..0acba3a090 100644 --- a/tests/e2e/e2e-subagent-sessions.test.ts +++ b/tests/e2e/e2e-subagent-sessions.test.ts @@ -394,6 +394,10 @@ async function ocRun( cwd: ctx.ocCwd, env: { ...cleanEnv(), + // Pure-SQLite is the default storage writer now (2026-11-13): this lane + // asserts the JSONL session envelopes — pin dual-write so coverage does + // not depend on the default (pure-SQLite path: unit tests + gate). + BILI_STORAGE_JSON_WRITER: "1", HOME: ctx.homeDir, TMPDIR: ctx.tmdir, XDG_CONFIG_HOME: ctx.xdg.config, From fdf4644c4f35c24c1a0191b857a606878554235f Mon Sep 17 00:00:00 2001 From: ranxianglei Date: Sat, 14 Nov 2026 00:50:08 +0800 Subject: [PATCH 03/11] tests: unpin CI storage-baseline env in notice-registry suite The CI-only baseline preload (tests/preload-storage-baseline.mjs) pins BILI_STORAGE_UNIFIED=legacy for the legacy-default corpus. The sqlite-default notice test asserts the production default (absent spelling => pure-sqlite), so without an explicit unpin it passes locally (no preload) and reds every CI test shard carrying this file. Also unpin BILI_STORAGE_JSON_WRITER for the same predicate. --- tests/notice-registry.test.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/notice-registry.test.ts b/tests/notice-registry.test.ts index 6d3b60edb4..1235be3a60 100644 --- a/tests/notice-registry.test.ts +++ b/tests/notice-registry.test.ts @@ -17,6 +17,14 @@ const cfgPath = path.join(fs.mkdtempSync(path.join(os.tmpdir(), "notice-reg-cfg- 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; +// The CI baseline preload (tests/preload-storage-baseline.mjs) pins +// BILI_STORAGE_UNIFIED=legacy for the legacy-default corpus. This suite +// asserts the PRODUCTION default (absent spelling ⇒ pure-sqlite ⇒ the +// sqlite-default notice is active), so both storage-selection knobs must be +// unpinned explicitly — relying on the ambient default passes locally (no +// preload) but reds CI (the #4011 lesson written into that baseline file). +delete process.env.BILI_STORAGE_UNIFIED; +delete process.env.BILI_STORAGE_JSON_WRITER; const { NOTICES, visibleNotices, SQLITE_DEFAULT_NOTICE_ID } = await import("../src/notices.ts"); const { IOT_INCOMPAT_NOTICE_ID, PCK_NOTICE_ID, WM_FASTPATH_INTRO_ID, dismissUpgradeNotice } = await import("../src/pck-notice.ts"); From d252543a0be61c82400d7363907fb3f5509bdd8f Mon Sep 17 00:00:00 2001 From: ranxianglei Date: Sat, 14 Nov 2026 01:43:36 +0800 Subject: [PATCH 04/11] e2e: pin dual-write storage in dsh-persona lane too MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit tests/e2e/e2e-native-dsh-persona.test.ts asserts JSONL session envelopes ('the raw conversation key persisted a session') but its spawned env missed the same pin as the other client lanes — red in the e2e-dsh lane. --- tests/e2e/e2e-native-dsh-persona.test.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/e2e/e2e-native-dsh-persona.test.ts b/tests/e2e/e2e-native-dsh-persona.test.ts index 82f3abc94b..06d0d4ab65 100644 --- a/tests/e2e/e2e-native-dsh-persona.test.ts +++ b/tests/e2e/e2e-native-dsh-persona.test.ts @@ -400,6 +400,11 @@ function buildRig(tag: string, withAutoReview: boolean): Rig { const env: NodeJS.ProcessEnv = { ...cleanEnv(), + // Pure-SQLite is the default storage writer now (2026-11-13): this lane + // asserts the JSONL session envelopes — pin dual-write (same reason as + // the other client e2e lanes); pure-sqlite semantics are covered by the + // unit tests and the real-model gate. + BILI_STORAGE_JSON_WRITER: "1", HOME: home, TMPDIR: tmp, DSH_HOME: dshHome, From 7c152dc08a75d360b9812e443fe4496ef761c7cf Mon Sep 17 00:00:00 2001 From: ranxianglei Date: Sat, 14 Nov 2026 04:05:53 +0800 Subject: [PATCH 05/11] test(persist): close store sidecars before tmp-dir teardown (Windows EBUSY) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The dual-write pins added with the pure-sqlite default flip make persist-zstd and persist-metadata-fold-gate open index.db; the suites never closed their stores, so the tmp-dir teardown raced a still-open SQLite handle — Windows cannot unlink an open file, and the retry budget in tmp-rm.ts lost deterministically (EBUSY unlink .../index.db on windows 22/1, 22/3, 24/1, 24/3; same suites green on v0.1.213). Close every store (closeQuietly: cancel pending writes + sidecar close) before rmrf. closeQuietly is idempotent-safe where flushAll already closed the sidecar. --- tests/persist-metadata-fold-gate.test.ts | 4 ++++ tests/persist-zstd.test.ts | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/tests/persist-metadata-fold-gate.test.ts b/tests/persist-metadata-fold-gate.test.ts index bf1a8301d6..788d4cedaf 100644 --- a/tests/persist-metadata-fold-gate.test.ts +++ b/tests/persist-metadata-fold-gate.test.ts @@ -62,6 +62,7 @@ test("metadata fold is refused while live metadata diverges from the last commit foldGate(store).dropResidentMetadata(s); assert.equal(isDroppedMetadata(s.metadata), false, "fold must be refused while live metadata diverges from committed bytes"); assert.equal((s.metadata as Record).lateStamp, "unsaved", "the unsaved mutation must stay resident"); + store.closeQuietly(); // dual-write pin opens index.db — close before teardown (Windows cannot unlink an open SQLite file; see persist-zstd.test.ts for the family) } finally { rmrf(dir); } @@ -85,6 +86,8 @@ test("metadata fold proceeds once the divergent mutation has been committed (#55 assert.ok(back, "session reloaded"); assert.equal((back?.metadata as Record).lateStamp, "unsaved", "committed mutation survives the round trip"); await reloaded.flushAll([]); + store.closeQuietly(); + reloaded.closeQuietly(); } finally { rmrf(dir); } @@ -99,6 +102,7 @@ test("metadata fold stays closed for a session with no committed save yet (#5506 foldGate(store).dropResidentMetadata(s); assert.equal(isDroppedMetadata(s.metadata), false, "no commit proof yet ⇒ fold must stay closed"); assert.equal((s.metadata as Record).onlyInMemory, true); + store.closeQuietly(); } finally { rmrf(dir); } diff --git a/tests/persist-zstd.test.ts b/tests/persist-zstd.test.ts index 93c668f7d7..887a0d4e49 100644 --- a/tests/persist-zstd.test.ts +++ b/tests/persist-zstd.test.ts @@ -48,31 +48,41 @@ function makeSession(id: string, fill = 0, fillRandom = false): Session { interface Harness { dir: string; logs: LogLine[]; + stores: SessionStore[]; } async function withTempDir(name: string, fn: (h: Harness) => Promise): Promise { await test(name, async () => { const dir = mkdtempSync(join(tmpdir(), "bili-zstd-")); const logs: LogLine[] = []; - const h = { dir, logs }; + const h: Harness = { dir, logs, stores: [] }; try { await fn(h); } finally { delete process.env.BILI_ENCRYPTION_KEY; delete process.env.BILI_PERSIST_ZSTD; _setZstdAvailableForTest(null); + // The dual-write pin above opens index.db in every store — Windows + // cannot unlink an open SQLite file, so close each sidecar before + // the tmp-dir teardown or the rmrf loses the EBUSY race (#5154 + // family, resurfaced by the pure-sqlite-default test pins). + for (const s of h.stores) { + try { s.closeQuietly(); } catch { /* already closed */ } + } rmrf(dir); } }); } function newStore(h: Harness, debounceMs = 0): SessionStore { - return new SessionStore({ + const store = new SessionStore({ dir: h.dir, debounceMs, enabled: true, log: (level, msg) => h.logs.push({ level, msg }), }); + h.stores.push(store); + return store; } function filePath(dir: string, id: string): string { From 09577a29a24de3f8193ca79a8021819ef9f234b9 Mon Sep 17 00:00:00 2001 From: ranxianglei Date: Sat, 14 Nov 2026 10:52:33 +0800 Subject: [PATCH 06/11] fix: keep the raw body text available to the plugin full-resend watermark fastpath (#5403/#5418 regression) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The #4753 input-release (bodyText = undefined before streaming) made the fastpath gate in prepare-openai (bodyText !== undefined && ...) unreachable: the watermark fastpath silently never fired, and plugin wire sessions paid the full reparse+rehash on every turn. Release the text only on the slice where the fastpath cannot fire (non-openai wire or flag off); the strict gate (pluginMode + !titleGen) in prepare-openai stays authoritative. Also update the A/B pin: #5687 moved the dsh single-shot sidecar distinction from "tool-less" to the sidecar budget (hasSingleShotBudget, <=8192), so the test's 64K tool-less turn-0 is now (correctly) a main turn — model the real sidecar with a 4K budget to keep pinning "side lane never stamps". --- src/server/handle.ts | 8 +++++++- tests/issue5403-watermark-fastpath.test.ts | 15 ++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/server/handle.ts b/src/server/handle.ts index 2627eb8841..8263a88cb1 100644 --- a/src/server/handle.ts +++ b/src/server/handle.ts @@ -91,6 +91,7 @@ import { handleIncrementalTurn, handleIncrementalProbe, incrementalTurnBodyShape import { handlePluginRender, PLUGIN_RENDER_PATH } from "../plugin-render.js"; import { ccrPluginWireOk, storeEffectiveCcr, storeEffectiveImageRescale, type CcrSettings } from "../store.js"; import { DEFAULT_DECIDE_MAX_TOKENS } from "../nudge-decide.js"; +import { featureEnabled } from "../rollout.js"; import { BodyTooLargeError, buildForwardTarget, declPinConflictWarned, forward, forwardUpstreamUrl, googleModelFromPath, googlePathKind, headroomEffectiveLogged, headroomFallbackLogged, headerValue, imageBillingFor, imageReserveFor, imageTokenCapFor, isCountTokensRequest, isPreflightFailFast, NON_CONVERSATION_RELAY_WARN_CAP, nonConversationRelayWarned, prepareCountTokens, preflightCompressIfNeeded, readBody, resolveKnownOutputCeiling, resolveUpstream, resignSettingsFor, selfAddressedLocalPath, scrubAnthropicPck, scrubCompatDrop, vertexAnthropicModelFromPath, warnModelNameMissIfNew, warnRouteMissIfNew, type Prepared } from "../server.js"; import { logRequestCost } from "./request-cost.js"; import { normalizeVertexModelId } from "../vertex.js"; @@ -747,7 +748,12 @@ async function handleRequest( // index builds (each one re-converts the full history wire→core). The // predicate over-approximates by design; see bodyMightCarryImages. const bodyMayCarryImages = protocol !== null && bodyText !== undefined ? bodyMightCarryImages(bodyText, protocol) : false; - bodyText = undefined; + // #5403/#5418: the plugin full-resend watermark fastpath (prepare-openai) needs + // the raw body text. #4753 released it unconditionally, which silently disabled + // the fastpath (its bodyText !== undefined gate could never fire). Keep the text + // only on the wire+flag slice where the fastpath can fire; the strict gate in + // prepare-openai (pluginMode + !titleGen) remains authoritative. + if (!(protocol === "openai" && featureEnabled("pluginFullResendWatermark"))) bodyText = undefined; // #903: inbound message count for the per-request cost line — messages // (anthropic/openai) or input (responses); null when the body has neither. const inboundMsgs: number | null = (() => { diff --git a/tests/issue5403-watermark-fastpath.test.ts b/tests/issue5403-watermark-fastpath.test.ts index 9e454422f0..7f0bbfe26b 100644 --- a/tests/issue5403-watermark-fastpath.test.ts +++ b/tests/issue5403-watermark-fastpath.test.ts @@ -119,7 +119,11 @@ function scriptTurns(): Array<{ messages: unknown[]; max_tokens: number; stream: { type: "image_url", image_url: { url: `data:image/png;base64,${PNG_1X1}` } }, ]; } - turns.push({ messages: history, max_tokens: 64_000, stream: false }); + // #5687 narrowed the single-shot sidecar gate to small budgets + // (hasSingleShotBudget, <=8192): a tool-less 64K turn is now correctly + // a MAIN turn. Turn 0 models the real dsh sidecar (4K budget) so it + // still rides the side lane and pins the "side lane never stamps" edge. + turns.push({ messages: history, max_tokens: t === 0 ? 4_096 : 64_000, stream: false }); } return turns; } @@ -206,10 +210,11 @@ test("#5418 A/B byte-equality + residency band (hermetic dual-proxy)", async () const corpus = scriptTurns(); for (let i = 0; i < 8; i++) { if (i === 0) { - // #5656 residual: turn 0 is a tool-less single-shot shape, so it - // rides the verbatim side lane (kernel no-touch) in BOTH phases - // — the gate predates this feature and ignores the rollout env — - // and the side lane neither scans nor stamps. + // #5656 residual: turn 0 is a tool-less small-budget sidecar + // shape, so it rides the verbatim side lane (kernel no-touch) + // in BOTH phases — the gate ignores the rollout env — + // and the side lane neither scans nor stamps. (#5687 moved the + // shape distinction from "tool-less" to the sidecar budget.) assert.equal(rb[i], null, `B stamp ${i}: side lane must not stamp`); continue; } From b604ff1bc462d4f91664441c60d14943d5afd5d4 Mon Sep 17 00:00:00 2001 From: ranxianglei Date: Sat, 14 Nov 2026 11:15:41 +0800 Subject: [PATCH 07/11] test: pin dual-write storage in plugin-fork CCR cold-restore tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The five 'HTTP CCR ... fails closed after cold disk restore' tests corrupt and re-read a .content-store.json envelope, which the pure-SQLite default writer (2026-11-13) never emits — ENOENT on sessions/ turned the e2e-dsh-plugin-lane red on this branch. Pin BILI_STORAGE_JSON_WRITER=1 (restore in finally) like the other e2e lanes (d252543a/74a925db); the tests still delete index.db before the cold restore, so the fail-closed 409 contract is unchanged. --- tests/plugin-fork.test.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/plugin-fork.test.ts b/tests/plugin-fork.test.ts index 2763aa2f4e..0d4c37a5cb 100644 --- a/tests/plugin-fork.test.ts +++ b/tests/plugin-fork.test.ts @@ -909,6 +909,15 @@ test("HTTP CCR shared payload deletion fails closed before persistence", { timeo for (const corruption of ["missing-ref", "missing-payload", "orphan-payload", "wrong-raw-alias", "changed-payload"] as const) { test(`HTTP CCR ${corruption} fails closed after cold disk restore`, async () => { + // Pure-SQLite is the default storage writer now (2026-11-13): these + // corruption tests corrupt and re-read a .content-store.json envelope, + // which never exists on disk under the default writer (ENOENT on + // sessions/ — red in the e2e-dsh-plugin-lane). Pin dual-write + // like the other e2e lanes (d252543a/74a925db); the test still removes + // index.db below, so the fail-closed 409 contract is unchanged, and + // pure-sqlite-only semantics stay covered by the storage unit tests. + const previousWriter = process.env.BILI_STORAGE_JSON_WRITER; + process.env.BILI_STORAGE_JSON_WRITER = "1"; const h = await harness(true); try { const parent = resolveConversation("parent").session!; @@ -966,7 +975,11 @@ for (const corruption of ["missing-ref", "missing-payload", "orphan-payload", "w assert.equal(parentState(), before); assert.equal(readFileSync(path, "utf8"), JSON.stringify(disk)); store2.closeQuietly(); - } finally { await h.close(); } + } finally { + if (previousWriter === undefined) delete process.env.BILI_STORAGE_JSON_WRITER; + else process.env.BILI_STORAGE_JSON_WRITER = previousWriter; + await h.close(); + } }); } From 0db33059e1c367729cf5cf771b549bf6a46dd2c8 Mon Sep 17 00:00:00 2001 From: ranxianglei Date: Sat, 14 Nov 2026 12:42:38 +0800 Subject: [PATCH 08/11] test: pin dual-write storage in fork-ccr-adoption companion test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 'child persists its own companion and survives a proxy restart (#1341)' counts the .content-store.json companion envelope on disk, which the pure-SQLite default writer (2026-11-13) never emits (0 !== 1 — red in the e2e-dsh-plugin-lane, run 43550710438). Pin BILI_STORAGE_JSON_WRITER=1 (restore in finally) like the other e2e lanes (74a925db/d252543a and the plugin-fork pin in b604ff1b). Full lane verified locally: 12 suites, 165 tests, 0 failures. --- tests/fork-ccr-adoption.test.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/fork-ccr-adoption.test.ts b/tests/fork-ccr-adoption.test.ts index 4cd9a7b586..5b5bedde45 100644 --- a/tests/fork-ccr-adoption.test.ts +++ b/tests/fork-ccr-adoption.test.ts @@ -290,6 +290,12 @@ test("refs cited by placeholder-shaped incoming messages are adopted too (#1341) }); test("child persists its own companion and survives a proxy restart (#1341)", async () => { + // Pure-SQLite is the default storage writer now (2026-11-13): this test + // counts the .content-store.json companion envelope on disk, which the + // default writer never emits (0 !== 1 in the e2e-dsh-plugin-lane). Pin + // dual-write like the other e2e lanes (74a925db/d252543a). + const previousWriter = process.env.BILI_STORAGE_JSON_WRITER; + process.env.BILI_STORAGE_JSON_WRITER = "1"; const dir = mkdtempSync(path.join(tmpdir(), "bili-fork-ccr-")); _setStoreForTest(new SessionStore({ dir, debounceMs: 0 })); try { @@ -323,6 +329,8 @@ test("child persists its own companion and survives a proxy restart (#1341)", as assert.match(ack, /acp-retrieved #m00003/); assert.ok(ack.includes(BIG_A.slice(0, 200)), "true original after reload (v2 tool result)"); } finally { + if (previousWriter === undefined) delete process.env.BILI_STORAGE_JSON_WRITER; + else process.env.BILI_STORAGE_JSON_WRITER = previousWriter; _setStoreForTest(new SessionStore({ enabled: false })); rmrf(dir); } From c1355dc1832ae3a7f2c3edbba56241f1abd11721 Mon Sep 17 00:00:00 2001 From: ranxianglei Date: Sat, 14 Nov 2026 13:50:21 +0800 Subject: [PATCH 09/11] fix: sessions index open survives a concurrent writer (#2195 CI gate) The e2e-fake-codex lane's #2195 test failed in CI (run 43557997361) with ERR_SQLITE_ERROR 'database is locked' from the very first statement of a fresh proxy: the machine-global $XDG_DATA_HOME/.../index.db is written by every bili instance on the box (#5082 supported topology), and a peer still holding the file (draining proxy, sibling job on the same runner) refused the startup outright: - the pre-migration quick_check ran before any busy_timeout existed on the connection -> raw SQLITE_BUSY instead of a bounded wait; - deeper: PRAGMA journal_mode needs exclusive access and BYPASSES the busy handler entirely - with the file in its legacy journal mode and a peer in a write transaction it throws at 0 ms even with busy_timeout=5000 installed (deterministic repro now in tests/storage-open-busy-lock.test.ts, which fails pre-fix). Fix, per the #5082 owner decision that a live foreign writer never blocks startup: install busy_timeout right after open; skip the journal switch when the file header already declares WAL (strict no-op, plain file read); defer it to the next open when the switch comes back BUSY. Pinned by tests/storage-open-busy-lock.test.ts (child-process lock holder; legacy-journal shape fails pre-fix, WAL shape guards the skip). --- src/storage/store.ts | 71 +++++++++++++- tests/storage-open-busy-lock.test.ts | 140 +++++++++++++++++++++++++++ 2 files changed, 210 insertions(+), 1 deletion(-) create mode 100644 tests/storage-open-busy-lock.test.ts diff --git a/src/storage/store.ts b/src/storage/store.ts index 5256cfb38a..7d9ba95dd0 100644 --- a/src/storage/store.ts +++ b/src/storage/store.ts @@ -452,6 +452,21 @@ export class StorageSecondWriterError extends Error { } } +/** + * #2195 release-gate fix (e2e-fake-codex failure, 2026-11-13_release-v0.1.214): + * true when the SQLite file header already declares WAL (header bytes 18-19 + * == 0x02). A plain file read — no database lock, so it is always safe, + * unlike asking the engine via `PRAGMA journal_mode`. + */ +function dbFileIsAlreadyWal(dbPath: string): boolean { + try { + const head = readFileSync(dbPath); + return head.length >= 100 && head[18] === 0x00 && head[19] === 0x02; + } catch { + return false; // file absent/unreadable → not WAL → let the pragma decide + } +} + export class UnifiedStore { readonly engine: SqliteEngineName; /** Where the engine came from (#2833): builtin / host / self-downloaded — logged at enable so field diagnosis can tell which acquisition path a lane ran on. */ @@ -496,6 +511,23 @@ export class UnifiedStore { ): UnifiedStore { mkdirSync(dirname(path), { recursive: true }); const { db, engine: used, source } = openSqliteDatabase(path, engine); + // The pre-migration quick_check below runs BEFORE the storagePragmas + // loop installs the connection's busy handler — on a bare handle the + // first statement throws raw SQLITE_BUSY the instant a concurrent + // writer holds the lock. That is a real, reachable shape, not a lab + // artifact: the launcher kills its proxy fire-and-forget on exit + // (stopProxy is a bare SIGTERM, no wait-for-exit), so the NEXT launch's + // opener routinely starts while the previous instance is still + // draining its graceful flush against the SAME shared sessions dir + // (one index.db per machine is the supported topology, #5082). The + // e2e #2195 gate hit exactly this: the fresh proxy parked on the + // startup-failure page ("database is locked") and the launcher burned + // its 60 s health budget on a child whose only problem was a missing + // busy handler. busy_timeout is a connection-level pragma that never + // touches the file, so it is safe to install before the corruption + // classification below; storagePragmas reapplies the same value + // idempotently for the remaining opens. + db.exec("PRAGMA busy_timeout = 5000"); // #4175/#4609: integrity self-check, verdict-cached and size-gated. // An unchanged file set (index.db + -wal stats + schema version) skips // the rescan; a small store checks synchronously BEFORE migrations (a @@ -604,7 +636,44 @@ export class UnifiedStore { } try { const limit = opts?.walJournalSizeLimitBytes ?? WAL_JOURNAL_SIZE_LIMIT; - for (const pragma of storagePragmas(limit)) db.exec(pragma); + for (const pragma of storagePragmas(limit)) { + if (pragma === "PRAGMA journal_mode = WAL") { + // The #2195 trap: `PRAGMA journal_mode` needs exclusive + // access and BYPASSES the connection's busy handler — it + // throws raw SQLITE_BUSY instantly while a peer holds a + // write transaction (repro: holder BEGIN IMMEDIATE + + // insert, fresh handle with busy_timeout=5000 installed → + // journal_mode throws at 0 ms, quick_check is fine). + // That peer is the normal one: stopProxy is fire-and- + // forget, so the previous proxy may still be draining its + // final flush on this same machine-global file when the + // next launch opens it (#5082). Two cases: + if (dbFileIsAlreadyWal(path)) { + // The store is ALREADY WAL (created WAL, never + // switched back) — skipping the pragma is a strict + // no-op and saves the exclusive acquisition entirely. + continue; + } + try { + db.exec(pragma); + } catch (err) { + const msg = String((err as { message?: unknown })?.message ?? err); + if (!msg.includes("SQLITE_BUSY") && !msg.includes("database is locked")) throw err; + // The file is still in its legacy journal mode and a + // peer holds the write transaction, so the switch + // cannot run right now. #5082 owner decision + // 2026-10-31: a live foreign writer never blocks + // startup — defer the switch to the next open (the + // previous open already moved the file to WAL in the + // normal case) and continue in the current journal + // mode, which is safe multi-process, just less + // concurrent. + loggerLog("warn", `[storage] journal_mode=WAL deferred for ${path} — a peer holds the write lock (#5082); continuing in the current journal mode, switch retries on the next open`); + continue; + } + } + db.exec(pragma); + } migrateSchema(db); } catch (err) { // The handle we just opened must not leak when the file turns out diff --git a/tests/storage-open-busy-lock.test.ts b/tests/storage-open-busy-lock.test.ts new file mode 100644 index 0000000000..0fbe1bcb7f --- /dev/null +++ b/tests/storage-open-busy-lock.test.ts @@ -0,0 +1,140 @@ +/** + * Release-gate pin (e2e #2195 failure on 2026-11-13_release-v0.1.214, run + * 43557997361): UnifiedStore.open must survive a CONCURRENT WRITER on the + * same index.db. The machine-global sessions dir is deliberately shared + * (one index.db per machine is the supported topology, #5082), and the + * launcher kills its proxy fire-and-forget on exit (stopProxy is a bare + * SIGTERM with no wait-for-exit), so a next launch's opener routinely + * starts while a peer is still holding the file: + * - this file's own sibling e2e lanes (bare `runs-on: ubuntu-latest` — + * no container — and GitHub's shared-pool runners run several jobs of + * several repos side by side under the same user); + * - a previous bili instance still draining its final flush. + * + * The pre-fix trap this suite pins (deterministic repro): `PRAGMA + * journal_mode` needs exclusive access and BYPASSES the connection's busy + * handler entirely — with the file still in its legacy journal mode and a + * peer holding a write transaction, it throws raw SQLITE_BUSY at 0 ms even + * with `busy_timeout = 5000` installed on the handle (quick_check and the + * other pragmas wait fine). The shadow layer then refused to start (no- + * degrade owner policy) and the launcher parked on the startup-failure + * page for its full 60 s health budget. + * + * The fix has two halves, each covered below: + * 1. `PRAGMA busy_timeout = 5000` is installed immediately after the + * handle opens, BEFORE the pre-migration quick_check — a transient + * lock now queues up to 5 s instead of throwing raw SQLITE_BUSY; + * 2. the journal_mode pragma never hard-fails a startup: it is skipped + * when the file header already declares WAL (a strict no-op — the + * store is created WAL and never switched back) and, for a legacy-mode + * file, a BUSY from the switch is DEFERRED to the next open (#5082 + * owner decision 2026-10-31: a live foreign writer never blocks + * startup) instead of refusing the boot. + * + * The lock holder is a CHILD PROCESS in both tests (not a second in- + * process connection): it matches the real topology (a separate node + * process still holding the file), and a same-process setTimeout could + * never run to release the lock while the opener blocks. + */ + +import { test } from "node:test"; +import assert from "node:assert/strict"; +import * as fs from "node:fs"; +import * as os from "node:os"; +import * as path from "node:path"; +import { spawn } from "node:child_process"; +import type { ChildProcess } from "node:child_process"; +import { UnifiedStore } from "../src/storage/store.ts"; + +// Hermeticity pins, same shape as the other storage suites: no developer +// config may leak a storage tier into these tests. +process.env.BILI_PERSIST_ZSTD = "0"; +const hermetic = fs.mkdtempSync(path.join(os.tmpdir(), "bili-open-busy-lock-")); +process.env.BILI_CONFIG_FILE = path.join(hermetic, "no-config.json"); +process.env.BILI_STORAGE_UNIFIED = "full"; + +/** Start the write-lock holder. `wal` selects the file's journal mode: + * true = production shape (created WAL, never switched back); false = + * legacy journal mode, the shape where the journal_mode pragma actually + * has to acquire exclusive access. The holder parks in a write + * transaction (BEGIN IMMEDIATE + insert — like a draining proxy's final + * flush) for `holdMs` after writing `readyPath`, then commits and exits. + * holdMs must stay well under the open path's 5 s busy_timeout so that, + * with the fix in place, every statement that needs the lock simply + * queues and completes. */ +function startHolder(dbPath: string, readyPath: string, wal: boolean, holdMs: number): ChildProcess { + const source = ` +import { DatabaseSync } from "node:sqlite"; +import { writeFileSync } from "node:fs"; +const db = new DatabaseSync(${JSON.stringify(dbPath)}); +${wal ? 'db.exec("PRAGMA journal_mode = WAL");' : ""} +db.exec("CREATE TABLE IF NOT EXISTS probe_lock (x INTEGER)"); +db.exec("INSERT INTO probe_lock VALUES (1)"); +db.exec("BEGIN IMMEDIATE"); +db.exec("INSERT INTO probe_lock VALUES (2)"); +writeFileSync(${JSON.stringify(readyPath)}, "locked"); +setTimeout(() => { db.exec("COMMIT"); db.close(); }, ${holdMs}); +`; + const child = spawn(process.execPath, ["--input-type=module", "-e", source], { stdio: "inherit" }); + return child; +} + +async function waitReady(readyPath: string): Promise { + const deadline = Date.now() + 15_000; + while (!fs.existsSync(readyPath)) { + if (Date.now() > deadline) throw new Error("holder never parked its write lock"); + await new Promise((r) => setTimeout(r, 20)); + } +} + +// Give the holder a head start so its transaction is definitely parked +// before the opener's first statement — keeps the pre-fix failure +// deterministic (0 ms throw) instead of timing-race dependent. +const HEAD_START_MS = 700; + +test("#2195: open defers (never refuses) when a peer holds the write lock on a legacy-journal file", { timeout: 60_000 }, async (t) => { + const dbPath = path.join(hermetic, "legacy", "index.db"); + const readyPath = path.join(hermetic, "legacy-ready"); + fs.mkdirSync(path.dirname(dbPath), { recursive: true }); + + const holder = startHolder(dbPath, readyPath, false, 2500); + t.after(() => { try { holder.kill("SIGKILL"); } catch { /* gone */ } }); + await waitReady(readyPath); + await new Promise((r) => setTimeout(r, HEAD_START_MS)); + + // Pre-fix this threw 'database is locked' at 0 ms from the + // journal_mode pragma (it bypasses the busy handler) and the shadow + // layer refused to start. Post-fix the switch is deferred to the next + // open and the remaining statements queue on busy_timeout until the + // holder commits at 2500 ms. + let store: UnifiedStore | undefined; + try { + const t0 = Date.now(); + store = UnifiedStore.open(dbPath); + const elapsed = Date.now() - t0; + assert.ok(elapsed >= 0, `open completed in ${elapsed} ms`); + } finally { + store?.close(); + // Never leak a holder past its commit window into the next test. + try { holder.kill("SIGKILL"); } catch { /* already committed + exited */ } + } +}); + +test("#2195: open is a no-op on the journal switch for a production (already-WAL) file under a live peer", { timeout: 60_000 }, async (t) => { + const dbPath = path.join(hermetic, "wal", "index.db"); + const readyPath = path.join(hermetic, "wal-ready"); + fs.mkdirSync(path.dirname(dbPath), { recursive: true }); + + const holder = startHolder(dbPath, readyPath, true, 2500); + t.after(() => { try { holder.kill("SIGKILL"); } catch { /* gone */ } }); + await waitReady(readyPath); + await new Promise((r) => setTimeout(r, HEAD_START_MS)); + + let store: UnifiedStore | undefined; + try { + store = UnifiedStore.open(dbPath); + } finally { + store?.close(); + try { holder.kill("SIGKILL"); } catch { /* already committed + exited */ } + } +}); From 50f8e282e474d8f80211b3953c4e37b3f50aa5a6 Mon Sep 17 00:00:00 2001 From: ranxianglei Date: Sat, 14 Nov 2026 13:50:21 +0800 Subject: [PATCH 10/11] test: isolate XDG_DATA_HOME in the three codex e2e lanes These lanes pinned XDG_CONFIG/CACHE/STATE per test but inherited XDG_DATA_HOME, so their spawned proxies wrote their session index to the machine-global sessions dir. The CI jobs are bare runs-on: ubuntu-latest (no container) and GitHub's shared-pool runners run several jobs of several repos side by side under the same user - every concurrently running bili proxy on that runner shares one index.db. #2195's t3 launcher burned its 60 s health budget on exactly this. Every other e2e lane already pins a per-test data dir (e2e-native-pi/dsh/opencode/pi- codex-ws); pin the same shape in e2e-codex-fake/-persona/e2e-codex. --- tests/e2e/e2e-codex-fake.test.ts | 48 +++++++++++++++++++++++------ tests/e2e/e2e-codex-persona.test.ts | 14 +++++---- tests/e2e/e2e-codex.test.ts | 6 ++-- 3 files changed, 51 insertions(+), 17 deletions(-) diff --git a/tests/e2e/e2e-codex-fake.test.ts b/tests/e2e/e2e-codex-fake.test.ts index c9ddd523b4..3d1a7c463f 100644 --- a/tests/e2e/e2e-codex-fake.test.ts +++ b/tests/e2e/e2e-codex-fake.test.ts @@ -118,7 +118,7 @@ type Ctx = { work: string; codexCwd: string; codexHome: string; - xdg: { config: string; cache: string; state: string }; + xdg: { config: string; cache: string; state: string; data: string }; port: number; fakePort: number; reqLog: string; @@ -135,7 +135,7 @@ async function startCtx(contextWindow: number, fakeEnv: Record = work, codexCwd: fs.mkdtempSync(path.join(CWD_ROOT, "cwd-")), codexHome: path.join(work, "codex-home"), - xdg: { config: path.join(work, "xdg-config"), cache: path.join(work, "xdg-cache"), state: path.join(work, "xdg-state") }, + xdg: { config: path.join(work, "xdg-config"), cache: path.join(work, "xdg-cache"), state: path.join(work, "xdg-state"), data: path.join(work, "xdg-data") }, port: await freePort(), fakePort: await freePort(), reqLog: path.join(work, "fake-requests.jsonl"), @@ -143,7 +143,7 @@ async function startCtx(contextWindow: number, fakeEnv: Record = resumed: false, turnCount: 0, }; - for (const d of [ctx.codexHome, ctx.xdg.config, ctx.xdg.cache, ctx.xdg.state]) fs.mkdirSync(d, { recursive: true }); + for (const d of [ctx.codexHome, ctx.xdg.config, ctx.xdg.cache, ctx.xdg.state, ctx.xdg.data]) fs.mkdirSync(d, { recursive: true }); await assertPortDead(ctx.fakePort); // #1689: prove still free right before the child binds it const fake = spawn(process.execPath, [FAKE_UPSTREAM], { @@ -177,6 +177,7 @@ async function startCtx(contextWindow: number, fakeEnv: Record = XDG_CONFIG_HOME: ctx.xdg.config, XDG_CACHE_HOME: ctx.xdg.cache, XDG_STATE_HOME: ctx.xdg.state, + XDG_DATA_HOME: ctx.xdg.data, BILLION_CONTEXT_NO_AUTO_UPDATE: "1", ...windowEnv(contextWindow), }, @@ -375,8 +376,9 @@ test("#1802: a hostile user .env cannot reroute a bili-launched codex", { skip: config: path.join(work, "xdg-config"), cache: path.join(work, "xdg-cache"), state: path.join(work, "xdg-state"), + data: path.join(work, "xdg-data"), }; - for (const d of [codexHome, xdg.config, xdg.cache, xdg.state]) fs.mkdirSync(d, { recursive: true }); + for (const d of [codexHome, xdg.config, xdg.cache, xdg.state, xdg.data]) fs.mkdirSync(d, { recursive: true }); const fakePort = await freePort(); const reqLog = path.join(work, "fake-requests.jsonl"); t.after(() => { for (const pid of [fake?.pid]) if (pid) { try { process.kill(pid, "SIGKILL"); } catch { /* gone */ } } }); @@ -433,6 +435,7 @@ test("#1802: a hostile user .env cannot reroute a bili-launched codex", { skip: XDG_CONFIG_HOME: xdg.config, XDG_CACHE_HOME: xdg.cache, XDG_STATE_HOME: xdg.state, + XDG_DATA_HOME: xdg.data, BILLION_CONTEXT_NO_AUTO_UPDATE: "1", BILI_CLIENT_BIN: CODEX_BIN, E2E_UPSTREAM_KEY: "fake", @@ -488,8 +491,9 @@ test("#1965: a clean bili exit writes the run's state back into the real home; n config: path.join(work, "xdg-config"), cache: path.join(work, "xdg-cache"), state: path.join(work, "xdg-state"), + data: path.join(work, "xdg-data"), }; - for (const d of [codexHome, xdg.config, xdg.cache, xdg.state]) fs.mkdirSync(d, { recursive: true }); + for (const d of [codexHome, xdg.config, xdg.cache, xdg.state, xdg.data]) fs.mkdirSync(d, { recursive: true }); const fakePort = await freePort(); const reqLog = path.join(work, "fake-requests.jsonl"); let fake: ReturnType | undefined; @@ -535,6 +539,7 @@ test("#1965: a clean bili exit writes the run's state back into the real home; n XDG_CONFIG_HOME: xdg.config, XDG_CACHE_HOME: xdg.cache, XDG_STATE_HOME: xdg.state, + XDG_DATA_HOME: xdg.data, BILLION_CONTEXT_NO_AUTO_UPDATE: "1", BILI_CLIENT_BIN: CODEX_BIN, E2E_UPSTREAM_KEY: "fake", @@ -582,6 +587,7 @@ test("#1965: a clean bili exit writes the run's state back into the real home; n XDG_CONFIG_HOME: xdg.config, XDG_CACHE_HOME: xdg.cache, XDG_STATE_HOME: xdg.state, + XDG_DATA_HOME: xdg.data, E2E_UPSTREAM_KEY: "fake", RUST_LOG: "error", }, @@ -616,12 +622,26 @@ test("#2195: two sequential bili launches keep every thread in the real home", { const work = fs.mkdtempSync(path.join(WORK_ROOT, "e2e-codex-2195-")); const codexCwd = fs.mkdtempSync(path.join(CWD_ROOT, "cwd-")); const codexHome = path.join(work, "codex-home"); + // XDG_DATA_HOME is pinned like the other three XDG vars: without it the + // spawned proxies write their session index to the MACHINE-GLOBAL + // $XDG_DATA_HOME/billion-context/sessions/index.db (#5082's one-db-per- + // machine topology). This lane's CI job is a bare `runs-on: ubuntu-latest` + // — no container — and GitHub's shared-pool runners run several jobs of + // several repos side by side under the same user, so every concurrently + // billed proxy on that runner shares this one index.db. #2195 hit exactly + // this: t3's fresh proxy threw "database is locked" from the pre-pragma + // quick_check (no busy handler yet) because a sibling job's proxy held the + // write lock, and the launcher burned its 60 s health budget (run + // 43557997361, e2e-fake-codex @ 0db33059). Every other e2e lane already + // pins a per-test data dir (e2e-native-pi / dsh / opencode / pi-codex-ws); + // this file was the exception. const xdg = { config: path.join(work, "xdg-config"), cache: path.join(work, "xdg-cache"), state: path.join(work, "xdg-state"), + data: path.join(work, "xdg-data"), }; - for (const d of [codexHome, xdg.config, xdg.cache, xdg.state]) fs.mkdirSync(d, { recursive: true }); + for (const d of [codexHome, xdg.config, xdg.cache, xdg.state, xdg.data]) fs.mkdirSync(d, { recursive: true }); const fakePort = await freePort(); let fake: ReturnType | undefined; t.after(() => { if (fake?.pid) { try { process.kill(fake.pid, "SIGKILL"); } catch { /* gone */ } } }); @@ -667,6 +687,7 @@ test("#2195: two sequential bili launches keep every thread in the real home", { XDG_CONFIG_HOME: xdg.config, XDG_CACHE_HOME: xdg.cache, XDG_STATE_HOME: xdg.state, + XDG_DATA_HOME: xdg.data, BILLION_CONTEXT_NO_AUTO_UPDATE: "1", BILI_CLIENT_BIN: CODEX_BIN, E2E_UPSTREAM_KEY: "fake", @@ -754,6 +775,7 @@ test("#2195: two sequential bili launches keep every thread in the real home", { XDG_CONFIG_HOME: xdg.config, XDG_CACHE_HOME: xdg.cache, XDG_STATE_HOME: xdg.state, + XDG_DATA_HOME: xdg.data, E2E_UPSTREAM_KEY: "fake", RUST_LOG: "error", }, @@ -787,8 +809,9 @@ async function runProfileCase( config: path.join(work, "xdg-config"), cache: path.join(work, "xdg-cache"), state: path.join(work, "xdg-state"), + data: path.join(work, "xdg-data"), }; - for (const d of [codexHome, xdg.config, xdg.cache, xdg.state]) fs.mkdirSync(d, { recursive: true }); + for (const d of [codexHome, xdg.config, xdg.cache, xdg.state, xdg.data]) fs.mkdirSync(d, { recursive: true }); fs.writeFileSync(path.join(codexHome, "config.toml"), opts.configToml); for (const [name, text] of Object.entries(opts.profileFiles ?? {})) fs.writeFileSync(path.join(codexHome, `${name}.config.toml`), text); const reqLogs = opts.fakePorts.map((_, i) => path.join(work, `fake-requests-${i}.jsonl`)); @@ -818,6 +841,7 @@ async function runProfileCase( XDG_CONFIG_HOME: xdg.config, XDG_CACHE_HOME: xdg.cache, XDG_STATE_HOME: xdg.state, + XDG_DATA_HOME: xdg.data, BILLION_CONTEXT_NO_AUTO_UPDATE: "1", BILI_CLIENT_BIN: CODEX_BIN, E2E_UPSTREAM_KEY: "fake", @@ -956,8 +980,9 @@ test("#2222: shared state — the live db stays in the real home across bili and config: path.join(work, "xdg-config"), cache: path.join(work, "xdg-cache"), state: path.join(work, "xdg-state"), + data: path.join(work, "xdg-data"), }; - for (const d of [codexHome, xdg.config, xdg.cache, xdg.state]) fs.mkdirSync(d, { recursive: true }); + for (const d of [codexHome, xdg.config, xdg.cache, xdg.state, xdg.data]) fs.mkdirSync(d, { recursive: true }); const fakePort = await freePort(); let fake: ReturnType | undefined; t.after(() => { if (fake?.pid) { try { process.kill(fake.pid, "SIGKILL"); } catch { /* gone */ } } }); @@ -1005,6 +1030,7 @@ test("#2222: shared state — the live db stays in the real home across bili and XDG_CONFIG_HOME: xdg.config, XDG_CACHE_HOME: xdg.cache, XDG_STATE_HOME: xdg.state, + XDG_DATA_HOME: xdg.data, BILLION_CONTEXT_NO_AUTO_UPDATE: "1", BILI_CLIENT_BIN: CODEX_BIN, E2E_UPSTREAM_KEY: "fake", @@ -1084,6 +1110,7 @@ test("#2222: shared state — the live db stays in the real home across bili and XDG_CONFIG_HOME: xdg.config, XDG_CACHE_HOME: xdg.cache, XDG_STATE_HOME: xdg.state, + XDG_DATA_HOME: xdg.data, E2E_UPSTREAM_KEY: "fake", RUST_LOG: "error", }, @@ -1112,8 +1139,9 @@ test("#3203: two concurrent bili codex sessions on ONE CODEX_HOME both run and k config: path.join(work, "xdg-config"), cache: path.join(work, "xdg-cache"), state: path.join(work, "xdg-state"), + data: path.join(work, "xdg-data"), }; - for (const d of [codexHome, xdg.config, xdg.cache, xdg.state]) fs.mkdirSync(d, { recursive: true }); + for (const d of [codexHome, xdg.config, xdg.cache, xdg.state, xdg.data]) fs.mkdirSync(d, { recursive: true }); const fakePort = await freePort(); let fake: ReturnType | undefined; t.after(() => { if (fake?.pid) { try { process.kill(fake.pid, "SIGKILL"); } catch { /* gone */ } } }); @@ -1160,6 +1188,7 @@ test("#3203: two concurrent bili codex sessions on ONE CODEX_HOME both run and k XDG_CONFIG_HOME: xdg.config, XDG_CACHE_HOME: xdg.cache, XDG_STATE_HOME: xdg.state, + XDG_DATA_HOME: xdg.data, BILLION_CONTEXT_NO_AUTO_UPDATE: "1", BILI_CLIENT_BIN: CODEX_BIN, E2E_UPSTREAM_KEY: "fake", @@ -1278,6 +1307,7 @@ test("#3203: two concurrent bili codex sessions on ONE CODEX_HOME both run and k XDG_CONFIG_HOME: xdg.config, XDG_CACHE_HOME: xdg.cache, XDG_STATE_HOME: xdg.state, + XDG_DATA_HOME: xdg.data, E2E_UPSTREAM_KEY: "fake", RUST_LOG: "error", }, diff --git a/tests/e2e/e2e-codex-persona.test.ts b/tests/e2e/e2e-codex-persona.test.ts index 536443fdd3..f569fb67bb 100644 --- a/tests/e2e/e2e-codex-persona.test.ts +++ b/tests/e2e/e2e-codex-persona.test.ts @@ -218,7 +218,7 @@ type UrlCtx = { work: string; codexCwd: string; codexHome: string; - xdg: { config: string; cache: string; state: string }; + xdg: { config: string; cache: string; state: string; data: string }; port: number; fakePort: number; reqLog: string; @@ -234,14 +234,14 @@ async function startUrlCtx(contextWindow: number): Promise { work, codexCwd: fs.mkdtempSync(path.join(CWD_ROOT, "url-cwd-")), codexHome: path.join(work, "codex-home"), - xdg: { config: path.join(work, "xdg-config"), cache: path.join(work, "xdg-cache"), state: path.join(work, "xdg-state") }, + xdg: { config: path.join(work, "xdg-config"), cache: path.join(work, "xdg-cache"), state: path.join(work, "xdg-state"), data: path.join(work, "xdg-data") }, port: await freePort(), fakePort: await freePort(), reqLog: path.join(work, "fake-requests.jsonl"), resumed: false, turnCount: 0, }; - for (const d of [ctx.codexHome, ctx.xdg.config, ctx.xdg.cache, ctx.xdg.state]) fs.mkdirSync(d, { recursive: true }); + for (const d of [ctx.codexHome, ctx.xdg.config, ctx.xdg.cache, ctx.xdg.state, ctx.xdg.data]) fs.mkdirSync(d, { recursive: true }); await assertPortDead(ctx.fakePort); const fake = spawn(process.execPath, [FAKE_UPSTREAM], { @@ -272,6 +272,7 @@ async function startUrlCtx(contextWindow: number): Promise { XDG_CONFIG_HOME: ctx.xdg.config, XDG_CACHE_HOME: ctx.xdg.cache, XDG_STATE_HOME: ctx.xdg.state, + XDG_DATA_HOME: ctx.xdg.data, BILLION_CONTEXT_NO_AUTO_UPDATE: "1", ...windowEnv(contextWindow), }, @@ -375,7 +376,7 @@ type LaunchCtx = { work: string; codexCwd: string; codexHome: string; - xdg: { config: string; cache: string; state: string }; + xdg: { config: string; cache: string; state: string; data: string }; fakePort: number; reqLog: string; fakePid?: number; @@ -389,13 +390,13 @@ async function startLaunchCtx(contextWindow: number): Promise { work, codexCwd: fs.mkdtempSync(path.join(CWD_ROOT, "launch-cwd-")), codexHome: path.join(work, "codex-home"), - xdg: { config: path.join(work, "xdg-config"), cache: path.join(work, "xdg-cache"), state: path.join(work, "xdg-state") }, + xdg: { config: path.join(work, "xdg-config"), cache: path.join(work, "xdg-cache"), state: path.join(work, "xdg-state"), data: path.join(work, "xdg-data") }, fakePort: await freePort(), reqLog: path.join(work, "fake-requests.jsonl"), resumed: false, turnCount: 0, }; - for (const d of [ctx.codexHome, ctx.xdg.config, ctx.xdg.cache, ctx.xdg.state]) fs.mkdirSync(d, { recursive: true }); + for (const d of [ctx.codexHome, ctx.xdg.config, ctx.xdg.cache, ctx.xdg.state, ctx.xdg.data]) fs.mkdirSync(d, { recursive: true }); await assertPortDead(ctx.fakePort); const fake = spawn(process.execPath, [FAKE_UPSTREAM], { @@ -450,6 +451,7 @@ async function launchTurn(ctx: LaunchCtx, prompt: string, extraArgs: string[] = XDG_CONFIG_HOME: ctx.xdg.config, XDG_CACHE_HOME: ctx.xdg.cache, XDG_STATE_HOME: ctx.xdg.state, + XDG_DATA_HOME: ctx.xdg.data, BILLION_CONTEXT_NO_AUTO_UPDATE: "1", BILI_CLIENT_BIN: CODEX_BIN, E2E_UPSTREAM_KEY: "fake", diff --git a/tests/e2e/e2e-codex.test.ts b/tests/e2e/e2e-codex.test.ts index 94def48451..3903221265 100644 --- a/tests/e2e/e2e-codex.test.ts +++ b/tests/e2e/e2e-codex.test.ts @@ -39,7 +39,7 @@ const SENTINELS = [4781, 2903, 6577, 1249, 8461, 30217]; type Ctx = { proxy?: { pid: number; logPath: string }; codexHome: string; - xdg: { config: string; cache: string; state: string }; + xdg: { config: string; cache: string; state: string; data: string }; port: number; resumed: boolean; turnCount: number; @@ -87,6 +87,7 @@ async function startProxy(ctx: Ctx, env: Record = {}): Promise { config: path.join(WORK, "xdg", "config"), cache: path.join(WORK, "xdg", "cache"), state: path.join(WORK, "xdg", "state"), + data: path.join(WORK, "xdg", "data"), }, port: await freePort(), resumed: false, turnCount: 0, }; - for (const d of [ctx.codexHome, ctx.xdg.config, ctx.xdg.cache, ctx.xdg.state]) fs.mkdirSync(d, { recursive: true }); + for (const d of [ctx.codexHome, ctx.xdg.config, ctx.xdg.cache, ctx.xdg.state, ctx.xdg.data]) fs.mkdirSync(d, { recursive: true }); return ctx; } From acc794423be2ece34253bec2fddcae4c3c269080 Mon Sep 17 00:00:00 2001 From: ranxianglei Date: Sat, 14 Nov 2026 14:52:32 +0800 Subject: [PATCH 11/11] ci: register storage-open-busy-lock suite in LIVE_FILES (#1248 tripwire) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit c1355dc18 added tests/storage-open-busy-lock.test.ts, which spawns lock-holder child processes, but never registered it in the shared LIVE_FILES table — the run-ci-tests.mjs tripwire (#1248/#3182) dies before any test runs, so every unit shard on every OS fails at the guard step. One-line registration; suite itself passes locally (2/2, hermetic mkdtemp, no port binds). --- scripts/live-files.mjs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/live-files.mjs b/scripts/live-files.mjs index 63adb1c646..b606dc43bd 100644 --- a/scripts/live-files.mjs +++ b/scripts/live-files.mjs @@ -57,6 +57,9 @@ export const LIVE_FILES = [ // both spawn the corrupt-index-child helper (unified-store cold-load // corruption probes, #4216/#4249 follow-ups); append-only per the note above "tests/storage-engine-proofs.test.ts", + // lock-holder CHILD process parks on a hermetic mkdtemp index.db (#2195 + // release-gate pin); binds no ports — zone slot is a formality + "tests/storage-open-busy-lock.test.ts", "tests/web-storage-banner.test.ts", // #4434 (split-brain surface): spawns bili CLI children against a throwaway // origin; own probe server is listen(0) so only the zone band matters