Skip to content

Commit 469afd8

Browse files
only21milclaudemaria-rcks
authored
fix(chat): commands that exit 0 no longer show as failed (#23351)
Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent e2d9d9a commit 469afd8

4 files changed

Lines changed: 41 additions & 8 deletions

File tree

‎apps/server/src/orchestration-v2/WireProjection.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,21 @@ describe("orchestration V2 wire projection", () => {
261261
});
262262
});
263263

264+
it.each([
265+
"logs/app.log:12: Error: ENOENT: no such file or directory",
266+
"fixtures/ci.txt:3: Process exited with exit code 2",
267+
])("trusts a zero exit code over failure text in the output: %s", (output) => {
268+
const projected = projectTurnItemForWire({
269+
...base,
270+
type: "command_execution" as const,
271+
input: "rg -n error logs fixtures",
272+
output,
273+
exitCode: 0,
274+
});
275+
expect(projected).not.toHaveProperty("outputIndicatesFailure");
276+
expect(projected).toMatchObject({ exitCode: 0, outputOmitted: true });
277+
});
278+
264279
it("omits inline file bodies but preserves file identity and change counts", () => {
265280
const item = {
266281
...base,

‎apps/server/src/orchestration-v2/WireProjection.ts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,14 @@ export function projectTurnItemForWire(item: OrchestrationV2TurnItem): Orchestra
157157
}
158158
case "command_execution": {
159159
const { output, ...projected } = item;
160+
// A successful search can print "ENOENT" or "exit code 2", so output text
161+
// decides only when the provider reported no exit code.
160162
const failed =
161-
item.outputIndicatesFailure === true ||
162-
(item.exitCode !== undefined && item.exitCode !== 0) ||
163-
(output !== undefined &&
164-
toolOutputIndicatesFailure(output.slice(0, MAX_DETAIL_STRING_BYTES)));
163+
item.exitCode === undefined
164+
? item.outputIndicatesFailure === true ||
165+
(output !== undefined &&
166+
toolOutputIndicatesFailure(output.slice(0, MAX_DETAIL_STRING_BYTES)))
167+
: item.exitCode !== 0;
165168
return {
166169
...projected,
167170
...(failed ? { outputIndicatesFailure: true } : {}),

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ function commandItem(
3131
updatedAt: DateTime.makeUnsafe("2026-09-08T00:00:00.000Z"),
3232
type: "command_execution",
3333
input: 'rg "command not found"',
34-
exitCode: 0,
3534
...fields,
3635
};
3736
}
@@ -63,6 +62,22 @@ describe("workEntryIndicatesToolFailure", () => {
6362
},
6463
);
6564

65+
it.each([
66+
"logs/app.log:12: Error: ENOENT: no such file or directory",
67+
"fixtures/ci.txt:3: Process exited with exit code 2",
68+
])("trusts a zero exit code over failure text in the output and command: %s", (output) => {
69+
const entry: WorkLogPresentationEntry = {
70+
...base,
71+
tone: "tool",
72+
itemType: "command_execution",
73+
toolLifecycleStatus: "completed",
74+
command: 'rg -n "ENOENT|exit code" logs fixtures',
75+
structuredPayload: commandItem({ output, exitCode: 0, outputIndicatesFailure: true }),
76+
};
77+
expect(workEntryIndicatesToolFailure(entry)).toBe(false);
78+
expect(workEntryDisplayIndicatesToolFailure(entry)).toBe(false);
79+
});
80+
6681
it("ignores failure phrases in reasoning text", () => {
6782
const entry: WorkLogPresentationEntry = {
6883
...base,

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,9 @@ function workEntryIndicatesToolFailureFromOutput(
278278
}
279279
const item = entry.structuredPayload;
280280
if (item?.type === "command_execution") {
281-
if (item.outputIndicatesFailure || (item.exitCode !== undefined && item.exitCode !== 0)) {
282-
return true;
283-
}
281+
// The exit code outranks text in the output or the command itself.
282+
if (item.exitCode !== undefined) return item.exitCode !== 0;
283+
if (item.outputIndicatesFailure) return true;
284284
if (item.output && toolOutputIndicatesFailure(item.output.slice(0, 32_768))) {
285285
return true;
286286
}

0 commit comments

Comments
 (0)