From 48d2ca0b83a687330a488cb6ca401f1aa941d0aa Mon Sep 17 00:00:00 2001 From: ci-check Date: Tue, 17 Nov 2026 23:45:13 +0800 Subject: [PATCH 1/2] fix(omp): identity register is NOT carriage evidence for compaction ownership (#7060) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The omp lane's ownsCompaction used state.identityAt === sid as local evidence to claim compaction ownership directly, but the identity registration only populates registeredIds — it does NOT create a tracked session. So the plugin could cancel native compaction for a conversation the proxy never tracked, leading to 'no fold + no fallback' overflow. This is the #1383 evidence gate hole on the identity-stamp path: the gate was designed to prevent #1382 (cancelling compaction for a conversation the proxy doesn't carry), but the identity-stamp path bypassed the carriage check. Fix: remove the omp local-evidence short-circuit so the status probe always runs for omp. The probe (GET /__bili/plugin/status) is the authoritative carriage check — if the proxy reports the conversation unknown, the plugin does NOT claim ownership and native compaction proceeds. This restores the documented design intent ('carriage evidence still decides', pi.ts:1010) and the safety principle ('a wrong cancel overflows the session', pi.ts:1016). Regression test: updated test (H) in tests/plugin-agent.test.ts to assert the correct behavior (identity-registered session is NOT carried by construction — proxy reports unknown → native compaction proceeds). --- src/agent/pi.ts | 11 +++++++---- tests/plugin-agent.test.ts | 9 ++++++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/agent/pi.ts b/src/agent/pi.ts index 17b1c295c4..bdf1665fda 100644 --- a/src/agent/pi.ts +++ b/src/agent/pi.ts @@ -1028,9 +1028,12 @@ export function createBiliPlugin(agentOverride?: string, opts?: { retryIntervalM // never runs once an earlier handler returned cancel. Accepted // evidence, in order: (1) local — we stamped // x-bili-plugin-conversation for this session id (tools registered - // AND a request routed through the proxy), or omp's identity register - // succeeded; (2) remote — the proxy confirms it carries the - // conversation id (/__bili/plugin/status ok). A non-http(s) baseUrl + // AND a request routed through the proxy) [pi only]; (2) remote — the + // proxy confirms it carries the conversation id (/__bili/plugin/status + // ok) [pi and omp]. omp's identity register is NOT carriage evidence + // (#7060: registration populates registeredIds without creating a + // tracked session, so a stamp-only claim cancels native compaction for + // a conversation the proxy never sees → overflow). A non-http(s) baseUrl // vetoes by default (opt-in via BILI_NON_HTTP_PROVIDERS below only // widens the candidate set; carriage evidence still decides). Hosts // exposing no stable session id keep the @@ -1056,7 +1059,7 @@ export function createBiliPlugin(agentOverride?: string, opts?: { retryIntervalM } const sid = ctx === undefined ? undefined : sessionIdOf(ctx); if (sid === undefined || sid.length === 0) return true; - if (agent === "pi" ? state.carriedSids?.has(sid) === true : state.identityAt === sid) return true; + if (agent === "pi" && state.carriedSids?.has(sid) === true) return true; try { return (await fetchStatus(proxyBase, sid)) !== undefined; } catch (err) { diff --git a/tests/plugin-agent.test.ts b/tests/plugin-agent.test.ts index a9d757cde7..cfc25a9b59 100644 --- a/tests/plugin-agent.test.ts +++ b/tests/plugin-agent.test.ts @@ -538,8 +538,11 @@ test("#1382: compaction cancel requires evidence the proxy carries this conversa await runOmpCase(true, true, "omp: proxy confirms carriage → announced auto compaction cancelled"); await runOmpCase(false, false, "omp: proxy never saw the conversation → announced auto compaction proceeds"); - // (H) omp identity fast path: a successful identity register is local - // evidence — the cancel holds even though the proxy reports unknown. + // (H) omp identity register is NOT carriage evidence (#7060): the + // proxy reports the conversation unknown, so the plugin must NOT claim + // ownership — native compaction proceeds even though the identity + // register succeeded (registration populates registeredIds without + // creating a tracked session). const identityProxy = await startFakeProxy({ statusOk: false }); try { await withEnv({ BILLION_CONTEXT_PROXY: identityProxy.origin }, async () => { @@ -551,7 +554,7 @@ test("#1382: compaction cancel requires evidence the proxy carries this conversa const payload = await omp.events.get("before_provider_request")!({ payload: { messages: [{ role: "user", content: "hi" }] } }, ctx); assert.equal((payload as { prompt_cache_key?: string })?.prompt_cache_key, "sess-omp-id", "identity registration completed with the request"); omp.events.get("auto_compaction_start")!({}, undefined); - assert.deepEqual(await omp.events.get("session_before_compact")!({}, ctx), { cancel: true }, "identity-registered session is carried by construction"); + assert.deepEqual(await omp.events.get("session_before_compact")!({}, ctx), undefined, "identity-registered session is NOT carried by construction — proxy reports unknown → native compaction proceeds"); }); } finally { await identityProxy.close(); From 3e7bb28f746395f2ad4df7d644b1ed650cd6aae9 Mon Sep 17 00:00:00 2001 From: ci-check Date: Wed, 18 Nov 2026 00:47:06 +0800 Subject: [PATCH 2/2] fix(omp): status 200 without a live session is NOT carriage evidence (#7060) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The #7076 probe-only fix still let ownsCompaction claim ownership on the status endpoint's no-session 200s: pre-first-request (runtime-info registered, no tracked session yet) and chain-advisory (content verdict only) both answer 200 with sessionId: null. In the exact #7060 bypass shape — proxy up, identity registered, runtime-info reported, but the conversation never tracked — the probe returned 200, the plugin claimed ownership, cancelled native compaction, and the session overflowed with no fold and no fallback. Carriage is a LIVE tracked session: require a non-null session id from the probe. A 200 without one is not carriage; native compaction proceeds. Test (H) now reproduces the real #7060 shape (200 pre-first-request, sessionId null → no claim) instead of the 404 "unknown" shape; the fake proxy status endpoint returns realistic full-session (sessionId set) and pre-first-request (sessionId null) responses. --- src/agent/pi.ts | 23 ++++++++++++++++++----- tests/plugin-agent.test.ts | 34 ++++++++++++++++++++++++---------- 2 files changed, 42 insertions(+), 15 deletions(-) diff --git a/src/agent/pi.ts b/src/agent/pi.ts index bdf1665fda..cc05c7874a 100644 --- a/src/agent/pi.ts +++ b/src/agent/pi.ts @@ -1030,10 +1030,14 @@ export function createBiliPlugin(agentOverride?: string, opts?: { retryIntervalM // x-bili-plugin-conversation for this session id (tools registered // AND a request routed through the proxy) [pi only]; (2) remote — the // proxy confirms it carries the conversation id (/__bili/plugin/status - // ok) [pi and omp]. omp's identity register is NOT carriage evidence - // (#7060: registration populates registeredIds without creating a - // tracked session, so a stamp-only claim cancels native compaction for - // a conversation the proxy never sees → overflow). A non-http(s) baseUrl + // reports a LIVE session, sessionId non-null) [pi and omp]. omp's + // identity register is NOT carriage evidence (#7060: registration + // populates registeredIds without creating a tracked session, so a + // stamp-only claim cancels native compaction for a conversation the + // proxy never sees → overflow). A 200 WITHOUT a session (pre-first- + // request / chain-advisory, sessionId: null) is likewise NOT carriage: + // the proxy knows the id from registration/runtime-info but has never + // folded it. A non-http(s) baseUrl // vetoes by default (opt-in via BILI_NON_HTTP_PROVIDERS below only // widens the candidate set; carriage evidence still decides). Hosts // exposing no stable session id keep the @@ -1061,7 +1065,16 @@ export function createBiliPlugin(agentOverride?: string, opts?: { retryIntervalM if (sid === undefined || sid.length === 0) return true; if (agent === "pi" && state.carriedSids?.has(sid) === true) return true; try { - return (await fetchStatus(proxyBase, sid)) !== undefined; + const status = await fetchStatus(proxyBase, sid); + // 200 is NOT carriage evidence by itself: the status endpoint + // answers 200 for conversations it has NOT tracked — + // pre-first-request (runtime-info registered, no session yet) + // and chain-advisory (content verdict only) both carry + // sessionId: null. Carriage is a LIVE tracked session, i.e. a + // non-null session id. Claiming on the no-session 200s re-opens + // the #7060 bypass (cancel native compaction for a + // conversation the proxy never folds → overflow). + return status !== undefined && typeof status.sessionId === "string" && status.sessionId.length > 0; } catch (err) { logHostEvent("error", "[native-client]", `bili-plugin(${agent}): compaction ownership probe failed (${err instanceof Error ? err.message : String(err)}) — leaving native compaction enabled`); return false; diff --git a/tests/plugin-agent.test.ts b/tests/plugin-agent.test.ts index cfc25a9b59..797bd8d7ac 100644 --- a/tests/plugin-agent.test.ts +++ b/tests/plugin-agent.test.ts @@ -90,7 +90,7 @@ type FakeProxy = { close(): Promise; }; -async function startFakeProxy(opts: { failRegister?: number; statusOk?: boolean; decompressFailure?: boolean } = {}): Promise { +async function startFakeProxy(opts: { failRegister?: number; statusOk?: boolean; decompressFailure?: boolean; statusPhase?: "pre-first-request" } = {}): Promise { const toolCalls: FakeProxy["toolCalls"] = []; const registers: FakeProxy["registers"] = []; const runtimeInfos: FakeProxy["runtimeInfos"] = []; @@ -153,9 +153,17 @@ async function startFakeProxy(opts: { failRegister?: number; statusOk?: boolean; if (opts.statusOk === false) { res.writeHead(404, { "content-type": "application/json" }); res.end(JSON.stringify({ ok: false, error: "unknown plugin conversation" })); + } else if (opts.statusPhase === "pre-first-request") { + // Realistic no-session 200: the proxy knows the id from + // runtime-info but has never tracked a session for it (the + // #7060 bypass shape). sessionId: null is the carriage + // discriminator — a 200 alone is NOT carriage evidence. + res.writeHead(200, { "content-type": "application/json" }); + res.end(JSON.stringify({ ok: true, phase: "pre-first-request", sessionId: null, contextTokens: 0 })); } else { + // Realistic full-session 200: a live tracked session (sessionId set). res.writeHead(200, { "content-type": "application/json" }); - res.end(JSON.stringify({ ok: true, contextTokens: 1234 })); + res.end(JSON.stringify({ ok: true, sessionId: "sess-carried", contextTokens: 1234 })); } return; } @@ -538,23 +546,29 @@ test("#1382: compaction cancel requires evidence the proxy carries this conversa await runOmpCase(true, true, "omp: proxy confirms carriage → announced auto compaction cancelled"); await runOmpCase(false, false, "omp: proxy never saw the conversation → announced auto compaction proceeds"); - // (H) omp identity register is NOT carriage evidence (#7060): the - // proxy reports the conversation unknown, so the plugin must NOT claim - // ownership — native compaction proceeds even though the identity - // register succeeded (registration populates registeredIds without - // creating a tracked session). - const identityProxy = await startFakeProxy({ statusOk: false }); + // (H) omp identity register is NOT carriage evidence (#7060): the proxy + // is UP and knows the id (identity registered + runtime-info reported) + // but has NEVER tracked a session for it — the status endpoint answers + // 200 pre-first-request with sessionId: null. That 200 is NOT carriage + // evidence, so the plugin must NOT claim ownership: native compaction + // proceeds. (The 404 "proxy never saw the conversation" shape is covered + // by runOmpCase(false, false) above.) + const identityProxy = await startFakeProxy({ statusPhase: "pre-first-request" }); try { await withEnv({ BILLION_CONTEXT_PROXY: identityProxy.origin }, async () => { const omp = makeFakePi(); createBiliPlugin("omp")(omp as never); // #1403: pck stamping (the identity signal) only fires for // destinations bili actually processes — route through /bili/. - const ctx = { ...httpCtx("sess-omp-id"), model: { contextWindow: 1000000, baseUrl: `${identityProxy.origin}/bili/https://api.example.com/v1` } }; + // model.id present so reportOmpRuntimeInfo fires (it is gated on a + // non-empty model id) — that is the precondition for the proxy to + // answer 200 pre-first-request, the real #7060 bypass shape. + const ctx = { ...httpCtx("sess-omp-id"), model: { id: "test-model", contextWindow: 1000000, baseUrl: `${identityProxy.origin}/bili/https://api.example.com/v1` } }; const payload = await omp.events.get("before_provider_request")!({ payload: { messages: [{ role: "user", content: "hi" }] } }, ctx); assert.equal((payload as { prompt_cache_key?: string })?.prompt_cache_key, "sess-omp-id", "identity registration completed with the request"); + assert.ok(identityProxy.runtimeInfos.some((r) => r.conversationId === "sess-omp-id"), "runtime-info was reported under the session id"); omp.events.get("auto_compaction_start")!({}, undefined); - assert.deepEqual(await omp.events.get("session_before_compact")!({}, ctx), undefined, "identity-registered session is NOT carried by construction — proxy reports unknown → native compaction proceeds"); + assert.deepEqual(await omp.events.get("session_before_compact")!({}, ctx), undefined, "identity-registered + runtime-info session is NOT carried — 200 pre-first-request (sessionId null) → native compaction proceeds"); }); } finally { await identityProxy.close();