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

推荐订阅源

aimingoo的专栏
aimingoo的专栏
WordPress大学
WordPress大学
阮一峰的网络日志
阮一峰的网络日志
博客园 - 司徒正美
月光博客
月光博客
宝玉的分享
宝玉的分享
Recent Announcements
Recent Announcements
小众软件
小众软件
H
Hackread – Cybersecurity News, Data Breaches, AI and More
美团技术团队
博客园 - 三生石上(FineUI控件)
A
About on SuperTechFans
J
Java Code Geeks
云风的 BLOG
云风的 BLOG
罗磊的独立博客
大猫的无限游戏
大猫的无限游戏
IT之家
IT之家
Vercel News
Vercel News
量子位
Martin Fowler
Martin Fowler
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Visual Studio Blog
腾讯CDC
有赞技术团队
有赞技术团队

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: guard tool event callbacks (AI-assisted) (#81696) · ...
enjoylife124 · 2026-06-19 · via Recent Commits to openclaw:main

@@ -299,12 +299,43 @@ function emitTrackedItemEvent(ctx: ToolHandlerContext, itemData: AgentItemEventD

299299

...(ctx.params.sessionKey ? { sessionKey: ctx.params.sessionKey } : {}),

300300

data: itemData,

301301

});

302-

void ctx.params.onAgentEvent?.({

302+

emitAgentEventCallbackBestEffort(ctx, {

303303

stream: "item",

304304

data: itemData,

305305

});

306306

}

307307308+

function warnBestEffortEventFailure(ctx: ToolHandlerContext, label: string, error: unknown): void {

309+

ctx.log.warn(`${label} callback failed: ${String(error)}`);

310+

}

311+312+

function emitExecutionPhaseBestEffort(

313+

ctx: ToolHandlerContext,

314+

info: Parameters<NonNullable<ToolHandlerContext["params"]["onExecutionPhase"]>>[0],

315+

): void {

316+

try {

317+

ctx.params.onExecutionPhase?.(info);

318+

} catch (error) {

319+

warnBestEffortEventFailure(ctx, "tool execution phase", error);

320+

}

321+

}

322+323+

function emitAgentEventCallbackBestEffort(

324+

ctx: ToolHandlerContext,

325+

event: Parameters<NonNullable<ToolHandlerContext["params"]["onAgentEvent"]>>[0],

326+

): void {

327+

try {

328+

const result = ctx.params.onAgentEvent?.(event);

329+

if (isPromiseLike<void>(result)) {

330+

void Promise.resolve(result).catch((error: unknown) => {

331+

warnBestEffortEventFailure(ctx, "tool agent event", error);

332+

});

333+

}

334+

} catch (error) {

335+

warnBestEffortEventFailure(ctx, "tool agent event", error);

336+

}

337+

}

338+308339

function readToolResultDetailsRecord(result: unknown): Record<string, unknown> | undefined {

309340

return readRecordField(asOptionalObjectRecord(result)?.details);

310341

}

@@ -780,7 +811,7 @@ export function handleToolExecutionStart(

780811

const args = evt.args;

781812

const runId = ctx.params.runId;

782813

ctx.state.toolExecutionSinceLastBlockReply = true;

783-

ctx.params.onExecutionPhase?.({

814+

emitExecutionPhaseBestEffort(ctx, {

784815

phase: "tool_execution_started",

785816

tool: toolName,

786817

toolCallId,

@@ -898,7 +929,7 @@ export function handleToolExecutionStart(

898929

};

899930

emitTrackedItemEvent(ctx, itemData);

900931

// Best-effort typing signal; do not block tool summaries on slow emitters.

901-

void ctx.params.onAgentEvent?.({

932+

emitAgentEventCallbackBestEffort(ctx, {

902933

stream: "tool",

903934

data: {

904935

phase: "start",

@@ -1037,7 +1068,7 @@ export function handleToolExecutionUpdate(

10371068

};

10381069

emitTrackedItemEvent(ctx, itemData);

10391070

if (!toolProgress) {

1040-

void ctx.params.onAgentEvent?.({

1071+

emitAgentEventCallbackBestEffort(ctx, {

10411072

stream: "tool",

10421073

data: {

10431074

phase: "update",

@@ -1075,7 +1106,7 @@ export function handleToolExecutionUpdate(

10751106

...(ctx.params.sessionKey ? { sessionKey: ctx.params.sessionKey } : {}),

10761107

data: outputData,

10771108

});

1078-

void ctx.params.onAgentEvent?.({

1109+

emitAgentEventCallbackBestEffort(ctx, {

10791110

stream: "command_output",

10801111

data: outputData,

10811112

});

@@ -1322,7 +1353,7 @@ export async function handleToolExecutionEnd(

13221353

: {}),

13231354

};

13241355

emitTrackedItemEvent(ctx, itemData);

1325-

void ctx.params.onAgentEvent?.({

1356+

emitAgentEventCallbackBestEffort(ctx, {

13261357

stream: "tool",

13271358

data: {

13281359

phase: "result",

@@ -1368,7 +1399,7 @@ export async function handleToolExecutionEnd(

13681399

...(ctx.params.sessionKey ? { sessionKey: ctx.params.sessionKey } : {}),

13691400

data: approvalData,

13701401

});

1371-

void ctx.params.onAgentEvent?.({

1402+

emitAgentEventCallbackBestEffort(ctx, {

13721403

stream: "approval",

13731404

data: approvalData,

13741405

});

@@ -1435,7 +1466,7 @@ export async function handleToolExecutionEnd(

14351466

...(ctx.params.sessionKey ? { sessionKey: ctx.params.sessionKey } : {}),

14361467

data: outputData,

14371468

});

1438-

void ctx.params.onAgentEvent?.({

1469+

emitAgentEventCallbackBestEffort(ctx, {

14391470

stream: "command_output",

14401471

data: outputData,

14411472

});

@@ -1461,7 +1492,7 @@ export async function handleToolExecutionEnd(

14611492

...(ctx.params.sessionKey ? { sessionKey: ctx.params.sessionKey } : {}),

14621493

data: approvalData,

14631494

});

1464-

void ctx.params.onAgentEvent?.({

1495+

emitAgentEventCallbackBestEffort(ctx, {

14651496

stream: "approval",

14661497

data: approvalData,

14671498

});

@@ -1507,7 +1538,7 @@ export async function handleToolExecutionEnd(

15071538

...(ctx.params.sessionKey ? { sessionKey: ctx.params.sessionKey } : {}),

15081539

data: patchData,

15091540

});

1510-

void ctx.params.onAgentEvent?.({

1541+

emitAgentEventCallbackBestEffort(ctx, {

15111542

stream: "patch",

15121543

data: patchData,

15131544

});