Repository navigation
feat: ACP-aware OpenCode V2 Responses WebSocket proxy - #1859
darkness-A wants to merge 3 commits into
Conversation
[bot] 🏷 Review complete — PR #1859(外部贡献者 PR,按仓库规范仅做 review + 验证,未向作者分支推送任何提交) 查重 / 方向关:本 PR 是 #1844(OpenCode v2.0.20 默认 WS transport 导致主流量绕过 ACP)的实现,非重复立项;与 #1467/#1472(透明非压缩 WS relay)机制不同——那是"relay",这是"ACP-aware processing",单独立项合理。方向经 owner 在 #1844 comment 3 明确批准(WS-native + 边界锁定),实现与批准边界逐项一致。PR 基于当前 master(bcef839)单 commit、无 stale base;无 验证证据(本地定向验证 + CI):
测试有效性(④):断言有牙。零 HTTP fallback( 结构化七问:
小问题(均 non-blocking,外部贡献者分支不便代改,列出供参考):
判定:审查通过,达到合并标准(代码质量、测试质量、回归审计、CI 全绿、owner 批准的方向与边界全部落实)。建议 un-draft 后由人工合并。 |
45ff200 to
a83a7f1
Compare
|
The sparse-terminal follow-up for #1866 is now included in the existing PR #1859, rebased onto master Fix commit: The original implementation dropped completed streamed tool calls when terminal output was sparse. Both client/upstream checkpoints now reconstruct indexed output independently; streaming frames and tool arguments remain unchanged. Coverage includes empty/omitted/partial-prefix/partial-suffix output, real ACP folds, and successive tool-result pairing. Final checks: typecheck/build/diff-check PASS; 26 dedicated WS tests PASS; real OpenCode V2.0.20 local WS E2E 2/2 PASS; real Codex fake-upstream E2E 3/3 PASS. Full Windows suite is 3548/3572 passing with 9 failures and 15 skips; a fresh master control has the exact same nine failing test locations (3521/3545 passing). No new failing tests relative to master. The real-upstream Codex lifecycle remains blocked locally because port 8199 is unavailable. User-run ChatGPT OAuth validation exercised checkpoint restoration and continued after an actual fold (335615 -> 172429 input tokens); the user reports the tool-repeat loop stopped. A later observation of frequent compression correlates with the pre-existing 70% emergency nudge, not frozen tool-result history; this patch does not change compression policy. The PR body contains updated evidence and limitations. The existing PR remains draft/open for updated CI and human review; it has not been merged or published. |
a83a7f1 to
1e282e9
Compare
|
Follow-up hardening pushed in 1e282e9: eight abnormal-combination cases plus scoped WS diagnostics (failure phase, numeric close code, checkpoint reset/recovery reason; no credential/payload/URL logging in the new diagnostics). The sparse-output fold regression now chains checkpoint loss, idle disconnect, and connection-limit rotation. Reviewed/rebased on master d4746c4; range-diff confirms the two prior patches are unchanged. Typecheck/build/diff-check pass; WS 34/34, real OpenCode fake-WS E2E 2/2, and real Codex fake-upstream E2E 3/3 pass. Full Windows suite: 3625 total / 3600 pass / 10 fail / 15 skipped; fresh master control: 3590 / 3565 / the same 10 failing locations / 15. Full suite is not green; baseline failures are documented in the updated PR body. No new production defect found in this hardening pass. Existing real-upstream gate still needs maintainer/CI infrastructure. PR remains draft for human review; no live service restart, merge, or publish. |
[bot] 🏷 第二轮审查完成(head 按仓库 PR Review 规范对新增的两个 commit 做了完整审查(feat 层已验证与首轮批准的 验证证据
结构化七问
小问题(不阻塞,记录在案): 判定:两个新 commit 审查通过。 feat 层(首轮)+ sparse-terminal 修复 + 诊断覆盖均达标,CI 14/14 绿,本地定向验证全绿,行为变更已披露。PR 达到合并标准,转 ready 与合并由你决定(我不代合)。#1866 的修复即在本 PR 内,合并后可关闭。 |
[bot] 🏷 确认:无新增变更,维持第二轮审查结论 刚重新 fetch 核对:分支 head 仍为我已完整审查的
状态不变:审查通过、达到合并标准,转 ready / 合并由你决定(我不代合)。若后续有新 commit 推上来,我会按新 diff 走完整审查轮次。 |
|
补充一次与当前 master 的兼容性验证(关联 #1844):我在独立分支上以 发现一处需要随合入处理的兼容点: 同时调整主请求测试夹具,使其包含真实宿主 action tool;新增单独回归验证辅助请求的工具被剥离、仍走 WS、主会话 usage/refs 不被改变,并能继续正常主请求。补充提交: 验证结果:
集成验证分支为 |
|
Reporter clarification: #1923 has been withdrawn and closed. These runtime observations came only from the unmerged WS build; no official-build/HTTP comparison has established an upstream defect. The notes below are observations for investigation of this WS patch's resource lifecycle, not a confirmed official bili bug. Resource-lifecycle follow-up for the WS patch: investigating idle subagent rows also found long-idle client sockets/checkpoints retained. Current-session logs recorded 38 connections opened without a subsequent client-close record, 30 with no upstream request for >30 minutes; a contemporaneous OS snapshot had 41 established inbound connections to bili (that TCP count also includes ordinary HTTP, so it is not a per-session attribution). Only 1 actual request was inFlight. Sampled idle session request/usage counters did not increase.
The misleading Web UI running badge is separately reported at #1923: it tests memory residency, not WS liveness or inFlight. These are distinct concerns. |
[bot] 🏷 第四轮审查:master 兼容性(Buffer body)核实完成 + PR 状态变化提醒 ① 缺陷核实(代码级证据,master ② 修复评审(commit ③ 集成态本地验证(codeload 拉取你的集成分支 结构化七问(针对本增量):1) 问题:WS transport 输入契约比 pipeline 输出契约窄,辅助请求(Buffer body)在 WS 通道被拒。2) 原因:设计时假定 body 为 JSON.stringify 产物(主 pipeline 路径如此),未覆盖 side-passthrough 这一既有机制的 Buffer 产出(#388/#1897)。3) 修法:在消费边界放宽到完整契约,不动任何生产者。4) 回归:string 路径逐字节不变;主请求流不受影响;master #1897 自带套件在集成树全绿;两种压缩模式无交互(side passthrough 按定义不触 kernel 状态)。5) 缓存:不涉及(本 commit 不碰检查点/continuation 逻辑)。6) 设计方向:不涉及。7) 新配置:无。
|
[bot] 🏷 资源生命周期发现(idle socket/checkpoint 保留)已核实并立项 按你在线程里给出的数据对代码做了逐点核实(
处置:已立 #1926(带来源标记,机制独立于本 PR):含完整数据、代码验证、三个候选方案(a 关客户端 socket / b 清检查点 / c 纯可观测)及建议次序——先做 c(暴露 live WS peer 数/idle 时长/保留字节,零契约风险,替代 OS 快照这种土法观测),再在 E2E 验证宿主恢复行为后做 a/b。不建议纳入本 PR:不同失败域,且本 PR 体量已大。#1923(UI running badge 测的是内存驻留而非 WS liveness/inFlight)你分得对,保持独立。 |
[bot] 🏷 两点说明: ① 本条与线程中 13:18 的兼容性验证是同一内容(重复转发),已在上方「第四轮审查」回复中完整处理,不重复展开:缺陷已按代码核实( ② 收到你对 #1923 的撤回澄清:相关运行时观察仅来自未合入的 WS 构建,不构成对官方构建缺陷的认定。我已同步更新 #1926 正文:标注 #1923 已撤回关闭,并明确该 issue 的保留行为发现独立成立于对 WS lane 代码本身的验证( |
[bot] 🏷 状态更新(来自对叠在其上的 #1936 的复审):master 已从 请作者 rebase 时以 |
|
Follow-up refactor (discussion in #1467, one-step generalization): extracted the transport-agnostic half of this PR into a reusable WebSocket bridge shell, leaving the Responses-specific half as the first entry of a codec table.
Verification: The branch is a pure fast-forward on top of this PR's head ( Happy to rework if you'd rather keep the PR single-protocol and land the shell separately — this shape just makes the second protocol (whatever it is) a codec file + one table entry. |
[bot] 🏷 第五轮审查:ws-bridge 重构 — 行为保持已验证;一个基线谱系的关键发现 本轮范围:commit ① 行为等价性(重构审查核心) — 逐行比对旧
② 本地验证(独立树 @85cf11db):typecheck PASS;定向 83/83(ws-bridge 3 + responses-websocket 34 + wire-contract + opencode-v2);build PASS,dist 自包含保持(ws 内联;bufferutil/utf-8-validate 仍为 ws 标准可选 addon)。CI on ③ ④ 两个小问题(补丁就绪;第一条已本地应用并验证通过): function stubLoopbackSocket(): net.Socket {
const socket = new net.Socket();
Object.defineProperty(socket, "remoteAddress", { value: "127.0.0.1" });
return socket;
}
// test 2 内:
const upgrade = (headers: Record<string, string>, duplex?: Duplex) => handler(
Object.assign(new http.IncomingMessage(stubLoopbackSocket()), { url: "/bili/fake/http://127.0.0.1:9/echo", headers }),
duplex ?? new Duplex(),
Buffer.alloc(0),
);
assert.equal(upgrade({ "x-bili-plugin": "opencode", "x-bili-plugin-conversation": "ses" }), false); // wrong marker
assert.equal(upgrade({ "x-bili-plugin-conversation": "ses" }), false); // missing marker
assert.equal(upgrade({ "x-bili-plugin": "fakehost" }), false); // missing conversation
const claimed = new Duplex({ read: () => {}, write: (c, e, cb) => cb(), final: (cb) => cb() });
claimed.on("error", () => {});
assert.equal(upgrade({ "x-bili-plugin": "fakehost", "x-bili-plugin-conversation": "ses" }, claimed), true); // positive controlb. zh-CN 镜像缺失:
这两点我没有直接 push 到 generic 分支:该分支反正要 replay 到 v180 线(见 ③),随 replay 一并落入可避免在 stale lineage 上的额外往返。如希望直接应用到当前 generic 分支,我可以执行。 七问结论:
判定:重构本身审查通过(行为保持,证据如上)。合入前必须先解决基线谱系(replay 至 v180 tip,含 Buffer fix)+ 落实上述两个小修,最终 head 全量 CI 绿 → human merge。 |
|
Huge thanks @darkness-A — this draft is the feature. The ACP-aware Responses-over-WebSocket design (dual-leg checkpoints, envelope dispatch into the existing pipeline, the diagnostics conventions, and the sparse-terminal reconstruction from #1866) all come from your work, and it's carried forward verbatim in the stack below. What we extended on top, and why:
All of your commits are inside PR #1968 ( |
Outcome
Fixes #1844. Fixes #1866.
Implements OpenCode V2 <-> WebSocket <-> bili ACP <-> WebSocket <-> OpenAI Responses, including the ChatGPT OAuth/Codex endpoint. Both model network legs use WS while the existing ACP pipeline still processes the conversation.
The user authorized this integration on 2026-10-01 and subsequently authorized the sparse-terminal follow-up after local OAuth acceptance found repeated tool calls. This updates the existing contribution rather than replacing it.
Implementation
wsas a build-time dependency. Add WS wire contract WC-013 and isolated real OpenCode V2.0.20 WS CI coverage; retain the existing V2.0.3 Chat Completions job.Follow-up: sparse terminal output (#1866)
The original PR saved only
response.completed.response.output. A response may already have delivered a completed tool call inresponse.output_item.donewhile terminal output is empty, omitted, or partial. Losing that call orphaned the next tool result during ACP processing and could cause repeated tool execution.Both checkpoint boundaries now accumulate completed output items by
output_indexand merge terminal items by ID. Internal non-streaming responses receive the complete assembled output; streaming frames and tool arguments stay unchanged. Only completed responses establish checkpoints. Diagnostics report restored item counts without payload contents.Regression tests cover full, empty, omitted, partial-prefix, and partial-suffix terminal output, indexed ordering/opaque reasoning, actual folds, and three successive tool-result continuations. The real OpenCode E2E asserts exactly one post-fold status call, its matching result, retained summary, removed bulky history, and no primary-request HTTP fallback.
Failure-combination hardening
The user requested abnormal-combination coverage and explicitly selected minimal diagnostics. This follow-up adds eight cases (34 dedicated WS tests in total) and extends the sparse-output real-fold case with a sequence of missing checkpoints, idle disconnects, and connection-limit rotation.
Minimal WS diagnostics include connection/session labels, failure phase, numeric close code, full/delta mode, and checkpoint-reset/recovery reasons. New diagnostic messages exclude credentials, URLs, raw close reasons, payloads, and upstream error bodies; assertions check that exclusion. Normal lifecycle details are debug, transport failures are warn. Existing HTTP error logging is outside this new diagnostic surface.
No new production defect was established by these cases. This is regression coverage and observability, not an exactly-once guarantee for arbitrary host-tool side effects or validation of the real OAuth refresh lifecycle.
Config surface
No new or renamed runtime config fields,
BILI_*variables, CLI flags, or config semantics. Existing activation, routing, compression hierarchy, and tunnel mechanisms express this feature.ACP_TEST_E2E_OC_WSis a test-only gate following the existing convention. The implementation does not rewrite the user's transport choice.No manual package-version bump, acp-kernel pin change, or persistence-format change. Version 0.1.179 is inherited from current master; socket checkpoints remain connection-local.
Final verification
Rebased the existing feature and sparse-terminal fix onto master
d4746c4ecd211adc5ff12fc0079d138337b50933.git range-diffreports both earlier patches unchanged; the hardening is an additive follow-up commit on the same PR.git diff --check: PASS..envrouting).d4746c4e, same environment: 3590 total, 3565 PASS, 10 FAIL, 15 skipped. All ten failing test locations match exactly: two intests/codex-overlay-env.test.ts, six intests/launcher.test.ts, one intests/update-dsh-self-refresh.test.ts, and one intests/update-pi-self-refresh.test.ts. These are existing Windows symlink/platform failures; the full local suite is not green. No failing assertions were weakened or skipped.127.0.0.1:8199/v1remains unverified locally. The earlier user-run live ChatGPT OAuth acceptance below remains the live evidence, distinct from these isolated fake-upstream regressions.The new logs take effect when the local proxy next starts from the rebuilt artifact. The user's live services were not restarted during this work.
User-run live ChatGPT OAuth acceptance
After installing the fixed local build, the user reported that repeated calls stopped. Their log records a real plugin compression with upstream input 335615 -> 172429, then continuing WS requests at 174342 and 174855 input tokens. Restoration diagnostics recovered 1, 5, 2, and 4 streamed output items absent from terminal output. This confirms the sparse-terminal fix was exercised on the live OAuth route; it is bounded acceptance, not a guarantee for every upstream shape or attribution of every historical repetition.
Review boundaries
view=ws-expandedsizes describe reconstructed processing envelopes, not incremental wire bytes. Socket reuse does not guarantee incremental input after every history edit.