fix(agent-jobs): prevent terminal status resurrection
This commit is contained in:
@@ -240,10 +240,18 @@ const isDeletableWorkspace = (job: Doc<'agentJobs'>) =>
|
||||
['failed', 'cancelled', 'timed_out'].includes(job.status) ||
|
||||
['stopped', 'expired', 'failed'].includes(job.workspaceStatus ?? '');
|
||||
|
||||
const TERMINAL_STATUSES = new Set([
|
||||
'failed',
|
||||
'cancelled',
|
||||
'timed_out',
|
||||
'draft_pr_opened',
|
||||
]);
|
||||
|
||||
const isTerminalStatus = (status: string) => TERMINAL_STATUSES.has(status);
|
||||
|
||||
const isTerminalJob = (job: Doc<'agentJobs'>) =>
|
||||
['failed', 'cancelled', 'timed_out', 'draft_pr_opened'].includes(
|
||||
job.status,
|
||||
) || ['stopped', 'expired', 'failed'].includes(job.workspaceStatus ?? '');
|
||||
isTerminalStatus(job.status) ||
|
||||
['stopped', 'expired', 'failed'].includes(job.workspaceStatus ?? '');
|
||||
|
||||
const deleteWorkspaceRows = async (ctx: MutationCtx, job: Doc<'agentJobs'>) => {
|
||||
const messages = await ctx.db
|
||||
@@ -1120,6 +1128,9 @@ export const updateStatus = mutation({
|
||||
if (job?.claimedBy !== args.workerId) {
|
||||
throw new ConvexError('Agent job not claimed by this worker.');
|
||||
}
|
||||
if (isTerminalStatus(job.status)) {
|
||||
return { success: true, ignored: true as const };
|
||||
}
|
||||
const now = Date.now();
|
||||
const patch: Partial<Doc<'agentJobs'>> = {
|
||||
status: args.status,
|
||||
|
||||
Reference in New Issue
Block a user