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

推荐订阅源

T
The Blog of Author Tim Ferriss
IT之家
IT之家
Engineering at Meta
Engineering at Meta
WordPress大学
WordPress大学
博客园 - 三生石上(FineUI控件)
博客园 - 聂微东
C
Check Point Blog
T
Tailwind CSS Blog
博客园 - Franky
H
Help Net Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Google DeepMind News
Google DeepMind News
博客园 - 叶小钗
J
Java Code Geeks
腾讯CDC
罗磊的独立博客
爱范儿
爱范儿
阮一峰的网络日志
阮一峰的网络日志
Martin Fowler
Martin Fowler
酷 壳 – CoolShell
酷 壳 – CoolShell
I
InfoQ
B
Blog
V
Visual Studio Blog
F
Fortinet All Blogs

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(gateway): bound loopback preflight calls · openclaw/o...
vincentkoc · 2026-05-27 · via Recent Commits to openclaw:main

@@ -24,6 +24,8 @@ import { extractPayloadText } from "./test-helpers.agent-results.js";

2424

const CLI_CRON_MCP_PROBE_MAX_ATTEMPTS = 10;

2525

const CLI_CRON_MCP_PROBE_VERIFY_POLLS = 20;

2626

const CLI_CRON_MCP_PROBE_VERIFY_POLL_MS = 2_000;

27+

const CLI_CRON_MCP_LOOPBACK_REQUEST_TIMEOUT_MS = 30_000;

28+

const CLI_CRON_MCP_LOOPBACK_MAX_BODY_BYTES = 1_048_576;

27292830

function shouldLogCliCronProbe(): boolean {

2931

return (

@@ -111,6 +113,17 @@ type LoopbackToolListEntry = {

111113

inputSchema?: unknown;

112114

};

113115116+

function parsePositiveInt(value: string | undefined, fallback: number, name: string): number {

117+

if (!value?.trim()) {

118+

return fallback;

119+

}

120+

const parsed = Number.parseInt(value, 10);

121+

if (!Number.isFinite(parsed) || parsed <= 0) {

122+

throw new Error(`invalid ${name}: ${value}`);

123+

}

124+

return parsed;

125+

}

126+114127

function asLoopbackSchemaRecord(schema: unknown): Record<string, unknown> | null {

115128

return schema && typeof schema === "object" && !Array.isArray(schema)

116129

? (schema as Record<string, unknown>)

@@ -170,6 +183,7 @@ async function callLoopbackJsonRpc(params: {

170183

messageProvider?: string;

171184

accountId?: string;

172185

body: Record<string, unknown>;

186+

env?: NodeJS.ProcessEnv;

173187

}): Promise<LoopbackJsonRpcResponse> {

174188

const runtime = getActiveMcpLoopbackRuntime();

175189

if (!runtime) {

@@ -186,12 +200,34 @@ async function callLoopbackJsonRpc(params: {

186200

if (params.accountId) {

187201

headers["x-openclaw-account-id"] = params.accountId;

188202

}

189-

const response = await fetch(`http://127.0.0.1:${runtime.port}/mcp`, {

190-

method: "POST",

191-

headers,

192-

body: JSON.stringify(params.body),

193-

});

194-

const text = await response.text();

203+

const timeoutMs = parsePositiveInt(

204+

params.env?.OPENCLAW_MCP_LOOPBACK_PROBE_TIMEOUT_MS,

205+

CLI_CRON_MCP_LOOPBACK_REQUEST_TIMEOUT_MS,

206+

"OPENCLAW_MCP_LOOPBACK_PROBE_TIMEOUT_MS",

207+

);

208+

const maxBodyBytes = parsePositiveInt(

209+

params.env?.OPENCLAW_MCP_LOOPBACK_PROBE_MAX_BODY_BYTES,

210+

CLI_CRON_MCP_LOOPBACK_MAX_BODY_BYTES,

211+

"OPENCLAW_MCP_LOOPBACK_PROBE_MAX_BODY_BYTES",

212+

);

213+

const controller = new AbortController();

214+

const timer = setTimeout(() => controller.abort(), timeoutMs);

215+

let response: Response | undefined;

216+

let text = "";

217+

try {

218+

response = await fetch(`http://127.0.0.1:${runtime.port}/mcp`, {

219+

method: "POST",

220+

headers,

221+

body: JSON.stringify(params.body),

222+

signal: controller.signal,

223+

});

224+

text = await readBoundedResponseText(response, maxBodyBytes);

225+

} finally {

226+

clearTimeout(timer);

227+

}

228+

if (!response) {

229+

throw new Error("mcp loopback did not return a response");

230+

}

195231

if (!response.ok) {

196232

throw new Error(`mcp loopback http ${response.status}: ${text}`);

197233

}

@@ -205,6 +241,28 @@ async function callLoopbackJsonRpc(params: {

205241

return parsed;

206242

}

207243244+

async function readBoundedResponseText(response: Response, byteLimit: number): Promise<string> {

245+

const reader = response.body?.getReader();

246+

if (!reader) {

247+

return "";

248+

}

249+

const chunks: Buffer[] = [];

250+

let totalBytes = 0;

251+

for (;;) {

252+

const { done, value } = await reader.read();

253+

if (done) {

254+

break;

255+

}

256+

totalBytes += value.byteLength;

257+

if (totalBytes > byteLimit) {

258+

await reader.cancel();

259+

throw new Error(`mcp loopback response body exceeded ${byteLimit} bytes`);

260+

}

261+

chunks.push(Buffer.from(value));

262+

}

263+

return Buffer.concat(chunks, totalBytes).toString("utf8");

264+

}

265+208266

export async function verifyCliCronMcpLoopbackPreflight(params: {

209267

sessionKey: string;

210268

port: number;

@@ -224,6 +282,7 @@ export async function verifyCliCronMcpLoopbackPreflight(params: {

224282

sessionKey: params.sessionKey,

225283

messageProvider: params.messageProvider,

226284

accountId: params.accountId,

285+

env: params.env,

227286

body: {

228287

jsonrpc: "2.0",

229288

id: "init",

@@ -235,12 +294,14 @@ export async function verifyCliCronMcpLoopbackPreflight(params: {

235294

sessionKey: params.sessionKey,

236295

messageProvider: params.messageProvider,

237296

accountId: params.accountId,

297+

env: params.env,

238298

body: { jsonrpc: "2.0", method: "notifications/initialized" },

239299

});

240300

const toolsList = await callLoopbackJsonRpc({

241301

sessionKey: params.sessionKey,

242302

messageProvider: params.messageProvider,

243303

accountId: params.accountId,

304+

env: params.env,

244305

body: { jsonrpc: "2.0", id: "tools-list", method: "tools/list" },

245306

});

246307

const tools = Array.isArray((toolsList.result as { tools?: unknown[] } | undefined)?.tools)

@@ -265,6 +326,7 @@ export async function verifyCliCronMcpLoopbackPreflight(params: {

265326

sessionKey: params.sessionKey,

266327

messageProvider: params.messageProvider,

267328

accountId: params.accountId,

329+

env: params.env,

268330

body: {

269331

jsonrpc: "2.0",

270332

id: "cron-add",