fix(agent-jobs): stop heartbeat from resurrecting terminated jobs
This commit is contained in:
@@ -119,6 +119,7 @@ describe('recoverStaleJobs', () => {
|
||||
|
||||
expect(result).toEqual({ recovered: 1 });
|
||||
expect(state.job?.status).toBe('timed_out');
|
||||
expect(state.job?.workspaceStatus).toBe('expired');
|
||||
expect(state.job?.completedAt).toBeTypeOf('number');
|
||||
expect(state.request?.status).toBe('failed');
|
||||
expect(state.thread?.status).toBe('failed');
|
||||
|
||||
@@ -24,7 +24,7 @@ const spoonInput = {
|
||||
|
||||
const seedJob = async (
|
||||
t: ReturnType<typeof convexTest>,
|
||||
status: 'cancelled' | 'running',
|
||||
status: 'cancelled' | 'running' | 'timed_out',
|
||||
) =>
|
||||
await t.mutation(async (ctx) => {
|
||||
const now = Date.now();
|
||||
@@ -109,7 +109,7 @@ describe('updateStatus terminal guard', () => {
|
||||
});
|
||||
|
||||
describe('heartbeatWorkspace cancellation propagation', () => {
|
||||
test('reports cancellation while refreshing the workspace heartbeat', async () => {
|
||||
test('requests teardown for a cancelled job without resurrecting it', async () => {
|
||||
const t = convexTest(schema, modules);
|
||||
const jobId = await seedJob(t, 'cancelled');
|
||||
|
||||
@@ -122,8 +122,25 @@ describe('heartbeatWorkspace cancellation propagation', () => {
|
||||
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');
|
||||
expect(job?.workspaceStatus).not.toBe('active');
|
||||
expect(job?.lastHeartbeatAt).toBeUndefined();
|
||||
});
|
||||
|
||||
test('requests teardown for a timed_out job without resurrecting it', async () => {
|
||||
const t = convexTest(schema, modules);
|
||||
const jobId = await seedJob(t, 'timed_out');
|
||||
|
||||
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('timed_out');
|
||||
expect(job?.workspaceStatus).not.toBe('active');
|
||||
expect(job?.lastHeartbeatAt).toBeUndefined();
|
||||
});
|
||||
|
||||
test('reports no cancellation for an active job', async () => {
|
||||
|
||||
Reference in New Issue
Block a user