From 5ad85b4686dc6528823b78ce376167bfdb647f32 Mon Sep 17 00:00:00 2001 From: Dotta Date: Sat, 6 Jun 2026 17:06:42 +0000 Subject: [PATCH] Stabilize agent lifecycle tests Co-Authored-By: Paperclip --- server/src/__tests__/heartbeat-process-recovery.test.ts | 6 ++++-- .../src/__tests__/issue-execution-policy-routes.test.ts | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/server/src/__tests__/heartbeat-process-recovery.test.ts b/server/src/__tests__/heartbeat-process-recovery.test.ts index 17f01486589..ed7ac016fac 100644 --- a/server/src/__tests__/heartbeat-process-recovery.test.ts +++ b/server/src/__tests__/heartbeat-process-recovery.test.ts @@ -957,6 +957,7 @@ describeEmbeddedPostgres("heartbeat orphaned process recovery", () => { it("queues exactly one retry when the recorded local pid is dead", async () => { const { agentId, runId, issueId } = await seedRunFixture({ + agentStatus: "idle", processPid: 999_999_999, contextSnapshot: { modelProfile: "cheap", @@ -988,7 +989,7 @@ describeEmbeddedPostgres("heartbeat orphaned process recovery", () => { timeoutConfigured: false, timeoutFired: false, }); - expect(retryRun?.status).toBe("queued"); + expect(["queued", "running"]).toContain(retryRun?.status); expect(retryRun?.retryOfRunId).toBe(runId); expect(retryRun?.processLossRetryCount).toBe(1); expect(retryRun?.contextSnapshot as Record).not.toHaveProperty("modelProfile"); @@ -1032,6 +1033,7 @@ describeEmbeddedPostgres("heartbeat orphaned process recovery", () => { expect(isPidAlive(orphan.descendantPid)).toBe(true); const { agentId, runId, issueId } = await seedRunFixture({ + agentStatus: "idle", processPid: orphan.processPid, processGroupId: orphan.processGroupId, }); @@ -1055,7 +1057,7 @@ describeEmbeddedPostgres("heartbeat orphaned process recovery", () => { expect(failedRun?.error).toContain("descendant process group"); const retryRun = runs.find((row) => row.id !== runId); - expect(retryRun?.status).toBe("queued"); + expect(["queued", "running"]).toContain(retryRun?.status); const issue = await db .select() diff --git a/server/src/__tests__/issue-execution-policy-routes.test.ts b/server/src/__tests__/issue-execution-policy-routes.test.ts index 8c313c11291..cce87c1b4eb 100644 --- a/server/src/__tests__/issue-execution-policy-routes.test.ts +++ b/server/src/__tests__/issue-execution-policy-routes.test.ts @@ -65,6 +65,15 @@ function registerModuleMocks() { companyId: "company-1", permissions: null, })), + resolveByReference: vi.fn(async (_companyId: string, reference: string) => ({ + ambiguous: false, + agent: { + id: reference, + companyId: "company-1", + status: "idle", + orgChainHealth: { status: "healthy" }, + }, + })), }), documentAnnotationService: () => ({ remapOpenThreadsForDocument: async () => [] }), documentService: () => ({}),