diff --git a/src/rollout.ts b/src/rollout.ts index 4ff2ace44b..07e5db8d11 100644 --- a/src/rollout.ts +++ b/src/rollout.ts @@ -96,8 +96,13 @@ export const ROLLOUT_FEATURES: Record = { // serve the outbound prefix from the server-owned transcript // (POST /__bili/plugin/render). The id-set algebra classifies vanishing // cohorts (compressed vs deleted) and detects generation switches. - // Default 0% — force on with `BILI_ROLLOUT_PLUGIN_LANE_SERVER_HISTORY=1`. - pluginLaneServerHistory: { percent: 0 }, + // GA (#6525/#6539, owner ruling 2026-11-13): pinned by default. The pin is + // the intended end-state of the msgid identity infrastructure — stamped + // ids become the recorded `messages.msg_id` so the resolve/settlement/fork + // consumers read real host identity, not content digests. The render + // endpoint it co-gates is inert until a client opts in (none calls it yet). + // Roll back with `BILI_ROLLOUT_PLUGIN_LANE_SERVER_HISTORY=0`. + pluginLaneServerHistory: { percent: 100 }, // #5825 identity-channel harvest seam (registry in identity-harvest.ts): // loopback clients without an explicit body channel get stable session+ // message identity aligned from their OWN local transcript/sqlite diff --git a/src/server/handle.ts b/src/server/handle.ts index 0166ebde6b..53c21f4918 100644 --- a/src/server/handle.ts +++ b/src/server/handle.ts @@ -1320,15 +1320,14 @@ async function handleRequest( } } } - // The pin-consumers are prepare-anthropic AND prepare-openai (#5825 - // parity): both read + strip MSG_IDS_BODY_FIELD unconditionally before - // it can reach the real upstream, then pin behind the rollout gate. - // So a non-body source (header / harvest) stamps the parsed body on - // BOTH wires now — nothing extra is ever forwarded either way; - // response-ish protocols keep feeding the resolve rung below via this - // local alone. - if (stampedInboundMsgIds === undefined && inboundMsgIds !== undefined && - (protocol === "openai" || protocol === "anthropic")) { + // The pin-consumers are prepare-openai, prepare-anthropic AND + // prepare-google/prepare-responses (#6525): all four read + strip + // MSG_IDS_BODY_FIELD unconditionally before it can reach the real + // upstream, then pin behind the rollout gate. So a non-body source + // (header / harvest) stamps the parsed body on EVERY wire now — + // nothing extra is ever forwarded either way, and a length/shape + // mismatch is rejected (bail) at the pin, never leaked or mis-pinned. + if (stampedInboundMsgIds === undefined && inboundMsgIds !== undefined) { (parsed as Record)[MSG_IDS_BODY_FIELD] = [...inboundMsgIds]; } // #5719: the RECORDED side of the msgid identity rung lives in the diff --git a/src/server/prepare-google.ts b/src/server/prepare-google.ts index f85b4dc1c1..39dc417939 100644 --- a/src/server/prepare-google.ts +++ b/src/server/prepare-google.ts @@ -3,6 +3,8 @@ import type { CompressionCore, Config, CoreMessage, NudgeDecision, PackSurface, import { renderNudgeText, viableRanges } from "acp-kernel"; import { coreToGoogle, googleToCore, normalizeGoogleUserPartOrder, type BiliMessage, type GoogleContent, type GoogleRequestBody, type GoogleSystemInstruction, type GoogleTool } from "acp-kernel/wire"; import type { ProxyOptions } from "../config.js"; +import { MSG_IDS_BODY_FIELD, applyMsgIdPin, validateMsgIds } from "../msgid-pin.js"; +import { featureEnabled } from "../rollout.js"; import { pluginAgentHeader } from "../plugin.js"; import { currentCalibrationFactor } from "../util.js"; import { diagNudge, diagTagSummary, deriveTitle, effectiveTokenCount, imageBillingFor, imageReserveFor, imageTokenCapFor, isAutoInjectedNotification, reapOrphansLogged, resolveKnownOutputCeiling, runNudgeDecision, stripKernelSummaries, usageGradeInputBaseline, type Prepared } from "../server.js"; @@ -88,6 +90,12 @@ export async function prepareGoogle( ): Promise { const sessionId = session.id; ++session.stats.requests; + // #6525: the client may stamp the envelope (`biliMsgIds`) on plugin-wire + // full-resend turns. Read + strip it before anything can reach the real + // upstream, then pin behind the rollout gate (same contract as the openai/ + // anthropic twins). Nothing extra is ever forwarded either way. + const incomingMsgIds = (parsed as Record)[MSG_IDS_BODY_FIELD]; + delete (parsed as Record)[MSG_IDS_BODY_FIELD]; const inboundMessageCount = Array.isArray(parsed.contents) ? parsed.contents.length : 1; let googleClientSystem = ""; let sysNotes: string[] = []; @@ -123,7 +131,9 @@ export async function prepareGoogle( logRawStripCounts(markerCounts, log, sessionId); try { - const { msgs, systemText } = googleToCore(parsed); + const coreOut = googleToCore(parsed); + let msgs = coreOut.msgs; + const systemText = coreOut.systemText; googleClientSystem = systemText; // Title-gen side-requests carry their own tiny system — reconciling // them would pollute the conversation's anchor state. @@ -133,6 +143,23 @@ export async function prepareGoogle( googleClientSystem = outcome.outbound; } originalMessages = msgs; + // #6525/#4491 parity: pin identity to client-supplied ids (plugin lanes + // only — pure proxy traffic has no msgid channel), the SAME gated + // contract as the openai/anthropic twins. No watermark fast-path on + // this wire, so there is no `wpHit` skip. + if (pluginMode && incomingMsgIds !== undefined) { + if (featureEnabled("pluginLaneServerHistory")) { + const v = validateMsgIds(incomingMsgIds, msgs.length); + if (v.ok) { + msgs = applyMsgIdPin(msgs, v.ids); + originalMessages = msgs; + } else { + log("warn", `[${sessionId}] [msgid] google-wire pin rejected (${v.reason}) — falling back to content-derived ids (#4491/#6525)`); + } + } else { + log("info", `[${sessionId}] [msgid] google-wire biliMsgIds present but pluginLaneServerHistory rollout is off for this install — field stripped, ids not pinned (#6525)`); + } + } // #3756 snapshot render: the outbound prefix renders from the unified // transcript (server-authoritative, fold-time ids — immune to identity // re-mints #3752); only the live tail keeps the client's bytes. diff --git a/src/server/prepare-responses.ts b/src/server/prepare-responses.ts index bd9b491f2a..2a5ffda381 100644 --- a/src/server/prepare-responses.ts +++ b/src/server/prepare-responses.ts @@ -5,6 +5,8 @@ import { injectResponsesDeveloperMessage, type BiliMessage, type ResponseInputIt import type { CompressReasoningConfig } from "../reasoning-drop.js"; import { resolveAbsorbSettings } from "../compress-settings.js"; import { effectivePromptCacheRouting, resolveCompressProtocol, type CompressSettings, type ProxyOptions } from "../config.js"; +import { MSG_IDS_BODY_FIELD, applyMsgIdPin, validateMsgIds } from "../msgid-pin.js"; +import { featureEnabled } from "../rollout.js"; import { currentCalibrationFactor, strippedResponseIdWarning } from "../util.js"; import { applyReasoningDrop, diagNudge, diagTagSummary, deriveTitle, effectiveTokenCount, imageBillingFor, imageReserveFor, imageTokenCapFor, isAutoInjectedNotification, planReasoningDrop, reapOrphansLogged, resolveKnownOutputCeiling, runNudgeDecision, stripKernelSummaries, usageGradeInputBaseline, warnResponsesReasoningPairs, type Prepared } from "../server.js"; import { collectSeparatorManifest, repairResponsesAssistantOrdering, type SeparatorSlot } from "./responses-ordering.js"; @@ -72,6 +74,12 @@ export async function prepareResponses( const inboundMessageCount = Array.isArray(parsed.input) ? parsed.input.length : 1; const stream = parsed.stream === true; ++session.stats.requests; + // #6525: the client may stamp the envelope (`biliMsgIds`) on plugin-wire + // full-resend turns. Read + strip it before anything can reach the real + // upstream, then pin behind the rollout gate (same contract as the openai/ + // anthropic twins). Nothing extra is ever forwarded either way. + const incomingMsgIds = (parsed as Record)[MSG_IDS_BODY_FIELD]; + delete (parsed as Record)[MSG_IDS_BODY_FIELD]; // #3222: #651's reasoning-drop plan, computed on the INBOUND history before // core.processTurn — see planReasoningDrop for why the post-turn view is too late. let reasoningPlan = new Set(); @@ -242,8 +250,27 @@ export async function prepareResponses( sysNotes = outcome.notes; if (outcome.outbound !== fresh) projection.systemParts = outcome.outbound ? [outcome.outbound] : []; } - const { msgs } = projection; + const { msgs: msgsIn } = projection; + let msgs = msgsIn; originalMessages = msgs; + // #6525/#4491 parity: pin identity to client-supplied ids (plugin lanes + // only), the SAME gated contract as the openai/anthropic twins. The + // store path (core.processTurn below) reads `projection.msgs` directly, + // so keep it in sync with the pinned array. + if (pluginMode && incomingMsgIds !== undefined) { + if (featureEnabled("pluginLaneServerHistory")) { + const v = validateMsgIds(incomingMsgIds, msgs.length); + if (v.ok) { + msgs = applyMsgIdPin(msgs, v.ids); + projection.msgs = msgs; + originalMessages = msgs; + } else { + log("warn", `[${sessionId}] [msgid] responses-wire pin rejected (${v.reason}) — falling back to content-derived ids (#4491/#6525)`); + } + } else { + log("info", `[${sessionId}] [msgid] responses-wire biliMsgIds present but pluginLaneServerHistory rollout is off for this install — field stripped, ids not pinned (#6525)`); + } + } // #3756 snapshot render: outbound prefix from the unified transcript // (fold-time ids, immune to identity re-mints); live tail keeps the // client's bytes. No-op when the lane is inactive/degraded; the diff --git a/tests/openai-msgid-pin.test.ts b/tests/openai-msgid-pin.test.ts index 1f2f085b3c..f6125ded77 100644 --- a/tests/openai-msgid-pin.test.ts +++ b/tests/openai-msgid-pin.test.ts @@ -126,7 +126,8 @@ test("openai wire: biliMsgIds never reach the upstream; rows carry client ids on assert.deepEqual(idsA.sort(), ["open-a-1", "open-u-1", "open-u-2"].sort(), "rows carry the CLIENT ids (pin)"); // Turn B: rollout OFF — same channel, stripped, NOT pinned. - delete process.env[ROLLOUT_ENV]; + // Force off explicitly (the default is now GA-on, #6525). + process.env[ROLLOUT_ENV] = "0"; await post("conv-openai-nopin"); const bodyB = JSON.parse(forwardedOf("question-two conv-openai-nopin")) as Record; assert.equal(bodyB.biliMsgIds, undefined, "strip is unconditional even when rollout is off"); diff --git a/tests/plugin-render-endpoint.test.ts b/tests/plugin-render-endpoint.test.ts index 345803d0f7..41193891d8 100644 --- a/tests/plugin-render-endpoint.test.ts +++ b/tests/plugin-render-endpoint.test.ts @@ -43,7 +43,7 @@ async function harness(gateOn: boolean): Promise { for (const key of ["XDG_STATE_HOME", "XDG_DATA_HOME", "XDG_CACHE_HOME", "XDG_CONFIG_HOME"]) process.env[key] = dir; process.env.BILI_STORAGE_UNIFIED = "full"; if (gateOn) process.env.BILI_ROLLOUT_PLUGIN_LANE_SERVER_HISTORY = "1"; - else delete process.env.BILI_ROLLOUT_PLUGIN_LANE_SERVER_HISTORY; + else process.env.BILI_ROLLOUT_PLUGIN_LANE_SERVER_HISTORY = "0"; _resetSessionsForTest(); _resetPluginStateForTest(); resetToolRingForTest(); @@ -123,7 +123,7 @@ test("probe advertises serverHistory with the gate state (capability discovery)" try { const p = await off.probe(); assert.equal(p.status, 200); - assert.equal(p.body.serverHistory, false, "default rollout 0% = capability hidden"); + assert.equal(p.body.serverHistory, false, "gate forced off = capability hidden"); } finally { await off.close(); }