fix(agent-jobs): stop heartbeat from resurrecting terminated jobs

This commit is contained in:
Gabriel Brown
2026-07-10 18:13:28 -04:00
parent ac68484059
commit 60dd5d3836
3 changed files with 27 additions and 5 deletions
+5 -1
View File
@@ -1223,6 +1223,7 @@ export const recoverStaleJobs = internalMutation({
const now = Date.now();
await ctx.db.patch(job._id, {
status: 'timed_out',
workspaceStatus: 'expired',
error:
job.error ??
'The worker stopped reporting progress; the job timed out.',
@@ -1512,12 +1513,15 @@ export const heartbeatWorkspace = mutation({
if (job?.claimedBy !== args.workerId) {
throw new ConvexError('Agent job not claimed by this worker.');
}
if (isTerminalStatus(job.status)) {
return { success: true, cancelRequested: true };
}
await ctx.db.patch(args.jobId, {
workspaceStatus: 'active',
lastHeartbeatAt: Date.now(),
updatedAt: Date.now(),
});
return { success: true, cancelRequested: job.status === 'cancelled' };
return { success: true, cancelRequested: false };
},
});