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

推荐订阅源

小众软件
小众软件
博客园_首页
博客园 - 聂微东
T
Tailwind CSS Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
J
Java Code Geeks
The Cloudflare Blog
aimingoo的专栏
aimingoo的专栏
Martin Fowler
Martin Fowler
D
Docker
人人都是产品经理
人人都是产品经理
WordPress大学
WordPress大学
博客园 - 三生石上(FineUI控件)
Microsoft Azure Blog
Microsoft Azure Blog
Recent Announcements
Recent Announcements
Apple Machine Learning Research
Apple Machine Learning Research
阮一峰的网络日志
阮一峰的网络日志
B
Blog RSS Feed
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Microsoft Security Blog
Microsoft Security Blog
L
LangChain Blog
Jina AI
Jina AI
博客园 - Franky
D
DataBreaches.Net

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(plugins): bound tool result middleware details · open...
vincentkoc · 2026-04-25 · via Recent Commits to openclaw:main

@@ -12,6 +12,9 @@ const log = createSubsystemLogger("agents/harness");

1212

const MAX_MIDDLEWARE_CONTENT_BLOCKS = 200;

1313

const MAX_MIDDLEWARE_TEXT_CHARS = 100_000;

1414

const MAX_MIDDLEWARE_IMAGE_DATA_CHARS = 5_000_000;

15+

const MAX_MIDDLEWARE_DETAILS_BYTES = 100_000;

16+

const MAX_MIDDLEWARE_DETAILS_DEPTH = 20;

17+

const MAX_MIDDLEWARE_DETAILS_KEYS = 1_000;

15181619

function isRecord(value: unknown): value is Record<string, unknown> {

1720

return value !== null && typeof value === "object" && !Array.isArray(value);

@@ -35,14 +38,71 @@ function isValidMiddlewareContentBlock(value: unknown): boolean {

3538

return false;

3639

}

374041+

function isValidMiddlewareDetails(

42+

value: unknown,

43+

state: { keys: number; bytes: number; seen: WeakSet<object> } = {

44+

keys: 0,

45+

bytes: 0,

46+

seen: new WeakSet<object>(),

47+

},

48+

depth = 0,

49+

): boolean {

50+

if (value === undefined || value === null) {

51+

return true;

52+

}

53+

if (depth > MAX_MIDDLEWARE_DETAILS_DEPTH) {

54+

return false;

55+

}

56+

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

57+

state.bytes += value.length;

58+

return state.bytes <= MAX_MIDDLEWARE_DETAILS_BYTES;

59+

}

60+

if (typeof value === "number" || typeof value === "boolean") {

61+

state.bytes += String(value).length;

62+

return state.bytes <= MAX_MIDDLEWARE_DETAILS_BYTES;

63+

}

64+

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

65+

return false;

66+

}

67+

if (state.seen.has(value)) {

68+

return false;

69+

}

70+

state.seen.add(value);

71+

if (Array.isArray(value)) {

72+

state.keys += value.length;

73+

if (state.keys > MAX_MIDDLEWARE_DETAILS_KEYS) {

74+

return false;

75+

}

76+

for (const entry of value) {

77+

if (!isValidMiddlewareDetails(entry, state, depth + 1)) {

78+

return false;

79+

}

80+

}

81+

return true;

82+

}

83+

for (const [key, entry] of Object.entries(value)) {

84+

state.keys += 1;

85+

state.bytes += key.length;

86+

if (state.keys > MAX_MIDDLEWARE_DETAILS_KEYS || state.bytes > MAX_MIDDLEWARE_DETAILS_BYTES) {

87+

return false;

88+

}

89+

if (!isValidMiddlewareDetails(entry, state, depth + 1)) {

90+

return false;

91+

}

92+

}

93+

return true;

94+

}

95+3896

function isValidMiddlewareToolResult(value: unknown): value is OpenClawAgentToolResult {

3997

if (!isRecord(value) || !Array.isArray(value.content)) {

4098

return false;

4199

}

42100

if (value.content.length > MAX_MIDDLEWARE_CONTENT_BLOCKS) {

43101

return false;

44102

}

45-

return value.content.every(isValidMiddlewareContentBlock);

103+

return (

104+

value.content.every(isValidMiddlewareContentBlock) && isValidMiddlewareDetails(value.details)

105+

);

46106

}

4710748108

function buildMiddlewareFailureResult(): OpenClawAgentToolResult {

@@ -54,7 +114,7 @@ function buildMiddlewareFailureResult(): OpenClawAgentToolResult {

54114

},

55115

],

56116

details: {

57-

status: "failed",

117+

status: "error",

58118

middlewareError: true,

59119

},

60120

};

@@ -72,17 +132,20 @@ export function createAgentToolResultMiddlewareRunner(

72132

for (const handler of handlers) {

73133

try {

74134

const next = await handler({ ...event, result: current }, ctx);

75-

if (next?.result) {

76-

if (isValidMiddlewareToolResult(next.result)) {

77-

current = next.result;

78-

} else {

79-

log.warn(

80-

`[${ctx.harness}] discarded invalid tool result middleware output for ${truncateUtf16Safe(

81-

event.toolName,

82-

120,

83-

)}`,

84-

);

85-

}

135+

// Middleware may mutate event.result in place for legacy Pi parity.

136+

// Validate the current object after every handler so in-place writes

137+

// cannot bypass the same shape and size bounds as returned results.

138+

const candidate = next?.result ?? current;

139+

if (isValidMiddlewareToolResult(candidate)) {

140+

current = candidate;

141+

} else {

142+

log.warn(

143+

`[${ctx.harness}] discarded invalid tool result middleware output for ${truncateUtf16Safe(

144+

event.toolName,

145+

120,

146+

)}`,

147+

);

148+

return buildMiddlewareFailureResult();

86149

}

87150

} catch {

88151

log.warn(