Repository navigation
fix: follow the live intercept state across WS hot-reimport (#3558) - #3580
Conversation
The Codex Responses WebSocket interceptor (src/agent/native-ws-intercept.ts) still wrapped globalThis.WebSocket once per process with a closure bound to the first module instance's state. A host hot-reimport that re-applies with a fresh state left the wrapper routing through the dead first instance — silent direct egress on any WS lane. This mirrors the fetch fix (#3394/#3395): the wrapper now rebinds the shared process-level active-state slot on every activation and resolves it per connection, so routing follows the newest applied instance; an empty slot passes through direct instead of hitting a disposed context. - extract bindLiveStateSlot() so the fetch and WS installers share one generation-bumped bind (fetch behavior unchanged) - export ACTIVE_STATE / ACTIVE_STATE_SEQ; the WS chain reads them per connection - _resetForTest drops the shared slot alongside the WS flag - port the three #3394 fetch regression tests to the WS lane (hot-reimport rebind, same-instance late-dispose no-op, latest-activation teardown->direct) Closes #3558
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.4230-pr.3580.fec9fe7This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr3580.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b) 查重:不重复。 这是 #3558(WS 半边边界记录)的实现 PR;#3558 本身是 #3394/#3395(fetch 半边,已合入 master PR 形态核对:单 commit |
[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b) 独立复审结论(未复用 issue 侧结论,diff 逐段重读、回归逐项清点、CI 日志下钻) 1. 是什么问题:宿主热替换插件模块时,fetch 拦截已在 #3395 修好,但 Codex Responses WebSocket 拦截还是旧模式—— 2. 什么原因导致的:install 函数每进程只真正执行一次(Symbol.for 标志幂等),而路由闭包捕获的是安装时刻的 state,不是调用时刻读取。热替换在旧实例与新实例之间没有任何 reset,旧闭包引用的 state 已死。根因是「安装时绑定」这一模式本身,与 fetch 半边 #3394 同族,不是 WS 层特有缺陷。 3. 影响范围与严重程度:当前潜伏——需要同时满足「宿主支持插件热替换」+「该宿主走 Codex Responses WS 通道」。据 #3558 排查,今天没有已知宿主同时满足(pi 用 WS 但不热替换;dsh 热替换但走 HTTP)。一旦未来某宿主两者兼备:该通道全部模型请求静默直连外发,无报错、无压缩,严重度高且难察觉。本修复提前恢复这条路径的可用性。 4. 怎么修复的:对齐 fetch 侧已验证的机制,不发明新东西——抽出 5. 是否有回归问题:审过的既有行为及结论——
6. 是否破坏缓存:不涉及——客户端路由层改动,代理侧缓存/重试/游标/去重键零触碰;URL 改写规则(线格式)不变。 7. 是否改了设计方向:没有——把 #3394/#3395 既有的 active-state 槽机制从 1 个传输扩到 2 个;单槽原子性(热替换时两传输整体切换)是该机制的自然推广,非转向。 8. 是否引入新配置:无。无新 env/config/CLI 面(config-surface-guard CI 绿)。 测试有效性:三个移植的回归测试断言有牙——热替换 rebind 测试断言精确改写 URL + dispatch 证据落到新实例(pre-fix 闭包绑旧实例必挂);teardown→direct 测试断言空槽直连(pre-fix 必挂);late-dispose no-op 测试钉双守卫语义(pre-fix 也过,属守卫钉住而非 bug 复现——PR 正文「三者均 pre-fix 失败」此处略过,不影响实质)。均走真实 本地定向验证:WS 22/22 + fetch 62/62 = 84/84 绿(node 22,Linux);typecheck 干净;kernel/pi-subagents 构建通过。全量判定按纪律交给 CI。 CI 状态与处置:e4f4675ee 上静态门禁全绿、e2e 各道全绿/按设计 skip;test 分片 ubuntu 22×3、ubuntu 24、windows 22-2 全绿,仅 windows-22-1 红。下钻该 job 日志(4192 测试仅 1 败):失败的是 判定:可合(待 windows flake 分片重跑转绿确认;该失败与本 PR 无关,如再次复现按独立问题处理)。 |
[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b) CI 重跑确认:rerun-failed-jobs 后 至此 e4f4675 上全部检查通过:静态门禁 11 项绿、test 分片 ubuntu 22×3 / ubuntu 24 / windows 22×2 全绿、e2e 各道按设计全绿/skip。 最终判定维持:可合。 八问结论见上一条回复。合并动作按规矩留给你:#3580 |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.542-master.c33ab30 # this exact build
npm install -g billion-context@master # always the newest merged build
|
The Codex Responses WebSocket interceptor (
src/agent/native-ws-intercept.ts) still used the pre-#3395 pattern:globalThis.WebSocketwas wrapped once per process, with the wrapper'srouted()closure bound to the first module instance'sstate. When a host hot-reimports the plugin (fresh module instance + freshstate, no reset in between), the wrapper kept routing through the dead first instance → silent direct egress on any WS lane.This is the WebSocket half of #3394/#3395 (which fixed the fetch half). It ports the exact shape of that fix onto the WS chain.
How
bindLiveStateSlot(state)innative-intercept.ts: one shared, generation-bumped bind of the process-level active-state slot. The fetch and WS installers both call it at the top of every activation (fetch behavior unchanged — verified by its full 62-test suite).ACTIVE_STATE/ACTIVE_STATE_SEQ; the WSrouted()now resolves the active state per connection instead of using the install-time closure. An empty slot (no active plugin) passes through direct rather than hitting a disposed context._resetForTestdrops the shared slot alongside the WS flag.Behavior change (old → new)
Normal single-install operation is unchanged (one install binds the slot once, same state as before). Two deltas, both the intended fix:
No new config / env var / wire-format change. No
kernel/orpi-subagents/change. Local targeted suites green (WS 22/22, fetch 62/62); typecheck + build clean; full-suite verdict deferred to CI.Closes #3558