Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
ce1da39
fix(overflow): recognize the native-intercept oversize-gate refusal a…
ranxianglei Nov 13, 2026
518b175
test(fork): name the straddled blocks on the resume-inheritance log l…
ranxianglei Nov 13, 2026
e072f19
Merge remote-tracking branch 'origin/master' into 2026-11-13_6122-gat…
ranxianglei Nov 13, 2026
cfa8ee4
fix(test): let the notice-registry suite see the fresh-install storag…
ranxianglei Nov 13, 2026
c6369fb
fix(tests): pin pure-sqlite selection in notice-registry suite
Nov 13, 2026
0a565fa
Merge origin/ci-fixes: converge notice-registry storage pin to the ci…
Nov 13, 2026
b1bc17b
fix(tests): pin BILI_STORAGE_JSON_WRITER=on in CCR cold-disk-restore …
Nov 14, 2026
cd8bc8a
Merge remote-tracking branch 'origin/master' into ci-fixes
Nov 14, 2026
a570049
Merge remote-tracking branch 'upstream/master' into wt-6548-ci-engine…
Nov 14, 2026
7492c35
fix(tests): pin BILI_STORAGE_JSON_WRITER=on in native opencode e2e lane
Nov 14, 2026
45f93db
fix(tests): pin BILI_STORAGE_JSON_WRITER=on in native dsh e2e lane
Nov 14, 2026
d67cc43
fix(tests): pin BILI_STORAGE_JSON_WRITER=on in pi codex-responses WS …
Nov 14, 2026
c392237
fix(tests): pin BILI_STORAGE_JSON_WRITER=on in pi package-native e2e …
Nov 14, 2026
974cd4c
fix(tests): pin BILI_STORAGE_JSON_WRITER=on in fork-ccr-adoption suite
Nov 14, 2026
271abba
fix(tests): pin BILI_STORAGE_JSON_WRITER=on in subagent-sessions e2e …
Nov 14, 2026
5d47196
fix(tests): pin BILI_STORAGE_JSON_WRITER=on in dsh-persona e2e lane
Nov 14, 2026
1ca4087
fix(tests): pin BILI_STORAGE_JSON_WRITER=on in update-state e2e lane
Nov 14, 2026
7b673c7
Merge remote-tracking branch 'origin/master' into ci-fixes
Nov 14, 2026
6b03788
merge ci-fixes: bring in the Windows EBUSY teardown fix (7c152dc08a) …
Nov 14, 2026
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
2 changes: 1 addition & 1 deletion src/fork-adoption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ export function maybeAdoptResume(args: {
session.state.timestampsHighWaterRefSeq = parent.state.timestampsHighWaterRefSeq;
log(
"info",
`[resume-inheritance] ${session.id} ${rel}: inherited ${seededRefs} ref(s) up to ${plan.maxRef || "n/a"}${plan.adoptedActive > 0 ? `, ${plan.adoptedActive} block(s) (~${plan.adoptedTokens} tokens)` : ""}; stale citations now resolve to their original messages (#1486)`,
`[resume-inheritance] ${session.id} ${rel}: inherited ${seededRefs} ref(s) up to ${plan.maxRef || "n/a"}${plan.adoptedActive > 0 ? `, ${plan.adoptedActive} block(s) (~${plan.adoptedTokens} tokens)` : ""}${plan.straddled > 0 ? `, ${plan.straddled} active block(s) straddled the fork point (adopted once fully present, #6122)` : ""}; stale citations now resolve to their original messages (#1486)`,
);
const wanted = new Set([...Object.keys(plan.refs.byRef), ...citedPlaceholderRefs(incomingMsgs)]);
const storeSlice = cloneStoreForRefs(contentStoreOf(parent), wanted);
Expand Down
14 changes: 14 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,20 @@ const CONTEXT_OVERFLOW_PATTERNS: RegExp[] = [
// ("Range of input length should be [1, 1000000]"), with no token or length
// subject phrase: unlisted here, the 400 is not an overflow and nothing arms.
/range of input length should be \[/i,
// #6122: the native-intercept gate's OWN oversize refusal (src/agent/
// native-intercept.ts) — bili's definitive "provably over window" signal.
// The field case: the gate refused an unattributed oversized body, the
// relay saw that refusal come back through the client as a 400, and — no
// parseable marker — logged the #4452 CANNOT-engage warning while the
// oversized history was re-sent on every turn (400 forever). The code
// covers all five oversize variants (bare / _fallback / _no_live_state /
// _unattributed / _unattributed_bytes). The compaction refusal
// (bili_gate_dsh_compaction_refused) is a different class (no proxy
// available, body fits fine) and must stay dark. No window number is
// learnable from the prose ("1,000,000 tokens" is a pricing FLOOR, not
// the model's window) — the no-window arm (min of judging window and
// payload estimate) is what engages.
/bili_gate_oversize_refusal/i,
];

function toTokenNumber(s: string): number | undefined {
Expand Down
39 changes: 39 additions & 0 deletions tests/context-overflow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,45 @@ test("empty body is NOT an overflow", () => {
assert.equal(inspectContextOverflow(400, "").isOverflow, false);
});

test("#6122: bili's own oversize-gate refusal (bili_gate_oversize_refusal*) is an overflow, window undefined", () => {
// Field case: the native-intercept gate refused an unattributed oversized
// body; the relay saw that refusal come back through the client as a 400
// and — with no parseable marker — logged the #4452 CANNOT-engage warning
// while the oversized history was re-sent every turn. bili's own refusal
// code IS the definitive over-window proof: it must read as an overflow so
// self-heal (same-request refold / emergency shrink) arms.
const body = JSON.stringify({
error: {
type: "server_error",
code: "bili_gate_oversize_refusal_unattributed",
message:
"billion-context refused this request locally: it is not attributed to any bili-managed session, and its core text is priced over the model's context window (conservative text pricing — every declared byte counts as text, and the bar is never assumed below the larger of the client-declared window and 1,000,000 tokens) — sending it directly to the provider can only be rejected (every retry re-sends the same oversized history, #4068). ",
retryable: false,
},
});
const info = inspectContextOverflow(400, body);
assert.equal(info.isOverflow, true, "the gate's own refusal must read as an overflow");
assert.equal(
info.window,
undefined,
"the 1,000,000 in the prose is a pricing FLOOR, not the model's window — the no-window arm (min of judging window and payload estimate) must fire",
);
// Every oversize variant shares the code prefix.
for (const code of [
"bili_gate_oversize_refusal",
"bili_gate_oversize_refusal_fallback",
"bili_gate_oversize_refusal_no_live_state",
"bili_gate_oversize_refusal_unattributed_bytes",
]) {
const v = inspectContextOverflow(400, JSON.stringify({ error: { type: "server_error", code } }));
assert.equal(v.isOverflow, true, `${code} must be recognized`);
}
// The compaction refusal is a different class (no proxy available, body
// fits fine) — it must stay dark.
const compaction = inspectContextOverflow(400, JSON.stringify({ error: { type: "server_error", code: "bili_gate_dsh_compaction_refused" } }));
assert.equal(compaction.isOverflow, false, "compaction refusal is not an over-window proof");
});

// reserveOutputHeadroom: the effective window handed to the kernel after
// reserving the model's per-request output budget. The kernel's nudge/truncate
// bands are a fraction of this window, so reserving maxOutput keeps the context
Expand Down
5 changes: 5 additions & 0 deletions tests/e2e/e2e-update-state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions tests/fork-ccr-adoption.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" };
Expand Down
25 changes: 25 additions & 0 deletions tests/issue4452-markerless-reject.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ const OPENAI_OVERFLOW_BODY = JSON.stringify({

const CJK_OVERFLOW_BODY = JSON.stringify({ error: { message: "上下文长度超出限制", type: "invalid_request_error" } });

// #6122 field case: bili's OWN oversize-gate refusal (native-intercept) came
// back through the client as a 400 and was logged as "no parseable overflow
// marker … CANNOT engage" — while it IS the definitive over-window proof.
const GATE_REJECTION_BODY = JSON.stringify({
error: {
type: "server_error",
code: "bili_gate_oversize_refusal_unattributed",
message:
"billion-context refused this request locally: it is not attributed to any bili-managed session, and its core text is priced over the model's context window (conservative text pricing — every declared byte counts as text, and the bar is never assumed below the larger of the client-declared window and 1,000,000 tokens) — sending it directly to the provider can only be rejected (every retry re-sends the same oversized history, #4068). ",
retryable: false,
},
});

test("generic gateway body on 413 is the markerless SIZE verdict and is flagged", () => {
// The first-order failure: the marker gate itself says "not overflow".
assert.equal(inspectContextOverflow(413, GENERIC_BODY).isOverflow, false);
Expand Down Expand Up @@ -77,6 +90,18 @@ test("5xx is excluded — those already self-heal via the local estimate (#604)"
assert.equal(isMarkerlessOverflowReject(507, GENERIC_BODY), false);
});

test("#6122: bili's own oversize-gate refusal is NOT markerless — self-heal engages from it", () => {
// The gate body IS the marker: it is bili's own definitive over-window
// proof. Reading it as an opaque gateway rewrite (the #4452 warn) is what
// left the #6122 child session 400-looping — the CANNOT-engage warning
// fires on its own refusal.
assert.equal(inspectContextOverflow(400, GATE_REJECTION_BODY).isOverflow, true);
assert.equal(isMarkerlessOverflowReject(400, GATE_REJECTION_BODY), false);
// …and the prose's "1,000,000 tokens" is a pricing floor, not a learnable
// model window — the no-window arm must be what fires, not a 1M learning.
assert.equal(inspectContextOverflow(400, GATE_REJECTION_BODY).window, undefined);
});

test("non-overflow 4xx and success codes are excluded (no false alarm on auth/malformed)", () => {
assert.equal(isMarkerlessOverflowReject(200, GENERIC_BODY), false);
assert.equal(isMarkerlessOverflowReject(401, GENERIC_BODY), false);
Expand Down
110 changes: 110 additions & 0 deletions tests/issue6122-fork-straddled-log.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import test from "node:test";
import assert from "node:assert/strict";
import { maybeAdoptResume, incomingCoreMessages } from "../src/fork-adoption.ts";
import { SessionStore, _setStoreForTest } from "../src/persist.ts";
import { type Session } from "../src/session.ts";

process.env.NODE_ENV = "test";

// #6122: a DSH fork that inherited 1 of 5 active blocks logged only the
// adopted count — the 4 straddling blocks were invisible in the log, so the
// field triage had to rebuild the ledger by hand to see what would (and when)
// still be adopted. The inherited line must name the straddled count, the
// way the lineage-reconcile line already does (#2807).

function fixtures(straddle: boolean) {
const parsed = {
model: "m",
max_tokens: 1,
messages: [
{ role: "user", content: "hello world 6122" },
{ role: "assistant", content: "hi there 6122" },
],
};
const msgs = incomingCoreMessages("anthropic", parsed)!;
const byRaw: Record<string, string> = {};
const byRef: Record<string, string> = {};
const tsStamps: Record<string, number> = {};
msgs.forEach((m, i) => {
const ref = `m${String(i + 1).padStart(5, "0")}`;
byRaw[m.id] = ref;
byRef[ref] = m.id;
tsStamps[m.id] = 1730000000 + i;
});
// b1 is fully present in the incoming core; b2 names a raw id the child
// never sent (a message the child's replay omitted) — it straddles.
const blocks = [
{ blockId: "b1", active: true, effectiveMessageIds: [msgs[0].id], directBlockIds: [], compressedTokens: 42 },
];
if (straddle) {
blocks.push({
blockId: "b2",
active: true,
effectiveMessageIds: [msgs[1].id, "raw-id-the-child-never-sent"],
directBlockIds: [],
compressedTokens: 13,
});
}
const meta = { protocol: "anthropic", upstreamOrigin: "test" };
const parent = {
id: "parent-6122",
meta,
blockContents: new Map(),
state: { blocks, tokenSnapshot: {}, nextBlockId: blocks.length + 1, nextRunId: 1, messageRefs: { byRaw, byRef }, tsStamps },
} as unknown as Session;
const child = {
id: "child-6122",
meta,
state: {
blocks: [] as unknown[],
tokenSnapshot: {} as Record<string, number>,
nextBlockId: 1,
nextRunId: 1,
messageRefs: { byRaw: {} as Record<string, string>, byRef: {} as Record<string, string> },
},
blockContents: new Map(),
} as unknown as Session;
return { parsed, parent, child };
}

test("#6122: the inherited line names the straddled active blocks", () => {
_setStoreForTest(new SessionStore({ enabled: false }));
const { parsed, parent, child } = fixtures(true);
const lines: string[] = [];
const outcome = maybeAdoptResume({
session: child,
parent,
sharedDepth: 0,
protocol: "anthropic",
parsed,
upstreamOrigin: "test",
blocksEnabled: true,
log: (_level, msg) => { lines.push(msg); },
});
const adoptLine = lines.find((l) => l.includes("inherited"));
assert.ok(adoptLine, "the inherited line was logged");
assert.equal(outcome.adoptedActive, 1, "only the fully-present block is adopted");
assert.ok(
adoptLine.includes("1 active block(s) straddled the fork point"),
`the straddled count must appear on the inherited line, got: ${adoptLine}`,
);
});

test("#6122: nothing straddling → the line keeps its pre-#6122 wording", () => {
_setStoreForTest(new SessionStore({ enabled: false }));
const { parsed, parent, child } = fixtures(false);
const lines: string[] = [];
maybeAdoptResume({
session: child,
parent,
sharedDepth: 0,
protocol: "anthropic",
parsed,
upstreamOrigin: "test",
blocksEnabled: true,
log: (_level, msg) => { lines.push(msg); },
});
const adoptLine = lines.find((l) => l.includes("inherited"));
assert.ok(adoptLine, "the inherited line was logged");
assert.ok(!adoptLine.includes("straddled"), `no straddle, no clause — got: ${adoptLine}`);
});
Loading