Skip to content

[PR] fix(agent/dsh): keep the no-init threw takeover-gate verdict synchronous for the WS-lane consumer (#4841) - #4844

Open
ranxianglei wants to merge 1 commit into
masterfrom
2026-10-26_ws-gate-sync-threw-fastpath
Open

ranxianglei wants to merge 1 commit into
masterfrom
2026-10-26_ws-gate-sync-threw-fastpath

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Part of #4841

What

The WS-lane consumer (src/agent/native-ws-intercept.ts) decides per connection with a SYNCHRONOUS compare:

if (state.takeoverGate !== undefined && state.takeoverGate(target) === false) { /* direct */ }

It cannot await before the socket opens. Any gate verdict that is a Promise — even one that resolves to false — never matches === false, so "refuse takeover, go direct" silently fails and the connection gets rewritten onto the proxy instead. The fetch lane awaits correctly (native-intercept.ts :1203 / :1372); only the WS lane was affected. On master, dsh's threw arm returned a Promise for every call shape (settleThrewAttribution(...).then(...)).

Fix (option B from the issue — provider-side contract, small closed loop)

  • src/agent/dsh-native.ts: the threw arm now answers no-init (WS-shaped) calls synchronously, with exactly the verdict of its exhausted-settle tail. That tail (doom check + event wording + refusal) is extracted into a shared threwExhaustedVerdict so both shapes judge oversize identically — one doom call, one event string. Rationale pinned in comments: without init there is no body to decode or doom-check; the settle-retry's tick-scale recovery is unreachable synchronously (the top-of-gate probe re-runs on every call, so self-heal is not lost); streak untouched (no settle attempt = no give-up budget consumed). Init-carrying (fetch-lane) calls keep the full async settle-retry path unchanged.
  • src/agent/native-intercept.ts: the takeoverGate field doc now states the contract explicitly — providers MUST return a non-Promise verdict for no-init (WS-shaped) calls; a Promise there is silently lost.
  • src/agent/native-ws-intercept.ts: pointer comment at the sync comparison site.
  • tests/dsh-native.test.ts: new regression test pins the verdict CLASS both directions — no-init call under threw yields raw === false BEFORE any await, logs the standard refusal line, consumes no settle budget (threwStreak stays 0); negative row: init-carrying call stays a Promise, settle-retry still refuses, streak increments; recovery re-claims once attribution returns. Three existing tests (#2924a claim-after-recovery, #3581a probe counts, #3581b latch arming) now drive their gate calls WITH init — they pin FETCH-LANE semantics, which by definition carry init; bare calls mean the WS shape under the new contract. All assertions preserved unchanged.

Behavior change (old → new, required disclosure)

dsh threw-state, no-init gate call: verdict was a Promise<false> → now synchronously false. The only observable difference is the WS lane, where the refusal now takes effect instead of being silently lost (connection goes direct instead of being rewritten onto the proxy). The fetch lane awaits and is unaffected. Reachable today only when a pi-installed WS wrapper reads a dsh-owned ACTIVE_STATE within one process — real hosts run separate processes, so no production behavior changes today; this closes the latent contract gap (#4841 reachability analysis, p3).

Notes

@ranxianglei ranxianglei changed the title fix(agent/dsh): keep the no-init threw takeover-gate verdict synchronous for the WS-lane consumer (#4841) [PR] fix(agent/dsh): keep the no-init threw takeover-gate verdict synchronous for the WS-lane consumer (#4841) Oct 26, 2026
@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-26_ws-gate-sync-threw-fastpath (76f1464)

Latest build — install this exact version

npm install -g billion-context@0.0.9278-pr.4844.43451f7

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Recent builds (commit → version)

commit version build
76f1464 billion-context@0.0.9278-pr.4844.43451f7 build
378ce9e billion-context@0.0.6253-pr.4844.17eaa53 build

Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr4844.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

查重: 不重复 —— 本条是 [PR] 镜像(对应 GitHub PR #4844,分支 2026-10-26_ws-gate-sync-threw-fastpath,单 commit 378ce9e80,base 即当前 master cdac1c099)。出站查重(open+closed,按失败签名「ws 车道同步 === false 判决消费」):无并列在途工作;相邻的 #4832 改的是同一闭包内相邻的 none arm hunk(61f31b921),本 PR 动的是 threw arm + settle 尾部,不同区;父 issue #4841 的 A 方案(消费方 DeferredWebSocket)明确不在本 PR 范围、留作后续决策。

这是已完成工作的 review 唤醒,不重做。按 PR Review 规范独立审:① 方向(对照 #4841)→ ② 回归面清点 → ③ 代码本体 → ④ 测试有效性 → ⑤/⑤b diff 与代码整洁 → CI 状态。结论按结构化八问给出,稍后回帖。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

独立审核完成(核对代码 + 定向验证 + 读 CI,非重做)。结论:ready to merge。

八问:

  1. 是什么问题:WS 车道在 socket 打开前用同步比较(=== false)决定接管与否;任何 Promise 判决都匹配不上,dsh threw 态的「拒绝接管、走直连」被静默吞掉——连接被改写到代理上而不是直连。
  2. 什么原因导致的:threw 臂对每种调用形状都返回 settleThrewAttribution(...).then(...) —— 即使调用方无法等待也是 Promise。异步部分(per-tick settle-retry)对 no-init 调用本无意义:没有 init 就没有可解码/可 doom-check 的 body,socket 路由在打开时一次性决定。真正的缺陷是契约缺口:takeoverGate 类型允许 Promise,而一个消费者只能同步处理,且没有任何地方写明哪种形状必须同步。
  3. 影响范围与严重程度:潜伏,p3。仅当 pi 安装的 WS wrapper 与 dsh 拥有的 ACTIVE_STATE 同进程共读时可达;生产宿主分进程运行,今天无用户可见影响。若触达:一条 WS 连接错误地走代理而非直连(未压缩降级),不崩溃、不丢数据。
  4. 怎么修复的:按 WS-lane takeover gate consumer misses Promise verdicts (sync === false comparison) | WS 车道 takeover gate 同步 === false 比较漏掉 Promise 判决(拒绝直连静默失效) #4841 推荐的 option B(provider 侧契约):threw 臂对 no-init 形状同步返回 exhausted-settle 判决 —— 尾部抽成共享 threwExhaustedVerdict,两种形状共用同一 doom 判定与事件措辞;takeoverGate 字段文档写明契约(no-init 调用必须返回非 Promise);同步比较处加指针注释。自愈保留:gate 顶部探测每次调用重跑。streak 不动:该路径不做 settle 尝试,不消耗 give-up 预算。
  5. 是否有回归问题:触碰路径的既有行为逐项审过 ——
    • ok 臂(同步 true + streak 复位):不变。
    • none 臂:本 PR 不动(其 no-init fast path 属 [PR] fix(agent/dsh): decode content-encoded request bodies in fork-adoption and recall body gates #4832 的 hunk,不在这里)。
    • threw 臂带 init(fetch 车道):逻辑不变 —— 尾部抽取逐字节一致(同一 doom 数学、同一事件措辞、同一 refusal 记账、.then() 内 streak 递增原样);#2924a/#3581a/#3581b 三个测试钉住 fetch-lane 语义,全过。
    • threw 臂不带 init:有意变更(见下方披露),是唯一行为差。
    • refusal 日志/健康信号(refuse()/noteAttrRefusal):两条路径走同一个 refuse(),每端点一次日志行,无双重计数,面板/banner 信号保持诚实。
    • 高危模式逐项:无阈值/时序/输出格式漂移;无 fail-fast 变吞错(拒绝反而从「失效」变「生效」);无缓存/重试失效(settle-retry 是 gate 内部机制,不碰 wire)。
  6. 是否破坏缓存:不涉及 —— 不碰缓存/重试游标/去重键。
  7. 是否改了设计方向:没有。按 WS-lane takeover gate consumer misses Promise verdicts (sync === false comparison) | WS 车道 takeover gate 同步 === false 比较漏掉 Promise 判决(拒绝直连静默失效) #4841 推荐在 provider 侧收口契约缺口;option A(consumer 侧 DeferredWebSocket)按 issue 决定留作后续决策,未夹带。
  8. 是否引入了新的配置:没有。

行为变更披露(旧→新):dsh threw 态 + no-init gate 调用:判决 Promise<false|refuse-oversized> → 同步 false|refuse-oversized。唯一可观察差异在 WS 车道(生产代码中唯一的 no-init 调用方;fetch 车道两处调用点均恒带 init,已逐一审计),拒绝从此生效而非静默丢失。

独立验证记录:

  • 调用点审计:生产代码恰好三个调用方 —— WS intercept(src/agent/native-ws-intercept.ts:417,永不传 init)、fetch 车道(src/agent/native-intercept.ts:1210 / :1379,恒传 init);dsh 是唯一安装 takeoverGate 的 provider。fast path 只可能被 WS 形状命中。
  • 抽取保真:threwExhaustedVerdict 与被替换的旧尾部逐字节一致;bodyProvablyOverWindow(undefined, …) 缺数据即返回 undefined(不 doom),fast path 对无 body 的 WS 调用只会落到普通 refuse() → false,不可能误拒。
  • 负控:本地临时移除 fast path 后新测试精确挂在 pre-await 断言上(raw 是 Promise),恢复后干净 —— 回归测试有牙。
  • 本地定向:PR head 上 dsh-native / native-ws-intercept / native-intercept / dsh-conversation-recall / dsh-llm-stream-attribution 五文件 168/168 绿。
  • 远程 CI(head 378ce9e):全矩阵绿 —— 8 个 test 分片(ubuntu 22/24、windows 22)、static-gates、mysql-contract、全部 guards(含 unused-exports / lock-sync / kernel-guard / config-surface-guard)、build-artifact。无继承红,不需要 merge ci-fixes。正文里提到的 issue4125-giveup-reason born-red 在本次 head 的 CI run 中未显形(矩阵全绿),无需追查。

交互提醒:#4832(未合入)给同一闭包的相邻 none 臂加同型 fast path —— hunk 不同、冲突风险低;谁后合并谁 rebase(与正文所述一致)。

判定:可合(合并按钮归人)。

…ous for the WS-lane consumer (#4841)

The WS intercept compares state.takeoverGate(target) === false without
awaiting; a Promise verdict never matches and the refusal is silently
lost. The dsh threw arm now answers no-init (WS-shaped) calls with the
same verdict as its exhausted-settle tail (extracted shared helper),
and the sync-by-contract rule is documented on the gate field and at
the ws comparison site. Regression test pins the verdict class both
ways (sync false pre-await / init-carrying stays a Promise).
@ranxianglei
ranxianglei force-pushed the 2026-10-26_ws-gate-sync-threw-fastpath branch from 378ce9e to 76f1464 Compare November 12, 2026 05:58
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Conflict resolved & pushed. Rebased the single-commit PR onto current master (c26c31ace4), resolved the 2-file conflict, and force-pushed with --force-with-lease → new head 76f1464cbf. The branch is now 1 ahead / 0 behind master (clean, no more merge conflict). Local verification on the rebased head: typecheck ✓, build ✓, targeted tests/dsh-native.test.ts 77/77 ✓ (includes the new #4841 sync-class test and #5838's egress-legs test).

⚠️ Key finding for the reviewer — master's #5838 already superseded this PR's core mechanism. The PR existed to fix the WS-lane consumer that compared takeoverGate(target) === false without awaiting (a Promise verdict never matched → refusal silently lost). Since the PR's base, master's #5838 restructured the WS lane to await the verdict inside its deferred window — so that specific bug class is already closed at the root on master. What remains in the PR after the rebase is coherent, tested, and non-regressing, but its value is now:

  • src/agent/dsh-native.ts — the DRY shared helper threwExhaustedVerdict + the no-init sync fast path (now a latency optimization — skips the settle-retry round-trip — not a correctness requirement, since every lane awaits).
  • src/agent/native-intercept.ts — doc comment (corrected, see below).
  • tests/dsh-native.test.ts — the sync-vs-async verdict-class pin.

Whether the PR is still worth merging for that remaining value is the owner's call at merge time — I did not need a decision to resolve the conflict deterministically, so I proceeded rather than parking it.

How the conflict was resolved (per file):

Transparency: this run's process was force-restarted once by the supervisor after ~35 min idle; after the restart I re-verified git state (rebase intact), reinstalled deps, and re-ran the full local verification above before pushing. No impact on the result.


八问(中文,供人工复核)

  1. 是什么问题:PR [PR] fix(agent/dsh): keep the no-init threw takeover-gate verdict synchronous for the WS-lane consumer (#4841) #4844 与 master 冲突(merge state dirty),需 rebase 消解后才能合并。
  2. 什么原因导致的:master 在 PR 基点之后推进了 390 个提交,其中 [Bug][DSH] Codex auto/WebSocket bypasses native fetch interception while compaction is disabled #5838 重构了 WS 车道(把同步 === false 比较改成在 deferred window 里 await 判定),与本 PR 改的同一批文件撞车;master 又用 [Bug][dsh] Model requests silently bypass the compression proxy (fail-open gate) — 927K-token prompt sent raw, 1-token reply, session bricked with 400 #5613/The default modelContextLimit of 200000 underestimates the context window for custom provider routing, and over-window | modelContextLimit 缺省 200000 会把自定义 provider 路由的窗口算小,且超窗的「无归因」请求会被照发而不是本地拒绝 #5907 把 bodyProvablyOverWindow 换成 bodyOverWindowDetail 双档计价,PR 抽出的 helper 引用的旧符号已不存在。
  3. 影响范围与严重程度:仅本 PR 分支;不消解则 PR 无法合并。对已发布/master 行为零影响。
  4. 怎么修复的:把 PR 单提交 rebase 到当前 master;native-ws-intercept.ts 整个取 master([Bug][DSH] Codex auto/WebSocket bypasses native fetch interception while compaction is disabled #5838 已取代 PR 的同步比较机制,保留会与 [Bug][DSH] Codex auto/WebSocket bypasses native fetch interception while compaction is disabled #5838 双重调用 gate,属回归);dsh-native.ts 把 master 的新双档计价并入 PR 的共享 helper threwExhaustedVerdict、保留 no-init 同步快路径;native-intercept.ts 修正因 [Bug][DSH] Codex auto/WebSocket bypasses native fetch interception while compaction is disabled #5838 而失效的 WS-lane takeover gate consumer misses Promise verdicts (sync === false comparison) | WS 车道 takeover gate 同步 === false 比较漏掉 Promise 判决(拒绝直连静默失效) #4841 文档注释;测试文件自动合并后已自洽。
  5. 是否有回归问题:无。native-ws-intercept.ts 与 master 逐字节一致(diff 为空);dsh 侧保留的是 PR 原有、已通过评审的行为;本地 typecheck + build + tests/dsh-native.test.ts 77/77 全绿。
  6. 是否破坏缓存:不涉及(未触碰缓存/重试/游标/去重键)。
  7. 是否改了设计方向:未改方向,但需知悉——PR 的原始动机(修 WS 消费端同步 === false 丢失拒绝)已被 master 的 [Bug][DSH] Codex auto/WebSocket bypasses native fetch interception while compaction is disabled #5838 从根上解决(WS 车道现 await 判定)。rebase 后 PR 剩余价值 = dsh 侧 DRY helper + no-init 同步快路径(现为降延迟优化,非正确性必需)+ 文档 + 测试;是否仍值得合并由 owner 合并时定夺。
  8. 是否引入了新的配置:不涉及。

收工判定:冲突已消解并推送,PR 现为干净可合并状态(1 ahead / 0 behind)。CI 将在新 head 76f1464cbf 上重跑——本轮未从镜像缓存断言红绿(缓存 ~60s 刷新,尚未覆盖新 head)。

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant