Repository navigation
fix: never spawn over a pinned model channel when the attach target is down (#1365) - #1370
Conversation
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.
…unreachable attach target (#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 #983/#1130 spawn fallback byte-for-byte. Late evidence rebinds the tool channel to where the models actually go (convergence rule). Stacked on PR #1275 (toolsReady gate); rebases onto master once that lands. Closes #1365
📦 Built Package ArtifactBranch: Option A — Install from npm PR tag (recommended)npm install -g billion-context@pr-1370Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf billion-context-pr1370.tgz
npm install -g packageInstall instructions are refreshed on each push. |
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.
The three BILI_ATTACH_* / BILI_PERSIST rows in CONFIGURATION.md's env table started with a space before the pipe, unlike every other row — inconsistent markdown table formatting.
[bot] 🏷 Review complete — direction correct, regression-clean, mergeable after #1275 lands. I pushed two small commits to the branch (details below); CI on the final head is still running, I'll confirm here once it's green. ① Original issue (direction gate). #1365 is real and correctly diagnosed. I verified the mechanism against master: the dead-target branch of ② Regression ledger (existing behaviors on touched paths, judged individually):
③ Code. Key verifications:
④ Test validity. The six integration regressions have teeth (spawn counters, env assertions, dual-origin traffic split, end-to-end self-heal). One gap: none of them exercised the two real recording sites — they all drive ⑤ Diff cleanliness. Clean: 10 files, every line purpose-related, no lockfile/version churn, no whitespace noise. One cosmetic defect fixed in passing (commit Local pre-flight (final head Stacking: still stacked on open PR #1275 (mergeable=true, no conflict detected). Rebase onto master once #1275 merges, as described — no semantic conflict expected since the evidence recording sits strictly before the gate await by design. CI on 中文摘要:核实了 #1365 的脑裂根因真实存在(attach 目标挂掉时无条件 spawn 第二实例,而静态路由的模型通道仍钉在原目标上),修复方向与实现均正确、回归清点未发现意外行为变更;已在分支上直接补上缺失的接线点回归测试(pre-gate 证据记录证明等 5 个)和文档表格格式小缺陷,本地全量测试绿,待 CI 确认,建议 #1275 合入后合并本 PR。 |
[bot] 🏷 CI update: fully green on final head The Corroborating evidence that this suite flakes under CI load rather than regressing here:
Per the loop guard I'm noting this here for you rather than auto-filing: if you want it tracked, the standalone issue would be "claude-native hook e2e (#1322/#1335 family) intermittently misclassifies the port owner under runner load — consider making the classification probe retry or the test more tolerant" — your call. Final verdict: ready to merge once #1275 lands. #1275 is still open (mergeable=true); rebase onto master after it merges, then this can go in. No outstanding review concerns from my side. 中文摘要:CI 已在最终提交上全绿(ubuntu-22 一次失败经同提交重跑通过,判定为 claude-native hook e2e 在负载下的偶发误分类,与本 PR 改动无关,证据已列);评审无遗留问题,待 #1275 合入并 rebase 后即可合并。 |
|
深审通过(独立验证,含真机 e2e): 设计核验(#1365 三层裁决全对):
实测(本机独立 worktree):
合并无阻塞。 |
[bot] 🏷 收到独立深审确认,谢谢。三层裁决在真机 e2e 下站住(每跳 intercepted+claimed、/acp status 活、acp_status+compress 真实执行)+ 我方无遗留事项。剩余为纯人工步骤:合入 #1275 → 本分支 rebase 到 master → 合并 #1370(当前 head 中文摘要:owner 独立核验设计与真机 e2e 通过、合并无阻塞;待办仅剩人工流程(#1275 先合 → rebase → 合并本 PR),agent 侧工作已全部完成。 |
Closes #1365
What & why
When a dsh/opencode attach target (
BILLION_CONTEXT_PROXY) is transiently unreachable,verifyAttachAndRecoverunconditionally fell back to spawning a second proxy instance. If the process's provider baseURL statically routes model traffic through that target (http://127.0.0.1:8787/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 (the issue's exact repro).Fix (evidence-driven pinning)
state.routedOrigin) whenever attributed/bili/<upstream>model traffic is observed — recorded before any gate await so the first request can never self-deadlock against fix: hold dsh first model request until ACP tool registration (+ real-dsh headless native-lane E2E) #1275's toolsReady gate.BILI_ATTACH_HEALTH_DEADLINE_MS, default 15s) instead of migrated away from. On timeout the failure is loud (persisted + console.error with actionable guidance), the register base is cleared, and every subsequent model request re-probes (~10s cadence) → self-heals when the external manager restarts the proxy. No second instance is ever spawned.BILI_ATTACH_EVIDENCE_GRACE_MS, default 5s) covers the decision-before-first-request race (probe fails at t≈0, first request lands at t≈1s). Expiry keeps the legacy [dsh] nativeproxyEnvOrigin()把临时 origin 冻结进 BILLION_CONTEXT_PROXY,绕过 ensureProxyRunning() 的 instance 验活;工具调用全部 fetch failed,需重启宿主 #983/native attach 模式无运行时 respawn:共享代理的属主退出后,attach 方全部模型请求永久硬失败 #1130 spawn fallback byte-for-byte (all existing regression tests pass unchanged).Both dsh-native and opencode-native lanes are fixed (same root cause instance in each). kimi/zcode already wait-or-throw and are untouched.
Behavior changes (old → new)
New env knobs are default-invariant when unset.
Stacking note
This branch is stacked on PR #1275 (toolsReady gate, hot files
src/agent/dsh-native.ts+src/agent/native-intercept.ts). It rebases onto master once #1275 merges; no semantic conflict expected — this fix records evidence strictly before the gate await by design.Pre-flight
npm run typecheck— cleannpm test— 2653 tests, 2642 pass, 0 fail, 11 skipped (by design)npm run build— OKtests/dsh-native.test.ts,tests/opencode-native.test.ts,tests/native-intercept.test.ts): 64/64 pass, including 8 new regression tests covering: pinned-wait-recovers (no spawn), pinned-persistent-dead (loud refusal + env kept + self-heal), late-evidence convergence, runtime-death-pinned (no migration), plusnoteRoutedOriginunit + pre-gate recording proof.