fix(agent-jobs): add heartbeat cancel and stale recovery

This commit is contained in:
Gabriel Brown
2026-07-10 18:03:45 -04:00
parent cbbb168e7c
commit 470af043fa
5 changed files with 266 additions and 1 deletions
@@ -107,3 +107,35 @@ describe('updateStatus terminal guard', () => {
expect(job?.status).toBe('checks_running');
});
});
describe('heartbeatWorkspace cancellation propagation', () => {
test('reports cancellation while refreshing the workspace heartbeat', async () => {
const t = convexTest(schema, modules);
const jobId = await seedJob(t, 'cancelled');
const result = await t.mutation(api.agentJobs.heartbeatWorkspace, {
workerToken: 'test-worker-token',
workerId: 'worker-1',
jobId,
});
expect(result).toEqual({ success: true, cancelRequested: true });
const job = await t.run(async (ctx) => await ctx.db.get(jobId));
expect(job?.status).toBe('cancelled');
expect(job?.workspaceStatus).toBe('active');
expect(job?.lastHeartbeatAt).toBeTypeOf('number');
});
test('reports no cancellation for an active job', async () => {
const t = convexTest(schema, modules);
const jobId = await seedJob(t, 'running');
const result = await t.mutation(api.agentJobs.heartbeatWorkspace, {
workerToken: 'test-worker-token',
workerId: 'worker-1',
jobId,
});
expect(result).toEqual({ success: true, cancelRequested: false });
});
});