Repository navigation
feat: ACP-aware OpenCode V2 Responses WebSocket proxy + generic WS bridge shell (#1844/#1467) - #1968
Conversation
f7386a7 to
c9e166c
Compare
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.2003-pr.1968.71bc2bcThis exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr1968.tgz
npm install -g packageInstall instructions are refreshed on each push. |
6ec579b to
beb24a2
Compare
[bot] 🏷 Review 完成,已推两个标注 fixup commit 到分支;等最后两条 CI leg 转绿后给结构化结论。 做了什么
CI(e7bf61a):10 条中 8 条绿,含此前失败的 |
21e9b67 to
b8d381d
Compare
[bot] 🏷 Review complete — branch rebased onto current master, two review fixes pushed, all CI green on head What I did on the branchWhile reviewing I found three merge blockers and fixed them as labeled commits (plus one of my fixes was superseded by a better author-side fix — see below):
Code review verdicts (the actual feature)
结构化七问
收工判定可合。 Head |
…ses becomes the first codec - src/ws-bridge.ts: protocol-independent shell (admission, upgrade, labeled logging, exactly-once shutdown teardown) driven by a codec table - src/responses-ws.ts: Responses-specific handling becomes responsesCodec (WsBridgeCodec/WsBridgeSession contract) - src/server.ts: single wiring site installWebSocketBridge(server, dispatch, log, [responsesCodec]); unclaimed upgrades keep the existing 426 - tests/ws-bridge.test.ts: drives the shell with a synthetic second codec to pin the codec-table abstraction - docs: architecture section covering the shell/codec split; new protocols are a codec file plus one table entry; unknown protocols stay on #1472
… lane envelopes Master's #1897 demotion (omp hosts registering bili's tools as extension tools) catches first-turn WS frames whose tools array is exactly bili's ACP set: the frame is demoted to the side passthrough, which cannot speak the lane's upstream transport (502 'Unsupported request in Responses WebSocket transport'), and the whole session dies on its first turn. The bridge now stamps x-bili-ws-lane=<codec name> onto the upgrade request before the session is created, so every in-process envelope rebuilt from the source inherits it. The demotion is vetoed for marked envelopes: the WS lane is that conversation's mainline, the omp leak mechanism cannot produce these envelopes, and side requests on this lane are identified by the #1699 persona header instead. Rebased onto master (dfca5a9) — 108 commits of drift resolved (import union in src/server.ts, package.json/lock kept from master).
…transport Review finding on c9e166c: a #1699 persona request (x-bili-plugin-agent: title) riding the WS lane is a #388 side request, whose passthrough forwards the inbound body as a Buffer — but the transport only accepted strings, so every such request 502'd with 'Unsupported request in Responses WebSocket transport' (reproduced locally before the fix). The c9e166c veto covers the transport boundary by normalizing string|Buffer|ArrayBuffer views to text.
… lost in rebase The rebase onto dfca5a9 resolved package.json from the PR side for three lines that must come from master: version 0.1.180 (content commits never touch version; merging 0.1.179 would downgrade master), acp-kernel 0.0.100 (exact pin follows master), and the test:e2e:image script (#1843/#1857). Lockfile re-synced from master plus the ws dev-deps.
…unners Windows CI legs failed 1-2 random WS fault tests per run on log-read races: the assertions snapshot bili.log right after a turn, but the server-side writer has not flushed lines that are logically already emitted (e.g. 'checkpoint reset reason=response.failed' read 78ms into the turn). Add a bounded readLogUntil helper and route the six synchronous log-read sites through it; negative patterns are vetted against the same settled snapshot (after any log-line filtering the test applies).
…c bridge Codex CLI (0.147.0, feature-flagged responses_websockets[_v2]) dials GET <base>/responses over WS in prefix mode: /bili/<upstream>/responses, conversation header session-id, one text frame per Responses event, full history replay every turn (previous_response_id is never sent), and a prewarm probe (input:[], generate:false) per connection. - ws-bridge: pluginMarker is now optional (prefix-lane codecs admit on loopback + conversation header + tunnel-guarded upstream, same trust level as prefix-mode HTTP); conversationHeader selects the client's session header; the claiming codec rides in WsBridgeContext for per-protocol transport policy (allowStreamFlag). - responses-ws: probe frames bypass the ACP pipeline and relay verbatim (empty input would be normalized into a phantom turn by #1862 rules and tool/philosophy injection is pure byte inflation on a no-generation request); stream:true accepted when the codec opts in (codex always sends it; opencode keeps the strict absent-flag policy). - tests/codex-responses-ws.test.ts: probe+turn pipeline ride, full-replay semantics, fold across a covered range, admission denials, non-stream protocol error.
346d1db to
163cfc5
Compare
… flush (ranxianglei#2040) The title-persona test was the last reader in this file still using a raw synchronous fs.readFileSync right after turn completion. On loaded runners the tee-logger write lags the wire completion, so the snapshot misses a line that was logically already emitted — observed as a red windows-latest/Node 22 cell in PR ranxianglei#2034's CI (run 37179443315), green on re-run, green on the other three matrix cells. Use the established readLogUntil() polling helper (added by 97ff781 for exactly this race class, ranxianglei#1968). Both original assertions are unchanged and now vet the settled snapshot.
…-file creation (windows-22 flake, #1968 class)
Closes #1844 (OpenCode V2 WebSocket bypass), closes #1866 (sparse terminal output loses tool calls after fold — fix
46ee9929rides in this stack). Supersedes nothing, duplicates nothing: this branch is PR #1859 (head1e282e91) + one refactor commit (85cf11db) — a pure fast-forward that feeds the generalization back into the #1859 review. Opened so the combined diff gets CI and inline review; merging this also merges all of #1859, or the author cangit merge --ff-onlythe branch into the PR branch instead.Base feature (unchanged, from #1859)
ACP-aware OpenCode V2 Responses WebSocket proxy (#1844): OpenCode V2 connects to bili over WebSocket, bili connects to the Responses upstream over WebSocket, frames enter the existing ACP request pipeline through in-process HTTP-shaped envelopes. Full design notes in
docs/opencode-responses-websocket.mdand the #1859 description.Refactor commit: generic WebSocket bridge shell (#1467 phase-2 shell)
One-step generalization discussed in #1467 — extract the transport-agnostic half, keep the Responses half as the first codec:
src/ws-bridge.ts(new): protocol-independent shell — admission (loopback source,x-bili-pluginlane marker,x-bili-plugin-conversationheader, existing tunnel-destination guard), upgrade handshake, per-connection labeled logging ([codec] [conn=N] [session=…]), exactly-once shutdown teardown (server.closepatched,closeevent kept as backstop). Driven by areadonly WsBridgeCodec[]table; unclaimed upgrades returnfalseso the existing 426 path is untouched.src/responses-ws.ts: everything belowinstallResponsesWebSocketmoves intoResponsesWsSession implements WsBridgeSession, exported asresponsesCodec(nameresponses-ws, markeropencode, claims/bili/responses/<upstream>). Frame validation,previous_response_idclient-history contract, upstream continuation checkpoints, SSE sink — behavior unchanged.src/server.ts: single wiring site —installWebSocketBridge(server, dispatch, log, [responsesCodec]).tests/ws-bridge.test.ts(new, 3 cases): synthetic second codec (fake protocol on/bili/fake/<upstream>/echo) pins the codec-table abstraction — second codec claims its own path+marker; foreign marker / missing conversation / unknown path fall through asfalse;server.closeshuts every session down exactly once and terminates peers.Follow-ups landed on this branch after the rebase onto master
c9e166c3): master's all-bili-tools side demotion caught first-turn WS frames (the harness turns declare exactly bili's ACP tools) and routed them into the 标题生成等侧请求污染主会话状态:prepareAnthropic 缺 isTitleGen 守卫、快照无条件覆盖、survivedCount 每请求空转 #388 side passthrough, which cannot speak this lane's upstream transport (502). The bridge now stampsx-bili-ws-lane=<codec>onto the upgrade request before the session is created; the demotion is vetoed for marked envelopes (this lane IS the conversation mainline; its side requests are identified by the opencode v2 title-gen requests get injected with compression philosophy (misclassified by isTitleGen) #1699 persona header instead). Regression test: "a first-turn all-bili tools frame is a main turn, not an OMP extension injects tools and compression philosophy in helper prompts #1897 side demotion".beb24a28,e7bf61a8): package.json re-resolved from master (version 0.1.180,acp-kernel0.0.100 pin,test:e2e:imagescript) alongside the PR'sws/@types/wsdevDeps.7b653947, review fix): the transport now accepts pipelineBufferbodies, so a opencode v2 title-gen requests get injected with compression philosophy (misclassified by isTitleGen) #1699 persona side request riding the WS lane no longer 502s.b8d381d9): Windows runners failed 1-2 random WS fault tests per run purely on a bili.log read race (assertions snapshotted the file before logically-emitted lines were flushed). The six synchronous log-read sites now go through a boundedreadLogUntilpoll.Second real codec: codex Responses over WebSocket (
346d1db7)Codex CLI 0.147.0 ships feature-flagged
responses_websockets[_v2](off by default, gradual rollout;supports_websocketsper-provider config). When enabled with a prefix-mode base_url it dialsGET <base>/responsesover WS — in bili terms/bili/<upstream>/responses. Captured on the wire (rig in~/tmp/dsh/codex-ws-capture):session-id(plusthread-id,x-codex-window-id,x-client-request-id,x-codex-turn-metadata,openai-beta: responses_websockets=2026-02-06,originator: codex_exec);response.createcarries the full Responses body withstream:true,store:false,prompt_cache_key= session uuid;previous_response_idis never sent, so folding simply shrinks the next replay;input: [],generate:false,request_kind=prewarmin turn metadata) that expects only a terminal event back.codexResponsesCodecclaims that dial on the generic bridge:x-bili-pluginmarker on the wire — trust rests on loopback source +session-idheader + tunnel-destination guard, the same level as prefix-mode HTTP.pluginMarkeris therefore optional onWsBridgeCodec, andconversationHeaderlets a codec point at its client's own session header.src/responses-ws.ts): empty-input +generate:falseframes relay verbatim around the ACP pipeline — the bug: Responses degenerate retry overlooks custom tool calls and drops completed-attempt usage #1862 empty-input normalization would turn the probe into a phantom turn (shifting every later fold anchor), and tool/philosophy injection is pure byte inflation on a no-generation request.allowStreamFlagper-codec transport policy: codex frames always carrystream:true(accepted); opencode keeps the strict absent-flag policy.tests/codex-responses-ws.test.ts(5 cases): probe+turn pipeline ride (verbatim probe, usage/stat accounting, tool injection, no side-request), full-replay semantics with stable refs, fold across a covered range (next replay drops the covered payload, keeps the summary), admission denials (missingsession-id, non-responses path → 426), non-stream protocol error frame.Docs updated (
docs/opencode-responses-websocket.md): the codex codec is documented as the second real codec on the shell.Idle-socket observability (#1926 option (c))
The retention the issue documents (idle client peers pinning one live upstream
connection + both checkpoints, no reclamation until client close) is now
visible instead of silent:
GET /__bili/statsgainswsBridge(per liveconnection: codec, connection id,
idleMs,retainedBytesacross bothcheckpoints,
inFlight), and a 60s scan logs onewarnper idle episode onceidle age crosses 30min (
BILI_WS_IDLE_WARN_SECONDSoverrides,0disables),reset by client activity. Pure observability — nothing is closed; idle-close
(a)/(b) stays pending verified retry-full host recovery per the issue's own
sequence.
Verification
tests/codex-responses-ws.test.ts5/5tests/ws-bridge.test.ts3/3tests/responses-websocket.test.ts36/36tests/fix-responses-guard.test.ts1/1,tests/responses-empty-messages.test.ts6/6,tests/responses-proxy-id-replay.test.ts6/6tests/protected-tools.test.ts7/7 (kernel pin follows master)b8d381d9(rebased onto master39250e7d)Refs #1844, #1467, #1859, #1472, #1699, #1897.