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

推荐订阅源

宝玉的分享
宝玉的分享
Engineering at Meta
Engineering at Meta
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 聂微东
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Last Week in AI
Last Week in AI
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 三生石上(FineUI控件)
T
Tailwind CSS Blog
Apple Machine Learning Research
Apple Machine Learning Research
Hugging Face - Blog
Hugging Face - Blog
爱范儿
爱范儿
博客园 - 司徒正美
人人都是产品经理
人人都是产品经理
Jina AI
Jina AI
博客园 - 叶小钗
雷峰网
雷峰网
罗磊的独立博客
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - Franky
WordPress大学
WordPress大学
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
阮一峰的网络日志
阮一峰的网络日志
量子位

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(agent-core): ignore truncated tool calls (#97140) · o...
steipete · 2026-06-27 · via Recent Commits to openclaw:main

@@ -164,6 +164,126 @@ describe("agentLoop streaming updates", () => {

164164

expect(update.assistantMessageEvent).not.toHaveProperty("partial");

165165

}

166166

});

167+168+

it("does not execute tool calls from a max-token-truncated assistant turn", async () => {

169+

const execute = vi.fn(

170+

async (): Promise<AgentToolResult<unknown>> => ({

171+

content: [{ type: "text", text: "should not run" }],

172+

details: {},

173+

}),

174+

);

175+

const contexts: Context[] = [];

176+

let streamCalls = 0;

177+

const streamFn: StreamFn = async (_model, context) => {

178+

contexts.push(context);

179+

streamCalls += 1;

180+

const stream = createAssistantMessageEventStream();

181+

if (streamCalls > 1) {

182+

const message: AssistantMessage = {

183+

role: "assistant",

184+

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

185+

api: model.api,

186+

provider: model.provider,

187+

model: model.id,

188+

usage: TEST_USAGE,

189+

stopReason: "stop",

190+

timestamp: 2,

191+

};

192+

queueMicrotask(() => {

193+

stream.push({ type: "done", reason: "stop", message });

194+

});

195+

return stream;

196+

}

197+

const toolCall = {

198+

type: "toolCall" as const,

199+

id: "call-truncated-spawn",

200+

name: "sessions_spawn",

201+

arguments: {},

202+

};

203+

const message: AssistantMessage = {

204+

role: "assistant",

205+

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

206+

api: model.api,

207+

provider: model.provider,

208+

model: model.id,

209+

usage: TEST_USAGE,

210+

stopReason: "length",

211+

timestamp: 1,

212+

};

213+214+

queueMicrotask(() => {

215+

stream.push({ type: "start", partial: { ...message, content: [] } });

216+

stream.push({ type: "toolcall_start", contentIndex: 1, partial: message });

217+

stream.push({

218+

type: "toolcall_end",

219+

contentIndex: 1,

220+

toolCall,

221+

partial: message,

222+

});

223+

stream.push({ type: "done", reason: "length", message });

224+

});

225+226+

return stream;

227+

};

228+229+

const stream = agentLoop(

230+

[{ role: "user", content: "spawn specialists", timestamp: 1 }],

231+

{

232+

systemPrompt: "",

233+

messages: [],

234+

tools: [

235+

{

236+

name: "sessions_spawn",

237+

label: "sessions_spawn",

238+

description: "Spawn a child session",

239+

parameters: Type.Object({}, { additionalProperties: false }),

240+

execute,

241+

},

242+

],

243+

},

244+

{

245+

...config,

246+

getFollowUpMessages: async () =>

247+

streamCalls === 1 ? [{ role: "user", content: "continue", timestamp: 2 }] : [],

248+

},

249+

undefined,

250+

streamFn,

251+

);

252+253+

const events = await collectEvents(stream);

254+

const messages = await stream.result();

255+

const truncatedMessageEnd = events.find(

256+

(event): event is Extract<AgentEvent, { type: "message_end" }> =>

257+

event.type === "message_end" &&

258+

event.message.role === "assistant" &&

259+

event.message.stopReason === "length",

260+

);

261+

const replayedTruncatedMessage = contexts[1]?.messages[1];

262+263+

if (!truncatedMessageEnd || !replayedTruncatedMessage) {

264+

throw new Error("expected the truncated assistant message to be emitted and replayed");

265+

}

266+267+

expect(execute).not.toHaveBeenCalled();

268+

expect(events.some((event) => event.type === "tool_execution_start")).toBe(false);

269+

expect(messages.map((message) => message.role)).toEqual([

270+

"user",

271+

"assistant",

272+

"user",

273+

"assistant",

274+

]);

275+

expect(messages[1]).toMatchObject({ role: "assistant", stopReason: "length" });

276+

expect(messages[1]).not.toMatchObject({

277+

content: expect.arrayContaining([expect.objectContaining({ type: "toolCall" })]),

278+

});

279+

expect(truncatedMessageEnd.message).not.toMatchObject({

280+

content: expect.arrayContaining([expect.objectContaining({ type: "toolCall" })]),

281+

});

282+

expect(replayedTruncatedMessage).toMatchObject({ role: "assistant", stopReason: "length" });

283+

expect(replayedTruncatedMessage).not.toMatchObject({

284+

content: expect.arrayContaining([expect.objectContaining({ type: "toolCall" })]),

285+

});

286+

});

167287

});

168288169289

describe("runAgentLoop deferred tool hydration", () => {

@@ -936,7 +1056,7 @@ describe("agentLoop thinking state", () => {

9361056

totalTokens: 0,

9371057

cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },

9381058

},

939-

stopReason: "stop",

1059+

stopReason: content.some((item) => item.type === "toolCall") ? "toolUse" : "stop",

9401060

timestamp: 1,

9411061

};

9421062

}

@@ -968,7 +1088,7 @@ describe("agentLoop thinking state", () => {

9681088

: [{ type: "text", text: "done" }];

9691089

stream.push({

9701090

type: "done",

971-

reason: "stop",

1091+

reason: content.some((item) => item.type === "toolCall") ? "toolUse" : "stop",

9721092

message: makeAssistantMessage(activeModel, content),

9731093

});

9741094

stream.end();