Skip to content

[PR] fix(#2791): heal setter-invisible globalThis.fetch evictions in the native intercept chain - #2804

Closed
ranxianglei wants to merge 2 commits into
masterfrom
2026-10-11_fetch-eviction-watchdog
Closed

ranxianglei wants to merge 2 commits into
masterfrom
2026-10-11_fetch-eviction-watchdog

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Follows #2791 — intercept-layer hardening for the dsh anthropic-messages lane bypass class. The silent-layer half (orphan-suspect detection at mint) is #2802; this PR covers the root-cause layer #2802 explicitly left open ("host fetch-capture timing").

What this changes

The #1158 guarded accessor on globalThis.fetch sees every ASSIGNMENT to the property, but not DELETE or REDEFINE — both bypass setters entirely on a configurable property. That shape silently un-routes every model request while the host keeps working: no setter write, no #1158 diagnostic, traffic leaves un-stamped, and the proxy mints an anonymous pfa-* session per cross-protocol switch (fold ledger orphaned, cold full-history re-fold — the incident shape).

installFetchChain now arms a periodic integrity watchdog alongside the guard (guarded install only; the classic path is untouched):

  • every 30 s it identity-compares the live descriptor against the installed accessor (cur.get === accessor.get && cur.set === accessor.set, the same comparison resetFetchChainForTest uses);
  • on eviction it adopts whatever fetch the evictor left behind as downstream (same policy as the setter arm; falls back to the module-load anchor when the property was deleted), re-installs the guard over it, and warns [bili-native] … lost the bili guarded accessor (#2791) … (reinstall N);
  • budget of 8 reinstalls, then one final give-up report and silence; a non-configurable property gets one give-up report;
  • the timer is unref'd (never holds the process alive); resetFetchChainForTest stops it (no timer leak across the suite).

Durability: new optional NativeInterceptState.onFetchIntegrityEvent hook receives each full diagnostic line; dsh-native wires it to persistClientEvent so GUI hosts (stderr invisible, #1158 lesson) keep the event in the shared bili.log. All other hosts stay console-only.

Behavior change disclosure

  • NEW: periodic (30 s) descriptor check on hosts with the guarded install (all native lanes by default). Cost: one getOwnPropertyDescriptor per tick.
  • NEW behavior: delete/redefine evictions were previously PERMANENT AND SILENT; they are now repaired within one tick (≤30 s) with a loud warn + durable event. Intended fix, not drift.
  • Unchanged: routing semantics, wire shape, config schema, persistence format, kernel/.

Config surface

No new knobs. The watchdog rides the existing BILI_RECLAIM_FETCH_PATCH escape hatch (=0 → classic install → no guard, no watchdog). The CONFIGURATION.md en/zh entries for that var are extended accordingly.

Tests

Five new suites in tests/native-intercept-selfheal.test.ts: intact-silent / defineProperty-eviction (+ durability hook + downstream adoption) / deletion-reanchor / budget-exhaustion-give-up / reclaim-off-no-watchdog — deterministic, console wording pinned. Local evidence: typecheck clean, selfheal suite 26/26, sibling native/dsh/pi/omp/opencode-native suites 141/141.

Not covered here: the exact host-side trigger of the original incident needs in-process instrumentation on the reporter's machine (static analysis eliminated options.fetch injection and cached-client capture for stock dsh 0.2.0-rc.2 — see issue thread). On any recurrence the watchdog discriminates: warn line present ⇒ main-realm delete/redefine eviction (repaired); absent ⇒ the trigger lives elsewhere (e.g. a worker realm the patch never reached).

@github-actions

github-actions Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-11_fetch-eviction-watchdog (472a63a)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.3092-pr.2804.575f7ca

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-pr2804.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] 🏷 PR #2804 review 完成 — 已拉分支逐行审完 diff(6 文件 +202/-4)、核对 #2791 方向、本地定向验证。发现并顺手修掉一处 CI 门禁失败,已推送到 PR 分支。

顺手小修(已推送,独立标注 commit 472a63acb):src/agent/fetch-chain/index.ts 的 FetchChainOptions 带 export 但仅模块内使用,unused-exports 门禁判 INTERNAL_ONLY 失败——这个红还连带跳过了 test job(ci.yml 里 test needs unused-exports),全量单测在 CI 上实际没跑过。已去掉 export(grep 证实无外部引用),等 CI 在 new head 重跑。本地验证:worktree 中 selfheal 套件 26/26、兄弟套件 native-intercept/native-fetch-chain/dsh-native 105/105 全绿,与 PR 描述一致。


结构化八问:

  1. 是什么问题:guarded accessor(方式一安装的dsh 原生插件:llm-pi-ai 传输(OpenAI SDK + options.fetch 注入)绕过 globalThis.fetch 拦截,模型请求不进代理、压缩完全不生效 #1158)只拦对 globalThis.fetch 的赋值;configurable 属性上的 DELETE / REDEFINE 完全绕过 setter——fetch 被静默换走,所有模型请求脱管,proxy 每次跨协议切换 mint 匿名 pfa-* 会话,fold ledger 成孤儿(即 dsh anthropic-messages lane bypasses native-intercept fetch patch: anonymous pfa-* session, fold ledger orphaned, silent ~182s re-fold on cross-protocol switch #2791 事故形态)。
  2. 什么原因导致:守卫装在 property descriptor 的 set 上,而 delete/redefine 根本不经过 set——是防御面缺口,不是某次调用出错。原事故的确切 host 侧触发点静态分析未定(stock dsh 0.2.0-rc.2 排除了 options.fetch 注入与 cached-client capture),本 PR 修的是「触发后永久失守且无声」这一层,feat: surface identity-loss takeovers with an identity-orphan conflict event (#2791) #2802 修 mint 时的孤儿嫌疑检测,分工清晰。
  3. 影响范围与严重程度:所有走 guarded install 的 native lane(GUI/daemon host 尤甚,stderr 不可见时连诊断都没有)。此前 delete/redefine 驱逐 = 永久 + 完全静默,属高危;修复后 ≤30s 自愈 + 响亮 warn + dsh 持久化事件。
  4. 怎么修复的:install 时并行挂一个周期完整性 watchdog(仅 guarded 路径,classic 不动):每 30s 用与 resetFetchChainForTest 相同的函数身份比较(cur.get === accessor.get && cur.set === accessor.set)核对活 descriptor;被驱逐则把驱逐者留下的 fetch 按 setter arm 同款策略 adopt 为下游(属性被删则回退 module-load anchor),重装 guard 并 warn (reinstall N);预算 8 次后终报一次转静默;非 configurable 属性直接终报。timer unref,reset 钩子停表。dsh-native 新增可选 onFetchIntegrityEvent 钩子接 persistClientEvent,GUI host 事件进共享 bili.log,其余 host 保持 console-only。
  5. 是否有回归问题:逐项审过既有行为——方式一安装的dsh 原生插件:llm-pi-ai 传输(OpenAI SDK + options.fetch 注入)绕过 globalThis.fetch 拦截,模型请求不进代理、压缩完全不生效 #1158 guarded install 路径纯增量无改动 ✓;reclaim-off/classic 路径零改动 ✓;resetFetchChainForTest 仅加停表 ✓;NativeInterceptState 加的是可选字段 ✓;console.warn 与该 host-side 模块既有模式(方式一安装的dsh 原生插件:llm-pi-ai 传输(OpenAI SDK + options.fetch 注入)绕过 globalThis.fetch 拦截,模型请求不进代理、压缩完全不生效 #1158/bili-native 安装/re-arm globalThis.fetch 不校验所有权,与网络 scope 类插件交错后全局 fetch 悬空 → 全进程 "baseFetch is not a function" #1410/DSH0.1.7-rc.2中billion-context与dsh-codex-subscription的冲突? #1662)一致(logger 规则管 proxy server 模块,此处不违例)✓;wire shape/config schema/persistence/kernel 全部未触碰 ✓。无 fail-fast 变吞错、无语义漂移。测试是真断言(rewritten URL 落点、descriptor 重新 accessorize、8+1 预算数学、reclaim-off 返回 false),同步 seam 确定性良好,teardown 经 _resetForTest() 无 timer 泄漏。
  6. 是否破坏缓存:不涉及——host 侧拦截链,不碰会话/持久化/前缀缓存任何失效策略。
  7. 是否改了设计方向:不改。在 方式一安装的dsh 原生插件:llm-pi-ai 传输(OpenAI SDK + options.fetch 注入)绕过 globalThis.fetch 拦截,模型请求不进代理、压缩完全不生效 #1158 guard 架构内加硬化的完整性自愈,复用其 adopt-as-downstream 策略与 anchor 哲学(bili-native 安装/re-arm globalThis.fetch 不校验所有权,与网络 scope 类插件交错后全局 fetch 悬空 → 全进程 "baseFetch is not a function" #1410 oldest-live-anchor);若 anchor 也死,send() 内既有的 dead-closure 恢复仍兜底。
  8. 是否引入了新的配置:无新 knob。watchdog 搭现有 BILI_RECLAIM_FETCH_PATCH 逃生门(=0 → classic install → 无 guard 无 watchdog),CONFIGURATION.md en/zh 两版条目已同步扩展(diff 中核实)。

行为变更披露确认(作者已披露,复核无误):NEW 每 30s 一次 getOwnPropertyDescriptor(可忽略开销);delete/redefine 驱逐从「永久+静默」变为「≤30s 修复+响报+durable event」——是有意修复而非漂移。

判定:代码与测试质量达标,方向正确,唯一红灯(unused-exports)已修并推送;CI 在 new head 全绿后可合并(合并由人执行)。复发判别逻辑(warn 有 ⇒ 主 realm delete/redefine 已修;无 ⇒ 触发点在 patch 够不到的 realm)写进了 PR 描述,合理。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 CI 全绿确认(new head 472a63acb):全部 11 个 workflow run 完成且 success——主 CI(含之前红的 unused-exports 与被其跳过的全量 test job)+ e2e real-codex / fake-codex / codex-persona / pi-codex-ws / native-pi / native-dsh / native-opencode / local-registry / Windows codex overlay / PR Build Artifact。

之前唯一红灯(FetchChainOptions unused export)已由标注 commit 472a63acb 修复并验证。无阻塞项,可合并(合并由人执行)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

(ai: zhipuai-lb/glm-5.3)

孤儿票清理:标题指向的 issue 已关闭,修复已由其他路径落地。关单;误判请 reopen。

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant