Skip to content
TypeScript

fix(chat): commands that exit 0 no longer show as failed (#23351)

Victor Vogel469afd8b53d0
diff --git a/apps/server/src/orchestration-v2/WireProjection.test.ts b/apps/server/src/orchestration-v2/WireProjection.test.ts
index 0d63d832f0c..6379cad45db 100644
--- a/apps/server/src/orchestration-v2/WireProjection.test.ts
+++ b/apps/server/src/orchestration-v2/WireProjection.test.ts
@@ -261,6 +261,21 @@ describe("orchestration V2 wire projection", () => {
});
});
+ it.each([
+ "logs/app.log:12: Error: ENOENT: no such file or directory",
+ "fixtures/ci.txt:3: Process exited with exit code 2",
+ ])("trusts a zero exit code over failure text in the output: %s", (output) => {
+ const projected = projectTurnItemForWire({
+ ...base,
+ type: "command_execution" as const,
+ input: "rg -n error logs fixtures",
+ output,
+ exitCode: 0,
+ });
+ expect(projected).not.toHaveProperty("outputIndicatesFailure");
+ expect(projected).toMatchObject({ exitCode: 0, outputOmitted: true });
+ });
+
it("omits inline file bodies but preserves file identity and change counts", () => {
const item = {
...base,
diff --git a/apps/server/src/orchestration-v2/WireProjection.ts b/apps/server/src/orchestration-v2/WireProjection.ts
index 2181b7feec5..1495a3effa6 100644
--- a/apps/server/src/orchestration-v2/WireProjection.ts
+++ b/apps/server/src/orchestration-v2/WireProjection.ts
@@ -157,11 +157,14 @@ export function projectTurnItemForWire(item: OrchestrationV2TurnItem): Orchestra
}
case "command_execution": {
const { output, ...projected } = item;
+ // A successful search can print "ENOENT" or "exit code 2", so output text
+ // decides only when the provider reported no exit code.
const failed =
- item.outputIndicatesFailure === true ||
- (item.exitCode !== undefined && item.exitCode !== 0) ||
- (output !== undefined &&
- toolOutputIndicatesFailure(output.slice(0, MAX_DETAIL_STRING_BYTES)));
+ item.exitCode === undefined
+ ? item.outputIndicatesFailure === true ||
+ (output !== undefined &&
+ toolOutputIndicatesFailure(output.slice(0, MAX_DETAIL_STRING_BYTES)))
+ : item.exitCode !== 0;
return {
...projected,
...(failed ? { outputIndicatesFailure: true } : {}),
diff --git a/packages/client-runtime/src/work-log/presentation.test.ts b/packages/client-runtime/src/work-log/presentation.test.ts
index 28caf074e4f..f79cd14c919 100644
--- a/packages/client-runtime/src/work-log/presentation.test.ts
+++ b/packages/client-runtime/src/work-log/presentation.test.ts
@@ -31,7 +31,6 @@ function commandItem(
updatedAt: DateTime.makeUnsafe("2026-09-08T00:00:00.000Z"),
type: "command_execution",
input: 'rg "command not found"',
- exitCode: 0,
...fields,
};
}
@@ -63,6 +62,22 @@ describe("workEntryIndicatesToolFailure", () => {
},
);
+ it.each([
+ "logs/app.log:12: Error: ENOENT: no such file or directory",
+ "fixtures/ci.txt:3: Process exited with exit code 2",
+ ])("trusts a zero exit code over failure text in the output and command: %s", (output) => {
+ const entry: WorkLogPresentationEntry = {
+ ...base,
+ tone: "tool",
+ itemType: "command_execution",
+ toolLifecycleStatus: "completed",
+ command: 'rg -n "ENOENT|exit code" logs fixtures',
+ structuredPayload: commandItem({ output, exitCode: 0, outputIndicatesFailure: true }),
+ };
+ expect(workEntryIndicatesToolFailure(entry)).toBe(false);
+ expect(workEntryDisplayIndicatesToolFailure(entry)).toBe(false);
+ });
+
it("ignores failure phrases in reasoning text", () => {
const entry: WorkLogPresentationEntry = {
...base,
diff --git a/packages/client-runtime/src/work-log/presentation.ts b/packages/client-runtime/src/work-log/presentation.ts
index 1d884f0b54e..29c5f938b5b 100644
--- a/packages/client-runtime/src/work-log/presentation.ts
+++ b/packages/client-runtime/src/work-log/presentation.ts
@@ -278,9 +278,9 @@ function workEntryIndicatesToolFailureFromOutput(
}
const item = entry.structuredPayload;
if (item?.type === "command_execution") {
- if (item.outputIndicatesFailure || (item.exitCode !== undefined && item.exitCode !== 0)) {
- return true;
- }
+ // The exit code outranks text in the output or the command itself.
+ if (item.exitCode !== undefined) return item.exitCode !== 0;
+ if (item.outputIndicatesFailure) return true;
if (item.output && toolOutputIndicatesFailure(item.output.slice(0, 32_768))) {
return true;
}