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

推荐订阅源

Google DeepMind News
Google DeepMind News
C
Check Point Blog
J
Java Code Geeks
腾讯CDC
Martin Fowler
Martin Fowler
MongoDB | Blog
MongoDB | Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园 - 三生石上(FineUI控件)
Apple Machine Learning Research
Apple Machine Learning Research
大猫的无限游戏
大猫的无限游戏
Engineering at Meta
Engineering at Meta
罗磊的独立博客
Last Week in AI
Last Week in AI
B
Blog
IT之家
IT之家
S
SegmentFault 最新的问题
D
DataBreaches.Net
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
GbyAI
GbyAI
博客园 - 聂微东
U
Unit 42
有赞技术团队
有赞技术团队
Y
Y Combinator Blog
MyScale Blog
MyScale 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(agents): guard malformed tool result text blocks · op...
cgdusek · 2026-04-25 · via Recent Commits to openclaw:main

@@ -152,6 +152,141 @@ describe("pruneContextMessages", () => {

152152

).not.toThrow();

153153

});

154154155+

it("does not crash on toolResult with malformed text block (missing text string)", () => {

156+

// Regression: a plugin returning undefined produces {type: "text"} with no text property,

157+

// which crashed estimateTextAndImageChars / collectTextSegments / collectPrunableToolResultSegments.

158+

// See https://github.com/openclaw/openclaw/issues/34979

159+

const malformedToolResult = {

160+

role: "toolResult",

161+

toolName: "sentinel_control",

162+

content: [{ type: "text" }],

163+

isError: false,

164+

timestamp: Date.now(),

165+

} as unknown as AgentMessage;

166+167+

const messages: AgentMessage[] = [

168+

makeUser("remove sentinel"),

169+

makeAssistant([

170+

{ type: "toolCall", toolCallId: "call_1", toolName: "sentinel_control", arguments: {} },

171+

] as unknown as AssistantContentBlock[]),

172+

malformedToolResult,

173+

makeUser("follow up"),

174+

makeAssistant([{ type: "text", text: "done" }]),

175+

];

176+177+

expect(() =>

178+

pruneContextMessages({

179+

messages,

180+

settings: DEFAULT_CONTEXT_PRUNING_SETTINGS,

181+

ctx: CONTEXT_WINDOW_1M,

182+

}),

183+

).not.toThrow();

184+

});

185+186+

it("does not crash on toolResult with malformed text block during soft-trim (image path)", () => {

187+

// The collectPrunableToolResultSegments path is exercised when the tool result

188+

// contains image blocks alongside a malformed text block.

189+

const malformedToolResult = {

190+

role: "toolResult",

191+

toolName: "read",

192+

content: [{ type: "text" }, { type: "image", data: "img", mimeType: "image/png" }],

193+

timestamp: Date.now(),

194+

} as unknown as AgentMessage;

195+196+

const messages: AgentMessage[] = [

197+

makeUser("show image"),

198+

malformedToolResult,

199+

makeAssistant([{ type: "text", text: "here it is" }]),

200+

];

201+202+

expect(() =>

203+

pruneContextMessages({

204+

messages,

205+

settings: {

206+

...DEFAULT_CONTEXT_PRUNING_SETTINGS,

207+

keepLastAssistants: 1,

208+

softTrimRatio: 0,

209+

hardClear: {

210+

...DEFAULT_CONTEXT_PRUNING_SETTINGS.hardClear,

211+

enabled: false,

212+

},

213+

softTrim: {

214+

maxChars: 5_000,

215+

headChars: 2_000,

216+

tailChars: 2_000,

217+

},

218+

},

219+

ctx: CONTEXT_WINDOW_1M,

220+

isToolPrunable: () => true,

221+

contextWindowTokensOverride: 1,

222+

}),

223+

).not.toThrow();

224+

});

225+226+

it("counts malformed non-string text blocks when deciding to trim tool results", () => {

227+

const malformedToolResult = {

228+

role: "toolResult",

229+

toolName: "read",

230+

content: [{ type: "text", text: { payload: "X".repeat(5_000) } }],

231+

timestamp: Date.now(),

232+

} as unknown as AgentMessage;

233+234+

const result = pruneContextMessages({

235+

messages: [

236+

makeUser("show data"),

237+

malformedToolResult,

238+

makeAssistant([{ type: "text", text: "done" }]),

239+

],

240+

settings: {

241+

...DEFAULT_CONTEXT_PRUNING_SETTINGS,

242+

keepLastAssistants: 1,

243+

softTrimRatio: 0,

244+

hardClear: {

245+

...DEFAULT_CONTEXT_PRUNING_SETTINGS.hardClear,

246+

enabled: false,

247+

},

248+

softTrim: {

249+

maxChars: 200,

250+

headChars: 80,

251+

tailChars: 40,

252+

},

253+

},

254+

ctx: CONTEXT_WINDOW_1M,

255+

isToolPrunable: () => true,

256+

contextWindowTokensOverride: 1,

257+

});

258+259+

const toolResult = result.find((message) => message.role === "toolResult") as Extract<

260+

AgentMessage,

261+

{ role: "toolResult" }

262+

>;

263+

const textBlock = toolResult.content[0] as { type: "text"; text: string };

264+

expect(textBlock.text).toContain("[Tool result trimmed:");

265+

});

266+267+

it("does not crash on toolResult with null content entries", () => {

268+

const malformedToolResult = {

269+

role: "toolResult",

270+

toolName: "read",

271+

content: [null, { type: "text", text: "ok" }],

272+

timestamp: Date.now(),

273+

} as unknown as AgentMessage;

274+275+

const messages: AgentMessage[] = [

276+

makeUser("hello"),

277+

malformedToolResult,

278+

makeAssistant([{ type: "text", text: "done" }]),

279+

];

280+281+

expect(() =>

282+

pruneContextMessages({

283+

messages,

284+

settings: DEFAULT_CONTEXT_PRUNING_SETTINGS,

285+

ctx: CONTEXT_WINDOW_1M,

286+

}),

287+

).not.toThrow();

288+

});

289+155290

it("handles well-formed thinking blocks correctly", () => {

156291

const messages: AgentMessage[] = [

157292

makeUser("hello"),