From 2eba41f34edeabd1a693e65f07c0cb054d2ca80c Mon Sep 17 00:00:00 2001 From: awork Date: Sat, 17 Oct 2026 15:02:03 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20gate-refusal=20log=20no=20longer=20claim?= =?UTF-8?q?s=20"sent=20DIRECT"=20=E2=80=94=20egress=20is=20decided=20after?= =?UTF-8?q?=20the=20gate=20(#3499)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/agent/dsh-native.ts | 13 ++++++++++--- tests/dsh-native.test.ts | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/agent/dsh-native.ts b/src/agent/dsh-native.ts index 86cff1b3c1..5e7de9861c 100644 --- a/src/agent/dsh-native.ts +++ b/src/agent/dsh-native.ts @@ -1337,8 +1337,15 @@ export function apply(ctx: PluginContext): void { // RETRY_INTERVAL_MS until a proxy lands. maybeRetry(ctx); - // #1158 L2: a refusal sends model traffic DIRECT. First refusal per - // endpoint logs once; same-state refusals accumulate silently and re-print + // #1158 L2: a refusal leaves the request uncompressed, but does NOT decide + // its egress — that is settled downstream in the intercept: direct-to- + // upstream for plain traffic on a raw URL, or stamped into the proxy's + // unattributed passthrough lane (every overlay-routed URL; a marker- + // sniffed compaction POST is diverted there too, where the #2709 guard + // runs the decisive check). The log must not claim "sent DIRECT" (#3499: + // the claim misread as upstream-direct cost a full diagnostic pass — the + // bytes can die inside the proxy instead). First refusal per endpoint + // logs once; same-state refusals accumulate silently and re-print // only on an attribution STATE change (none↔threw), always carrying the // cumulative count — bounded noise (#1117 silence preserved) while a // "dozens refused, one passed" distribution becomes visible. The durable @@ -1368,7 +1375,7 @@ export function apply(ctx: PluginContext): void { ? "initiator present but missing session id" : "no active initiator attribution (agentless/background lane, third-party in-process caller, or stale attribution after host resume?)"; const suffix = prev !== undefined ? ` (state ${prev.state}→${attr.state})` : ""; - const line = `bili-native-dsh: model request sent DIRECT (uncompressed) — takeover gate refused ${key}: ${reason} — refusals so far: ${count}${suffix}`; + const line = `bili-native-dsh: model request NOT taken over by bili (uncompressed) — takeover gate refused ${key}: ${reason} — egress: direct upstream or proxy passthrough lane (decided after the gate) — refusals so far: ${count}${suffix}`; persistClientEvent(line); } return false; diff --git a/tests/dsh-native.test.ts b/tests/dsh-native.test.ts index 293b6af152..af2e8e8b90 100644 --- a/tests/dsh-native.test.ts +++ b/tests/dsh-native.test.ts @@ -1768,7 +1768,7 @@ test("#1158 L2 gate three-state: thrown attribution is a distinct state; counts assert.equal(refusedLines().length, 3); // the durable copy carries the same lines into bili.log, [dsh-client]-marked const content = fs.readFileSync(logFile, "utf8"); - assert.match(content, /\[warn\] \[v=[^\]]+\] \[dsh-client\] bili-native-dsh: model request sent DIRECT \(uncompressed\) — takeover gate refused https:\/\/api\.gate-l2\.test\/v1\/chat\/completions: currentInitiator\(\) threw \(agent initiator scope is disposed\) — agent scope disposed\/closing mid-request\? — refusals so far: 5 \(state none→threw\)$/m); + assert.match(content, /\[warn\] \[v=[^\]]+\] \[dsh-client\] bili-native-dsh: model request NOT taken over by bili \(uncompressed\) — takeover gate refused https:\/\/api\.gate-l2\.test\/v1\/chat\/completions: currentInitiator\(\) threw \(agent initiator scope is disposed\) — agent scope disposed\/closing mid-request\? — egress: direct upstream or proxy passthrough lane \(decided after the gate\) — refusals so far: 5 \(state none→threw\)$/m); assert.equal(errs.filter((e) => e.includes("takeover gate refused")).length, 0, "#2831: must not reach the terminal surface"); } finally { console.error = origErr;