Repository navigation
fix: hold dsh first model request until ACP tool registration (+ real-dsh headless native-lane E2E) - #1275
Conversation
📦 Built Package ArtifactBranch: Option A — Install from npm PR tag (recommended)npm install -g billion-context@pr-1275Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf billion-context-pr1275.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 收到。开始 review PR #1275(Closes #1268,Fixes #1274)。初步检查已过:分支已 rebase 到当前 master(088bb34),diff 干净(6 文件 +987/-7,无无关改动),方向正确——hold 首请求直到注册完成是决策点级的根因修复(R1 无法事后补章,#1158 同类失效类别),#1274 带合规来源标记。继续:E2E 测试有效性、 |
[bot] 🏷 Review 结论:可以合并(合并由人来)。PR #1275(Closes #1268,Fixes #1274)五项审查全部通过,证据如下。 ① 原 issue 方向关:通过。#1268 要求真 dsh + 确定性假上游零 token 断言 #1239 四项验收——PR 逐项落地且无降级方案(headless 可非交互驱动已实测)。#1274 的修复方向正确:盖章决策必须发生在「注册尝试完成」这一事实之后,R1 无法事后补章,hold 是决策点级根因修复而非症状掩蔽;有界( ② 回归审查(diff 触碰路径的既有行为清点,逐项结论):
③ 代码审查:gate 设计正确——首次注册尝试完成(成功或失败)即解除,后续 ④ 测试有效性:单元 3 例断言有牙(精确 header 值 + 时序边界 ⑤ diff 整洁度:6 文件全部与 PR 目的相关,无空行/重排噪音,无锁文件扰动,无 version 改动。
验证证据(rebased head a5d744d,当前 master 之上):本地 typecheck 干净; 热文件协调提醒(不阻塞本 PR):#1272(opencode native E2E)也改 小观察(非阻塞,不立项): 一句话中文摘要:review 通过——PR 修复了 dsh native lane 首请求抢跑导致整会话静默不认领的盖章竞争(#1274,根因级 hold-gate 修复,仅影响 dsh lane,超时精确回落旧行为),并按 #1239 四项验收落地真 dsh headless 零 token E2E(逐跳盖章断言有牙、负向对照已验证),本地与 CI 全绿、diff 干净,可以合并;唯一注意项是与 #1272 共享 fake-upstream 文件的合并顺序协调。 |
a5d744d to
c7f345f
Compare
|
Independent deep review complete — executed for real, locally: rebased onto current master (clean, head The fix is correct and narrow:
Ready to merge when CI is green. |
|
独立复核完成 — 可合并 验证链(全在 c7f345f 上)
修复本体(#1274 R1 印记竞速)逐点核过
E2E(#1268 车道)
非阻塞观察
无阻塞项,建议合并。(#1274 自动关;#1268 本体由这条的 E2E 车道覆盖,合并后可一并关;#1346 同步。) |
A fresh dsh native session fires its first model request as soon as the proxy origin is ready, but ACP manifest registration lands ~90ms later (proxy spawn dominates boot). The first request then short-circuits at headersFor (!toolsReady) and rides wire mode un-stamped — the #1158 'zero proxy traffic silently unclaimed' failure class, deterministic for single-shot headless invocations where the whole session is round one. Add an optional toolsReady gate to NativeInterceptState: model-API requests await it (bounded by readyTimeoutMs) before headersFor is consulted, in both the routed (/bili/) and main rewrite paths. Only the dsh lane arms it (apply() resolves it when the first registration attempt finishes, success or failure); every other lane leaves it undefined and is behaviorally unchanged. Timeout or failed registration falls through to exactly today's wire-mode behavior; a later maybeRetry success flips stamping on without re-arming.
#1268) Drives a real @deepseek-ai/dsh (pinned 0.1.5-rc.3) in its production profile-install form — hermetic DSH_HOME, headless profile, local build wired into the profile node_modules with the shipped dsh.bundle.patch.yml, llm-pi-ai fake provider pointing at tests/e2e/fake-upstream-chat.mjs — and asserts the four #1239 acceptance items on the JSONL oracle: 1. EVERY request hop carries x-bili-plugin=dsh + one stable x-bili-plugin-conversation=session-* id (direct defense of #1158); 2. /acp session binding + status endpoint reachable live (GET /__bili/plugin/status?conversationId=<conv>); 3. acp_status really executes client-side (tool call + panel result in re-sent history); 4. compress really folds (persisted kernel session blocks>=1, metadata.pluginAgent=dsh, '[Compressed ... N block(s)' result row). The dsh-http-proxy bundle coexistence case ships as env-only (proxy vars pointed at a dead loopback port): rc.3 installs an undici dispatcher, not a globalThis.fetch replacement, so it cannot evict the patch — the every-hop stamp assertion pins that layering against future drift. Gate ACP_TEST_E2E_DSH_NATIVE=1 (skip by default), E2E_CHECK=1 preflight. CI workflow mirrors ci-e2e-native.yml.
c7f345f to
d9e6a26
Compare
[bot] 🏷 确认收到你的独立复核——结论一致。补一个针对当前 head 的核验(我上一轮 review 的是
至此双重独立验证齐了(我的 review + 你的本地执行),无遗留问题。合并由你来(系统规则禁止 agent 合并):#1275 一句话中文摘要:针对 rebase 后的最新 head d9e6a26 复验通过——修复与测试内容相对我原 review 版本零漂移,8 条 CI(含真 dsh e2e)全绿,与你本地独立执行结果一致,可以合并。 |
[bot] 🏷 确认。两轮独立 review(我的 + 你的)结论完全对齐,逐点无分歧——门位置(headersFor 之前求值会永久冻结未盖章决定)、失败语义(resolve-on-first-attempt、失败回落与 PR 前逐字节相同、maybeRetry 无需重臂)、有界等待(15s 上限、稳态零成本)、三条路径区分(routed/main 过门、unattributed 不过门)、三种测试形状 + 真时序断言、 合并目标 head 的最终状态: PR 当前:open、 一句话中文摘要:两轮独立复核结论完全一致、无阻塞项,合并目标 head d9e6a26 已验证零漂移且 CI 全绿,万事俱备,等你手动合并即可。 |
The six integration regressions drive noteRoutedOrigin through the _test hooks, bypassing the two real recording sites: - fetch-patch routed branch (native-intercept): add a pre-gate proof (first attributed /bili/ request records state.routedOrigin while the toolsReady gate is still pending — the exact #1275 self-deadlock race), an unattributed-rider boundary test (#1117: another plugin's channel must not pin ours), and unit coverage for noteRoutedOrigin (sticky/transition-hook/malformed) plus observeRoutedOrigin (immediate on pre-set evidence, clean expiry, mid-window arrival). - opencode V2 route (createNativeRoute): already-routed /bili/ URLs are skipped by isModelApiUrl by design, so assert the route records the pinned origin before that gate. Also consumes the previously dangling noteRoutedOrigin import.
…unreachable attach target (ranxianglei#1365) When a dsh/opencode attach target (BILLION_CONTEXT_PROXY) is transiently unreachable, the old verifyAttachAndRecover unconditionally fell back to spawning a second proxy instance. If the process's provider baseURL statically routes model traffic through that target (/bili/<upstream>), the model channel stays pinned to the original origin while bili tools move to the spawned one — every tool call then 404s 'unknown plugin conversation', the context can no longer be compressed, and preflight fails with 502 until the session is abandoned. Fix: observe routed-channel evidence (state.routedOrigin, recorded by the shared fetch patch and the opencode V2 route before any gate await). With evidence, a dead attach target is WAITED ON (BILI_ATTACH_HEALTH_DEADLINE_MS, default 15s) instead of migrated away from; on timeout the failure is loud and self-healing (register base cleared, re-probed on every model request, ~10s cadence) and the env stays frozen. Without evidence, a grace window (BILI_ATTACH_EVIDENCE_GRACE_MS, default 5s) covers the decision-before-first-request race; expiry keeps the legacy ranxianglei#983/ranxianglei#1130 spawn fallback byte-for-byte. Late evidence rebinds the tool channel to where the models actually go (convergence rule). Stacked on PR ranxianglei#1275 (toolsReady gate); rebases onto master once that lands. Closes ranxianglei#1365
Closes #1268
Fixes #1274
What this does
1. Fix — R1 stamp race on the dsh native spawn lane (#1274, found while building the E2E).
A fresh dsh native session fires its first model request as soon as the proxy origin is ready, but ACP manifest registration lands ~90ms later (proxy spawn dominates boot, ~850ms). The first request short-circuits at
headersFor(!toolsReady) before the session id is even read and rides wire mode un-stamped — nox-bili-pluginheader, anonymouspfa-*session, no named conversation. That is exactly the #1158 "zero proxy traffic silently unclaimed" failure class, and it is deterministic for every single-shot headless invocation (dsh --profile headless "<task>"), where the whole session IS round one.Observed timeline (BILI_DBG + bili.log):
The fix adds an optional
toolsReady?: Promise<unknown>toNativeInterceptState. Model-API requests await it (bounded byreadyTimeoutMs, default 15s) beforeheadersForis consulted — in both the routed (/bili/) and main rewrite paths ofsrc/agent/native-intercept.ts. Only the dsh lane arms it (src/agent/dsh-native.tsapply()resolves it when the first registration attempt finishes, success or failure); every other lane leaves itundefinedand is behaviorally unchanged (one extra microtask on the routed path at most). Timeout or failed registration falls through to exactly today's wire-mode behavior; a latermaybeRetrysuccess flips stamping on without re-arming. A one-shot warn is logged when a request was held ≥50ms:[bili-native] held model request ${held}ms for ACP tool registration (#1268).2. Test — the issue's actual deliverable: real dsh + bili profile vs deterministic fake upstream (#1239's four acceptance items).
tests/e2e/e2e-native-dsh.test.tsdrives a real@deepseek-ai/dsh(pinned 0.1.5-rc.3) in its production profile-install form — hermeticDSH_HOME, wired headless profile (local build into the profilenode_modulesvia the shippeddsh.bundle.patch.yml),llm-pi-aifake provider pointing attests/e2e/fake-upstream-chat.mjs, cwd outside the repo — and asserts on the JSONL oracle:x-bili-plugin=dsh+ one stablex-bili-plugin-conversation=session-*id — direct defense of 方式一安装的dsh 原生插件:llm-pi-ai 传输(OpenAI SDK + options.fetch 注入)绕过 globalThis.fetch 拦截,模型请求不进代理、压缩完全不生效 #1158;/acpbinding + status endpoint reachable live (GET /__bili/plugin/status?conversationId=<conv>against the instance-record origin);acp_statusreally executes client-side (tool call + panel result visible in re-sent history — plugin-mode carrier);compressreally folds: persisted kernel sessionblocks>=1,metadata.pluginAgent=dsh,[Compressed m…–m… → N block(s), … tokens saved.]result row.The scripted sequence (filler ×~63KB → acp_status ×3 → compress of the oldest user message) runs inside ONE headless process because headless has no
--resume— same driving style as the #1158 floor-8 harness.dsh-specific risks answered in-thread: (a) headless drives fine non-interactively — no HTTP-only degraded harness needed; (b)
dsh-http-proxycoexistence: rc.3 installs an undici dispatcher, not aglobalThis.fetchreplacement, so it structurally cannot evict the patch — the E2E ships with proxy env vars pointed at a dead loopback port and asserts every hop stays stamped, pinning that layering against future drift; unit-level re-arm behavior remains pinned bytests/native-intercept-selfheal.test.ts(#1187/v0.1.140 guarded accessor).Gating mirrors the pi lane (#1246):
ACP_TEST_E2E_DSH_NATIVE=1(skip by default),E2E_CHECK=1zero-token preflight;.github/workflows/ci-e2e-dsh-native.ymlmirrorsci-e2e-native.yml(manual-dispatch + PR trigger).readyTimeoutMs(default 15000ms; in practice <100ms) and arrive stamped (plugin=dsh, namedsession-*conversation) — plugin mode from round 1. On timeout or failed registration the request proceeds exactly as before (wire mode fallback). Only the dsh lane arms the gate; pi/opencode/other lanes are unchanged.compress.preserveRecentTokens: 0so the kernel's default 5K-token protection window doesn't swallow the scripted filler; precedent =src/preflight.ts:900auto-relaxes exactly these knobs on overflow. Production defaults untouched.Verification (rebased head, kernel 0.0.86)
npm run typecheckcleannpm test: 2495/2504 pass, 0 fail (9 skipped by design)npm run buildOKrequest must be plugin-stamped (x-bili-plugin), got null); restored → green. The assertions have teeth.Commits:
fix:(gate, 3 files +172/-5 incl. unit tests) +test:(E2E + workflow + fake-upstream oracle fields, +815/-2).