Repository navigation
fix(dsh-native): threw gate attribution gets a bounded settle-retry; provably-oversized bodies fail locally - #2940
Conversation
…provably-oversized bodies fail locally (ranxianglei#2924) Direction 2 (recovery, owner triage priority): a `threw` attribution is an internal error in the host's lookup (disposed agent scope), never a legitimate agentless lane. The gate now settle-retries (default 3 attempts x 250ms) before deciding; a scope that settles within the window gets its request CLAIMED — the only path that restores an over-window session, since the host's own compaction and the direct fallback must both ship the full history upstream. Direction 1 (honest failure): when `threw` persists and the body provably cannot fit the effective window (floor estimate bytes/4, so the guard cannot false-refuse), the fetch lane fails this ONE request locally with a protocol-shaped 422 (ranxianglei#2709 precedent) instead of handing upstream a guaranteed 400 that kills the session. Unknown window or unreadable body keeps ranxianglei#1117 direct semantics; `none` (legitimate agentless lanes) is unchanged. The gate signature widens to (url, body?) => GateVerdict | Promise<GateVerdict>; the sync contract is preserved (awaiting a boolean is a boolean), and the WS lane's `=== false` check is unaffected. Fixes ranxianglei#2924.
…ne too The direction-1 local 422 was only wired into the raw-URL branch; an already-routed (settings overlay) request whose gate verdict was "refuse-oversized" fell into the ranxianglei#1117 unattributed bucket and rode the x-bili-passthrough marker through the proxy verbatim — the same guaranteed upstream 400 the raw lane now refuses. Check the verdict in the routed lane as well: provably-oversized fails LOCALLY (422, x-bili-gate: oversize-refusal), everything else keeps ranxianglei#1117 semantics.
|
Review follow-up (pushed as e915b00, credit for the base fix stays with @YunzhouLi-hub): Independent review found one non-blocking gap in direction 1 — the
Everything else in the review came back clean: the oversize arm cannot false-refuse (bytes/4 floor, window resolution is all try/catch → arm disarms on any miss), the settle-retry latency is bounded at ~500ms, |
Verification complete —
结构化八问(验证结论)
判定:代码与测试全部核实通过,PR 就绪。CI 剩余 8 个长 e2e lane 跑完即全绿(当前 0 红);merge 按规矩留给人来执行。 |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.373-master.35591c3 # this exact build
npm install -g billion-context@master # always the newest merged build
|
What changed
Implements the fix directions the owner's triage on #2924 recommended (direction 2 for recovery + direction 1 for honest failure), scoped strictly to the
threwattribution state.none(legitimate agentless lanes) keeps today's #1117 DIRECT semantics byte-for-byte.Direction 2 —
threwgets a bounded settle-retry (the only path that can RESTORE a session)src/agent/dsh-native.ts—attributionOf()returningthrew(an internal error in the host's lookup, e.g.cannot get required service "agents" in inactive context) no longer collapses into the samereturn falseasnone. The gate now retries attribution on a bounded schedule (default 3 attempts × 250 ms, so a dying turn pays at most ~500 ms) before deciding:nonemeanwhile → today's refusal (state-transition log, unchanged);threw→ direction 1's size check below.Rationale (from the triage): once a local transcript exceeds the window, ACP compression is the only path that can shrink it — the host's own compaction and the #1117 direct fallback must both ship the full history upstream and 400. So the instant the gate lets go, all recovery paths vanish simultaneously; retrying attribution is the only way back.
Direction 1 — provably-oversized bodies fail LOCALLY (422), not upstream (400)
When
threwpersists and the body provably cannot fit the effective window, the fetch lane now answers with a protocol-shaped 422 (#2709 precedent: not credential-class, not transient-class — hosts treat it as a policy refusal of this ONE request) instead of handing upstream a request that can only 400. On a >window history that 400 is fatal — every later request carries the same history, so the session dies.Conservatism is deliberate: the size arm refuses only when the floor estimate (
bytes / 4) already exceeds the window, so the guard cannot false-refuse — the reporter's own session ledger shows real bodies run above the byte estimate on this host (calibratedEstimate ≈ 1.14), and that bias cuts toward more headroom, not less. Unknown window, stream/FormData body, or absent body ⇒ the size arm disarms and #1117 direct semantics apply (never a false refusal from missing data).Window resolution reuses exactly the
headersForpath (#2381: the session's live model first, host global default as fallback, cached model info only) — no new lookup, no new source of truth.Interface widening (the one mechanical cost flagged in the proposal)
takeoverGatewidens from(url) => booleanto(url, body?) => GateVerdict | Promise<GateVerdict>withGateVerdict = boolean | "refuse-oversized". Both fetch call sitesawait(a sync boolean is unchanged —await falseisfalse, so every other host's gate keeps working untouched). The WS lane'sstate.takeoverGate(target) === falsecheck needed no change: a Promise is never=== false, so a mid-retry WS connection is claimed rather than refused — consistent with direction 2 and irrelevant in practice (the dsh gate never meets the codex-WS lane).Config surface
None. No new config field, env var, or CLI flag. Retry cadence and the size arm derive entirely from existing in-process state; the retry constants are module-level with a
_setThrewRetryForTesthook (same discipline asBILI_MODEL_INFO_RETRY_MS), not a user knob. If the owner wants the cadence configurable it can be routed throughsrc/knobs.tslater — deliberately not done here (Configuration Surface Discipline).Kernel
No changes under
kernel/— everything lives insrc/agent/(dsh-native, native-intercept) plus tests.Pre-flight (rebased on master @ c76650f)
messagePathOf/storagework indurable-message-guards.ts/plugin.ts/session.ts+ 2 test files) — verified by stashing this change and re-running; identical set.dsh-native53/53 (incl. the 2 new tests below and the updated 方式一安装的dsh 原生插件:llm-pi-ai 传输(OpenAI SDK + options.fetch 注入)绕过 globalThis.fetch 拦截,模型请求不进代理、压缩完全不生效 #1158 L2 test),native-intercept57/57 (incl. 3 new tests),native-ws-intercept19/19.opencode-native34/34, selfheal 22/22), i.e. parallel-run port/timeout flakiness on Windows (fix: emit /acp panel as persistent custom message and strip it from the proxy model context (#359) #360 class), not regressions. Happy to re-run any of them on CI.npm run buildgreen (dist-import-annotations: OK).Tests
New (regression: the original bug + the new outcomes):
#2924 gate threw attribution: bounded settle-retry recovers and CLAIMS the request— the field-report shape: initiator throws twice (disposed scope), settles on the third read; the gate returnstrueand the recovery is durably logged.#2924 gate threw persists: provably-oversized body refuses LOCALLY, everything else keeps #1117 semantics—4004 B / 4 = 1001 tok > 1000 window→"refuse-oversized"+ durable LOCAL-refusal line; boundary4000 B(== window) →false; unreadable body →false; no resolvable window →false.#2924 takeoverGate refuse-oversized: local protocol-shaped 422, upstream never called— both wire shapes (anthropic + openai envelopes),sinkempty,onDispatch"refused".#2924 takeoverGate may return a Promise(+ an async-refusal companion) — the widened contract flows through the same branches.Updated: the #1158 L2 three-state test now awaits its two
threwverdicts and injects a fast retry cadence (its assertions are otherwise untouched).Deliberately NOT in this PR
nonepath — third-party repro on [dsh-native] takeover-gate refusal (threw state) fails open with the FULL uncompressed transcript; a >window local history dies upstream with 400 (maximum context length) #2924 confirms legitimate agentless traffic exists and must keep DIRECT.Fixes #2924. Review focus per §7.5: both call-site semantics under each verdict, and the retry's bounded-deadline behavior on a closing scope.