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

推荐订阅源

腾讯CDC
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
P
Proofpoint News Feed
D
DataBreaches.Net
D
Docker
云风的 BLOG
云风的 BLOG
大猫的无限游戏
大猫的无限游戏
月光博客
月光博客
J
Java Code Geeks
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
罗磊的独立博客
Martin Fowler
Martin Fowler
U
Unit 42
Engineering at Meta
Engineering at Meta
IT之家
IT之家
Vercel News
Vercel News
B
Blog RSS Feed
人人都是产品经理
人人都是产品经理
博客园 - Franky
博客园 - 【当耐特】
Stack Overflow Blog
Stack Overflow Blog
G
Google Developers Blog
MongoDB | Blog
MongoDB | Blog

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): refresh stale channel health cache · opencl...
steipete · 2026-05-01 · via Recent Commits to openclaw:main

@@ -1,12 +1,87 @@

1+

import type { ChannelAccountSnapshot } from "../../channels/plugins/types.public.js";

2+

import type { ChannelHealthSummary, HealthSummary } from "../../commands/health.types.js";

13

import { getStatusSummary } from "../../commands/status.js";

24

import { ErrorCodes, errorShape } from "../protocol/index.js";

5+

import type { ChannelRuntimeSnapshot } from "../server-channel-runtime.types.js";

36

import { HEALTH_REFRESH_INTERVAL_MS } from "../server-constants.js";

47

import { formatError } from "../server-utils.js";

58

import { formatForLog } from "../ws-log.js";

69

import type { GatewayRequestHandlers } from "./types.js";

710811

const ADMIN_SCOPE = "operator.admin";

91213+

function cachedAccountForRuntimeSnapshot(params: {

14+

cachedChannel: ChannelHealthSummary | undefined;

15+

accountId: string | undefined;

16+

}): ChannelHealthSummary | undefined {

17+

const accountId = params.accountId;

18+

if (accountId && params.cachedChannel?.accounts?.[accountId]) {

19+

return params.cachedChannel.accounts[accountId];

20+

}

21+

return undefined;

22+

}

23+24+

function cachedLifecycleDiffersFromRuntime(params: {

25+

cachedAccount: ChannelHealthSummary | undefined;

26+

runtimeSnapshot: ChannelAccountSnapshot;

27+

}): boolean {

28+

for (const key of ["running", "connected"] as const) {

29+

const runtimeValue = params.runtimeSnapshot[key];

30+

if (typeof runtimeValue !== "boolean") {

31+

continue;

32+

}

33+

if (params.cachedAccount?.[key] !== runtimeValue) {

34+

return true;

35+

}

36+

}

37+

return false;

38+

}

39+40+

function cachedHealthDiffersFromRuntime(

41+

cached: HealthSummary,

42+

runtime: ChannelRuntimeSnapshot,

43+

): boolean {

44+

for (const [channelId, runtimeSnapshot] of Object.entries(runtime.channels)) {

45+

if (!runtimeSnapshot) {

46+

continue;

47+

}

48+

const cachedChannel = cached.channels[channelId];

49+

if (

50+

cachedLifecycleDiffersFromRuntime({

51+

cachedAccount: cachedChannel,

52+

runtimeSnapshot,

53+

})

54+

) {

55+

return true;

56+

}

57+

}

58+59+

for (const [channelId, accounts] of Object.entries(runtime.channelAccounts)) {

60+

if (!accounts) {

61+

continue;

62+

}

63+

const cachedChannel = cached.channels[channelId];

64+

for (const [accountId, runtimeSnapshot] of Object.entries(accounts)) {

65+

if (!runtimeSnapshot) {

66+

continue;

67+

}

68+

if (

69+

cachedLifecycleDiffersFromRuntime({

70+

cachedAccount: cachedAccountForRuntimeSnapshot({

71+

cachedChannel,

72+

accountId,

73+

}),

74+

runtimeSnapshot,

75+

})

76+

) {

77+

return true;

78+

}

79+

}

80+

}

81+82+

return false;

83+

}

84+1085

export const healthHandlers: GatewayRequestHandlers = {

1186

health: async ({ respond, context, params, client }) => {

1287

const { getHealthCache, refreshHealthSnapshot, logHealth } = context;

@@ -15,7 +90,23 @@ export const healthHandlers: GatewayRequestHandlers = {

1590

const includeSensitive = scopes.includes(ADMIN_SCOPE);

1691

const now = Date.now();

1792

const cached = getHealthCache();

18-

if (!wantsProbe && cached && now - cached.ts < HEALTH_REFRESH_INTERVAL_MS) {

93+

let cachedDiffersFromRuntime = false;

94+

if (!wantsProbe && cached) {

95+

try {

96+

cachedDiffersFromRuntime = cachedHealthDiffersFromRuntime(

97+

cached,

98+

context.getRuntimeSnapshot(),

99+

);

100+

} catch {

101+

cachedDiffersFromRuntime = false;

102+

}

103+

}

104+

if (

105+

!wantsProbe &&

106+

cached &&

107+

!cachedDiffersFromRuntime &&

108+

now - cached.ts < HEALTH_REFRESH_INTERVAL_MS

109+

) {

19110

respond(true, cached, undefined, { cached: true });

20111

void refreshHealthSnapshot({ probe: false, includeSensitive }).catch((err) =>

21112

logHealth.error(`background health refresh failed: ${formatError(err)}`),