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
12 changes: 11 additions & 1 deletion plugins/codex/scripts/codex-companion.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,17 @@ async function handleStatus(argv) {
pollIntervalMs: options["poll-interval-ms"]
})
: buildSingleJobSnapshot(cwd, reference);
outputCommandResult(snapshot, renderJobStatusReport(snapshot.job), options.json);
if (snapshot.waitTimedOut) {
process.exitCode = 1;
}
outputCommandResult(
snapshot,
renderJobStatusReport(snapshot.job, {
waitTimedOut: snapshot.waitTimedOut,
timeoutMs: snapshot.timeoutMs
}),
options.json
);
return;
}

Expand Down
7 changes: 6 additions & 1 deletion plugins/codex/scripts/lib/render.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,13 @@ export function renderStatusReport(report) {
return `${lines.join("\n").trimEnd()}\n`;
}

export function renderJobStatusReport(job) {
export function renderJobStatusReport(job, options = {}) {
const lines = ["# Codex Job Status", ""];
if (options.waitTimedOut) {
const timeoutSeconds = Math.max(1, Math.round((Number(options.timeoutMs) || 0) / 1000));
lines.push(`Timed out after ${timeoutSeconds}s while the job was still ${job.status || "active"}.`);
lines.push("");
}
pushJobDetails(lines, job, {
showElapsed: job.status === "queued" || job.status === "running",
showDuration: job.status !== "queued" && job.status !== "running",
Expand Down
59 changes: 58 additions & 1 deletion tests/runtime.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1345,13 +1345,70 @@ test("status --wait times out cleanly when a job is still active", () => {
cwd: workspace
});

assert.equal(result.status, 0, result.stderr);
assert.equal(result.status > 0, true, result.stderr);
const payload = JSON.parse(result.stdout);
assert.equal(payload.job.id, "task-live");
assert.equal(payload.job.status, "running");
assert.equal(payload.waitTimedOut, true);
});

test("status --wait reports a timeout in text output when the job is still active", () => {
const workspace = makeTempDir();
const stateDir = resolveStateDir(workspace);
const jobsDir = path.join(stateDir, "jobs");
fs.mkdirSync(jobsDir, { recursive: true });

const logFile = path.join(jobsDir, "task-live.log");
fs.writeFileSync(logFile, "[2026-03-18T15:30:00.000Z] Starting Codex Task.\n", "utf8");
fs.writeFileSync(
path.join(jobsDir, "task-live.json"),
JSON.stringify(
{
id: "task-live",
status: "running",
title: "Codex Task",
logFile
},
null,
2
),
"utf8"
);

fs.writeFileSync(
path.join(stateDir, "state.json"),
`${JSON.stringify(
{
version: 1,
config: { stopReviewGate: false },
jobs: [
{
id: "task-live",
status: "running",
title: "Codex Task",
jobClass: "task",
summary: "Investigate flaky test",
logFile,
createdAt: "2026-03-18T15:30:00.000Z",
startedAt: "2026-03-18T15:30:01.000Z",
updatedAt: "2026-03-18T15:30:02.000Z"
}
]
},
null,
2
)}\n`,
"utf8"
);

const result = run("node", [SCRIPT, "status", "task-live", "--wait", "--timeout-ms", "25"], {
cwd: workspace
});

assert.match(result.stdout, /Timed out after \d+s while the job was still running/i);
assert.equal(result.status > 0, true);
});

test("result returns the stored output for the latest finished job by default", () => {
const workspace = makeTempDir();
const stateDir = resolveStateDir(workspace);
Expand Down