From a731d247dce8d2a84dea844ff330287069d3c87a Mon Sep 17 00:00:00 2001 From: Afloat Date: Thu, 12 Nov 2026 18:36:13 +0800 Subject: [PATCH 01/14] fix: retain reconciliation brackets for very long histories --- src/fold-reconcile.ts | 11 ++-- tests/fold-reconcile-large-history.test.ts | 58 ++++++++++++++++++++++ 2 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 tests/fold-reconcile-large-history.test.ts diff --git a/src/fold-reconcile.ts b/src/fold-reconcile.ts index 2475a0c657..6b047726a8 100644 --- a/src/fold-reconcile.ts +++ b/src/fold-reconcile.ts @@ -1004,7 +1004,8 @@ export function planReconciliation( // claimed. A gap cell is bracketed when verified claims exist on both // sides — order ownership that the tiers below may corroborate. const gapPairs: { oldIdx: number; oldId: string; newId: string }[] = []; - const claimedIdx: number[] = []; + let minClaimed = Infinity; + let maxClaimed = -Infinity; const recordGap = (oldIdx: number, oldId: string, newId: string): void => { if (oldId !== newId && missingSet.has(oldId) && !covered.has(newId) && !claimedCandidates.has(newId)) { gapPairs.push({ oldIdx, oldId, newId }); @@ -1034,7 +1035,8 @@ export function planReconciliation( plan.claims.set(oldId, [newId]); claimedCandidates.add(newId); plan.byPos++; - claimedIdx.push(i); + minClaimed = Math.min(minClaimed, i); + maxClaimed = Math.max(maxClaimed, i); i++; } const tail = Math.min(oldOrder.length, newOrder.length) - prefix; @@ -1064,7 +1066,8 @@ export function planReconciliation( plan.claims.set(oldId, [newId]); claimedCandidates.add(newId); plan.byPos++; - claimedIdx.push(iOld); + minClaimed = Math.min(minClaimed, iOld); + maxClaimed = Math.max(maxClaimed, iOld); j++; } } @@ -1387,8 +1390,6 @@ export function planReconciliation( // when something verified it. if (gapPairs.length > 0) { const fenced = plan.byPos > 0 || plan.resyncs > 0; - const minClaimed = claimedIdx.length > 0 ? Math.min(...claimedIdx) : -1; - const maxClaimed = claimedIdx.length > 0 ? Math.max(...claimedIdx) : -1; for (const gap of gapPairs) { if (plan.claims.has(gap.oldId) || claimedCandidates.has(gap.newId)) continue; const anchor = anchors[gap.oldId]; diff --git a/tests/fold-reconcile-large-history.test.ts b/tests/fold-reconcile-large-history.test.ts new file mode 100644 index 0000000000..26c9c51392 --- /dev/null +++ b/tests/fold-reconcile-large-history.test.ts @@ -0,0 +1,58 @@ +import assert from "node:assert/strict"; +import { test } from "node:test"; +import type { CoreMessage } from "acp-kernel"; +import { planReconciliation, positionalFingerprint, type FoldAnchor } from "../src/fold-reconcile.ts"; + +function remintedHistory(count: number, gaps: number[]) { + const order = Array.from({ length: count }, (_, i) => `old_${i}`); + const messages: CoreMessage[] = order.map((_, i) => ({ id: `new_${i}`, role: "assistant", contentType: "text", text: `unchanged response ${i}` })); + const positions = { ids: order, canon: messages.map(positionalFingerprint) }; + const anchors: Record = {}; + for (const gap of gaps) { + anchors[order[gap]] = { r: "assistant", c: "text", b: messages[gap].text!.length }; + messages[gap] = { ...messages[gap], text: `reformatted response ${gap}` }; + } + return { order, messages, positions, anchors, covered: new Set(order) }; +} + +test("reconciles a gap bracketed by 150,000 verified positional claims", () => { + const gap = 75_000; + const h = remintedHistory(150_001, [gap]); + const plan = planReconciliation(h.order, h.anchors, h.messages, h.covered, h.positions); + assert.equal(plan.byPos, 150_000); + assert.equal(plan.byOrder, 1); + assert.equal(plan.claims.size, h.order.length); + assert.deepEqual(plan.claims.get(h.order[gap]), [`new_${gap}`]); + assert.deepEqual(plan.claims.get(h.order[0]), ["new_0"]); + assert.deepEqual(plan.claims.get(h.order.at(-1)!), ["new_150000"]); + assert.deepEqual(plan.unmatched, []); +}); + +test("keeps leading and trailing gaps outside the verified bracket", () => { + const h = remintedHistory(20, [0, 10, 19]); + const plan = planReconciliation(h.order, h.anchors, h.messages, h.covered, h.positions); + assert.equal(plan.byPos, 17); + assert.equal(plan.byOrder, 1); + assert.deepEqual(plan.claims.get("old_10"), ["new_10"]); + assert.deepEqual(plan.unmatched, ["old_0", "old_19"]); +}); + +test("does not infer a bracket without any verified positional claims", () => { + const h = remintedHistory(5, [0, 1, 2, 3, 4]); + const plan = planReconciliation(h.order, h.anchors, h.messages, h.covered, h.positions); + assert.equal(plan.byPos, 0); + assert.equal(plan.byOrder, 0); + assert.equal(plan.claims.size, 0); + assert.deepEqual(plan.unmatched, h.order); +}); + +test("keeps the zero-drift fast path for a large unchanged history", () => { + const h = remintedHistory(150_001, []); + for (let i = 0; i < h.messages.length; i++) h.messages[i].id = h.order[i]; + const plan = planReconciliation(h.order, h.anchors, h.messages, h.covered, h.positions); + assert.equal(plan.claims.size, 0); + assert.equal(plan.byPos, 0); + assert.equal(plan.byOrder, 0); + assert.deepEqual(plan.unmatched, []); + assert.deepEqual(plan.newOrder, h.order); +}); From b8545db19c86260036cd4e486fdf29f8ade6be13 Mon Sep 17 00:00:00 2001 From: ci-check Date: Fri, 13 Nov 2026 16:12:28 +0800 Subject: [PATCH 02/14] fix(incremental): keep canonical-pointer upkeep linear past the argument limit (#6490) Same mechanism as the reconciliation fix in this PR: Math.max(...ptrs) spreads the session's full canonical-pointer list (one entry per settled canonical message) into a single call, which trips V8's argument-spread limit (~125K-130K args on Node 22/24 x64) -> RangeError. The error is caught and only logged as a warn, so the failure is silent: the pointer list stops advancing and every later turn re-parses rows from the stale max pointer instead of the fresh tail. Replace the spread with a two-argument reduce (initial 0 - pointers are verified non-negative by readCanonicalPointers) and export the function for the regression test, which pins 150,000 pointers: pre-fix it fails with the RangeError warn, post-fix it passes and the upkeep reads rows after the highest pointer. --- src/incremental-lane.ts | 9 ++- tests/issue6490-spread-argument-limit.test.ts | 58 +++++++++++++++++++ 2 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 tests/issue6490-spread-argument-limit.test.ts diff --git a/src/incremental-lane.ts b/src/incremental-lane.ts index a233e6f5b9..7756c44e23 100644 --- a/src/incremental-lane.ts +++ b/src/incremental-lane.ts @@ -421,8 +421,8 @@ function stableMessageKey(m: Record): string { * handful of fresh rows instead of walking the whole table every turn. * Any miss → leave the previous pointers untouched (never a partial list); * with the debounced save this is the common case right after a turn — a - * later settled turn records them. */ -function recordCanonicalPointers(sessionId: string, msgs: BiliMessage[], log: (l: string, m: string) => void): void { + * later settled turn records them. Exposed for unit tests (#6490). */ +export function recordCanonicalPointers(sessionId: string, msgs: BiliMessage[], log: (l: string, m: string) => void): void { try { const store = getStore(); const prevPtrs = readCanonicalPointers(sessionId); @@ -430,7 +430,10 @@ function recordCanonicalPointers(sessionId: string, msgs: BiliMessage[], log: (l let rows: { seq: number; content: string; ts: number | null }[] | null; if (prevPtrs !== null && prevPtrs.length <= msgs.length) { ptrs = [...prevPtrs]; - rows = store.unifiedRawMessages(sessionId, ptrs.length > 0 ? Math.max(...ptrs) : -1); + // reduce, not Math.max(...spread): a long session's pointer list + // outgrows V8's argument-spread limit (~65K-125K depending on + // build; measured 125K ok / 130K throws on Node 22 x64) → RangeError (#6490). + rows = store.unifiedRawMessages(sessionId, ptrs.length > 0 ? ptrs.reduce((m, p) => (p > m ? p : m), 0) : -1); } else { ptrs = []; rows = store.unifiedRawMessages(sessionId); diff --git a/tests/issue6490-spread-argument-limit.test.ts b/tests/issue6490-spread-argument-limit.test.ts new file mode 100644 index 0000000000..c684a8a6fb --- /dev/null +++ b/tests/issue6490-spread-argument-limit.test.ts @@ -0,0 +1,58 @@ +// #6490: Math.min/Math.max argument spread over unbounded arrays trips V8's +// argument-spread limit (~65K args) → RangeError. The reconciliation site +// (planReconciliation) is pinned by fold-reconcile-large-history.test.ts; +// this file pins the second same-mechanism site in src/ — the incremental +// lane's canonical-pointer upkeep, which spreads the session's full pointer +// list (one entry per settled canonical message) into Math.max. +import assert from "node:assert/strict"; +import test from "node:test"; +import { mkdtempSync, rmSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import type { BiliMessage } from "acp-kernel/wire"; +import { SessionStore, _setStoreForTest, _resetStoreForTest } from "../src/persist.ts"; +import { recordCanonicalPointers } from "../src/incremental-lane.ts"; + +// Beyond V8's argument-spread limit (~125K–130K on Node 22/24 x64, lower on +// some builds): spreading this many arguments throws RangeError: Maximum call +// stack size exceeded. Same size as the fold-reconcile-large-history case. +const SPREAD_LIMIT = 150_000; + +test("#6490: canonical-pointer upkeep survives a pointer list beyond the argument limit", () => { + const dir = mkdtempSync(join(tmpdir(), "bili-6490-")); + const store = new SessionStore({ dir, enabled: true }); + _setStoreForTest(store); + try { + const ptrs = Array.from({ length: SPREAD_LIMIT }, (_, i) => i); + store.setSessionExt("conv-6490", "inc:canonical-ptrs", ptrs); + const msgs: BiliMessage[] = Array.from({ length: SPREAD_LIMIT }, (_, i) => ({ + id: `m${i}`, + role: "user", + contentType: "text", + text: `turn ${i}`, + })); + const warnings: string[] = []; + let seenFromSeq: number | undefined; + const orig = store.unifiedRawMessages.bind(store); + store.unifiedRawMessages = (sessionId: string, fromSeqExclusive?: number) => { + seenFromSeq = fromSeqExclusive; + return orig(sessionId, fromSeqExclusive); + }; + recordCanonicalPointers("conv-6490", msgs, (level, m) => { + if (level === "warn") warnings.push(m); + }); + assert.equal( + warnings.filter((w) => w.includes("Maximum call stack")).length, + 0, + `no argument-limit RangeError: ${warnings.join(" | ")}`, + ); + assert.equal(seenFromSeq, SPREAD_LIMIT - 1, "the upkeep reads rows after the highest pointer"); + const after = store.getSessionExt("conv-6490", "inc:canonical-ptrs"); + assert.ok(Array.isArray(after), "pointer list preserved"); + assert.equal((after as number[]).length, SPREAD_LIMIT); + assert.equal((after as number[])[SPREAD_LIMIT - 1], SPREAD_LIMIT - 1); + } finally { + rmSync(dir, { recursive: true, force: true }); + _resetStoreForTest(); + } +}); From c6369fb6a195fbd1e8794c911adaff87d4dba0f0 Mon Sep 17 00:00:00 2001 From: ework-agent Date: Sat, 14 Nov 2026 04:35:44 +0800 Subject: [PATCH 03/14] fix(tests): pin pure-sqlite selection in notice-registry suite MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The suite baseline preload (preload-storage-baseline.mjs) pins BILI_STORAGE_UNIFIED="legacy" for the broad corpus. After #6480 flipped the storage default to pure-sqlite, the notice-registry suite's visibleNotices assertions expect the pure-sqlite default notice, which is gated on unifiedSelectionIsSqlite (unified "sqlite" or absent) — the preload's "legacy" made the notice silent, so the suite was born-red on master. Pin the selection explicitly (#4011 lesson: a test that depends on the production default passes locally but fails in CI). --- tests/notice-registry.test.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/notice-registry.test.ts b/tests/notice-registry.test.ts index 6d3b60edb4..b3b0d0e8a4 100644 --- a/tests/notice-registry.test.ts +++ b/tests/notice-registry.test.ts @@ -17,6 +17,11 @@ 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; +// #4011 lesson: this suite asserts the pure-sqlite default notice is visible, +// which requires the pure-sqlite SELECTION (unified "sqlite" or absent — the +// gate is unifiedSelectionIsSqlite, not the resolved mode). The suite baseline +// preload pins "legacy" for the broad corpus, so pin the selection explicitly. +process.env.BILI_STORAGE_UNIFIED = "sqlite"; 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 b1bc17b40454480c7204c2d2e7b44afb5216e367 Mon Sep 17 00:00:00 2001 From: ework-agent Date: Sat, 14 Nov 2026 10:20:31 +0800 Subject: [PATCH 04/14] fix(tests): pin BILI_STORAGE_JSON_WRITER=on in CCR cold-disk-restore test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The dsh plugin lane (ci-e2e-dsh.yml) runs node --import tsx --test WITHOUT the preload-storage-baseline.mjs preload, so BILI_STORAGE_UNIFIED is unset and the storage mode defaults to 'full'. Under the pure-sqlite default flip (5a80e2b8e, #6480), 'full' mode turns the JSON envelope writer OFF — so the .content-store.json sidecar is never written, and the test's readdirSync(namespace) hits ENOENT. Pin BILI_STORAGE_JSON_WRITER=on in the test so the content-store sidecar is written regardless of the storage mode. This keeps the corrupted-store detection path exercised in both full and legacy modes. Closes: dsh plugin lane red on master (run 43532980164, job 132255459726) --- tests/plugin-fork.test.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/plugin-fork.test.ts b/tests/plugin-fork.test.ts index 2763aa2f4e..4bd98e328f 100644 --- a/tests/plugin-fork.test.ts +++ b/tests/plugin-fork.test.ts @@ -909,6 +909,12 @@ 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 () => { + // The corrupted-store detection path needs the JSON content-store + // sidecar on disk. Under the pure-sqlite default (5a80e2b8e) the + // JSON writer is OFF, so pin it ON to keep exercising the envelope + // corruption path this test was written for. + const oldJsonWriter = process.env.BILI_STORAGE_JSON_WRITER; + process.env.BILI_STORAGE_JSON_WRITER = "on"; const h = await harness(true); try { const parent = resolveConversation("parent").session!; @@ -966,7 +972,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 (oldJsonWriter === undefined) delete process.env.BILI_STORAGE_JSON_WRITER; + else process.env.BILI_STORAGE_JSON_WRITER = oldJsonWriter; + await h.close(); + } }); } From 7492c35c2ad980560c3289c4cdb73e9f32af9dfe Mon Sep 17 00:00:00 2001 From: ework-agent Date: Sat, 14 Nov 2026 12:11:32 +0800 Subject: [PATCH 05/14] fix(tests): pin BILI_STORAGE_JSON_WRITER=on in native opencode e2e lane The pure-sqlite default flip (5a80e2b8e, #6480) turns the JSON envelope writer OFF, so the .json session file this lane asserts on is never written and 'proxy must persist the session' / 'no persisted session carried compressed blocks' fail after the 20s wait. Pin the writer ON in the spawned client's env (the bootstrapped proxy inherits it) so the envelope this test was written for is still produced. Closes: native opencode lane red on master (run 43547593803, job 132302438610) --- tests/e2e/e2e-native-opencode.test.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/e2e/e2e-native-opencode.test.ts b/tests/e2e/e2e-native-opencode.test.ts index 8b5578020d..78975d418d 100644 --- a/tests/e2e/e2e-native-opencode.test.ts +++ b/tests/e2e/e2e-native-opencode.test.ts @@ -421,6 +421,11 @@ async function ocRun( cwd: ctx.ocCwd, env: { ...cleanEnv(), + // Pure-sqlite default (5a80e2b8e, #6480) turns the JSON envelope + // writer OFF, but this lane asserts on the on-disk .json session + // file. Pin the writer ON so the envelope this test was written for + // is still produced regardless of the storage-mode default. + BILI_STORAGE_JSON_WRITER: "on", HOME: ctx.homeDir, TMPDIR: ctx.tmdir, XDG_CONFIG_HOME: ctx.xdg.config, From 45f93dbb8fc88523e3015a413ea7620281d11d1e Mon Sep 17 00:00:00 2001 From: ework-agent Date: Sat, 14 Nov 2026 12:11:32 +0800 Subject: [PATCH 06/14] fix(tests): pin BILI_STORAGE_JSON_WRITER=on in native dsh e2e lane MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Same pure-sqlite default flip (5a80e2b8e, #6480) as the opencode lane: the JSON envelope writer is OFF, so 'proxy must persist the session within 20000ms' fails — the on-disk .json session file is never written. Pin the writer ON in the spawned dsh client's env (the bootstrapped proxy inherits it). Closes: native dsh lane red on master (run 43547497015, job 132302138843) --- tests/e2e/e2e-native-dsh.test.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/e2e/e2e-native-dsh.test.ts b/tests/e2e/e2e-native-dsh.test.ts index 7b7402356c..ea8c3969e4 100644 --- a/tests/e2e/e2e-native-dsh.test.ts +++ b/tests/e2e/e2e-native-dsh.test.ts @@ -463,6 +463,11 @@ function dshRun( cwd: ctx.dshCwd, env: { ...cleanEnv(), + // Pure-sqlite default (5a80e2b8e, #6480) turns the JSON envelope + // writer OFF, but this lane asserts on the on-disk .json session + // file. Pin the writer ON so the envelope this test was written for + // is still produced regardless of the storage-mode default. + BILI_STORAGE_JSON_WRITER: "on", HOME: ctx.homeDir, TMPDIR: ctx.tmpDir, DSH_HOME: ctx.dshHome, From d67cc43557b98d9aa9ce61c24f4dcff93d882558 Mon Sep 17 00:00:00 2001 From: ework-agent Date: Sat, 14 Nov 2026 12:11:32 +0800 Subject: [PATCH 07/14] fix(tests): pin BILI_STORAGE_JSON_WRITER=on in pi codex-responses WS e2e lane MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Same pure-sqlite default flip (5a80e2b8e, #6480) as the opencode/dsh lanes: the JSON envelope writer is OFF, so 'session persisted' fails — the on-disk .json session file is never written. Pin the writer ON in the spawned pi client's env (the bootstrapped proxy inherits it). Closes: pi codex-responses WS lane red on master (run 43547626291, job 132302540960) --- tests/e2e/e2e-pi-codex-ws.test.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/e2e/e2e-pi-codex-ws.test.ts b/tests/e2e/e2e-pi-codex-ws.test.ts index 15788e0224..c5b3625224 100644 --- a/tests/e2e/e2e-pi-codex-ws.test.ts +++ b/tests/e2e/e2e-pi-codex-ws.test.ts @@ -342,6 +342,12 @@ function piRun( cwd: ctx.piCwd, env: { ...cleanEnv(opts.extraEnv), + // Pure-sqlite default (5a80e2b8e, #6480) turns the JSON + // envelope writer OFF, but this lane asserts on the on-disk + // .json session file. Pin the writer ON so the envelope this + // test was written for is still produced regardless of the + // storage-mode default. + BILI_STORAGE_JSON_WRITER: "on", PI_CODING_AGENT_DIR: ctx.piAgentDir, XDG_CONFIG_HOME: ctx.xdg.config, XDG_CACHE_HOME: ctx.xdg.cache, From c392237d4702601246f5bcb70235b46f8becdc8d Mon Sep 17 00:00:00 2001 From: ework-agent Date: Sat, 14 Nov 2026 13:18:32 +0800 Subject: [PATCH 08/14] fix(tests): pin BILI_STORAGE_JSON_WRITER=on in pi package-native e2e lane MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 4th lane of the pure-sqlite default flip (5a80e2b8e, #6480) family: the JSON envelope writer is OFF, so 'proxy must persist the session' and 'at least one persisted session must carry compressed blocks' fail — the on-disk .json session file is never written. Pin the writer ON in the spawned pi client's env (the bootstrapped proxy inherits it). Closes: pi package-native lane red on ci-fixes (run 43558179054, job 132336647955) --- tests/e2e/e2e-native-pi.test.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/e2e/e2e-native-pi.test.ts b/tests/e2e/e2e-native-pi.test.ts index 151b1606e1..cbedc8dd9b 100644 --- a/tests/e2e/e2e-native-pi.test.ts +++ b/tests/e2e/e2e-native-pi.test.ts @@ -468,8 +468,13 @@ 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. - BILI_PI_INLINE: "0", - PI_CODING_AGENT_DIR: ctx.piAgentDir, + BILI_PI_INLINE: "0", + // Pure-sqlite default (5a80e2b8e, #6480) turns the JSON envelope + // writer OFF, but this lane asserts on the on-disk .json session + // file. Pin the writer ON so the envelope this test was written for + // is still produced regardless of the storage-mode default. + BILI_STORAGE_JSON_WRITER: "on", + PI_CODING_AGENT_DIR: ctx.piAgentDir, XDG_CONFIG_HOME: ctx.xdg.config, XDG_CACHE_HOME: ctx.xdg.cache, XDG_STATE_HOME: ctx.xdg.state, From 974cd4c2f67c9ee5a1f8879709224cc00b2f91df Mon Sep 17 00:00:00 2001 From: ework-agent Date: Sat, 14 Nov 2026 13:18:32 +0800 Subject: [PATCH 09/14] fix(tests): pin BILI_STORAGE_JSON_WRITER=on in fork-ccr-adoption suite Same pure-sqlite default flip (5a80e2b8e, #6480) family: the JSON writer is OFF, so the per-session CCR content-store sidecar (.content-store.json) that 'child persists its own companion and survives a proxy restart' asserts on is never written (0 !== 1). The earlier b1bc17b40 pin only covered tests/plugin-fork.test.ts, not this file. Pin the writer ON at module load (before any SessionStore is constructed). Closes: dsh plugin lane red on ci-fixes (run 43558179102, job 132336519539) --- tests/fork-ccr-adoption.test.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/fork-ccr-adoption.test.ts b/tests/fork-ccr-adoption.test.ts index 4cd9a7b586..ea8004f747 100644 --- a/tests/fork-ccr-adoption.test.ts +++ b/tests/fork-ccr-adoption.test.ts @@ -38,6 +38,12 @@ import { maybeAdoptForkBlocks } from "../src/fork-adoption.ts"; import { rmrf } from "./tmp-rm.ts"; process.env.BILI_PERSIST = "0"; +// Pure-sqlite default (5a80e2b8e, #6480) turns the JSON envelope writer OFF, +// so the per-session CCR content-store sidecar (.content-store.json) this +// suite asserts on is never written. Pin the writer ON at module load (before +// any SessionStore is constructed) so the companion-envelope coverage this +// test was written for still runs regardless of the storage-mode default. +process.env.BILI_STORAGE_JSON_WRITER = "on"; const LIMIT = 200_000; const META = { protocol: "openai" as const, upstreamOrigin: "http://upstream.example/v1" }; From 271abba541666260a2142767c78cb2e53ea00595 Mon Sep 17 00:00:00 2001 From: ework-agent Date: Sat, 14 Nov 2026 13:31:56 +0800 Subject: [PATCH 10/14] fix(tests): pin BILI_STORAGE_JSON_WRITER=on in subagent-sessions e2e lane MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pure-sqlite default flip (5a80e2b8e, #6480) family: the JSON envelope writer is OFF, so 'proxy must persist the session' fails — the on-disk .json session file is never written. Pin the writer ON in the spawned opencode client's env (the bootstrapped proxy inherits it). --- tests/e2e/e2e-subagent-sessions.test.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/e2e/e2e-subagent-sessions.test.ts b/tests/e2e/e2e-subagent-sessions.test.ts index af08050217..b1a6188bca 100644 --- a/tests/e2e/e2e-subagent-sessions.test.ts +++ b/tests/e2e/e2e-subagent-sessions.test.ts @@ -394,6 +394,11 @@ async function ocRun( cwd: ctx.ocCwd, env: { ...cleanEnv(), + // Pure-sqlite default (5a80e2b8e, #6480) turns the JSON envelope + // writer OFF, but this lane asserts on the on-disk .json session + // file. Pin the writer ON so the envelope this test was written for + // is still produced regardless of the storage-mode default. + BILI_STORAGE_JSON_WRITER: "on", HOME: ctx.homeDir, TMPDIR: ctx.tmdir, XDG_CONFIG_HOME: ctx.xdg.config, From 5d47196a267e20b63ed7965b6fea58374cc599f7 Mon Sep 17 00:00:00 2001 From: ework-agent Date: Sat, 14 Nov 2026 13:31:56 +0800 Subject: [PATCH 11/14] fix(tests): pin BILI_STORAGE_JSON_WRITER=on in dsh-persona e2e lane Pure-sqlite default flip (5a80e2b8e, #6480) family: the JSON envelope writer is OFF, so the on-disk .json session envelope this lane asserts on (exactly ONE persisted session under the raw key) is never written. Pin the writer ON in the spawned dsh client's env. --- 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..8d3ea3d34c 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 default (5a80e2b8e, #6480) turns the JSON envelope + // writer OFF, but this lane asserts on the on-disk .json session + // envelope. Pin the writer ON so the envelope this test was written + // for is still produced regardless of the storage-mode default. + BILI_STORAGE_JSON_WRITER: "on", HOME: home, TMPDIR: tmp, DSH_HOME: dshHome, From 1ca40871581c5009fdb69eea944f448d002098e7 Mon Sep 17 00:00:00 2001 From: ework-agent Date: Sat, 14 Nov 2026 13:31:56 +0800 Subject: [PATCH 12/14] fix(tests): pin BILI_STORAGE_JSON_WRITER=on in update-state e2e lane MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pure-sqlite default flip (5a80e2b8e, #6480) family: the JSON envelope writer is OFF, so the on-disk .json session file this lane asserts on (state survival across the OLD→NEW update) is never written. Pin the writer ON in the spawned proxy's env (both update phases share envBase). --- tests/e2e/e2e-update-state.test.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/e2e/e2e-update-state.test.ts b/tests/e2e/e2e-update-state.test.ts index 03f2b1db22..e31baf7659 100644 --- a/tests/e2e/e2e-update-state.test.ts +++ b/tests/e2e/e2e-update-state.test.ts @@ -299,6 +299,11 @@ test("self-update keeps live compression state: folds survive the OLD→NEW hop envBase.BILI_UPDATE_POLICY_URL = "http://127.0.0.1:1/no-policy.json"; envBase.BILI_PERSIST_DEBOUNCE_MS = "200"; envBase.BILI_SESSIONS_DIR = sessionsDir; + // Pure-sqlite default (5a80e2b8e, #6480) turns the JSON envelope + // writer OFF, but this lane asserts on the on-disk .json session file + // (state survival across the update). Pin the writer ON so the + // envelope this test was written for is still produced. + envBase.BILI_STORAGE_JSON_WRITER = "on"; const port = await freePort(); proxy = spawnProxy(installDir, port, envBase); From 93040525591e2efd9aefb1ba72a2484627e7e20f Mon Sep 17 00:00:00 2001 From: ci-check Date: Sat, 14 Nov 2026 15:42:23 +0800 Subject: [PATCH 13/14] fix: align e2e-native-pi env block indentation to the 8-space style The BILI_STORAGE_JSON_WRITER pin landed with a stray leading space (9-space indent) against the surrounding 8-space env properties. Mechanical style fix from review; no behavior change. --- tests/e2e/e2e-native-pi.test.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/e2e/e2e-native-pi.test.ts b/tests/e2e/e2e-native-pi.test.ts index cbedc8dd9b..304c0cf395 100644 --- a/tests/e2e/e2e-native-pi.test.ts +++ b/tests/e2e/e2e-native-pi.test.ts @@ -468,13 +468,13 @@ 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. - BILI_PI_INLINE: "0", - // Pure-sqlite default (5a80e2b8e, #6480) turns the JSON envelope - // writer OFF, but this lane asserts on the on-disk .json session - // file. Pin the writer ON so the envelope this test was written for - // is still produced regardless of the storage-mode default. - BILI_STORAGE_JSON_WRITER: "on", - PI_CODING_AGENT_DIR: ctx.piAgentDir, + BILI_PI_INLINE: "0", + // Pure-sqlite default (5a80e2b8e, #6480) turns the JSON envelope + // writer OFF, but this lane asserts on the on-disk .json session + // file. Pin the writer ON so the envelope this test was written for + // is still produced regardless of the storage-mode default. + BILI_STORAGE_JSON_WRITER: "on", + PI_CODING_AGENT_DIR: ctx.piAgentDir, XDG_CONFIG_HOME: ctx.xdg.config, XDG_CACHE_HOME: ctx.xdg.cache, XDG_STATE_HOME: ctx.xdg.state, From 04f998bbfdf02d7ed31f40ee5028e5a257e8939e Mon Sep 17 00:00:00 2001 From: Afloat Date: Sat, 14 Nov 2026 16:24:08 +0800 Subject: [PATCH 14/14] test: preserve long-history pointer handler coverage --- tests/inc-canonical-pointers.test.ts | 61 +++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/tests/inc-canonical-pointers.test.ts b/tests/inc-canonical-pointers.test.ts index bdc730e143..451b69bc94 100644 --- a/tests/inc-canonical-pointers.test.ts +++ b/tests/inc-canonical-pointers.test.ts @@ -5,7 +5,9 @@ import test from "node:test"; import { mkdtempSync, rmSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; +import { Readable } from "node:stream"; import { defaultConfig } from "acp-kernel"; +import { anthropicToCore } from "acp-kernel/wire"; import { startServer } from "../src/server.ts"; import type { ProxyOptions } from "../src/config.ts"; import { SessionStore, _setStoreForTest, getStore } from "../src/persist.ts"; @@ -13,7 +15,7 @@ import { _resetPluginStateForTest } from "../src/plugin.ts"; import { _resetSessionsForTest } from "../src/session.ts"; import { _setForTest } from "../src/registry.ts"; import { resetToolRingForTest } from "../src/tool-ring.ts"; -import { __resetIncrementalLaneForTests, __incrementalPtrChainForTests } from "../src/incremental-lane.ts"; +import { __resetIncrementalLaneForTests, __incrementalPtrChainForTests, handleIncrementalTurn } from "../src/incremental-lane.ts"; /** * #3901 / #3798 — incremental canonical row pointers. @@ -88,6 +90,63 @@ async function harness(): Promise<{ const core = (id: string, text: string): Record => ({ id, role: "user", contentType: "text", content: text.repeat(200) }); +test("pointer upkeep extends very long restored histories from their highest row", async (t) => { + _resetSessionsForTest(); + _resetPluginStateForTest(); + __resetIncrementalLaneForTests(); + const dir = mkdtempSync(join(testRoot, "long-")); + const store = new SessionStore({ dir, enabled: false }); + _setStoreForTest(store); + const count = 250_000; + const ptrs = Array.from({ length: count }, (_, i) => i); + [ptrs[0], ptrs[count - 1]] = [ptrs[count - 1]!, ptrs[0]!]; + const rows = Array.from({ length: count }, (_, seq) => ({ + seq, content: JSON.stringify({ id: `prefix-${seq}`, role: "user", contentType: "text", text: "x" }), ts: null, + })); + const delta = { role: "assistant" as const, content: "new tail" }; + const tail = anthropicToCore({ messages: [delta] }).msgs[0]!; + const reads: number[] = []; + const written: unknown[] = []; + const warnings: string[] = []; + t.mock.method(store, "getSessionExt", (_id: string, key: string) => key === "inc:canonical-ptrs" ? ptrs : undefined); + t.mock.method(store, "setSessionExt", (_id: string, key: string, value: unknown) => { + if (key === "inc:canonical-ptrs") written.push(value); + }); + t.mock.method(store, "unifiedRawMessages", (_id: string, after?: number) => { + if (after === undefined) return rows; + reads.push(after); + return [{ seq: count, content: JSON.stringify(tail), ts: null }]; + }); + t.mock.method(store, "afterNextFlush", async () => true); + try { + const req = Readable.from([]) as unknown as http.IncomingMessage; + Object.assign(req, { + method: "POST", url: "/v1/messages", + headers: { "x-bili-plugin": "dsh", "x-bili-plugin-conversation": "long-pointers" }, + socket: { remoteAddress: "127.0.0.1", localPort: 43210 }, + }); + const res = { + writeHead: () => {}, setHeader: () => {}, end: () => {}, on: () => res, + } as unknown as http.ServerResponse; + let forwarded = false; + await handleIncrementalTurn(req, res, (level, message) => { if (level === "warn") warnings.push(message); }, async (_req, response) => { + forwarded = true; + response.writeHead(200); + response.end(); + }, "/v1/messages", Buffer.from(JSON.stringify({ + conversationId: "long-pointers", sinceSeq: count, + request: { model: "claude-test", max_tokens: 512 }, messages: [delta], + }))); + assert.equal(forwarded, true); + assert.deepEqual(warnings, []); + assert.deepEqual(reads, [count - 1], "query only rows above the highest pointer, even when it is not last"); + assert.deepEqual(written, [[...ptrs, count]], "the settled delta extends the persisted canonical"); + } finally { + __resetIncrementalLaneForTests(); + store.closeQuietly(); + } +}); + test("cold canonical rebuild: identical resync keeps the shared prefix; delta assembles the FULL history", async () => { const h = await harness(); try {