Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/tool-surfaces/codex.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import assert from "node:assert/strict";
import test from "node:test";
import { processLogFields } from "./codex.js";

test("process logging keeps a running command successful", () => {
assert.deepEqual(
processLogFields({
sessionId: 7,
output: "",
outputTruncated: false,
running: true,
wallTimeMs: 10,
}),
{ sessionId: 7, running: true, exitCode: undefined, success: true },
);
});

test("process logging marks a zero exit code successful", () => {
assert.deepEqual(
processLogFields({
output: "done",
outputTruncated: false,
running: false,
exitCode: 0,
wallTimeMs: 20,
}),
{ sessionId: undefined, running: false, exitCode: 0, success: true },
);
});

test("process logging marks a non-zero exit code failed", () => {
assert.deepEqual(
processLogFields({
output: "failed",
outputTruncated: false,
running: false,
exitCode: 1,
wallTimeMs: 30,
}),
{
sessionId: undefined,
running: false,
exitCode: 1,
success: false,
error: "Process exited with code 1.",
},
);
});
17 changes: 17 additions & 0 deletions src/tool-surfaces/codex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
SHELL_TOOL_ANNOTATIONS,
toolNames,
workspaceIdDescription,
type ToolLogFields,
type ToolRegistrationContext,
} from "./types.js";
import {
Expand Down Expand Up @@ -228,6 +229,7 @@ function registerCodexProcessTools(context: ToolRegistrationContext): void {
maxOutputTokens,
});
},
processLogFields,
);

return processToolResponse(snapshot);
Expand Down Expand Up @@ -313,9 +315,24 @@ function registerCodexProcessTools(context: ToolRegistrationContext): void {
maxOutputTokens,
});
},
processLogFields,
);

return processToolResponse(snapshot);
},
);
}

export function processLogFields(result: ProcessSnapshot): Partial<ToolLogFields> {
const success = result.running || result.exitCode === 0;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Signal exits remain successful

When a terminated PTY reports both exitCode: 0 and a signal, this expression classifies the process as successful, causing the tool call to be logged at the info level without an error even though it was terminated by a signal.

Suggested change
const success = result.running || result.exitCode === 0;
const success = result.running || (!result.signal && result.exitCode === 0);

Knowledge Base Used: Agent tool surfaces

const termination = result.signal
? `Process terminated by signal ${result.signal}.`
: `Process exited with code ${result.exitCode ?? "unknown"}.`;
return {
sessionId: result.sessionId,
running: result.running,
exitCode: result.exitCode,
success,
...(success ? {} : { error: termination }),
};
}
5 changes: 4 additions & 1 deletion src/tool-surfaces/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,15 @@ export async function runLoggedToolOperation<T>(
fields: Omit<ToolLogFields, "success" | "durationMs" | "error">,
startedAt: number,
operation: () => Promise<T>,
resultFields?: (result: T) => Partial<ToolLogFields>,
): Promise<T> {
try {
const result = await operation();
const resultMetadata = resultFields?.(result);
logToolCall(config, {
...fields,
success: true,
...resultMetadata,
success: resultMetadata?.success ?? true,
durationMs: Math.round(performance.now() - startedAt),
});
return result;
Expand Down
3 changes: 3 additions & 0 deletions src/tool-surfaces/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ export interface ToolLogFields {
workingDirectory?: string;
command?: string;
commandLength?: number;
sessionId?: number;
running?: boolean;
exitCode?: number;
success: boolean;
durationMs: number;
error?: string;
Expand Down