Repository navigation
fix(agent): proxy-death fallback no longer forwards incremental payloads upstream (#3304) - #3529
Conversation
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.4309-pr.3529.9c727d5This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr3529.tgz
npm install -g packageInstall instructions are refreshed on each push. |
252cc5c to
5b20110
Compare
Catch 2026-10-17_incremental-direct-send-guard up to current master (13 commits, incl. the #3394/#3395 live-state-slot refactor that rewrote installNativeFetchIntercept). Single conflict in src/agent/native-intercept.ts: kept the #3304 withRestoredBody helper and adopted #3394's installNativeFetchIntercept(initialState) signature + doc-comment. The #3304 guard (prepareForDirectSend/directSendOrRefuse) sits inside the per-request fetch-chain callback after the 'const state = g[ACTIVE_STATE]' binding, so it reads the active state under host hot-reimport - semantically compatible with #3394. Verified locally: tsc --noEmit clean; 107 targeted tests green (issue3304-incremental-direct-send + native-intercept + native-intercept-selfheal).
(ai: vllm-qwen/qwen3.8-27b) 查重:不重复。 PR #3529 本身就是 #3304 的修复 PR —— #3304 是该缺陷唯一的源 issue(open,带「发版/下次发版」标签),描述的正是「增量 lane 把 delta envelope 转给上游导致 400」,本 PR 的 fix + test 与之逐一对应。近期未发现针对同一失败签名的其它 open/closed issue 或 PR。 独立审完(未照抄 issue 结论,diff 逐段重读 + 本地复现验证)。先说结论:技术方向对、测试扎实、自身 head 上 CI 曾全绿;唯一阻塞是与 master 刚合入的 #3394 的冲突——我已替你 sync 到当前 master 并本地验证通过,现可直接等 fresh CI 绿后人工合并。 结构化八问
我处理的阻塞项(已 push)PR 原本基于旧 base,和 master 刚合入的 #3394/#3395(
测试有效性真断言、有牙:校验真实转发字节 —— 恢复时 一处非阻塞小建议:pi 的 判定可合并(待 fresh CI 绿;人工合并)。不建议 auto-merge —— 按 §7.4 属 must-stay-human:动了 fallback 行为(产品决策)+ 新增 hook 机制 + load-bearing wire-adjacent 路径。CI 我盯着,绿了就能合。 |
(ai: vllm-qwen/qwen3.8-27b) 跟进(接上一条八问审核):已把本分支 sync 到当前 master,解决了与刚合入的 #3394/#3395(live-state-slot 重构)在 本地验证通过: 现状:PR 判定不变:full CI 绿后人工合并即可(不 auto-merge —— 动了 fallback 行为 + 新增 hook + load-bearing wire 路径,按 §7.4 属人工合并)。 |
Only conflict: src/agent/native-intercept.ts — both sides appended a new export after replaceRequestPayload. Kept BOTH (union of intent): - withRestoredBody (#3304, this PR) — full-body restore for fall-back sends - bindLiveStateSlot (#3394/#3558, master) — live-state slot rebind on install Evidence: typecheck + tsup build green; targeted suites green on the merged tree — issue3304-incremental-direct-send, native-intercept (covers bindLiveStateSlot/ACTIVE_STATE + hot-replace), native-intercept-selfheal, opencode-incremental, omp-native-incremental, incremental-lane, incremental-client-recovery (130 pass / 0 fail). Full-suite verdict per §7.2: remote CI on this pushed head.
…tal-direct-send-guard
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.566-master.2524598 # this exact build
npm install -g billion-context@master # always the newest merged build
|
(ai: vllm-qwen/qwen3.8-27b)
Closes #3304
What was broken
The incremental lane replaces the outgoing request body with a lane-only delta envelope (
{conversationId, sinceSeq, path, request, messages}+x-bili-plugin-turnmarker) BEFORE the fetch layer runs. When the bili proxy dies inside the 30s probe window and native-intercept gives up on respawn, its fall-back direct send forwarded THAT mutated payload to the real upstream → hard 400 (the envelope has no top-levelmodel). Pre-incremental behavior was "proxy down ⇒ degraded direct send of the full body still works"; after the lane landed that guarantee silently broke for every host whose adapter swaps before the intercept sees the request.Affected instances (one mechanism, four lanes): dsh-native and pi / pi-native (already on master via #3273 phase 2), opencode and omp (#3292). claude/codex CLI never enter the lane.
Fix (A+B hybrid, as proposed in the issue)
Every fall-back direct send in
native-intercept.tsnow goes through an optionalstate.prepareDirectSend(url, input, init)hook with three outcomes:as-is— no lane touched this request (hook absent or no turn id) → byte-identical to today's behavior;restored— the lane hands back the stashed pre-swap body; the direct send carries the ORIGINAL full payload (availability preserved);unrestorable— the body WAS mutated but the original is gone (stale/gone turn id, hook crash) → the direct send is refused locally with aTypeErrortelling the host to retry the turn (safety: mutated bytes never reach the upstream).Correlation:
x-bili-turn-id, [bug] incremental turns (#3248): pending-ack maps are keyed by request URL, not conversation id — a late response mis-attributes x-bili-applied-seq to another conversation and kills incremental turns for both #3329) that is already stamped atomically with the swap; each adapter now stashes the exact pre-swap body string under that id (TTL 5min, cap 256, non-consuming so a host-level retry re-reads it).before_provider_requestreturns a replacement payload; the event carries no headers), so it uses an envelope-shape sniff (same shape test as the server divert gate) + per-conversation-id stash (pi conversations are strictly serial — same invariant as its pending-ack map).All six real-upstream fall-back sites are guarded (routed gate-fail, routed give-up, signed passthrough opt-in, raw gate-direct, bootstrap-fail, rewrite give-up); non-model URLs, compaction diverts, self-URL sends and retry-to-recovered-proxy paths are untouched by construction.
Behavior changes (disclosure)
as-is, byte-identical dispatch).TypeErrorwhen the original bytes are unrecoverable (host retry re-runs the normal decision). No data loss either way — the host keeps full history and the server canonical state never saw the delta.onGiveUpstill fires exactly where it fired before; the refusal path additionally reportsonDispatch(url, "refused")for observability.Config surface
None. No new env var, config key, CLI flag, or default value. No new dependency.
Kernel boundary
Not touched. All changes are host-side (
src/agent/*).Tests
New
tests/issue3304-incremental-direct-send.test.ts(23 tests): the strict hook's five states; envelope sniffing accept/reject matrix;withRestoredBodysemantics (string/Request inputs, init precedence); integration throughinstallNativeFetchInterceptwith a dead-proxy stub — rewrite give-up restores the original bytes, routed give-up restores throughmakeTarget(routedTarget), missing stash refuses WITHOUT any upstream call, throwing hook fails safe, bootstrap-fail restores a swapped Request-object input (opencode shape), and no-hook falls back byte-identically to pre-fix; plus per-adapter assertions that dsh/omp/opencode/pi each stash the EXACT pre-swap bytes under their correlation token. Adjacent suites green locally (native-intercept,native-intercept-selfheal,opencode-incremental,omp-native-incremental); full suite delegates to CI.