Skip to content

Commit 6465153

Browse files
authored
fix(agents): preserve failed-exec warnings on silent turns (#135119)
* fix(agents): preserve failed-exec warnings on silent turns Separate user warnings from internal tool-progress formatting, record their owner fact for cron classification, and persist warning-only WebChat replies without changing the recorded runtime outcome. Fixes #135068 Reported-by: nick.sy (Discord) * test(agents): align tool-event warning label expectations
1 parent 9c1de09 commit 6465153

14 files changed

Lines changed: 202 additions & 170 deletions

‎docs/concepts/messages.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ Tool result `content` is the model-visible result; `details` is runtime metadata
9797
- Persisted session transcripts keep only bounded `details`; oversized metadata is replaced with a compact summary marked `persistedDetailsTruncated: true`.
9898
- Plugins and tools should put text the model must read in `content`, not only in `details`.
9999

100+
When a tool-error warning is the agent's only reply, WebChat displays and retains it. The warning does not by itself change a completed agent run into a runtime failure; the failed tool result remains recorded separately.
101+
100102
## Queueing and followups
101103

102104
When a run is already active, inbound messages steer into it by default. `messages.queue` controls the mode:

‎src/agents/embedded-agent-runner/run/payloads.ts‎

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -389,16 +389,18 @@ export function buildEmbeddedRunPayloads(params: {
389389
})
390390
: false;
391391
if (!duplicateWarning) {
392-
replyItems.push({
392+
const warning = {
393393
text: failureWarning.text,
394-
...(!isRestartStatus
395-
? {
396-
isError: true,
397-
nonTerminalToolErrorWarning:
398-
hasUserFacingReply && failureWarning.nonTerminalToolErrorWarning,
399-
}
400-
: {}),
401-
});
394+
...(!isRestartStatus ? { isError: true } : {}),
395+
};
396+
if (!isRestartStatus) {
397+
setReplyPayloadMetadata(warning, {
398+
toolErrorWarning: { toolName: params.lastToolError.toolName },
399+
nonTerminalToolErrorWarning:
400+
hasUserFacingReply && failureWarning.nonTerminalToolErrorWarning,
401+
});
402+
}
403+
replyItems.push(warning);
402404
}
403405
}
404406
}
@@ -437,11 +439,6 @@ export function buildEmbeddedRunPayloads(params: {
437439
) {
438440
markReplyPayloadForSourceSuppressionDelivery(payload);
439441
}
440-
if (item.nonTerminalToolErrorWarning) {
441-
setReplyPayloadMetadata(payload, {
442-
nonTerminalToolErrorWarning: true,
443-
});
444-
}
445442
if (heartbeatTerminalToolFailure) {
446443
setReplyPayloadMetadata(payload, {
447444
heartbeatTerminalToolFailure,

‎src/agents/embedded-agent-runner/run/source-reply-payloads.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ type EmbeddedRunReplyItem = {
2424
presentation?: ReplyPayload["presentation"];
2525
interactive?: ReplyPayload["interactive"];
2626
channelData?: Record<string, unknown>;
27-
nonTerminalToolErrorWarning?: boolean;
2827
sourceReplyMirror?: { idempotencyKey?: string; transcriptOwner?: true };
2928
};
3029

‎src/agents/embedded-agent-runner/run/tool-error-warning.test.ts‎

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ describe("buildEmbeddedRunPayloads tool warnings", () => {
221221
});
222222

223223
expectSinglePayloadSummary(payloads, {
224-
text: "⚠️ 🛠️ Exec failed (exit 1)",
224+
text: "⚠️ Exec failed (exit 1)",
225225
isError: true,
226226
});
227227
});
@@ -239,19 +239,19 @@ describe("buildEmbeddedRunPayloads tool warnings", () => {
239239
});
240240

241241
expectSinglePayloadSummary(payloads, {
242-
text: "⚠️ 🛠️ Exec failed: `python3 /path/to/daily-cost-audit.py`: Command exited with code 1",
242+
text: "⚠️ Exec failed: `python3 /path/to/daily-cost-audit.py`: Command exited with code 1",
243243
isError: true,
244244
});
245245
expect(payloads[0]?.text).not.toContain("`run python3");
246246
});
247247

248248
it.each([
249-
[false, "off", "⚠️ 🛠️ Exec blocked (exit 7)"],
250-
[false, "full", "⚠️ 🛠️ Exec blocked: `make build`: Command exited with code 7"],
251-
[true, "off", "⚠️ 🛠️ Exec failed (exit 7)"],
252-
[true, "full", "⚠️ 🛠️ Exec failed: `make build`: Command exited with code 7"],
253-
[undefined, "off", "⚠️ 🛠️ Exec failed (exit 7)"],
254-
[undefined, "full", "⚠️ 🛠️ Exec failed: `make build`: Command exited with code 7"],
249+
[false, "off", "⚠️ Exec blocked (exit 7)"],
250+
[false, "full", "⚠️ Exec blocked: `make build`: Command exited with code 7"],
251+
[true, "off", "⚠️ Exec failed (exit 7)"],
252+
[true, "full", "⚠️ Exec failed: `make build`: Command exited with code 7"],
253+
[undefined, "off", "⚠️ Exec failed (exit 7)"],
254+
[undefined, "full", "⚠️ Exec failed: `make build`: Command exited with code 7"],
255255
] as const)(
256256
"renders executionStarted=%s at %s verbosity from structured state",
257257
(executionStarted, verboseLevel, expected) => {
@@ -276,51 +276,50 @@ describe("buildEmbeddedRunPayloads tool warnings", () => {
276276
title: "prefers raw exec metadata when tool progress detail includes it",
277277
meta: "run python3 /tmp/audit.py · `python3 /tmp/audit.py`",
278278
toolResultFormat: "markdown",
279-
expected: "⚠️ 🛠️ Exec failed: `python3 /tmp/audit.py`: Command exited with code 1",
279+
expected: "⚠️ Exec failed: `python3 /tmp/audit.py`: Command exited with code 1",
280280
},
281281
{
282282
title: "prefers raw exec metadata when the literal command contains backticks",
283283
meta: "run node inline script, `node -e 'console.log(1, `x`)'`",
284284
toolResultFormat: "markdown",
285-
expected: "⚠️ 🛠️ Exec failed: ``node -e 'console.log(1, `x`)'``: Command exited with code 1",
285+
expected: "⚠️ Exec failed: ``node -e 'console.log(1, `x`)'``: Command exited with code 1",
286286
},
287287
{
288288
title: "leaves exec metadata unwrapped for plain tool results",
289289
meta: "run node inline script, `node -e 'console.log(1, `x`)'`",
290290
toolResultFormat: "plain",
291-
expected: "⚠️ 🛠️ Exec failed: node -e 'console.log(1, `x`)': Command exited with code 1",
291+
expected: "⚠️ Exec failed: node -e 'console.log(1, `x`)': Command exited with code 1",
292292
},
293293
{
294294
title: "preserves raw exec context before trailing raw command metadata",
295295
meta: "run python3 /tmp/audit.py, node: mac-1, `python3 /tmp/audit.py`",
296296
toolResultFormat: "markdown",
297-
expected:
298-
"⚠️ 🛠️ Exec failed: `node: mac-1 · python3 /tmp/audit.py`: Command exited with code 1",
297+
expected: "⚠️ Exec failed: `node: mac-1 · python3 /tmp/audit.py`: Command exited with code 1",
299298
},
300299
{
301300
title: "does not promote display-summary commas into raw exec context",
302301
meta: 'search "foo,bar" in src, `rg "foo,bar" src`',
303302
toolResultFormat: "markdown",
304-
expected: '⚠️ 🛠️ Exec failed: `rg "foo,bar" src`: Command exited with code 1',
303+
expected: '⚠️ Exec failed: `rg "foo,bar" src`: Command exited with code 1',
305304
},
306305
{
307306
title: "does not treat parenthesized raw command arguments as cwd context",
308307
meta: 'list files in (in progress) · `ls "(in progress)"`',
309308
toolResultFormat: "markdown",
310-
expected: '⚠️ 🛠️ Exec failed: `ls "(in progress)"`: Command exited with code 1',
309+
expected: '⚠️ Exec failed: `ls "(in progress)"`: Command exited with code 1',
311310
},
312311
{
313312
title: "does not duplicate compact cwd labels already present in raw command arguments",
314313
meta: 'print text (repo) · `printf "%s" "(repo)"`',
315314
toolResultFormat: "markdown",
316-
expected: '⚠️ 🛠️ Exec failed: `printf "%s" "(repo)"`: Command exited with code 1',
315+
expected: '⚠️ Exec failed: `printf "%s" "(repo)"`: Command exited with code 1',
317316
},
318317
{
319318
title: "keeps arbitrary exec cwd suffixes inside markdown command text",
320319
meta: "run python3 /tmp/audit.py (in /tmp/build @everyone)",
321320
toolResultFormat: "markdown",
322321
expected:
323-
"⚠️ 🛠️ Exec failed: `python3 /tmp/audit.py (in /tmp/build @everyone)`: Command exited with code 1",
322+
"⚠️ Exec failed: `python3 /tmp/audit.py (in /tmp/build @everyone)`: Command exited with code 1",
324323
},
325324
] as const)("$title", ({ meta, toolResultFormat, expected }) => {
326325
const payloads = buildPayloads({
@@ -373,15 +372,15 @@ describe("buildEmbeddedRunPayloads tool warnings", () => {
373372
});
374373

375374
expectSinglePayloadSummary(cwdPayloads, {
376-
text: "⚠️ 🛠️ Exec failed: `python3 audit.py (in /tmp/build)`: Command exited with code 1",
375+
text: "⚠️ Exec failed: `python3 audit.py (in /tmp/build)`: Command exited with code 1",
377376
isError: true,
378377
});
379378
expectSinglePayloadSummary(workspaceNodePayloads, {
380-
text: "⚠️ 🛠️ Exec failed: `node: mac-1 · python3 audit.py (workspace)`: Command exited with code 1",
379+
text: "⚠️ Exec failed: `node: mac-1 · python3 audit.py (workspace)`: Command exited with code 1",
381380
isError: true,
382381
});
383382
expectSinglePayloadSummary(semanticCompactPayloads, {
384-
text: "⚠️ 🛠️ Exec failed: `git status (repo)`: Command exited with code 1",
383+
text: "⚠️ Exec failed: `git status (repo)`: Command exited with code 1",
385384
isError: true,
386385
});
387386
});
@@ -391,52 +390,52 @@ describe("buildEmbeddedRunPayloads tool warnings", () => {
391390
name: "strips a literal synthetic run prefix",
392391
meta: "run make build",
393392
error: "Command failed with exit code 2",
394-
expected: "⚠️ 🛠️ Exec failed: `make build`: Command failed with exit code 2",
393+
expected: "⚠️ Exec failed: `make build`: Command failed with exit code 2",
395394
},
396395
{
397396
name: "preserves a semantic test summary",
398397
meta: "run tests",
399398
error: "Command failed with exit code 1",
400-
expected: "⚠️ 🛠️ Exec failed: `run tests`: Command failed with exit code 1",
399+
expected: "⚠️ Exec failed: `run tests`: Command failed with exit code 1",
401400
},
402401
{
403402
name: "preserves a semantic deploy summary",
404403
meta: "run deploy",
405404
error: "Command failed with exit code 1",
406-
expected: "⚠️ 🛠️ Exec failed: `run deploy`: Command failed with exit code 1",
405+
expected: "⚠️ Exec failed: `run deploy`: Command failed with exit code 1",
407406
},
408407
{
409408
name: "preserves a compound summary",
410409
meta: "run tests → install dependencies",
411410
error: "Command failed with exit code 1",
412411
expected:
413-
"⚠️ 🛠️ Exec failed: `run tests → install dependencies`: Command failed with exit code 1",
412+
"⚠️ Exec failed: `run tests → install dependencies`: Command failed with exit code 1",
414413
},
415414
{
416415
name: "preserves an inline-script summary",
417416
meta: "run node inline script",
418417
error: "Command failed with exit code 1",
419-
expected: "⚠️ 🛠️ Exec failed: `run node inline script`: Command failed with exit code 1",
418+
expected: "⚠️ Exec failed: `run node inline script`: Command failed with exit code 1",
420419
},
421420
{
422421
name: "preserves a heredoc summary",
423422
meta: "run python3 inline script (heredoc)",
424423
error: "Command failed with exit code 1",
425424
expected:
426-
"⚠️ 🛠️ Exec failed: `run python3 inline script (heredoc)`: Command failed with exit code 1",
425+
"⚠️ Exec failed: `run python3 inline script (heredoc)`: Command failed with exit code 1",
427426
},
428427
{
429428
name: "preserves a sed summary",
430429
meta: "run sed on file",
431430
error: "Command failed with exit code 1",
432-
expected: "⚠️ 🛠️ Exec failed: `run sed on file`: Command failed with exit code 1",
431+
expected: "⚠️ Exec failed: `run sed on file`: Command failed with exit code 1",
433432
},
434433
{
435434
name: "preserves a pipeline summary",
436435
meta: "run tests -> show first 3 lines",
437436
error: "Command failed with exit code 1",
438437
expected:
439-
"⚠️ 🛠️ Exec failed: `run tests -> show first 3 lines`: Command failed with exit code 1",
438+
"⚠️ Exec failed: `run tests -> show first 3 lines`: Command failed with exit code 1",
440439
},
441440
])("formats exec metadata: $name", ({ meta, error, expected }) => {
442441
const payloads = buildPayloads({
@@ -468,7 +467,7 @@ describe("buildEmbeddedRunPayloads tool warnings", () => {
468467
});
469468

470469
expectSinglePayloadSummary(payloads, {
471-
text: "⚠️ 🛠️ Bash failed: `show matrix-progress-@room-@alice:matrix-qa.test-!room:matrix-qa.test.txt` (workspace): Command exited with code 1",
470+
text: "⚠️ Bash failed: `show matrix-progress-@room-@alice:matrix-qa.test-!room:matrix-qa.test.txt` (workspace): Command exited with code 1",
472471
isError: true,
473472
});
474473
});

‎src/agents/embedded-agent-runner/run/tool-error-warning.ts‎

Lines changed: 24 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce";
22
import type { VerboseLevel } from "../../../auto-reply/thinking.js";
3-
import { formatToolAggregate } from "../../../auto-reply/tool-meta.js";
3+
import { formatToolAggregateParts } from "../../../auto-reply/tool-meta.js";
44
import { formatInlineCodeSpan } from "../../../shared/markdown-code.js";
5+
import { resolveToolDisplay } from "../../tool-display.js";
56
import { isExecLikeToolName, type ToolErrorSummary } from "../../tool-error-summary.js";
67

7-
type ToolErrorWarningPolicy = {
8-
showWarning: boolean;
9-
includeDetails: boolean;
10-
};
11-
12-
function isVerboseToolDetailEnabled(level?: VerboseLevel): boolean {
13-
return level === "full";
14-
}
15-
16-
function shouldMarkNonTerminalToolErrorWarning(lastToolError: ToolErrorSummary): boolean {
17-
return lastToolError.middlewareError === true;
8+
function formatWarningToolLabel(
9+
toolName: string,
10+
metas: string[] | undefined,
11+
markdown: boolean,
12+
): string {
13+
// Progress prefixes are reserved internal traces. User warnings use the label
14+
// and the same escaped details so every text-only display can retain them.
15+
const { label } = resolveToolDisplay({ name: toolName });
16+
const { detail } = formatToolAggregateParts(toolName, metas, { markdown });
17+
return detail ? `${label}: ${detail}` : label;
1818
}
1919

2020
function formatToolErrorWarningText(params: {
@@ -25,10 +25,10 @@ function formatToolErrorWarningText(params: {
2525
const failureVerb = params.lastToolError.executionStarted === false ? "blocked" : "failed";
2626
const terminalDiagnostic = params.lastToolError.terminalDiagnostic;
2727
if (terminalDiagnostic?.kind === "process") {
28-
const toolLabel = formatToolAggregate(
28+
const toolLabel = formatWarningToolLabel(
2929
"process",
3030
params.includeDetails ? [terminalDiagnostic.sessionId] : undefined,
31-
{ markdown: params.useMarkdown },
31+
params.useMarkdown,
3232
);
3333
const reason =
3434
terminalDiagnostic.reason.kind === "exit"
@@ -47,9 +47,7 @@ function formatToolErrorWarningText(params: {
4747
const includeError =
4848
params.includeDetails || params.lastToolError.errorCode === "approval_timeout";
4949
if (isExecLikeToolName(params.lastToolError.toolName)) {
50-
const toolLabel = formatToolAggregate(params.lastToolError.toolName, undefined, {
51-
markdown: params.useMarkdown,
52-
});
50+
const toolLabel = resolveToolDisplay({ name: params.lastToolError.toolName }).label;
5351
const subject = params.includeDetails
5452
? formatExecLikeFailureSubject(params.lastToolError.meta, params.useMarkdown)
5553
: "";
@@ -63,10 +61,10 @@ function formatToolErrorWarningText(params: {
6361
: `⚠️ ${toolLabel} ${failureVerb}${conciseExitSuffix}${errorSuffix}`;
6462
}
6563

66-
const toolSummary = formatToolAggregate(
64+
const toolSummary = formatWarningToolLabel(
6765
params.lastToolError.toolName,
6866
params.includeDetails && params.lastToolError.meta ? [params.lastToolError.meta] : undefined,
69-
{ markdown: params.useMarkdown },
67+
params.useMarkdown,
7068
);
7169
const errorSuffix =
7270
includeError && params.lastToolError.error ? `: ${params.lastToolError.error}` : "";
@@ -288,22 +286,6 @@ function maybeWrapInlineCode(value: string, markdown: boolean): string {
288286
return markdown ? formatInlineCodeSpan(value) : value;
289287
}
290288
/** Warn only when a tool failure would otherwise leave the user with no reply. */
291-
function resolveToolErrorWarningPolicy(params: {
292-
hasUserFacingReply: boolean;
293-
suppressToolErrors: boolean;
294-
suppressToolErrorWarnings?: boolean;
295-
verboseLevel?: VerboseLevel;
296-
}): ToolErrorWarningPolicy {
297-
const includeDetails = isVerboseToolDetailEnabled(params.verboseLevel);
298-
return {
299-
showWarning:
300-
!params.hasUserFacingReply &&
301-
!params.suppressToolErrors &&
302-
params.suppressToolErrorWarnings !== true,
303-
includeDetails,
304-
};
305-
}
306-
307289
export function buildFailureWarning(params: {
308290
lastToolError: ToolErrorSummary;
309291
hasUserFacingReply: boolean;
@@ -312,16 +294,19 @@ export function buildFailureWarning(params: {
312294
verboseLevel?: VerboseLevel;
313295
useMarkdown: boolean;
314296
}): { text: string; nonTerminalToolErrorWarning: boolean } | undefined {
315-
const warningPolicy = resolveToolErrorWarningPolicy(params);
316-
if (!warningPolicy.showWarning) {
297+
if (
298+
params.hasUserFacingReply ||
299+
params.suppressToolErrors ||
300+
params.suppressToolErrorWarnings === true
301+
) {
317302
return undefined;
318303
}
319304
return {
320305
text: formatToolErrorWarningText({
321306
lastToolError: params.lastToolError,
322-
includeDetails: warningPolicy.includeDetails,
307+
includeDetails: params.verboseLevel === "full",
323308
useMarkdown: params.useMarkdown,
324309
}),
325-
nonTerminalToolErrorWarning: shouldMarkNonTerminalToolErrorWarning(params.lastToolError),
310+
nonTerminalToolErrorWarning: params.lastToolError.middlewareError === true,
326311
};
327312
}

‎src/agents/embedded-agent-subscribe.handlers.tools.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2744,7 +2744,7 @@ describe("handleToolExecutionEnd timeout metadata", () => {
27442744
sessionKey: "agent:unit-session",
27452745
toolResultFormat: "markdown",
27462746
});
2747-
expect(payloads[0]?.text).toBe("⚠️ 🛠️ Exec failed (exit 1)");
2747+
expect(payloads[0]?.text).toBe("⚠️ Exec failed (exit 1)");
27482748
});
27492749

27502750
it("records structured error codes for failed tool results", async () => {
@@ -3079,7 +3079,7 @@ describe("handleToolExecutionEnd exec approval prompts", () => {
30793079
sessionKey: "agent:unit-session",
30803080
toolResultFormat: "markdown",
30813081
});
3082-
expect(payloads[0]?.text).toBe("⚠️ 🛠️ Exec blocked");
3082+
expect(payloads[0]?.text).toBe("⚠️ Exec blocked");
30833083
});
30843084

30853085
it("records an actionable failure when unavailable-approval notice delivery rejects", async () => {

‎src/auto-reply/reply-payload.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,8 @@ export type ReplyPayloadMetadata = {
356356
idempotencyKey?: string;
357357
};
358358
beforeAgentRunBlocked?: boolean;
359+
/** The warning owner observed this tool failure; presentation text is not evidence. */
360+
toolErrorWarning?: { toolName: string };
359361
/** Warning synthesized from an observed tool error after the run produced assistant output. */
360362
nonTerminalToolErrorWarning?: boolean;
361363
/** Unresolved mutating tool failure that makes a heartbeat run terminally failed. */

0 commit comments

Comments
 (0)