惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

人人都是产品经理
人人都是产品经理
有赞技术团队
有赞技术团队
WordPress大学
WordPress大学
月光博客
月光博客
T
Tailwind CSS Blog
阮一峰的网络日志
阮一峰的网络日志
小众软件
小众软件
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Last Week in AI
Last Week in AI
大猫的无限游戏
大猫的无限游戏
S
SegmentFault 最新的问题
罗磊的独立博客
Jina AI
Jina AI
酷 壳 – CoolShell
酷 壳 – CoolShell
宝玉的分享
宝玉的分享
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 三生石上(FineUI控件)
量子位
雷峰网
雷峰网
Apple Machine Learning Research
Apple Machine Learning Research
美团技术团队
博客园 - 聂微东
V
V2EX

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix: lazy-load undici dispatchers · openclaw/openclaw@85e...
shakkernerd · 2026-05-06 · via Recent Commits to openclaw:main

@@ -1,9 +1,12 @@

1-

import { Agent, EnvHttpProxyAgent, getGlobalDispatcher, setGlobalDispatcher } from "undici";

21

import { hasEnvHttpProxyAgentConfigured, resolveEnvHttpProxyAgentOptions } from "./proxy-env.js";

32

import {

43

createUndiciAutoSelectFamilyConnectOptions,

54

resolveUndiciAutoSelectFamily,

65

} from "./undici-family-policy.js";

6+

import {

7+

loadUndiciGlobalDispatcherDeps,

8+

type UndiciGlobalDispatcherDeps,

9+

} from "./undici-runtime.js";

710811

export const DEFAULT_UNDICI_STREAM_TIMEOUT_MS = 30 * 60 * 1000;

912

@@ -46,10 +49,12 @@ function resolveDispatcherKey(params: {

4649

return `${params.kind}:${params.timeoutMs}:${autoSelectToken}`;

4750

}

485149-

function resolveCurrentDispatcherKind(): DispatcherKind | null {

52+

function resolveCurrentDispatcherKind(

53+

runtime: Pick<UndiciGlobalDispatcherDeps, "getGlobalDispatcher">,

54+

): DispatcherKind | null {

5055

let dispatcher: unknown;

5156

try {

52-

dispatcher = getGlobalDispatcher();

57+

dispatcher = runtime.getGlobalDispatcher();

5358

} catch {

5459

return null;

5560

}

@@ -63,13 +68,15 @@ export function ensureGlobalUndiciEnvProxyDispatcher(): void {

6368

if (!shouldUseEnvProxy) {

6469

return;

6570

}

71+

const runtime = loadUndiciGlobalDispatcherDeps();

72+

const { EnvHttpProxyAgent, setGlobalDispatcher } = runtime;

6673

if (lastAppliedProxyBootstrap) {

67-

if (resolveCurrentDispatcherKind() === "env-proxy") {

74+

if (resolveCurrentDispatcherKind(runtime) === "env-proxy") {

6875

return;

6976

}

7077

lastAppliedProxyBootstrap = false;

7178

}

72-

const currentKind = resolveCurrentDispatcherKind();

79+

const currentKind = resolveCurrentDispatcherKind(runtime);

7380

if (currentKind === null) {

7481

return;

7582

}

@@ -92,10 +99,19 @@ export function ensureGlobalUndiciStreamTimeouts(opts?: { timeoutMs?: number }):

9299

}

93100

const timeoutMs = Math.max(DEFAULT_UNDICI_STREAM_TIMEOUT_MS, Math.floor(timeoutMsRaw));

94101

_globalUndiciStreamTimeoutMs = timeoutMs;

95-

const kind = resolveCurrentDispatcherKind();

102+

if (!hasEnvHttpProxyAgentConfigured()) {

103+

lastAppliedTimeoutKey = null;

104+

return;

105+

}

106+

const runtime = loadUndiciGlobalDispatcherDeps();

107+

const { EnvHttpProxyAgent, setGlobalDispatcher } = runtime;

108+

const kind = resolveCurrentDispatcherKind(runtime);

96109

if (kind === null) {

97110

return;

98111

}

112+

if (kind !== "env-proxy") {

113+

return;

114+

}

99115100116

const autoSelectFamily = resolveUndiciAutoSelectFamily();

101117

const nextKey = resolveDispatcherKey({ kind, timeoutMs, autoSelectFamily });

@@ -105,23 +121,13 @@ export function ensureGlobalUndiciStreamTimeouts(opts?: { timeoutMs?: number }):

105121106122

const connect = createUndiciAutoSelectFamilyConnectOptions(autoSelectFamily);

107123

try {

108-

if (kind === "env-proxy") {

109-

const proxyOptions = {

110-

...resolveEnvHttpProxyAgentOptions(),

111-

bodyTimeout: timeoutMs,

112-

headersTimeout: timeoutMs,

113-

...(connect ? { connect } : {}),

114-

} as ConstructorParameters<typeof EnvHttpProxyAgent>[0];

115-

setGlobalDispatcher(new EnvHttpProxyAgent(proxyOptions));

116-

} else {

117-

setGlobalDispatcher(

118-

new Agent({

119-

bodyTimeout: timeoutMs,

120-

headersTimeout: timeoutMs,

121-

...(connect ? { connect } : {}),

122-

}),

123-

);

124-

}

124+

const proxyOptions = {

125+

...resolveEnvHttpProxyAgentOptions(),

126+

bodyTimeout: timeoutMs,

127+

headersTimeout: timeoutMs,

128+

...(connect ? { connect } : {}),

129+

} as ConstructorParameters<UndiciGlobalDispatcherDeps["EnvHttpProxyAgent"]>[0];

130+

setGlobalDispatcher(new EnvHttpProxyAgent(proxyOptions));

125131

lastAppliedTimeoutKey = nextKey;

126132

} catch {

127133

// Best-effort hardening only.

@@ -140,17 +146,29 @@ export function resetGlobalUndiciStreamTimeoutsForTests(): void {

140146

*/

141147

export function forceResetGlobalDispatcher(): void {

142148

lastAppliedTimeoutKey = null;

149+

if (!hasEnvHttpProxyAgentConfigured()) {

150+

if (!lastAppliedProxyBootstrap) {

151+

return;

152+

}

153+

lastAppliedProxyBootstrap = false;

154+

try {

155+

const { Agent, setGlobalDispatcher } = loadUndiciGlobalDispatcherDeps();

156+

setGlobalDispatcher(new Agent());

157+

} catch {

158+

// Best-effort reset only.

159+

}

160+

return;

161+

}

143162

lastAppliedProxyBootstrap = false;

144163

try {

164+

const { EnvHttpProxyAgent, setGlobalDispatcher } = loadUndiciGlobalDispatcherDeps();

145165

const proxyOptions = resolveEnvHttpProxyAgentOptions();

146-

if (hasEnvHttpProxyAgentConfigured()) {

147-

setGlobalDispatcher(

148-

new EnvHttpProxyAgent(proxyOptions as ConstructorParameters<typeof EnvHttpProxyAgent>[0]),

149-

);

150-

lastAppliedProxyBootstrap = true;

151-

} else {

152-

setGlobalDispatcher(new Agent());

153-

}

166+

setGlobalDispatcher(

167+

new EnvHttpProxyAgent(

168+

proxyOptions as ConstructorParameters<UndiciGlobalDispatcherDeps["EnvHttpProxyAgent"]>[0],

169+

),

170+

);

171+

lastAppliedProxyBootstrap = true;

154172

} catch {

155173

// Best-effort reset only.

156174

}