Repository navigation
fix: guard native fetch intercept against third-party re-arm (#1158 L1) - #1187
Merged
Merged
Conversation
dsh-http-proxy 0.1.3 re-applies by writing its module-load-time frozen originalFetch over globalThis.fetch (settings hot-reload triggers refresh), silently un-routing every model request away from bili while the session keeps working. Reproduced live on Windows (issue #1158, run5: zero proxied requests after a settings touch; task still completed). Guard the property instead of trusting the assignment to survive: install a configurable accessor whose setter re-chains any third-party fetch as the downstream of a fresh chain top, so model traffic keeps routing through bili. Re-arm limit (16) stops two self-healers from fighting forever; non-configurable host properties keep the classic direct install. Verified on the same Windows VM with the same repro: requests keep flowing through bili after the settings refresh (plugin mode, acp-usage recorded).
Contributor
📦 Built Package ArtifactBranch: Option A — Install from npm PR tag (recommended)npm install -g billion-context@pr-1187Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf billion-context-pr1187.tgz
npm install -g packageInstall instructions are refreshed on each push. |
5 tasks done
…the fetch guard (#1158) Reporter follow-up on #1158: (1) an escape hatch for setups that NEED the third-party egress on top (bili's upstream proxying is HTTP-only — a SOCKS5 egress configured in dsh-http-proxy stops riding claimed traffic while the guard holds); BILI_RECLAIM_FETCH_PATCH=0 restores the classic direct install. (2) Evict attempts now log a [bili-native] warning with a running count, so 'un-routed by a third party' is diagnosable instead of silent. Documented in CONFIGURATION.md/zh with the egress note.
This was referenced Sep 23, 2026
This was referenced Oct 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
installNativeFetchInterceptnow installsglobalThis.fetchas a guarded accessor instead of a plain assignment. Any third party that later writesglobalThis.fetch(e.g. dsh-http-proxy's settings-refresh re-apply) becomes the downstream of a fresh chain top, so model traffic keeps routing through bili instead of being silently un-routed.Root cause (L1 of #1158)
dsh-http-proxy 0.1.3 captures
originalFetch = globalThis.fetchonce at apply time and, on every settings hot-reload (refresh()), writesglobalThis.fetch = createRoutingFetch(entry.fetch, originalFetch, hosts)— using the frozen pre-bili capture. Load order (dsh-http-proxy first, bili second) means bili's patch wraps dsh's routing fetch; the first settings change after startup re-arms dsh with the bare fetch and kicks bili out of the chain. The session keeps working (requests go direct through dsh's chain), so compression silently stops — zero error, zero proxied request.Reproduced live on the Windows 10 VM (issue #1158 repro, run5): after a 13s settings touch,
bili.logshows zero forwarded requests for the whole task, while the task completes normally.Fix
makeChain(downstream)parameterizes the patch body;warned/replacedOriginsstay shared across re-armed links.fetchproperty is configurable (Node default), installObject.definePropertywith aget/setpair:get→ the current chain top (always ours);set→ re-chain:top = makeChain(v)— the third-party function becomes our downstream.[bili-native] third-party globalThis.fetch install detected (#1158) — re-chaining as downstream (evict attempt N)— "un-routed by a third party" is now diagnosable instead of silent.BILI_RECLAIM_FETCH_PATCH=0restores the classic direct install (no guard) — for setups that need the third-party egress on top; see the egress note below._resetForTest()restores the pre-install data-property descriptor captured at install time.The dsh flow after this change: dsh re-arm writes its routing fetch → our setter re-chains it → host model calls read
globalThis.fetch(our top) → URL rewritten to the bili proxy → dispatched through dsh's routing fetch (loopback target, outsideproxyHosts, goes direct to the local bili proxy).While the guard holds, claimed model traffic is dispatched by the bili proxy itself — it no longer rides the third-party chain's egress. In particular: a SOCKS5 proxy configured in dsh-http-proxy stops receiving claimed traffic, and bili's own upstream proxying supports HTTP proxies only (SOCKS5 is rejected/ignored — Clash users should use the HTTP form of a mixed port). If you need the third-party egress back: set
BILI_RECLAIM_FETCH_PATCH=0and configure the egress at bili's level ("proxy": "http://…"). Documented in CONFIGURATION.md / CONFIGURATION.zh-CN.md.Verification
forward POST+[plugin] [acp-usage]with 99% cache hit all the way to task completion. Control (unpatched 0.1.139, run5): zero proxied requests after the touch.processTurnin bili.log, prefix cache 99–100%, tool channel alive — compression, nudge and budget all restored.tests/native-intercept-selfheal.test.ts: 5 tests — frozen-bare-fetch reset re-chains; third-party wrapper becomes downstream (model URL rewritten through it, non-model URLs pass through untouched); guarded property is transparent when nobody fights; non-function/self writes ignored;BILI_RECLAIM_FETCH_PATCH=0keeps the classic direct install (third party wins).npm run typecheck✅,npm test2356 pass / 0 fail (2 gated E2E skips) ✅,npm run build✅.Scope
This is the host-side defense for L1 (bili keeps routing no matter what a third-party fetch patch does). The reporter's chained-fix for dsh-http-proxy itself (blind overwrite → chain onto the current global) is the upstream half of the defense-in-depth — tracked in the issue. L3 (commandcode provider freezing
fetchImplat construction) needs its own upstream fix; L2 is downgraded to watch (gate 6/6 pass).Refs #1158