Repository navigation
[PR] fix: arm the pi lane's direct-send window guard so a proxy outage cannot egress an oversized history - #5027
Conversation
(ai: vllm-qwen/qwen3.8-27b) 查重: 不重复。 与既有护栏家族逐条对照:#4516(直发 oversized 护栏本体,已合入)→ #4894/PR #4904(dsh 车道未武装,已修复合入)→ 本 PR = 同一机制的 pi 车道实例。三者是「护栏存在 → dsh 武装 → pi 武装」的完整链条,各修各的车道,不重叠;open/closed 无其他覆盖 pi 直发窗口来源的条目。 标签: bug / pi / scope/wiring / p2(已打)——客户端接入层缺陷;仅在「代理不可用 + 历史超窗」条件下触发,无数据丢失、无缓存泄露,代理恢复后会话即恢复正常 → p2 而非 p1。 初步独立核验(对着 origin/master
审核中发现的新问题 → 已立项 #5032:omp-native / opencode-native 存在同样的未武装槽位(已核实:opencode-native.ts:817 同样在盖章前 return、两文件均未设 定向测试与 CI 跟进中,最终结论按八问体例随后贴出。 |
|
跟进 #5032 的 opencode 半边:已提 PR #5037(同一机制,opencode V1 车道武装 omp 那半边仍未动 —— 复核结论与 #5032 描述一致: 顺带补充一条便于后续判断的事实:opencode 的 V2/native 车道本来就有自己的 #3308 refuse-oversized 分支( |
(ai: vllm-qwen/qwen3.8-27b) 审核结论(八问) — 独立对着 origin/master
行为变更披露(必须报告):pi 车道、代理不可用路径上的超大模型请求——旧:裸奔出网 → 上游 本地定向验证(head 8ffff3a): CI 现状(如实):镜像缓存中该 head 的全部 check 为 cancelled(无判决);期间 master 已前进至 对跟进评论的独立核实(三条都对上了):#5037 存在(镜像确认,CI queued、base behind);opencode V2/native 车道确有自己的 #3308 refuse-oversized( 过程披露一行:排查立项 API 路径时向镜像发过一次预期失败的写请求,返回 404、未创建任何数据,已确认无副作用(后续改走 GitHub REST 正常立项 #5032)。 判定:代码审核通过(逻辑/不变量/测试牙齿/diff 整洁逐项达标,diff 恰好 3 文件 221+/1- 单提交),未发现拦合问题;待 sync 后 head 的 CI 全量判决落地即可合并。 |
…not egress an oversized history (ranxianglei#5025) Without a live proxy, directSendOrRefuse measured the raw body against a window it read from the stamped x-bili-plugin-context-window header or from state.declaredWindowForDirect. On the pi lane BOTH were empty on exactly that path: before_provider_headers returns at `proxyBase === undefined` before it stamps the header, and the lane never armed the slot (ranxianglei#4894 armed dsh only). The check then failed open by construction, so a long session's unfurled history (multi-million tokens) went straight to the provider, whose "input exceeds the context window" 400 repeated on every retry and made the session unrecoverable for as long as the proxy stayed down. Record the per-request ctx.model.contextWindow at the TOP of the headers hook (before the readiness return) and arm it as declaredWindowForDirect in pi-native.ts. An unknown window records undefined — the guard keeps failing open instead of guessing — and a healthy proxy is unchanged, since the stamped header still outranks the reader. Verification: tests/issue5025-pi-direct-window.test.ts (5 cases: recording before the early return, unknown-window reset, the armed reader, local oversize refusal with no upstream egress, and no false refusal when the body fits); typecheck; issue4894/pi-native/issue3433/issue2072/fix-1897 suites; unused-export and test-import-graph gates.
536f690 to
cfcb3f9
Compare
|
按 #5077 复核里那条建议(「合 #5027 本体前触发一次新鲜绿跑」),我把本 PR 也移到了最新 master 上,并顺手查清了上一轮那 3 个红分片是什么。 新 head
上一轮 3 个红分片的归因(与本案无关): 这是 #5140 带进来的 fork/cold-restore 用例,与本 PR 改的 pi 直发窗口守卫( 新 head 上的本地验证(重跑,不沿用旧 head 结果):
CI 已在新 head 上排队(22 项 pending)。合并顺序仍然是你上次给的:#5027 → #5077(与 #5037 无依赖,任意顺序)。 |
…xianglei#5140 storage-mode test pin) into PR branch (ranxianglei#4599)
…k-snapshot recon gates) into PR branch (ranxianglei#4599)
|
先同步一个事实:本 PR 的 head 已被哨兵重排到新 base 当前这个红 check 不是本 PR 的 diff 引起的,是 master 侧的 LIFECYCLE.md 漂移。 证据(在纯
本 PR 面本身没有新增任何 env 读取( 我这边没有可执行的动作,除了等这个 gate 在 master 侧被修好。 |
(ai: vllm-qwen/qwen3.8-27b) Sync round 3 done: merged |
|
Landed via batch PR #6482 (merged) — closing as superseded. |
(ai: vllm-qwen/qwen3.8-27b) 状态确认(已 live 核实,非凭旧记忆):
|
(ai: vllm-qwen/qwen3.8-27b) Acknowledged — verified #6482 is merged (2026-11-14T01:11:17Z, head d04a8ad), so this PR is superseded. Final state of this branch: last synced to master |
Fixes #5025.
What went wrong
With no live proxy,
directSendOrRefuse(src/agent/native-intercept.ts:1204) measures the outgoing raw body against a window it resolves from the stampedx-bili-plugin-context-windowheader, elsestate.declaredWindowForDirect. On the pi lane both were empty in exactly the state that egresses uncompressed:pi.on("before_provider_headers")(src/agent/pi.ts:1276) returns atif (proxyBase === undefined) return;before stamping the header — and when the proxy is down the base never resolves.state.declaredWindowForDirectwas armed only bysrc/agent/dsh-native.ts:2402([Bug][dsh] 0.1.208: attributed-but-not-ready direct send has no window guard, and takeover is declared before readiness — long sessions 400 with prompt_too_long | 归因正常但代理未就绪时直发无窗口护栏 + 就绪前就宣告接管 → 长会话必 400 #4894);grep -rn declaredWindowForDirect src/shows no pi arm.So
declaredWindow === undefined→ nothing measured → fail-open direct send. A long session's unfurled history (multi-million tokens) went to the provider, came backinput exceeds the context window, and every retry re-sent the same body; the host's overflow-recovery summarization hit the same 400, leaving the session unusable while the proxy stayed down.Change
src/agent/pi.ts: recordctx.model.contextWindowat the top of thebefore_provider_headershandler, before any proxy-readiness early return; export it aspiDeclaredWindowForDirect()plus a test reset. A missing/unknown window recordsundefined, so the guard still fails open rather than guessing.src/agent/pi-native.ts:state.declaredWindowForDirect = piDeclaredWindowForDirectnext to the existingstate.prepareDirectSend.Result: no-proxy + a body whose media-excluded core text provably cannot fit the model's window → local retryable
oversize-refusal-fallbackgate error (#4516) instead of an upstream 400 storm. Anything that fits, and every healthy-proxy request (stamped header outranks the reader), behaves exactly as before.Tests
tests/issue5025-pi-direct-window.test.ts— 5 cases:pi-nativearms the reader (this one goes red if the arm line is removed);oversize-refusal-fallback, zero upstream egress;Also run locally:
npm run typecheck,tests/issue4894-direct-window-guard.test.ts,tests/pi-native.test.ts,tests/issue3433-pi-incremental-guard.test.ts,tests/issue2072-native-caller-stamping.test.ts,tests/fix-1897-leaked-tools-side.test.ts(38 pass),npm run check:unused-exports,npm run check:test-import-graph.Out of scope
omp-native.ts/opencode-native.tshave the same unarmed slot; same one-line pattern, separate PRs, to keep this change surgical to the lane that hit the storm.