Repository navigation
[PR] feat(#1926): WS bridge idle-socket observability + WS test hardening (post-#1968 follow-up) - #2004
[PR] feat(#1926): WS bridge idle-socket observability + WS test hardening (post-#1968 follow-up)#2004ranxianglei wants to merge 8 commits into
Conversation
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.2046-pr.2004.2a8d71bThis exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr2004.tgz
npm install -g packageInstall instructions are refreshed on each push. |
…one-shot idle-retention warns GET /__bili/stats gains wsBridge: per live connection (codec, connection id, idleMs, retainedBytes across both checkpoints, inFlight). A 60s scan logs one warn per idle episode once idle age crosses 30min (BILI_WS_IDLE_WARN_SECONDS overrides, 0 disables), reset by client activity — option (c) from #1926, zero contract risk; idle-close (a)/(b) stays pending verified host recovery.
Seventh site of the log-race family (windows-24 CI leg): the completed frame can arrive before the side-request line is flushed on slow runners. Switch the last bare readFileSync+match to readLogUntil, same as the six migrated sites.
- codex-responses-ws / ws-bridge: explicit Item casts, typed dispatch promise - issue1993 + issue1987 (master's own new tests): import ProxyOptions from config.ts (server.ts only re-imports the type); AddressInfo cast for .address().port
337e384 to
6d71115
Compare
[bot] 🏷 Review 完成。结论先行:可合并(等 ① 是什么问题:Responses WS 通道没有任何回收机制——空闲的客户端 socket 会一直钉住一条 live 上游连接 + 两个 checkpoint,直到客户端自己关闭(#1926 观测:38 条无 close 连接,其中 30 条 30min+ 无上游请求)。本 PR 实现 issue 建议顺序里的 option (c):纯可观测性,不关闭任何东西,(a)/(b) 保留给验证过宿主恢复之后再做。 ② 什么原因导致的:桥接 shell 只在 peer close / server shutdown 时回收,没有定时器或 idle 扫描;真正的风险面是上游 WS 连接槽位耗尽(bili 已有 ③ 怎么修复的:shell 层加可选 ④ 是否有回归问题:触碰路径的既有行为逐项清点——
⑤ 是否破坏缓存:不涉及——prefix cache、重试、增量游标、去重键全部未触碰。 ⑥ 是否改了设计方向:没有——纯加性可观测 hook + stats 键,架构/边界/数据流不变;idle-close (a)/(b) 继续等宿主恢复的 E2E 验证,#1926 保持 open。 ⑦ 是否引入新配置:是——新增 env var Review 中直接修掉的小问题(两个 commit 已推上本分支):
Stale-base 与协调事项(需 owner 拍板):
验证证据(final head 判定:可合并(human 合并)。合并后 #1926 保持 open,等 (a)/(b) 的宿主恢复验证。 |
…one-shot idle-retention warns GET /__bili/stats gains wsBridge: per live connection (codec, connection id, idleMs, retainedBytes across both checkpoints, inFlight). A 60s scan logs one warn per idle episode once idle age crosses 30min (BILI_WS_IDLE_WARN_SECONDS overrides, 0 disables), reset by client activity — option (c) from #1926, zero contract risk; idle-close (a)/(b) stays pending verified host recovery.
# Conflicts: # tests/codex-responses-ws.test.ts # tests/issue1987-preflight-baseline-anchor.test.ts # tests/ws-bridge.test.ts
|
(ai: zhipuai-lb/glm-5.3) 孤儿票清理:标题指向的 issue 已关闭,修复已由其他路径落地。关单;误判请 reopen。 |
Follow-up to the merged #1968 — it carries the two commits that landed on the branch after the merge point (the merge took
163cfc54; these rode later pushes). Rebased onto current master (33d58e5e) during review; see the stale-base note under item 3.feat(Responses WS lane: idle client sockets pin live upstream connections and checkpoints with no reclamation #1926): WS bridge observability — option (c) from the issue's suggested sequence
GET /__bili/statsgainswsBridge: per live connection — codec, connection id,idleMs,retainedBytes(client-leg + upstream-leg checkpoints, fromResponsesWsHistory.bytes()),inFlight.warnper idle episode (60s scan, unref'd, default threshold 30min,BILI_WS_IDLE_WARN_SECONDSoverrides,0disables), tagged(#1926), reset by client activity. Pure observability — nothing is closed.WsBridgeSession.stats()hook; the Responses session implements it.test(OpenCode V2.0.20 OpenAI default WebSocket bypasses bili native HTTP interception; only title request creates empty ACP session #1844): poll the side-request log line in the title-persona WS test — the seventh site of the log-race family that flaked the windows-24 CI leg (completed frame arrives before the
side request (agent=title)line flushes on slow runners); migrated toreadLogUntillike the six earlier sites.test: satisfy the widened typecheck — the
typecheckscript moved totsconfig.json(src+tests) after feat: ACP-aware OpenCode V2 Responses WebSocket proxy + generic WS bridge shell (#1844/#1467) #1968 merged, which exposed latent type errors in the WS test files, and one import in fix(preflight): log+dump rejected summary bodies and shrink-retry hard 400/413 #1994's new preflight test (ProxyOptionslives insrc/config.ts, not re-exported byserver.ts). Stale-base note: this PR branched at129200db; fix: preflight transport resilience + shipped-payload baseline anchor (#1987) #1989 then merged over the now-widened gate carrying its own red test file (tests/issue1987-preflight-baseline-anchor.test.ts), so master'snpm run typecheckwas red before this PR landed. The rebased head fixes all four affected files; master's typecheck is green again at this head.Review additions (pushed to this branch during review)
fix(ws-bridge): non-numeric or negativeBILI_WS_IDLE_WARN_SECONDSnow falls back to the 30-min default instead of silently disabling the warn scan (garbage →NaN→ disabled under the original parse). Behavior change for degenerate input only: invalid value previously = scan off, now = default on — matches the sibling-knob convention (BILI_MODEL_INFO_RETRY_MS,BILI_UPDATE_CHECK_INTERVAL_MS).docs:BILI_WS_IDLE_WARN_SECONDSmirrored into the CONFIGURATION.md env-var tables (en/zh); it was previously documented only indocs/opencode-responses-websocket.md.Config surface
New env var
BILI_WS_IDLE_WARN_SECONDS(no config-file field):1800;0disables the warn scan (stats stay live); non-numeric or negative values fall back to1800. Scan cadence fixed at 60 s.wsBridgesection in~/.config/billion-context/config.json), and no existing knob covers idle retention on the WS lane — the HTTP-lane knobs (BILI_KEEP_ALIVE_TIMEOUT_MS,BILI_CLIENT_ERROR_BACKSTOP_MS,BILI_POST_RESPONSE_LINGER_MS) act on different mechanisms and close sockets, whereas this one only warns (Responses WS lane: idle client sockets pin live upstream connections and checkpoints with no reclamation #1926: closing is deliberately not done yet).compresshierarchy (n/a — not compression), launcher↔extension channel (n/a — server-side diagnostic). A plainBILI_*env var follows the established convention for diagnostic/backstop knobs (the [0.1.158] MITM 链路上客户端侧疑似闲置连接拆除 RST+上游短周期停滞无看门狗——附一次客户端进程崩溃的完整取证,请评估是否需要加固 #1452/clientError drain path lacks terminal backstop: silent peer holds half-open socket indefinitely (#1528 item-1 follow-up) #1529/建议:客户端侧连接请优雅关闭(close_notify+FIN),避免向下游客户端发出 RST #1982 family) and keeps the config file untouched.Verification (final head
55d43e80, rebased on33d58e5e)npm run typecheck(tsconfig.json, src+tests) clean — includingtests/issue1987-preflight-baseline-anchor.test.tsfrom fix: preflight transport resilience + shipped-payload baseline anchor (#1987) #1989tests/ws-bridge.test.ts4/4 (incl. injected-clock scanner test: threshold crossing, exactly-once per episode, reset on activity, stats lifecycle),tests/codex-responses-ws.test.ts5/5,tests/responses-websocket.test.ts36/36,tests/issue1993-preflight-400.test.ts1/1 (import fix only), plustests/issue1987-preflight-baseline-anchor.test.ts+tests/preflight-transport-recovery.test.ts10/10; full regression left to CIRefs #1926 (option (c) done; (a)/(b) idle-close pending verified host recovery — issue stays open), #1968, #1844.