From 9bcd9c44488c9225da46e57e86eb81f49f9beddc Mon Sep 17 00:00:00 2001 From: Afloat Date: Thu, 12 Nov 2026 19:12:56 +0800 Subject: [PATCH 01/12] fix: honor Request cancellation in the inline engine --- src/inline-engine.ts | 4 +- tests/inline-request-signal.test.ts | 130 ++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 tests/inline-request-signal.test.ts diff --git a/src/inline-engine.ts b/src/inline-engine.ts index c156b0fa36..904e1b76e0 100644 --- a/src/inline-engine.ts +++ b/src/inline-engine.ts @@ -269,7 +269,10 @@ function responseFrom(res: InlineRes): Response { function makeDispatcher(ctx: EngineContext): InlineEngine["dispatch"] { return async (input, init, rawFetch) => { + const signal = init?.signal !== undefined ? init.signal : input instanceof Request ? input.signal : undefined; + signal?.throwIfAborted(); const req = await toInlineReq(input, init); + signal?.throwIfAborted(); const res = new InlineRes(); // Spawn-mode cancel parity (#3278 review): honor the caller's // AbortSignal. Destroying res drives the pipeline's own close plumbing @@ -277,7 +280,6 @@ function makeDispatcher(ctx: EngineContext): InlineEngine["dispatch"] { // socket close does over HTTP, stopping the upstream round trip; the // raced promise makes the caller reject with the abort reason like // undici would instead of running to completion and burning tokens. - const signal = init?.signal; let onAbort: (() => void) | undefined; let abortPromise: Promise | undefined; if (signal != null) { diff --git a/tests/inline-request-signal.test.ts b/tests/inline-request-signal.test.ts new file mode 100644 index 0000000000..f98086b2af --- /dev/null +++ b/tests/inline-request-signal.test.ts @@ -0,0 +1,130 @@ +import { after, test } from "node:test"; +import assert from "node:assert/strict"; +import http from "node:http"; +import { once } from "node:events"; +import type { AddressInfo } from "node:net"; + +function deferred() { + let resolve!: () => void; + const promise = new Promise((done) => { resolve = done; }); + return { promise, resolve }; +} + +interface Fixture { + started: ReturnType; + closed: ReturnType; + response?: http.ServerResponse; + stream?: boolean; +} +const pending = new Map(); +let upstreamHits = 0; +const upstream = http.createServer((req, res) => { + req.resume(); + req.on("end", () => { + upstreamHits++; + const fixture = pending.get(req.url ?? ""); + if (!fixture) { res.end("complete"); return; } + fixture.response = res; + res.once("close", fixture.closed.resolve); + if (fixture.stream) { + res.writeHead(200, { "content-type": "application/octet-stream" }); + res.write("first"); + } + fixture.started.resolve(); + }); +}); +upstream.listen(0, "127.0.0.1"); +await once(upstream, "listening"); +const origin = `http://127.0.0.1:${(upstream.address() as AddressInfo).port}`; +const ie = await import("../src/inline-engine.ts"); + +after(async () => { + upstream.closeAllConnections(); + await new Promise((resolve) => upstream.close(() => resolve())); + const { flushAllSessions } = await import("../src/session.ts"); + await flushAllSessions(); + ie._resetInlineEngineForTest(); +}); + +async function bounded(promise: Promise): Promise { + let timer: NodeJS.Timeout | undefined; + try { + return await Promise.race([ + promise, + new Promise((_, reject) => { + timer = setTimeout(() => reject(new Error("inline cancellation did not settle")), 3000); + }), + ]); + } finally { clearTimeout(timer); } +} + +for (const explicitUndefined of [false, true]) { + test(`Request.signal cancels before headers (${explicitUndefined ? "undefined signal override" : "omitted init"})`, { timeout: 30_000 }, async () => { + const engine = await ie.getInlineEngine(); + const endpoint = `/pending-${explicitUndefined}`; + const fixture: Fixture = { started: deferred(), closed: deferred() }; + pending.set(endpoint, fixture); + const controller = new AbortController(); + const reason = new Error("request caller cancelled"); + const request = new Request(`${ie.INLINE_ORIGIN}/bili/${origin}${endpoint}`, { signal: controller.signal }); + const call = engine.dispatch(request, explicitUndefined ? { signal: undefined } : undefined, globalThis.fetch); + try { + await bounded(fixture.started.promise); + controller.abort(reason); + await assert.rejects(bounded(call), (error: unknown) => error === reason); + await bounded(fixture.closed.promise); + } finally { + fixture.response?.end("released"); + await call.then((response) => response.text(), () => {}).catch(() => {}); + pending.delete(endpoint); + } + }); +} + +test("Request.signal aborts a committed body and closes the live upstream", { timeout: 30_000 }, async () => { + const engine = await ie.getInlineEngine(); + const endpoint = "/stream"; + const fixture: Fixture = { started: deferred(), closed: deferred(), stream: true }; + pending.set(endpoint, fixture); + const controller = new AbortController(); + const request = new Request(`${ie.INLINE_ORIGIN}/bili/${origin}${endpoint}`, { signal: controller.signal }); + const response = await bounded(engine.dispatch(request, {}, globalThis.fetch)); + const reader = response.body!.getReader(); + let read: ReturnType | undefined; + try { + assert.equal(new TextDecoder().decode((await bounded(reader.read())).value), "first"); + controller.abort(); + read = reader.read(); + await assert.rejects(bounded(read), /abort/i); + await bounded(fixture.closed.promise); + } finally { + fixture.response?.end(); + await read?.catch(() => {}); + reader.releaseLock(); + pending.delete(endpoint); + } +}); + +test("a pre-aborted Request never reaches the upstream", { timeout: 30_000 }, async () => { + const engine = await ie.getInlineEngine(); + const controller = new AbortController(); + const reason = new Error("already cancelled"); + controller.abort(reason); + const request = new Request(`${ie.INLINE_ORIGIN}/bili/${origin}/ok`, { signal: controller.signal }); + const before = upstreamHits; + await assert.rejects(engine.dispatch(request, undefined, globalThis.fetch), (error: unknown) => error === reason); + assert.equal(upstreamHits, before); +}); + +for (const override of ["signal", "null"] as const) { + test(`init.signal=${override} overrides an aborted Request signal`, { timeout: 30_000 }, async () => { + const engine = await ie.getInlineEngine(); + const controller = new AbortController(); + controller.abort(); + const request = new Request(`${ie.INLINE_ORIGIN}/bili/${origin}/ok`, { signal: controller.signal }); + const init = { signal: override === "null" ? null : new AbortController().signal }; + const response = await engine.dispatch(request, init, globalThis.fetch); + assert.equal(response.status, 200); + assert.equal(await response.text(), "complete"); + }); +} From c6369fb6a195fbd1e8794c911adaff87d4dba0f0 Mon Sep 17 00:00:00 2001 From: ework-agent Date: Sat, 14 Nov 2026 04:35:44 +0800 Subject: [PATCH 02/12] 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 03/12] 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 04/12] 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 05/12] 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 06/12] 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 07/12] 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 08/12] 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 09/12] 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 10/12] 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 11/12] 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 dc0efc3d02f6309f6e03429f3313b5b9b3b8f99d Mon Sep 17 00:00:00 2001 From: ci-check Date: Sat, 14 Nov 2026 16:14:47 +0800 Subject: [PATCH 12/12] fix: classify inline-lane cancellation by signal state, not reason name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The pi-inline transport's catch only re-threw errors named "AbortError", but the engine rejects with the signal's REASON — for a custom abort (controller.abort(new Error(...))) that reason is not an AbortError, so a caller cancellation was misclassified as an engine failure and degraded to a direct (uncompressed) resend that also consumed the one-shot warning. Classify by the effective signal's aborted state (resolved exactly as the engine does) so any caller cancellation propagates. Pinned by a regression test (custom-reason Request.signal cancel must propagate, never degrade). --- src/agent/pi-inline.ts | 7 +++++- tests/pi-inline.test.ts | 53 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/src/agent/pi-inline.ts b/src/agent/pi-inline.ts index 238d3c73d1..9e23fbeef0 100644 --- a/src/agent/pi-inline.ts +++ b/src/agent/pi-inline.ts @@ -42,7 +42,12 @@ export function installInlineTransport(): boolean { } catch (err) { // Caller-side cancel is not an engine failure — propagate it: // degrading would consume the one-shot warning and re-send a - // request the caller already abandoned. + // request the caller already abandoned. The engine rejects with + // the signal's REASON, which for a custom abort + // (controller.abort(new Error(...))) is not an AbortError — so + // classify by the signal's state, not the reason's name. + const cancelSignal = init?.signal !== undefined ? init.signal : input instanceof Request ? input.signal : undefined; + if (cancelSignal?.aborted) throw err; if (err instanceof Error && err.name === "AbortError") throw err; const msg = err instanceof Error ? err.message : String(err); if (url.startsWith(MODEL_PREFIX)) { diff --git a/tests/pi-inline.test.ts b/tests/pi-inline.test.ts index 00b175a4ff..3421c69495 100644 --- a/tests/pi-inline.test.ts +++ b/tests/pi-inline.test.ts @@ -372,3 +372,56 @@ test("#3278 engine: caller abort cancels the in-process round trip (spawn-mode p await new Promise((r) => setTimeout(r, 300)); assert.equal(slowCompleted, false, "upstream round trip must not complete after the caller aborted"); }); + +test("#6504 transport: a custom-reason Request.signal cancel propagates, never degrades to a direct resend", async () => { + // The engine rejects with the signal's REASON. For a custom abort + // (controller.abort(new Error(...))) that reason is NOT an AbortError, so + // the transport must classify the cancel by the signal's state — not by + // the reason's name — or it would degrade: consume the one-shot warning + // and re-send an already-abandoned request direct, uncompressed. + const ie = await import("../src/inline-engine.ts"); + ie._resetInlineEngineForTest(); + const reason = new Error("caller cancelled"); + ie._setEngineFactoryForTest(async () => ({ + origin: ie.INLINE_ORIGIN, + dispatch: async (input: string | URL | Request, init?: RequestInit): Promise => { + // Mirror the engine's signal resolution + pre-header abort reject. + const signal = init?.signal !== undefined ? init.signal : input instanceof Request ? input.signal : undefined; + await new Promise((_, reject) => { + if (signal?.aborted) reject(signal.reason); + else signal?.addEventListener("abort", () => reject(signal.reason), { once: true }); + }); + return new Response("unreachable"); + }, + dispatchHttp: async () => {}, + wsOrigin: Promise.resolve(undefined), + webOrigin: Promise.resolve(undefined), + })); + try { + await freshChain(); + const ac = new AbortController(); + const req = new Request(`${ie.INLINE_ORIGIN}/bili/${upstreamOrigin}/v1/messages`, { + method: "POST", + body: "{}", + signal: ac.signal, + }); + const before = hits.length; + const settled = fetch(req).then( + (r) => { throw new Error(`expected cancellation, got HTTP ${r.status}`); }, + (e: unknown) => e, + ); + setTimeout(() => ac.abort(reason), 50); + const err = await withTimeout(settled, 10_000, "cancel propagation") as Error; + // The caller's custom reason must propagate verbatim. + assert.equal(err, reason, "the caller's abort reason must propagate verbatim"); + // No direct resend: the real upstream must stay untouched. + assert.equal(hits.length, before, "a cancelled request must not be re-sent direct"); + } finally { + const piInline = await import("../src/agent/pi-inline.ts"); + const fc = await import("../src/agent/fetch-chain/index.ts"); + piInline._resetInlineTransportForTest(); + fc.resetFetchChainForTest(); + ie._setEngineFactoryForTest(undefined); + ie._resetInlineEngineForTest(); + } +});