Repository navigation
feat: #2359 intercept azure Responses WebSocket lanes; strip consumed x-bili-* at azure egress - #2371
Conversation
… x-bili-* at azure egress OpenCode V2's experimental.ws.handshake hook only admitted providerID "openai", so an azure providerID socket was never URL-rewritten/header-stamped and bypassed bili entirely (no compression, stale /acp carriage). Two coupled changes: - Admit "azure" alongside "openai" in the guard (src/agent/opencode-v2.ts), keeping the existing ws:// scheme + /responses pathname checks. Any other provider stays unintercepted. - Strip bili-internal x-bili-* headers at final upstream egress ONLY to hosts ending in .openai.azure.com (src/responses-ws.ts). Azure OpenAI caps custom request headers on the WS upgrade (documented 10); the forwarded x-bili-* metadata (already consumed at ingress) plus OpenCode's own x-* headers push a typical handshake past it, so the gateway closes with 1011 before any event. Auth + OpenCode headers stay intact; every other host keeps its existing forwarding byte-for-byte. Extracted into exported finalizeResponsesWsUpstreamHeaders so the exact wire decision is asserted directly rather than via a permissive round-trip mock. Tests: pure unit test of the egress decision (azure strips x-bili-*, non-azure retains them, hop markers always dropped); guard test proving azure is intercepted while an uncovered provider is left untouched; control assertion in the existing full-flow test that a non-azure upstream still receives x-bili-*. Closes #2359
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.2543-pr.2371.2d36030This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr2371.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 已拉取并审阅分支 结构化七问
测试有效性:有牙。纯函数单测直接断言精确 wire 集合(正例留 auth+OpenCode、负例去 hop/sec-websocket/x-bili;非 azure 留 x-bili)而非宽松 round-trip mock;guard 集成测证 azure 被拦截(URL 重写+打戳)、未覆盖 provider 不动;full-flow 加控制断言。这是能抓住真实网关拒绝的最小断言。 诚实边界(作者已声明,我认同):无法 hermetic 复现真 azure 的上限强制(mock 需 顺带观察(非本 PR 缺陷,不单独立项): 判定:可合并,待上述 4 个全量回归 |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.130-master.3234e5a # this exact build
npm install -g billion-context@master # always the newest merged build
|
Intercepts OpenCode V2 azure Responses WebSocket lanes (previously bypassed) and keeps them under Azure's WS custom-header cap so the connection actually succeeds.
What changed
src/agent/opencode-v2.ts— theexperimental.ws.handshakeguard now admits providerIDazurealongsideopenai, keeping the existingws://scheme +/responsespathname checks. Any other provider stays unintercepted.src/responses-ws.ts— at final upstream egress, bili-internalx-bili-*headers are stripped only for hosts ending in.openai.azure.com. Extracted into exportedfinalizeResponsesWsUpstreamHeaders(url, headers)(used byResponsesWsUpstream.connect) so the exact wire decision is unit-testable.Behavior changes (old → new)
/responsesWS socket was never rewritten/stamped → bypassed bili entirely (no compression, not counted, stale/acp). New: intercepted and compressed like openai. Why: OpenCode V2 Azure Responses WebSocket bypasses native ACP interception; status can show stale compressed context #2359 — cover azure on the same lane.x-bili-*) was forwarded to the azure upstream; a typical OpenCode handshake (6 OpenCodex-*+ 5x-bili-*+api-key= 12) exceeded Azure's documented 10-custom-header cap → gateway closed with1011before any event. New:x-bili-*dropped at egress to*.openai.azure.comonly, landing at ~7 custom headers. Auth (api-key) + OpenCode headers preserved; every non-azure host is byte-for-byte unchanged.Both compression modes
The change only governs which model traffic reaches the upstream and what headers ride it; it does not touch the
acp_summarycarrier, tool/nudge injection, or preflight/compact paths. Plugin-mode and proxy-mode summary carriers are unaffected.Config surface
None added. The
.openai.azure.commatch is hardcoded to match the verified hotfix scope (Azure OpenAI endpoints are uniformly*.openai.azure.com); a config knob would invent surface without need. Flag if you'd rather make the strip host(s) configurable.Tests
finalizeResponsesWsUpstreamHeaders: azure stripsx-bili-*, retains auth + OpenCode headers, always drops hop/sec-websocket markers; non-azure retainsx-bili-*. Asserts the exact wire set directly — stronger than a permissive round-trip mock (which would miss the real gateway rejection).x-bili-*verbatim.tests/responses-websocket.test.ts40/40, build OK. Full regression left to CI.Note: full recovery/error-code parity and compression folds specifically over the Azure WS transport remain unverified hermetically (a live-azure limit-enforcing mock isn't reachable without
/etc/hosts); the unit-level wire assertion covers the header-leak regression and CI covers the rest.Closes #2359