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

推荐订阅源

罗磊的独立博客
U
Unit 42
N
Netflix TechBlog - Medium
人人都是产品经理
人人都是产品经理
Hugging Face - Blog
Hugging Face - Blog
腾讯CDC
小众软件
小众软件
V
Visual Studio Blog
T
Tailwind CSS Blog
Engineering at Meta
Engineering at Meta
博客园 - 叶小钗
GbyAI
GbyAI
爱范儿
爱范儿
雷峰网
雷峰网
Microsoft Azure Blog
Microsoft Azure Blog
D
DataBreaches.Net
博客园_首页
D
Docker
A
About on SuperTechFans
G
Google Developers Blog
I
InfoQ
T
The Blog of Author Tim Ferriss
V
V2EX
博客园 - Franky

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): normalize hallucinated Office file extension...
vincentkoc · 2026-06-22 · via Recent Commits to openclaw:main
11

/**

22

* Shared validation for model-supplied tool parameters.

33

* Converts malformed file-tool arguments into retryable errors and fixes the

4-

* specific XML suffix corruption seen in path arguments.

4+

* specific XML suffix and Office-extension corruption seen in path arguments.

55

*/

66

import type { AnyAgentTool } from "./agent-tools.types.js";

77

@@ -14,7 +14,13 @@ export type RequiredParamGroup = {

14141515

const RETRY_GUIDANCE_SUFFIX = " Supply correct parameters before retrying.";

1616

const XML_ARG_VALUE_SUFFIX_RE = /<\/arg_value>>+$/;

17-

const XML_ARG_VALUE_PATH_PARAM_KEYS = new Set(["path"]);

17+

const FILE_TOOL_PATH_PARAM_KEYS = new Set(["path"]);

18+

const HALLUCINATED_OFFICE_PATH_EXTENSION_RE = /\.(doc|ppt|xls)(?:odex|codex|xodex|xcodex)$/i;

19+

const OFFICE_EXTENSION_BY_FAMILY: Record<string, string> = {

20+

doc: ".docx",

21+

ppt: ".pptx",

22+

xls: ".xlsx",

23+

};

18241925

function parameterValidationError(message: string): Error {

2026

return new Error(`${message}.${RETRY_GUIDANCE_SUFFIX}`);

@@ -110,6 +116,18 @@ export function stripMalformedXmlArgValueSuffix(value: string): string {

110116

return value.includes("</arg_value>") ? value.replace(XML_ARG_VALUE_SUFFIX_RE, "") : value;

111117

}

112118119+

/** Normalize known model-hallucinated Office/codex path extensions. */

120+

export function normalizeHallucinatedOfficePathExtension(value: string): string {

121+

return value.replace(HALLUCINATED_OFFICE_PATH_EXTENSION_RE, (_match, family: string) => {

122+

return OFFICE_EXTENSION_BY_FAMILY[family.toLowerCase()] ?? _match;

123+

});

124+

}

125+126+

/** Normalize model-supplied file-tool path params without touching payload text. */

127+

export function normalizeFileToolPathParam(value: string): string {

128+

return normalizeHallucinatedOfficePathExtension(stripMalformedXmlArgValueSuffix(value));

129+

}

130+113131

/** Strip malformed XML suffixes from selected string fields without mutating input. */

114132

export function stripMalformedXmlArgValueSuffixFromKeys<T extends Record<string, unknown>>(

115133

record: T,

@@ -130,13 +148,31 @@ export function stripMalformedXmlArgValueSuffixFromKeys<T extends Record<string,

130148

return normalized ?? record;

131149

}

132150133-

function resolveMalformedXmlArgValuePathKeys(

134-

groups: readonly RequiredParamGroup[] | undefined,

135-

): string[] {

151+

/** Normalize selected file-tool path fields without mutating input. */

152+

export function normalizeFileToolPathParamsFromKeys<T extends Record<string, unknown>>(

153+

record: T,

154+

keys: readonly string[],

155+

): T {

156+

let normalized: T | undefined;

157+

for (const key of keys) {

158+

const value = record[key];

159+

if (typeof value !== "string") {

160+

continue;

161+

}

162+

const normalizedValue = normalizeFileToolPathParam(value);

163+

if (normalizedValue !== value) {

164+

normalized ??= { ...record };

165+

normalized[key as keyof T] = normalizedValue as T[keyof T];

166+

}

167+

}

168+

return normalized ?? record;

169+

}

170+171+

function resolveFileToolPathParamKeys(groups: readonly RequiredParamGroup[] | undefined): string[] {

136172

const keys = new Set<string>();

137173

for (const group of groups ?? []) {

138174

for (const key of group.keys) {

139-

if (XML_ARG_VALUE_PATH_PARAM_KEYS.has(key)) {

175+

if (FILE_TOOL_PATH_PARAM_KEYS.has(key)) {

140176

keys.add(key);

141177

}

142178

}

@@ -195,10 +231,10 @@ export function wrapToolParamValidation(

195231

...tool,

196232

execute: async (toolCallId, params, signal, onUpdate) => {

197233

const record = getToolParamsRecord(params);

198-

const pathKeys = resolveMalformedXmlArgValuePathKeys(requiredParamGroups);

234+

const pathKeys = resolveFileToolPathParamKeys(requiredParamGroups);

199235

const normalizedParams =

200236

record && pathKeys.length > 0

201-

? stripMalformedXmlArgValueSuffixFromKeys(record, pathKeys)

237+

? normalizeFileToolPathParamsFromKeys(record, pathKeys)

202238

: params;

203239

if (requiredParamGroups?.length) {

204240

assertRequiredParams(getToolParamsRecord(normalizedParams), requiredParamGroups, tool.name);