Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/rollout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,13 @@ export const ROLLOUT_FEATURES: Record<string, RolloutPlan> = {
// 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
Expand Down
17 changes: 8 additions & 9 deletions src/server/handle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown>)[MSG_IDS_BODY_FIELD] = [...inboundMsgIds];
}
// #5719: the RECORDED side of the msgid identity rung lives in the
Expand Down
29 changes: 28 additions & 1 deletion src/server/prepare-google.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -88,6 +90,12 @@ export async function prepareGoogle(
): Promise<Prepared> {
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<string, unknown>)[MSG_IDS_BODY_FIELD];
delete (parsed as Record<string, unknown>)[MSG_IDS_BODY_FIELD];
const inboundMessageCount = Array.isArray(parsed.contents) ? parsed.contents.length : 1;
let googleClientSystem = "";
let sysNotes: string[] = [];
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down
29 changes: 28 additions & 1 deletion src/server/prepare-responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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<string, unknown>)[MSG_IDS_BODY_FIELD];
delete (parsed as Record<string, unknown>)[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<string>();
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tests/openai-msgid-pin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown>;
assert.equal(bodyB.biliMsgIds, undefined, "strip is unconditional even when rollout is off");
Expand Down
4 changes: 2 additions & 2 deletions tests/plugin-render-endpoint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async function harness(gateOn: boolean): Promise<Harness> {
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();
Expand Down Expand Up @@ -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();
}
Expand Down
Loading