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
1 change: 1 addition & 0 deletions reference/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ billion-context/
│ ├── registry-snapshot.json # Bundled full models.dev snapshot (offline floor)
│ ├── session.ts # Session model + in-memory store (bounded, MAX_SESSIONS)
│ ├── session-id.ts # Session identity: client value verbatim + persona fork fingerprint
│ ├── snapshot-lane.ts # Proxy-lane snapshot id-pinning: stored ids stamped onto resends, identity-upgrade immunity (#3756)
│ ├── session-gc.ts # Session-file GC, opt-in (sessions.gc.* / BILI_SESSION_GC*) (#1082)
│ ├── persist.ts # On-disk session persistence (kernel StateStore)
│ ├── persist-eperm.ts # EPERM/EACCES write-failure alert layer (#362)
Expand Down
9 changes: 9 additions & 0 deletions src/rollout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ export const ROLLOUT_FEATURES: Record<string, RolloutPlan> = {
// `rollout.features.anthropicThreadsReforge: true` or
// `BILI_ROLLOUT_ANTHROPIC_THREADS_REFORGE=1`.
anthropicThreadsReforge: { percent: 0 },
// #3756 snapshot lane: proxy-lane outbound history is pinned onto the
// server-side unified-store snapshot so historical message ids are never
// re-minted by a kernel identity-function change (#3752 R2 root fix).
// Default 0% — every session keeps today's derive-on-resend behavior;
// unsupported shapes always pass through byte-identical even when on.
// Also requires the unified store to be live (shadow or full). Force on
// with `rollout.features.proxySnapshotLane: true` or
// `BILI_ROLLOUT_PROXY_SNAPSHOT_LANE=1`.
proxySnapshotLane: { percent: 0 },
};

export const BP_MAX = 10_000;
Expand Down
6 changes: 5 additions & 1 deletion src/server/prepare-anthropic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { countSystemAndToolsTokens, emergencyNudge, emergencyNudgeArmed, project
import { effectiveAbsorbBlock } from "./prepare-responses.js";
import { injectSystem, injectTool } from "./inject.js";
import { nudgeOn, resolveLaneDecisions } from "./lane-decisions.js";
import { pinSnapshotIds } from "../snapshot-lane.js";

export async function prepareAnthropic(
parsed: AnthropicRequestBody,
Expand Down Expand Up @@ -194,7 +195,10 @@ export async function prepareAnthropic(
logRawStripCounts(markerCounts, log, sessionId);

try {
const { msgs, cacheControls } = anthropicToCore(parsed);
const { msgs: parsedMsgs, cacheControls } = anthropicToCore(parsed);
// #3756: pin historical ids onto the server-side snapshot before any
// downstream metering/mutation (alignment runs on pristine parse bytes).
const msgs = pinSnapshotIds({ sessionId, protocol: "anthropic", pluginMode, msgs: parsedMsgs, state: session.state, log });
originalMessages = msgs;
// #1320: signature-only thinking blocks bill restored thinking tokens upstream
// but project as empty text locally — attribute the provider-vs-local residual
Expand Down
6 changes: 5 additions & 1 deletion src/server/prepare-openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { clampOutgoingOutput, countSystemAndToolsTokens, dshLedgerFloorTokens, e
import { effectiveAbsorbBlock } from "./prepare-responses.js";
import { injectOpenaiTool, injectTool } from "./inject.js";
import { nudgeOn, resolveLaneDecisions } from "./lane-decisions.js";
import { pinSnapshotIds } from "../snapshot-lane.js";

export async function prepareOpenai(
parsed: OpenAIRequestBody,
Expand Down Expand Up @@ -101,7 +102,10 @@ export async function prepareOpenai(
// OUT of the fold space: system content is host runtime state and
// must not feed ids/fingerprints. Capture it and re-inject below —
// otherwise the proxy would forward payloads without any system.
const { msgs, systemText } = openaiToCore(parsed);
const { msgs: parsedMsgs, systemText } = openaiToCore(parsed);
// #3756: pin historical ids onto the server-side snapshot (proxy lane
// only; passthrough byte-identical whenever the lane does not engage).
const msgs = pinSnapshotIds({ sessionId, protocol: "openai", pluginMode, msgs: parsedMsgs, state: session.state, log });
openaiSystemText = systemText;
warnDroppedOpenaiParts(parsed, sessionId, log);
// Title-gen side-requests carry their own tiny system — reconciling
Expand Down
5 changes: 4 additions & 1 deletion src/server/prepare-responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { applyImageRescaleItems } from "../image-rescale.js";
import { clampOutgoingOutput, countLoadedToolTokens, countSystemAndToolsTokens, dshLedgerFloorTokens, emergencyNudge, emergencyNudgeArmed, modelVisibleTools } from "./budget.js";
import { FORCE_TEXT_PROTOCOL, injectResponsesTool, injectTool } from "./inject.js";
import { nudgeOn, resolveLaneDecisions } from "./lane-decisions.js";
import { pinSnapshotIds } from "../snapshot-lane.js";

export async function prepareResponses(
parsed: ResponsesRequestBody,
Expand Down Expand Up @@ -206,7 +207,9 @@ export async function prepareResponses(
sysNotes = outcome.notes;
if (outcome.outbound !== fresh) projection.systemParts = outcome.outbound ? [outcome.outbound] : [];
}
const { msgs } = projection;
// #3756: pin historical ids onto the server-side snapshot (proxy lane
// only; passthrough byte-identical whenever the lane does not engage).
const msgs = pinSnapshotIds({ sessionId, protocol: "responses", pluginMode, msgs: projection.msgs, state: session.state, log });
originalMessages = msgs;
if (opts.debug) {
log("info", `[${sessionId}] input items: ${Array.isArray(parsed.input) ? parsed.input.map((i: ResponseInputItem) => i.type).join(",") : "(string)"}`);
Expand Down
Loading
Loading