Skip to content
Merged
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
10 changes: 10 additions & 0 deletions scripts/gate/bili-gate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ TURN_MS=$(jget turnTimeoutMs "300000")
AGENTS=$(jget agents "dsh,pi,codex,opencode,claude,dsh-google")
AGENTS_R=$(jget agentsR "dsh,pi")
SNAPBASE=$(jget snapBase "")
LANE_SCRIPT=$(jget laneScript "")
SNAP_RENDER=$(jget snapshotRender "")
R_CORPUS=$(jget r.corpusTokens "80000")
R_WINDOW=$(jget r.window "16384")
R_CAP=$(jget r.capRatio "0.4")
Expand Down Expand Up @@ -115,6 +117,14 @@ if [ -n "$GIT_PROXY" ]; then RUN+=(-e GATE_GIT_PROXY="$GIT_PROXY"); fi
# Must be appended AFTER the RUN=(...) init above — an earlier append is wiped
# by the reassignment.
if [ -n "$SNAPBASE" ]; then RUN+=(-e GATE_SNAPBASE="$SNAPBASE"); fi
# GATE_LANE_SCRIPT: force the P-lane harness script copy (e.g. the bundled
# /gate-tools/plugin-lanes.mjs when the candidate predates a harness fix —
# the entrypoint prefers the candidate's OWN scripts/gate copy when present).
if [ -n "$LANE_SCRIPT" ]; then RUN+=(-e GATE_LANE_SCRIPT="$LANE_SCRIPT"); fi
# GATE_SNAPSHOT_RENDER: force the candidate's snapshotRender egress body
# plane live in the P/R lane bili.json (config tier — the env tier never
# reaches the lane proxies because cleanEnv() strips BILI_* by design).
if [ -n "$SNAP_RENDER" ]; then RUN+=(-e GATE_SNAPSHOT_RENDER="$SNAP_RENDER"); fi
if [ "$NETWORK" = "bridge" ]; then
RUN+=(--add-host=host.docker.internal:host-gateway)
else
Expand Down
4 changes: 4 additions & 0 deletions scripts/gate/config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
"agentsR": "",
"_doc_snapBase": "P/R lanes only: run the candidate's snapBase egress plane (storage.snapBase) ON in the gate's bili.json. \"all\" = every protocol cohort; \"openai,responses,anthropic,google\" subset = explicit cohorts; absent or \"off\" = off (byte-identical gate). For candidate-branch verification (e.g. #6785).",
"snapBase": "",
"_doc_laneScript": "Optional: force the P-lane harness script copy, e.g. \"/gate-tools/plugin-lanes.mjs\". Needed when the candidate checkout predates a harness fix (the gate otherwise prefers the candidate's OWN scripts/gate/plugin-lanes.mjs).",
"laneScript": "",
"_doc_snapshotRender": "Optional: \"1\" writes rollout.features.snapshotRender=true into the P/R lane bili.json (config tier, beats the 0% rollout default) so the candidate's snapshotRender egress body plane renders live. Plugin-mode lanes (dsh profile bundle, pi native) stay client-authoritative by design.",
"snapshotRender": "",
"r": {
"corpusTokens": 80000,
"window": 16384,
Expand Down
16 changes: 15 additions & 1 deletion scripts/gate/plugin-lanes.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,19 @@ export function gateStorageCfg() {
const cohorts = v.toLowerCase() === "all" ? [] : v.split(",").map((x) => x.trim()).filter(Boolean);
return { storage: cohorts.length ? { snapBase: { enabled: true, cohorts } } : { snapBase: { enabled: true } } };
}

// GATE_SNAPSHOT_RENDER (#6785 verification): flip the candidate's snapshotRender
// egress body plane LIVE through the CONFIG tier —
// rollout.features.snapshotRender=true (a forced-on shorthand the rollout
// resolver honors above bucketing). The env tier
// (BILI_ROLLOUT_SNAPSHOT_RENDER) does NOT reach the lane proxies: cleanEnv()
// strips BILI_* from the spawn env by design (2026-11-16 gate run 3 showed
// snapshotRender=off(bucket) with the env set).
export function gateRolloutCfg() {
const v = String(process.env.GATE_SNAPSHOT_RENDER || "");
if (!v || v === "0" || v.toLowerCase() === "off") return {};
return { rollout: { features: { snapshotRender: true } } };
}
const MODEL_MAIN = MODEL_IDS[0];
const AGENTS = (process.env.GATE_AGENTS || "dsh,pi,codex,opencode,claude")
.split(",").map((s) => s.trim().toLowerCase()).filter(Boolean);
Expand Down Expand Up @@ -289,6 +302,7 @@ async function runLane(agent, recipe) {
},
compress: { preserveRecentTokens: 0 },
...gateStorageCfg(),
...gateRolloutCfg(),
}, null, 2));
writeWindow(BIG_WINDOW);

