Skip to content

Commit 1dedd33

Browse files
only21milclaude
andcommitted
fix(chat): trust a zero exit code before scanning command output for errors
A successful search through logs or test fixtures can print ENOENT or "exit code 2". The wire projection and the shared work-log classifier ran the text heuristic even when the command reported exit code 0, so the row showed as a failed tool. A numeric exit code now decides; text inference stays for providers that report none. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent bd6940b commit 1dedd33

4 files changed

Lines changed: 42 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
@@ -254,6 +254,21 @@ describe("orchestration V2 wire projection", () => {
254254
});
255255
});
256256

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

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,14 @@ export function projectTurnItemForWire(item: OrchestrationV2TurnItem): Orchestra
9999
}
100100
case "command_execution": {
101101
const { output, ...projected } = item;
102+
// A successful search can print "ENOENT" or "exit code 2", so output text
103+
// decides only when the provider reported no exit code.
102104
const failed =
103-
item.outputIndicatesFailure === true ||
104-
(item.exitCode !== undefined && item.exitCode !== 0) ||
105-
(output !== undefined &&
106-
toolOutputIndicatesFailure(output.slice(0, MAX_DETAIL_STRING_BYTES)));
105+
item.exitCode === undefined
106+
? item.outputIndicatesFailure === true ||
107+
(output !== undefined &&
108+
toolOutputIndicatesFailure(output.slice(0, MAX_DETAIL_STRING_BYTES)))
109+
: item.exitCode !== 0;
107110
return {
108111
...projected,
109112
...(failed ? { outputIndicatesFailure: true } : {}),

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ function commandItem(
3434
updatedAt: DateTime.makeUnsafe("2026-09-08T00:00:00.000Z"),
3535
type: "command_execution",
3636
input: 'rg "command not found"',
37-
exitCode: 0,
3837
...fields,
3938
};
4039
}
@@ -67,6 +66,23 @@ describe("workEntryIndicatesToolFailure", () => {
6766
},
6867
);
6968

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

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,9 @@ function workEntryIndicatesToolFailureFromOutput(
394394
}
395395
const item = entry.structuredPayload;
396396
if (item?.type === "command_execution") {
397-
if (item.outputIndicatesFailure || (item.exitCode !== undefined && item.exitCode !== 0)) {
398-
return true;
399-
}
397+
// The exit code outranks text in the output or the command itself.
398+
if (item.exitCode !== undefined) return item.exitCode !== 0;
399+
if (item.outputIndicatesFailure) return true;
400400
if (item.output && toolOutputIndicatesFailure(item.output.slice(0, 32_768))) {
401401
return true;
402402
}

0 commit comments

Comments
 (0)