Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/core/batch-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ interface ProblemJson {
}

/** Terminal run states — a run stops progressing once it reaches one of these. */
export const TERMINAL_STATUSES: ReadonlySet<string> = new Set(["completed", "stopped", "deleted"]);
export const TERMINAL_STATUSES: ReadonlySet<string> = new Set(["completed", "stopped", "failed", "deleted"]);

interface RequestOpts {
apiKey: string;
Expand Down
16 changes: 16 additions & 0 deletions tests/batch-api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,19 @@ test("waitForJob polls until a terminal status", async () => {
assert.equal(job.latest_run.status, "completed");
assert.equal(i, 3);
});

test("waitForJob treats failed as terminal", async () => {
const statuses = ["running", "failed"];
let i = 0;
const impl = (async () => {
const status = statuses[Math.min(i++, statuses.length - 1)]!;
return new Response(
JSON.stringify({ job_id: "j", latest_run: { status, failure_reason: "insufficient_credits", stats: { total: 1, completed: 0, successful: 0, failed: 0 } } }),
{ status: 200, headers: { "content-type": "application/json" } },
);
}) as unknown as typeof fetch;

const job = await waitForJob("j", { apiKey: "k", fetchImpl: impl, sleepImpl: async () => {} });
assert.equal(job.latest_run.status, "failed");
assert.equal(i, 2);
});
Loading