Expand Down Expand Up @@ -373,7 +387,7 @@ async function runLane(agent, recipe) {
// the corpus middle — models sometimes elide it despite the chunk-read
// instruction (observed in proxy mode). Verify the precondition at t1
// instead of letting downstream recalls fail for fixture reasons.
const t1 = await recipe.turn(ctx, `Read corpus.md in your cwd fully (~1300 lines). Your read tool may truncate or ELIDE the middle of a long file (e.g. claude-code's Read shows head+tail with "... N lines elided ...") — read in sequential chunks (offset 1, 201, 401, …, ~200 lines each, or equivalent line-range calls) until you have seen EVERY line including the middle; do not stop at a truncation or elision. Then reply with ONLY the TITLE lines of sections S40 and S07 (one per line). Do not run any other tool or command.`, sid, "t1");
const t1 = await recipe.turn(ctx, `Read corpus.md in your cwd fully (it is ${fs.readFileSync(path.join(laneDir, "work", "corpus.md"), "utf8").split("\n").length} lines — do not stop early because the file looks shorter than you expected). Your read tool may truncate or ELIDE the middle of a long file (e.g. claude-code's Read shows head+tail with "... N lines elided ...") — read in sequential chunks (offset 1, 201, 401, …, ~200 lines each, or equivalent line-range calls) until you have seen EVERY line including the middle; do not stop at a truncation or elision. Then reply with ONLY the TITLE lines of sections S40 and S07 (one per line). Do not run any other tool or command.`, sid, "t1");
fs.writeFileSync(path.join(ctx.laneDir, `turn-t1.txt`), t1.out || "");
record(agent, "t1 read @ big window completes", t1.ok, t1.why.slice(0, 160));
record(agent, "S40 marker answered (t1)", MARK_RE(39).test(t1.out), `"${t1.out.trim().slice(0, 80)}"`);
Expand Down
4 changes: 2 additions & 2 deletions scripts/gate/restart-lanes.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ import { spawn, spawnSync } from "node:child_process";
import fs from "node:fs";
import net from "node:net";
import path from "node:path";
import { buildCorpus, CODEWORDS, gateStorageCfg } from "./plugin-lanes.mjs";
import { buildCorpus, CODEWORDS, gateStorageCfg, gateRolloutCfg } from "./plugin-lanes.mjs";

const HERE = path.dirname(new URL(import.meta.url).pathname);
const WORK = process.env.RESTART_LANES_WORK || path.join(process.env.WORKDIR || process.cwd(), "restart-lanes");
Expand All @@ -86,7 +86,7 @@ const MODEL1 = {
};
const MODEL_IDS = String(MODEL1.model).split(",").map((s) => s.trim()).filter(Boolean);

const laneCfg = (providers) => ({ providers, compress: { preserveRecentTokens: 0 }, ...gateStorageCfg() });
const laneCfg = (providers) => ({ providers, compress: { preserveRecentTokens: 0 }, ...gateStorageCfg(), ...gateRolloutCfg() });
const MODEL_MAIN = MODEL_IDS[0];
const AGENTS = (process.env.GATE_AGENTS_R || process.env.GATE_AGENTS || "dsh,pi")
.split(",").map((s) => s.trim().toLowerCase()).filter(Boolean);
Expand Down
6 changes: 6 additions & 0 deletions tests/issue4612-gc-online-guard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,17 @@ test("#4612: zero-ref sweep deletes every garbage row in batches with progress l
// line lands every 10th batch plus always on the final batch
const raw = new DatabaseSync(dbPath);
try {
// One transaction: 21,000 autocommit inserts would pay one fsync
// per row (WAL + synchronous=FULL) — ~17 min on slow-fsync disks,
// past the runner timeout (#4599). BEGIN/COMMIT collapses it to a
// single fsync without changing the resulting row set.
raw.exec("BEGIN");
const ins = raw.prepare("INSERT INTO content (hash, byte_len, refcount, algo, bytes) VALUES (?, ?, 0, 'sha256', ?)");
for (let i = 0; i < N; i++) {
const body = Buffer.from(`zero-ref body ${i}`);
ins.run(`4612-zero-ref-${i}`, body.length, body);
}
raw.exec("COMMIT");
} finally {
raw.close();
}
Expand Down
8 changes: 8 additions & 0 deletions tests/storage-durability.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ test("quick_check: a corrupt db fails open with a typed error, files left UNTOUC
raw[i] = raw[i] ^ 0xff;
}
writeFileSync(path, raw);
// The flip keeps size + mtime (4 ms granularity), so the #4609 verdict
// cache (index.db.chk) would still match and skip quick_check — drop it
// so the reopen re-scans from fresh evidence (#4599).
rmSync(`${path}.chk`, { force: true });

// 3. Reopen — must fail with a typed, greppable integrity error
// (migrations must never run against a corrupt file).
Expand Down Expand Up @@ -146,6 +150,10 @@ test("shadow open ALARMS on a corrupt index.db set — nothing renamed, boot pro
raw[i] = raw[i] ^ 0xff;
}
writeFileSync(path, raw);
// Drop the #4609 verdict cache: the flip keeps size + mtime, so a
// cached "ok" would skip quick_check and the shadow would open the
// corrupt set instead of alarming (#4599).
rmSync(`${path}.chk`, { force: true });
const beforeHash = createHash("sha256").update(raw).digest("hex");

// The shadow's maybeOpen (full mode) must ALARM, not refuse — come
Expand Down
46 changes: 30 additions & 16 deletions tests/wire-exit-matrix.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,25 +217,39 @@ mitm: { enabled: false, domains: [] },
}

/** Opens a request, waits for the first body byte (or headers for JSON),
* then destroys the client socket — simulating a user hitting Ctrl-C. */
function abortAfterFirstByte(url: string, headers: Record<string, string>, body: string): Promise<"header" | "first-byte"> {
* then destroys the client socket — simulating a user hitting Ctrl-C.
* `ready` (when given) must hold before the socket is destroyed: the abort
* only has an upstream socket to tear down once the proxy has actually
* forwarded, and the 400 ms fallback used to fire first on slow runners,
* leaving requests=0 / closed=0 (#4599). The wait is capped so a genuine
* forward hang still fails the teardown assertion. */
function abortAfterFirstByte(url: string, headers: Record<string, string>, body: string, ready?: () => boolean): Promise<"header" | "first-byte"> {
return new Promise((resolve, reject) => {
let done = false;
const req = http.request(url, { method: "POST", headers }, (res) => {
res.once("data", () => {
req.destroy();
resolve("first-byte");
});
res.once("data", () => finish("first-byte"));
// hang-json never sends a body — abort on headers after a beat.
res.once("end", () => resolve("header"));
res.once("end", () => finish("header"));
});
req.on("error", (e: NodeJS.ErrnoException) => {
if (e.code === "ECONNRESET") resolve("first-byte");
if (e.code === "ECONNRESET") finish("first-byte");
else reject(e);
});
setTimeout(() => {
req.destroy();
resolve("header");
}, 400).unref();
setTimeout(() => finish("header"), 400).unref();
function finish(outcome: "header" | "first-byte"): void {
if (done) return;
done = true;
const t0 = Date.now();
const destroy = (): void => {
req.destroy();
resolve(outcome);
};
const waitReady = (): void => {
if (!ready || ready() || Date.now() - t0 > 5000) destroy();
else setTimeout(waitReady, 25).unref();
};
waitReady();
}
req.end(body);
});
}
Expand Down Expand Up @@ -267,7 +281,7 @@ test("abort x proxy-openai-sse: client abort mid-stream destroys the upstream re
const proxyPort = (proxy.address() as { port: number }).port;
try {
const url = `http://127.0.0.1:${proxyPort}/bili/http://127.0.0.1:${up.port}/v1/chat/completions`;
const outcome = await abortAfterFirstByte(url, { "content-type": "application/json", "x-acp-session": "mx-abort-oai" }, JSON.stringify({ model: "m-test", max_tokens: 1024, stream: true, messages: [{ role: "user", content: "hi" }] }));
const outcome = await abortAfterFirstByte(url, { "content-type": "application/json", "x-acp-session": "mx-abort-oai" }, JSON.stringify({ model: "m-test", max_tokens: 1024, stream: true, messages: [{ role: "user", content: "hi" }] }), () => up.requests() >= 1);
assert.ok(outcome === "first-byte" || outcome === "header");
await awaitUpstreamTeardown(up.socketsClosed);
assert.ok(up.socketsClosed() >= 1, `upstream socket(s) must be destroyed after the client abort (closed=${up.socketsClosed()})`);
Expand All @@ -289,7 +303,7 @@ test("abort x proxy-anthropic-sse: client abort mid-stream destroys the upstream
const proxyPort = (proxy.address() as { port: number }).port;
try {
const url = `http://127.0.0.1:${proxyPort}/bili/http://127.0.0.1:${up.port}/v1/messages`;
await abortAfterFirstByte(url, { "content-type": "application/json", "x-acp-session": "mx-abort-ant" }, JSON.stringify({ model: "m-test", max_tokens: 1024, stream: true, messages: [{ role: "user", content: "hi" }] }));
await abortAfterFirstByte(url, { "content-type": "application/json", "x-acp-session": "mx-abort-ant" }, JSON.stringify({ model: "m-test", max_tokens: 1024, stream: true, messages: [{ role: "user", content: "hi" }] }), () => up.requests() >= 1);
await awaitUpstreamTeardown(up.socketsClosed);
assert.ok(up.socketsClosed() >= 1, `upstream socket(s) destroyed after client abort (closed=${up.socketsClosed()})`);
} finally {
Expand All @@ -309,7 +323,7 @@ test("abort x proxy-responses-sse: client abort mid-stream destroys the upstream
const proxyPort = (proxy.address() as { port: number }).port;
try {
const url = `http://127.0.0.1:${proxyPort}/bili/http://127.0.0.1:${up.port}/v1/responses`;
await abortAfterFirstByte(url, { "content-type": "application/json", "x-acp-session": "mx-abort-resp" }, JSON.stringify({ model: "m-test", max_tokens: 1024, stream: true, instructions: "You are a test agent.", input: [{ type: "message", role: "user", content: "hi" }] }));
await abortAfterFirstByte(url, { "content-type": "application/json", "x-acp-session": "mx-abort-resp" }, JSON.stringify({ model: "m-test", max_tokens: 1024, stream: true, instructions: "You are a test agent.", input: [{ type: "message", role: "user", content: "hi" }] }), () => up.requests() >= 1);
await awaitUpstreamTeardown(up.socketsClosed);
assert.ok(up.socketsClosed() >= 1, `upstream socket(s) destroyed after client abort (closed=${up.socketsClosed()})`);
} finally {
Expand All @@ -329,7 +343,7 @@ test("abort x proxy-json: client abort while the JSON is buffering destroys the
const proxyPort = (proxy.address() as { port: number }).port;
try {
const url = `http://127.0.0.1:${proxyPort}/bili/http://127.0.0.1:${up.port}/v1/chat/completions`;
await abortAfterFirstByte(url, { "content-type": "application/json", "x-acp-session": "mx-abort-json" }, JSON.stringify({ model: "m-test", max_tokens: 1024, messages: [{ role: "user", content: "hi" }] }));
await abortAfterFirstByte(url, { "content-type": "application/json", "x-acp-session": "mx-abort-json" }, JSON.stringify({ model: "m-test", max_tokens: 1024, messages: [{ role: "user", content: "hi" }] }), () => up.requests() >= 1);
await awaitUpstreamTeardown(up.socketsClosed);
assert.ok(up.socketsClosed() >= 1, `upstream socket(s) destroyed after client abort (closed=${up.socketsClosed()})`);
} finally {
Expand Down
Loading