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

推荐订阅源

The Cloudflare Blog
小众软件
小众软件
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
T
Tailwind CSS Blog
WordPress大学
WordPress大学
有赞技术团队
有赞技术团队
博客园 - 司徒正美
V
Visual Studio Blog
G
Google Developers Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
月光博客
月光博客
aimingoo的专栏
aimingoo的专栏
博客园_首页
Blog — PlanetScale
Blog — PlanetScale
博客园 - 聂微东
S
SegmentFault 最新的问题
T
The Blog of Author Tim Ferriss
D
Docker
Vercel News
Vercel News
Recent Announcements
Recent Announcements
Last Week in AI
Last Week in AI
爱范儿
爱范儿
J
Java Code Geeks
大猫的无限游戏
大猫的无限游戏

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(cli): speed up gateway status config reads · openclaw...
vincentkoc · 2026-04-27 · via Recent Commits to openclaw:main

@@ -1,3 +1,5 @@

1+

import fs from "node:fs/promises";

2+

import JSON5 from "json5";

13

import {

24

createConfigIO,

35

resolveConfigPath,

@@ -66,6 +68,12 @@ type DaemonConfigContext = {

6668

configMismatch: boolean;

6769

};

687071+

type StatusConfigRead = {

72+

summary: ConfigSummary;

73+

cfg: OpenClawConfig;

74+

mode: "fast" | "full";

75+

};

76+6977

type ResolvedGatewayStatus = {

7078

gateway: GatewayStatusSummary;

7179

daemonPort: number;

@@ -119,6 +127,104 @@ function resolveSnapshotRuntimeConfig(snapshot: ConfigFileSnapshot | null): Open

119127

return snapshot.runtimeConfig;

120128

}

121129130+

function coerceStatusConfig(value: unknown): OpenClawConfig {

131+

if (!value || typeof value !== "object" || Array.isArray(value)) {

132+

return {};

133+

}

134+

return value as OpenClawConfig;

135+

}

136+137+

function hasOwnKey(value: unknown, key: string): boolean {

138+

return Boolean(

139+

value &&

140+

typeof value === "object" &&

141+

!Array.isArray(value) &&

142+

Object.prototype.hasOwnProperty.call(value, key),

143+

);

144+

}

145+146+

function needsFullStatusConfigRead(raw: string, parsed: unknown): boolean {

147+

return raw.includes("$include") || raw.includes("${") || hasOwnKey(parsed, "env");

148+

}

149+150+

async function readFastStatusConfig(configPath: string): Promise<StatusConfigRead | null> {

151+

let raw: string;

152+

try {

153+

raw = await fs.readFile(configPath, "utf8");

154+

} catch {

155+

return null;

156+

}

157+158+

let parsed: unknown;

159+

try {

160+

parsed = JSON5.parse(raw);

161+

} catch (err) {

162+

return {

163+

summary: {

164+

path: configPath,

165+

exists: true,

166+

valid: false,

167+

issues: [{ path: "", message: `JSON5 parse failed: ${String(err)}` }],

168+

},

169+

cfg: {},

170+

mode: "fast",

171+

};

172+

}

173+174+

if (needsFullStatusConfigRead(raw, parsed)) {

175+

return null;

176+

}

177+178+

const cfg = coerceStatusConfig(parsed);

179+

return {

180+

summary: {

181+

path: configPath,

182+

exists: true,

183+

valid: true,

184+

controlUi: cfg.gateway?.controlUi,

185+

},

186+

cfg,

187+

mode: "fast",

188+

};

189+

}

190+191+

async function readFullStatusConfig(params: {

192+

env: NodeJS.ProcessEnv;

193+

configPath: string;

194+

}): Promise<StatusConfigRead> {

195+

const io = createConfigIO({

196+

env: params.env,

197+

configPath: params.configPath,

198+

pluginValidation: "skip",

199+

});

200+

const snapshot = await io.readConfigFileSnapshot().catch(() => null);

201+

const cfg = resolveSnapshotRuntimeConfig(snapshot) ?? io.loadConfig();

202+

return {

203+

summary: {

204+

path: snapshot?.path ?? params.configPath,

205+

exists: snapshot?.exists ?? false,

206+

valid: snapshot?.valid ?? true,

207+

...(snapshot?.issues?.length ? { issues: snapshot.issues } : {}),

208+

controlUi: cfg.gateway?.controlUi,

209+

},

210+

cfg,

211+

mode: "full",

212+

};

213+

}

214+215+

async function readStatusConfig(params: {

216+

env: NodeJS.ProcessEnv;

217+

configPath: string;

218+

}): Promise<StatusConfigRead> {

219+

return (

220+

(await readFastStatusConfig(params.configPath)) ??

221+

(await readFullStatusConfig({

222+

env: params.env,

223+

configPath: params.configPath,

224+

}))

225+

);

226+

}

227+122228

function appendProbeNote(

123229

existing: string | undefined,

124230

extra: string | undefined,

@@ -207,57 +313,27 @@ async function loadDaemonConfigContext(

207313

mergedDaemonEnv as NodeJS.ProcessEnv,

208314

resolveStateDir(mergedDaemonEnv as NodeJS.ProcessEnv),

209315

);

210-211-

const cliIO = createConfigIO({

316+

const sameConfigPath = cliConfigPath === daemonConfigPath;

317+

const cliConfigRead = await readStatusConfig({

212318

env: process.env,

213319

configPath: cliConfigPath,

214-

pluginValidation: "skip",

215320

});

216-

const sharesDaemonConfigContext = !serviceEnv && cliConfigPath === daemonConfigPath;

217-

const daemonIO = sharesDaemonConfigContext

218-

? cliIO

219-

: createConfigIO({

220-

env: mergedDaemonEnv,

321+

const sharesDaemonConfigContext =

322+

sameConfigPath && (cliConfigRead.mode === "fast" || !serviceEnv);

323+

const daemonConfigRead = sharesDaemonConfigContext

324+

? cliConfigRead

325+

: await readStatusConfig({

326+

env: mergedDaemonEnv as NodeJS.ProcessEnv,

221327

configPath: daemonConfigPath,

222-

pluginValidation: "skip",

223328

});

224329225-

const cliSnapshotPromise = cliIO.readConfigFileSnapshot().catch(() => null);

226-

const daemonSnapshotPromise = sharesDaemonConfigContext

227-

? cliSnapshotPromise

228-

: daemonIO.readConfigFileSnapshot().catch(() => null);

229-

const [cliSnapshot, daemonSnapshot] = await Promise.all([

230-

cliSnapshotPromise,

231-

daemonSnapshotPromise,

232-

]);

233-

const cliCfg = resolveSnapshotRuntimeConfig(cliSnapshot) ?? cliIO.loadConfig();

234-

const daemonCfg =

235-

sharesDaemonConfigContext && cliSnapshot === daemonSnapshot

236-

? cliCfg

237-

: (resolveSnapshotRuntimeConfig(daemonSnapshot) ?? daemonIO.loadConfig());

238-239-

const cliConfigSummary: ConfigSummary = {

240-

path: cliSnapshot?.path ?? cliConfigPath,

241-

exists: cliSnapshot?.exists ?? false,

242-

valid: cliSnapshot?.valid ?? true,

243-

...(cliSnapshot?.issues?.length ? { issues: cliSnapshot.issues } : {}),

244-

controlUi: cliCfg.gateway?.controlUi,

245-

};

246-

const daemonConfigSummary: ConfigSummary = {

247-

path: daemonSnapshot?.path ?? daemonConfigPath,

248-

exists: daemonSnapshot?.exists ?? false,

249-

valid: daemonSnapshot?.valid ?? true,

250-

...(daemonSnapshot?.issues?.length ? { issues: daemonSnapshot.issues } : {}),

251-

controlUi: daemonCfg.gateway?.controlUi,

252-

};

253-254330

return {

255331

mergedDaemonEnv,

256-

cliCfg,

257-

daemonCfg,

258-

cliConfigSummary,

259-

daemonConfigSummary,

260-

configMismatch: cliConfigSummary.path !== daemonConfigSummary.path,

332+

cliCfg: cliConfigRead.cfg,

333+

daemonCfg: daemonConfigRead.cfg,

334+

cliConfigSummary: cliConfigRead.summary,

335+

daemonConfigSummary: daemonConfigRead.summary,

336+

configMismatch: cliConfigRead.summary.path !== daemonConfigRead.summary.path,

261337

};

262338

}

263339