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

推荐订阅源

博客园 - 叶小钗
雷峰网
雷峰网
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Martin Fowler
Martin Fowler
MyScale Blog
MyScale Blog
博客园 - 聂微东
有赞技术团队
有赞技术团队
The Cloudflare Blog
T
Tailwind CSS Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
月光博客
月光博客
T
The Blog of Author Tim Ferriss
D
Docker
L
LangChain Blog
Vercel News
Vercel News
C
Check Point Blog
博客园 - Franky
博客园 - 三生石上(FineUI控件)
Recent Announcements
Recent Announcements
H
Hackread – Cybersecurity News, Data Breaches, AI and More
量子位
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
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
feat: add gateway stall diagnostics · openclaw/openclaw@e...
steipete · 2026-05-05 · via Recent Commits to openclaw:main

@@ -0,0 +1,96 @@

1+

import { performance } from "node:perf_hooks";

2+

import {

3+

areDiagnosticsEnabledForProcess,

4+

emitDiagnosticEvent,

5+

type DiagnosticPhaseDetails,

6+

type DiagnosticPhaseSnapshot,

7+

} from "../infra/diagnostic-events.js";

8+9+

const RECENT_PHASE_CAPACITY = 40;

10+11+

type ActiveDiagnosticPhase = {

12+

name: string;

13+

startedAt: number;

14+

startedWallMs: number;

15+

cpuStarted: NodeJS.CpuUsage;

16+

details?: DiagnosticPhaseDetails;

17+

};

18+19+

let activePhaseStack: ActiveDiagnosticPhase[] = [];

20+

let recentPhases: DiagnosticPhaseSnapshot[] = [];

21+22+

function roundMetric(value: number, digits = 1): number {

23+

if (!Number.isFinite(value)) {

24+

return 0;

25+

}

26+

const factor = 10 ** digits;

27+

return Math.round(value * factor) / factor;

28+

}

29+30+

function pushRecentPhase(snapshot: DiagnosticPhaseSnapshot): void {

31+

recentPhases.push(snapshot);

32+

if (recentPhases.length > RECENT_PHASE_CAPACITY) {

33+

recentPhases = recentPhases.slice(-RECENT_PHASE_CAPACITY);

34+

}

35+

}

36+37+

export function getCurrentDiagnosticPhase(): string | undefined {

38+

return activePhaseStack.at(-1)?.name;

39+

}

40+41+

export function getRecentDiagnosticPhases(limit = 8): DiagnosticPhaseSnapshot[] {

42+

return recentPhases.slice(-Math.max(0, limit)).map((phase) => ({ ...phase }));

43+

}

44+45+

export function recordDiagnosticPhase(snapshot: DiagnosticPhaseSnapshot): void {

46+

pushRecentPhase(snapshot);

47+

if (!areDiagnosticsEnabledForProcess()) {

48+

return;

49+

}

50+

emitDiagnosticEvent({

51+

type: "diagnostic.phase.completed",

52+

...snapshot,

53+

});

54+

}

55+56+

export async function withDiagnosticPhase<T>(

57+

name: string,

58+

run: () => Promise<T> | T,

59+

details?: DiagnosticPhaseDetails,

60+

): Promise<T> {

61+

const active: ActiveDiagnosticPhase = {

62+

name,

63+

startedAt: Date.now(),

64+

startedWallMs: performance.now(),

65+

cpuStarted: process.cpuUsage(),

66+

details,

67+

};

68+

activePhaseStack.push(active);

69+

try {

70+

return await run();

71+

} finally {

72+

const endedAt = Date.now();

73+

const durationMs = roundMetric(performance.now() - active.startedWallMs, 1);

74+

const cpu = process.cpuUsage(active.cpuStarted);

75+

const cpuUserMs = roundMetric(cpu.user / 1_000, 1);

76+

const cpuSystemMs = roundMetric(cpu.system / 1_000, 1);

77+

const cpuTotalMs = roundMetric(cpuUserMs + cpuSystemMs, 1);

78+

activePhaseStack = activePhaseStack.filter((entry) => entry !== active);

79+

recordDiagnosticPhase({

80+

name,

81+

startedAt: active.startedAt,

82+

endedAt,

83+

durationMs,

84+

cpuUserMs,

85+

cpuSystemMs,

86+

cpuTotalMs,

87+

cpuCoreRatio: roundMetric(cpuTotalMs / Math.max(1, durationMs), 3),

88+

details: active.details,

89+

});

90+

}

91+

}

92+93+

export function resetDiagnosticPhasesForTest(): void {

94+

activePhaseStack = [];

95+

recentPhases = [];

96+

}