Skip to content

Commit 0b3d1d8

Browse files
fix(server): a merge whose output shows it failed does not count as the agent's own
The watch reactor read `outputIndicatesFailure`, which only the wire projection sets, so a command a provider reported as completed with no exit code and failure text in its output still counted as the agent's own merge. Both now use `commandIndicatesFailure`, which reads the exit code, or failing that, the output. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 64e894e commit 0b3d1d8

4 files changed

Lines changed: 24 additions & 14 deletions

File tree

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
type ThreadId,
1313
type ThreadPullRequestWatch,
1414
} from "@t3tools/contracts";
15+
import { commandIndicatesFailure } from "@t3tools/shared/toolOutput";
1516
import {
1617
changeRequestsClosedBy,
1718
isChangeRequestCloseCommand,
@@ -903,14 +904,9 @@ export const make = Effect.gen(function* () {
903904
agentEnds.delete(event.threadId);
904905
}
905906
});
906-
// Some providers report a command that exited nonzero as completed.
907-
const succeeded =
908-
item.status === "completed" &&
909-
(item.exitCode === undefined
910-
? item.outputIndicatesFailure !== true
911-
: item.exitCode === 0);
907+
// Some providers report a command that failed as completed.
912908
return Effect.andThen(
913-
succeeded ? Effect.void : done,
909+
item.status === "completed" && !commandIndicatesFailure(item) ? Effect.void : done,
914910
FiberMap.run(
915911
agentReads,
916912
item.id,

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ import {
1616
dedupeTurnItemBodies,
1717
} from "@t3tools/shared/orchestrationV2DedupedBodies";
1818
import {
19+
commandIndicatesFailure,
1920
compactDynamicToolOutput,
2021
omitToolOutputImageData,
2122
toolOutputImages,
22-
toolOutputIndicatesFailure,
2323
} from "@t3tools/shared/toolOutput";
2424

2525
// A checkpoint over vendored or generated trees can list 15k+ files; the card needs a prefix.
@@ -166,12 +166,7 @@ export function projectTurnItemForWire(item: OrchestrationV2TurnItem): Orchestra
166166
const { output, ...projected } = item;
167167
// A successful search can print "ENOENT" or "exit code 2", so output text
168168
// decides only when the provider reported no exit code.
169-
const failed =
170-
item.exitCode === undefined
171-
? item.outputIndicatesFailure === true ||
172-
(output !== undefined &&
173-
toolOutputIndicatesFailure(output.slice(0, MAX_DETAIL_STRING_BYTES)))
174-
: item.exitCode !== 0;
169+
const failed = commandIndicatesFailure(item);
175170
return {
176171
...projected,
177172
...(failed ? { outputIndicatesFailure: true } : {}),

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4051,6 +4051,12 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
40514051
exitCode: 1,
40524052
wakes: ["#19: merged, stopped watching", "#20: closed, stopped watching"],
40534053
},
4054+
{
4055+
name: "failure-output",
4056+
status: "completed",
4057+
output: "GraphQL: Pull request is not mergeable\n<exited with exit code 1>",
4058+
wakes: ["#19: merged, stopped watching", "#20: closed, stopped watching"],
4059+
},
40544060
] as const)(
40554061
"ends a watch without a wake when the thread's own agent merged it ($name)",
40564062
({ name: key, status: ended, wakes: expected, ...result }) =>

‎packages/shared/src/toolOutput.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,19 @@ export function toolOutputIndicatesFailure(text: string): boolean {
246246
);
247247
}
248248

249+
/** Whether a command failed. A reported exit code outranks text in its output. */
250+
export function commandIndicatesFailure(command: {
251+
readonly exitCode?: number | undefined;
252+
readonly outputIndicatesFailure?: boolean | undefined;
253+
readonly output?: string | undefined;
254+
}): boolean {
255+
if (command.exitCode !== undefined) return command.exitCode !== 0;
256+
return (
257+
command.outputIndicatesFailure === true ||
258+
(command.output !== undefined && toolOutputIndicatesFailure(command.output.slice(0, 32_768)))
259+
);
260+
}
261+
249262
export interface ToolOutputImage {
250263
readonly mimeType: string;
251264
readonly data?: string;

0 commit comments

Comments
 (0)