diff --git a/server/src/__tests__/issue-blocker-attention.test.ts b/server/src/__tests__/issue-blocker-attention.test.ts index 8cead6ccd3e..50ed40400bb 100644 --- a/server/src/__tests__/issue-blocker-attention.test.ts +++ b/server/src/__tests__/issue-blocker-attention.test.ts @@ -194,6 +194,69 @@ describeEmbeddedPostgres("issue blocker attention", () => { }); }); + it("classifies a blocked parent as covered when its child's wake already created a queued run that has not started", async () => { + const { companyId, agentId } = await createCompany("PBQ"); + const parentId = await insertIssue({ companyId, identifier: "PBQ-1", title: "Parent", status: "blocked" }); + const childId = await insertIssue({ + companyId, + identifier: "PBQ-2", + title: "Queued child", + status: "todo", + parentId, + assigneeAgentId: agentId, + }); + await block({ companyId, blockerIssueId: childId, blockedIssueId: parentId }); + const runId = await activeRun({ companyId, agentId, issueId: childId, status: "queued", current: false }); + await db.insert(agentWakeupRequests).values({ + companyId, + agentId, + source: "assignment", + status: "queued", + runId, + payload: { issueId: childId }, + }); + + const parent = (await svc.list(companyId, { status: "blocked" })).find((issue) => issue.id === parentId); + + expect(parent?.blockerAttention).toMatchObject({ + state: "covered", + reason: "active_child", + coveredBlockerCount: 1, + attentionBlockerCount: 0, + }); + }); + + it("does not cover a blocked parent through a wake whose created run already finished", async () => { + const { companyId, agentId } = await createCompany("PBF"); + const parentId = await insertIssue({ companyId, identifier: "PBF-1", title: "Parent", status: "blocked" }); + const childId = await insertIssue({ + companyId, + identifier: "PBF-2", + title: "Finished child run", + status: "todo", + parentId, + assigneeAgentId: agentId, + }); + await block({ companyId, blockerIssueId: childId, blockedIssueId: parentId }); + const runId = await activeRun({ companyId, agentId, issueId: childId, status: "failed", current: false }); + await db.insert(agentWakeupRequests).values({ + companyId, + agentId, + source: "assignment", + status: "queued", + runId, + payload: { issueId: childId }, + }); + + const parent = (await svc.list(companyId, { status: "blocked" })).find((issue) => issue.id === parentId); + + expect(parent?.blockerAttention).toMatchObject({ + state: "needs_attention", + coveredBlockerCount: 0, + attentionBlockerCount: 1, + }); + }); + it("classifies an assigned backlog blocker leaf without a waiting path as attention-needed", async () => { const { companyId, agentId } = await createCompany("PBB"); const parentId = await insertIssue({ companyId, identifier: "PBB-1", title: "Parent", status: "blocked" }); diff --git a/server/src/services/issues.ts b/server/src/services/issues.ts index 77aad51fcd2..e4d579abe1d 100644 --- a/server/src/services/issues.ts +++ b/server/src/services/issues.ts @@ -4179,6 +4179,13 @@ async function readIssueBlockerAttentionBatch( >`${agentWakeupRequests.payload} ->> 'issueId'`, }) .from(agentWakeupRequests) + .leftJoin( + heartbeatRuns, + and( + eq(heartbeatRuns.id, agentWakeupRequests.runId), + eq(heartbeatRuns.companyId, companyId), + ), + ) .where( and( eq(agentWakeupRequests.companyId, companyId), @@ -4186,7 +4193,10 @@ async function readIssueBlockerAttentionBatch( agentWakeupRequests.status, BLOCKER_ATTENTION_ACTIVE_WAKE_STATUSES, ), - sql`${agentWakeupRequests.runId} is null`, + or( + sql`${agentWakeupRequests.runId} is null`, + inArray(heartbeatRuns.status, BLOCKER_ATTENTION_ACTIVE_RUN_STATUSES), + ), inArray( sql`${agentWakeupRequests.payload} ->> 'issueId'`, chunk,