Skip to content

fix(#1795): route preset BILLION_CONTEXT_PROXY to attach in the pi and omp native lanes - #1796

Merged
ranxianglei merged 3 commits into
masterfrom
2026-09-30_pi-attach-preset-proxy
Oct 1, 2026
Merged

ranxianglei merged 3 commits into
masterfrom
2026-09-30_pi-attach-preset-proxy

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Sep 30, 2026 •

Copy link
Copy Markdown
Owner

Closes #1795.

Two commits, two lanes, one posture (#886/#983 mechanism):

The hole (#1795)

A preset BILLION_CONTEXT_PROXY (outer bili MITM launch, or user-exported proxy) closed nativeBootstrapGate, so the fetch intercept never installed: model traffic went direct and uncompressed, while the shared plugin still found the proxy through the env — every tool forward 404'd against a proxy that never saw the session. omp had the same hole, with ompTrafficRidesBili treating the preset as "riding bili" for the #1774 watchdog — hiding it.

The fix (both lanes)

  • planNative*: kill-switch (BILLION_CONTEXT_PLUGIN=0 / lane var) > /bili/ launch (BILI_PROVIDER_REWRITES) > attach (BILLION_CONTEXT_ATTACH ?? BILLION_CONTEXT_PROXY) > spawn. Garbage/blank presets fall back to spawn (self-managed), never dead-off.
  • attach mode arms even under NODE_TEST_CONTEXT; env written synchronously so readers align immediately; runtime death re-probed; bug: dsh-native — attach 目标瞬时不可达 → 回退 spawn 第二实例:routed baseURL 下工具/模型通道必然脑裂(工具 404 → preflight 502 → 会话不可自愈) #1365 late routed-evidence rebind (only converges on a reachable target).
  • verifyAttachAndRecover: healthy target stays attached (no migration); DEAD + routed evidence → wait for the pinned origin (no second instance that would 404 tools); DEAD with no evidence past BILI_ATTACH_EVIDENCE_GRACE_MS → unfreeze the env, fall back to a self-spawned proxy.
  • installNativeFetchIntercept installs whenever mode !== "off" — the actual hole.
  • ompTrafficRidesBili keeps its pinned semantics — unchanged.

Tests

…tive lane

The pi native plugin treated a preset BILLION_CONTEXT_PROXY as an opt-out (nativeBootstrapGate returns false) -> no fetch intercept installed -> all model traffic direct and uncompressed. Port the #886/#983 plan-based attach mode (planNativePi + verifyAttachAndRecover) so a preset proxy attaches to it and routes through it, falling back to spawn only when dead.
@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-30_pi-attach-preset-proxy (39aa737)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.1833-pr.1796.fee7655

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

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr1796.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

[bot] 🏷 On it — this is a completed agent PR (ework-agent-pr marker), so I'm reviewing rather than redoing. Status so far:

  • Duplicate screen: no other open/closed issue or PR covers the pi-lane preset-proxy stand-down; this is the only open PR touching pi-native.ts attach behavior. Not a duplicate.
  • Branch: single commit 06dd0b64 on 2026-09-30_pi-attach-preset-proxy, base = current master 834f7d14 (fresh, no drift). Diff: src/agent/pi-native.ts (+211/−29), tests/pi-native.test.ts (+99). No version bump, no lockfile, no config surface.
  • CI at first glance: real pi package-native lane e2e ✅, real codex e2e ✅, hermetic registry e2e ✅, build-artifact ✅; unit tests (ubuntu/windows × node 22/24) + dsh/codex-MCP jobs still in progress.

I'll post the full structured review (七问) once CI settles and I've finished reading the diff against the opencode/dsh reference implementations.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review 完成(已拉取分支逐行核对代码、本地复跑、CI 日志取证)。结论:可合并 —— CI 仅有的两处红是 pre-existing 的 dsh Windows flake,与本 PR 无关(已单独立项 ranxianglei/billion-context#1797)。

结构化七问

  1. 是什么问题:pi native lane 在 BILLION_CONTEXT_PROXY 被预设时(父级 bili launcher 导出、或 shell 残留)静默丢失全部压缩——所有模型请求直连上游、零 bili.log、400 不透明。opencode v2: preset BILLION_CONTEXT_PROXY disarms native routing while tools still find the proxy — all tool forwards 404 #886(opencode)/[dsh] native proxyEnvOrigin() 把临时 origin 冻结进 BILLION_CONTEXT_PROXY,绕过 ensureProxyRunning() 的 instance 验活;工具调用全部 fetch failed,需重启宿主 #983(dsh)修过的同类缺陷,pi lane 漏掉了。
  2. 什么原因导致的:nativeBootstrapGate() 把「env 里已有 PROXY」当作 opt-out → 不装 fetch intercept。因果链还有一层自触发:bootstrap 自己写 process.env.BILLION_CONTEXT_PROXY = origin,子进程 pi 继承这个 env 后同样 disarm——opencode/dsh 早已用 plan-based attach 化解,pi 没移植。
  3. 怎么修复的:把 opencode/dsh 成熟的 plan-based attach 模式原样移植进 src/agent/pi-native.ts:新增 planNativePi(env) → {off|attach|spawn}(预设 PROXY / 显式 BILLION_CONTEXT_ATTACH → attach 到该 origin;stand-down 只剩 kill-switches 与 BILI_PROVIDER_REWRITES);新增 verifyAttachAndRecover(origin) 三态判定(健康→attach;pinned 目标已死→拒绝 spawn、保留 env;无路由证据→grace 后回退 spawn);fetch intercept 在 attach/spawn 两种模式都安装。我逐行对照了参考实现(opencode-native.ts:93/:175、dsh-native.ts:109/:276):逻辑一致,差异仅为 log 前缀与 lane 适配(env 写入位置——pi.ts 从 env 读 proxy,dsh 那里刻意不写 env,属合理差异而非不一致)。
  4. 是否有回归问题:对触碰路径的既有行为逐项清点:kill-switches / BILI_PROVIDER_REWRITES → off 不变;显式 ATTACH 语义不变;无效/垃圾 preset 值由「stand-down 直连」变为「spawn 自有 proxy」(严格更优,非漂移);唯一新增副作用是 preset-PROXY 场景现在也会打 BILLION_CONTEXT_NATIVE=pi 标记(旧 gate 关闭时不打)→ 共存的 legacy 扩展会 back off,堵住了潜在双重压缩洞(有意为之);attach 模式不注册 origin waiter → 已验证 awaitNativeProxyOrigin() 无 waiter 时立即返回 undefined,无挂起风险;fallback-to-spawn 窗口有界(probe 失败 + ≤5s grace + spawn)且 intercept live-resolve 自愈。fail-fast 未变吞错(pinned-dead 路径保持 refuse)。无阈值/时序/输出格式漂移。
  5. 是否破坏缓存:不涉及。不动 message refs / prefix cache / 增量游标;attach 只是路由到既有 proxy,压缩状态在该 proxy 的 session store 中(设计意图)。
  6. 是否改了设计方向:没有——这是 pi lane 向 opencode/dsh lane 的收敛(同一 plan-based attach 模式),无边界/数据流转向。双压缩模式均已推演:此路径仅 plugin-mode carrier(proxy-mode acp_summary 不受影响),diff 无任何 server/wire 侧文件。
  7. 是否引入了新的配置:无。读取的所有 env key 均为既有(BILLION_CONTEXT_PROXY/BILLION_CONTEXT_ATTACH、BILI_PROVIDER_REWRITES、BILI_ATTACH_HEALTH_DEADLINE_MS/BILI_ATTACH_EVIDENCE_GRACE_MS 随函数从 opencode lane 带入,默认值不变)。

验证证据

  • 本地:npm ci + node --import tsx --test tests/pi-native.test.ts → 14/14 pass。5 个新回归测试断言有牙:preset→attach 决策表(trailing-slash 归一化、kill-switch//bili/ 优先于 preset、垃圾 preset→spawn 而非 off)、显式 ATTACH 优先、native attach 模式(opencode 面)同样缺运行时 respawn:V2 route hook fail-closed + V1 launcher 插件 frozen origin #1135 dead-target 回退 spawn(真实 verifyAttachAndRecover 对死端口 + stubbed spawn)、healthy target 保持 attached(真实本地 HTTP server 验证 manifest 可达)。无恒真断言。
  • CI @ 06dd0b64:ubuntu 22/24 全量绿(head 3474 tests = master 3469 + 恰好这 5 个新测试,全过);e2e、real codex/dsh/opencode/pi 真客户端 lane、hermetic registry、build-artifact、version-guard 全绿。
  • Windows 两处红的取证(下载了三个失败 job 的完整日志):w22 与 w24 各自唯一失败测试都是 tests/dsh-native.test.ts 的 #983 maybeRetry self-heals a base-less register after a failed respawn(dsh lane,与本 PR diff 零交集);pristine master 834f7d14 的 windows-22 同一测试同样失败,且 master 一次历史 run 里 windows-24 也失败过(重跑转绿)→ pre-existing、Windows-only 时序敏感 flake,非本 PR 引入。作者沙箱观察到的两个 Linux 失败(runLaunch dsh … #535 phase 4、clientError backstop #1529)与 CI 实际失败者不同名,但同属「master 可复现的时序敏感 flake」一类,不影响结论。
  • diff 整洁度:仅 src/agent/pi-native.ts(+211/−29)+ tests/pi-native.test.ts(+99/−1);无 version/lockfile/跑题文件;base 新鲜零漂移。符合 §7.4 auto-merge gate 各项条件。

判定

可合并,建议直接 merge。 合并前无需任何改动;Windows matrix 的红由 ranxianglei/billion-context#1797(来源标记:分析本 PR 时发现)跟踪,不阻塞本 PR。

ranxianglei and others added 2 commits October 1, 2026 17:15
…ative lane

omp had the same pseudo-attach hole as pi (#1795): a preset
BILLION_CONTEXT_PROXY closed nativeBootstrapGate, so the fetch
intercept never installed — model traffic went direct and
uncompressed while tools still found the proxy through the env,
and every tool forward 404'd. ompTrafficRidesBili even treated the
preset as "riding bili" for the #1774 watchdog, hiding the hole.

Port the #886/#983 posture to the omp lane (mirrors pi PR #1796
and opencode/dsh):

- planNativeOmp: kill-switch > /bili/ rewrite launch > attach
  (BILLION_CONTEXT_ATTACH ?? BILLION_CONTEXT_PROXY) > spawn;
  garbage/blank presets fall back to spawn, never dead-off
- armNativeOmp: attach mode arms even under NODE_TEST_CONTEXT —
  env written synchronously (pi.ts readers align), runtime death
  re-probed via verifyAttachAndRecover, #1365 routed-origin rebind
- verifyAttachAndRecover: healthy target stays attached (no
  migration); DEAD + routed evidence waits for the pinned origin
  (no second instance that would 404 tools); DEAD with no evidence
  past BILI_ATTACH_EVIDENCE_GRACE_MS unfreezes the env and falls
  back to a self-spawned proxy
- installNativeFetchIntercept now installs whenever mode !== off —
  the actual hole

ompTrafficRidesBili keeps its pinned semantics (a preset proxy
means a launcher owns routing, regardless of the native opt-out).

Tests: plan semantics incl. the #1795 regression pin, dead-target
fallback spawn replacing the env origin, healthy-target stay-put
against a real manifest server.
@ranxianglei ranxianglei changed the title fix(#1795): route preset BILLION_CONTEXT_PROXY to attach in the pi native lane fix(#1795): route preset BILLION_CONTEXT_PROXY to attach in the pi and omp native lanes Oct 1, 2026
@ranxianglei
ranxianglei merged commit c95f9fb into master Oct 1, 2026
13 checks passed
@ranxianglei
ranxianglei deleted the 2026-09-30_pi-attach-preset-proxy branch October 15, 2026 05:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant