Skip to content

Commit 6ddbbc9

Browse files
perf(client): skip irrelevant exit-code scans in tool output
1 parent c2fa9fc commit 6ddbbc9

2 files changed

Lines changed: 56 additions & 3 deletions

File tree

‎packages/client-runtime/src/work-log/presentation.test.ts‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,58 @@ describe("workEntryIndicatesToolFailure", () => {
8686
).toBe(false);
8787
});
8888

89+
it.each([
90+
"FILE NOT FOUND",
91+
"No files found",
92+
"ENOENT",
93+
"No such file or directory",
94+
"No such file",
95+
"CommandNotFoundException",
96+
"Command not found",
97+
"Cannot find path 'example'\nbecause it does not exist",
98+
"The term 'example'\nis not recognized",
99+
"Is not recognized as the name of a cmdlet",
100+
"A parameter cannot be found that matches parameter name",
101+
"<exited with exit code 12>",
102+
"Exited with exit code\t2",
103+
"Exit with exit code 1",
104+
"Exit code: 9",
105+
"Exit code\n3",
106+
])("detects an error after a long successful output: %s", (error) => {
107+
const entry = {
108+
...base,
109+
tone: "tool" as const,
110+
toolLifecycleStatus: "completed",
111+
detail: `${"Synthetic successful output.\n".repeat(512)}${error}`,
112+
};
113+
expect(workEntryIndicatesToolFailure(entry)).toBe(true);
114+
expect(workEntryDisplayIndicatesToolFailure(entry)).toBe(true);
115+
});
116+
117+
it.each([
118+
"Cannot find path",
119+
"Because it does not exist",
120+
"Is not recognized",
121+
"The term 'example'",
122+
"<exited with exit code 0>",
123+
"Exit code: 0",
124+
"Exit code: -1",
125+
"Exit code: 12things",
126+
])("keeps incomplete or non-failure markers successful: %s", (detail) => {
127+
expect(workEntryIndicatesToolFailure({ ...base, tone: "tool", detail })).toBe(false);
128+
});
129+
130+
it("matches paired failure phrases across legacy detail and command fields", () => {
131+
const entry = {
132+
...base,
133+
tone: "tool" as const,
134+
detail: "Cannot find path 'example'",
135+
command: "Because it does not exist",
136+
};
137+
expect(workEntryIndicatesToolFailure(entry)).toBe(true);
138+
expect(workEntryDisplayIndicatesToolFailure(entry)).toBe(false);
139+
});
140+
89141
it("does not treat error text in a command as rendered failure", () => {
90142
const entry = {
91143
label: "Ran command",

‎packages/client-runtime/src/work-log/presentation.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,10 @@ function toolDetailTextLooksLikeFailure(text: string): boolean {
409409
(normalized.includes("is not recognized") && normalized.includes("the term '")) ||
410410
normalized.includes("is not recognized as the name of a cmdlet") ||
411411
normalized.includes("a parameter cannot be found that matches parameter name") ||
412-
/<exited with exit code\s+[1-9]\d*\s*>/i.test(text) ||
413-
/exit(?:ed)? with exit code\s+[1-9]\d*/i.test(text) ||
414-
/exit code\s*[:\s]\s*[1-9]\d*\b/i.test(text)
412+
(normalized.includes("exit code") &&
413+
(/<exited with exit code\s+[1-9]\d*\s*>/i.test(text) ||
414+
/exit(?:ed)? with exit code\s+[1-9]\d*/i.test(text) ||
415+
/exit code\s*[:\s]\s*[1-9]\d*\b/i.test(text)))
415416
);
416417
}
417418

0 commit comments

Comments
 (0)