The open-source app everyone uses to manage agents at work
TypeScript acpxagent-orchestrationagent-skillsagentic-aiai-agentsai-engineeringai-governanceai-toolsautonomous-agentsclaudeclaude-codeclaude-skillscodexhermesllmmcpmulti-agentopenclawproject-managementworkflow-automation
fix: promote review tasks when continuations start (#13318)
Dotta24007a980458
diff --git a/server/src/__tests__/heartbeat-auto-checkout.test.ts b/server/src/__tests__/heartbeat-auto-checkout.test.tsindex f9b60c0e57..51edb14dc3 100644--- a/server/src/__tests__/heartbeat-auto-checkout.test.ts+++ b/server/src/__tests__/heartbeat-auto-checkout.test.ts@@ -1,5 +1,7 @@import { describe, expect, it } from "vitest";-import { shouldAutoCheckoutIssueForWake } from "../services/heartbeat.ts";+import {+ shouldAutoCheckoutIssueForWake,+} from "../services/heartbeat.ts";describe("shouldAutoCheckoutIssueForWake", () => {it("auto-checks out an assigned todo issue for an actionable wake", () => {@@ -12,6 +14,16 @@ describe("shouldAutoCheckoutIssueForWake", () => {})).toBe(true);});+ it("leaves an idle review issue in review without an actionable wake", () => {+ expect(shouldAutoCheckoutIssueForWake({+ contextSnapshot: {},+ issueStatus: "in_review",+ issueAssigneeAgentId: "agent-1",+ isDependencyReady: true,+ agentId: "agent-1",+ })).toBe(false);+ });+it("does not auto-checkout pending execution-review state even if the row status is todo", () => {const reviewerAgentId = "11111111-1111-4111-8111-111111111111";const coderAgentId = "22222222-2222-4222-8222-222222222222";diff --git a/server/src/__tests__/heartbeat-stale-queue-invalidation.test.ts b/server/src/__tests__/heartbeat-stale-queue-invalidation.test.tsindex faf7f719c9..3fdf0fbb90 100644--- a/server/src/__tests__/heartbeat-stale-queue-invalidation.test.ts+++ b/server/src/__tests__/heartbeat-stale-queue-invalidation.test.ts@@ -12,6 +12,7 @@ import {heartbeatRuns,issueComments,issueDocuments,+ issueThreadInteractions,issues,} from "@paperclipai/db";import { ISSUE_CONTINUATION_SUMMARY_DOCUMENT_KEY } from "@paperclipai/shared";@@ -153,6 +154,7 @@ describeEmbeddedPostgres("heartbeat stale queued-run invalidation", () => {tempDb = await startEmbeddedPostgresTestDatabase("paperclip-heartbeat-stale-queue-");db = createDb(tempDb.connectionString);heartbeat = heartbeatService(db, {+ runtimeEnv: { ...process.env, PAPERCLIP_IN_WORKTREE: "false" },beforeResolvedInteractionContinuationDispatchCheck: async (input) => {await beforeContinuationDispatchCheck?.(input);},@@ -1590,15 +1592,53 @@ describeEmbeddedPostgres("heartbeat stale queued-run invalidation", () => {expect(countExecuteCallsForRun(runId)).toBe(0);});- it.each(["accepted", "rejected"])("resumes a %s connection outcome after native waiting moves the task to review", async (interactionStatus) => {+ it.each([+ ["accepted", "connection_intent"],+ ["rejected", "connection_intent"],+ ["rejected", "request_confirmation"],+ ])("resumes a %s %s outcome and promotes the claimed review task", async (interactionStatus, interactionKind) => {const { companyId, agentId } = await seedCompanyAndAgent();const issueId = randomUUID();+ const interactionId = randomUUID();+ const wakeCommentId = randomUUID();+ let claimedIssue: { status: string; executionRunId: string | null } | null = null;+ afterContinuationDispatchCheck = async ({ runId: checkedRunId, issueId: checkedIssueId }) => {+ if (checkedIssueId !== issueId) return;+ claimedIssue = await db+ .select({ status: issues.status, executionRunId: issues.executionRunId })+ .from(issues)+ .where(eq(issues.id, issueId))+ .then((rows) => rows[0] ?? null);+ expect(claimedIssue).toEqual({ status: "in_progress", executionRunId: checkedRunId });+ };await db.insert(issues).values({ id: issueId, companyId, title: "Waiting for connection", status: "in_review", priority: "medium", assigneeAgentId: agentId });- const { runId } = await seedQueuedRun({ companyId, agentId, issueId, wakeReason: "issue_commented", invocationSource: "automation",- contextExtras: { interactionId: randomUUID(), interactionKind: "connection_intent", interactionStatus,- interactionResolvedAt: new Date().toISOString(), mutation: "interaction", source: "connection_intent.resolved", forceFreshSession: true } });+ await db.insert(issueComments).values({+ id: wakeCommentId,+ companyId,+ issueId,+ authorUserId: "local-board",+ body: "Continue after the interaction result.",+ });+ if (interactionKind === "request_confirmation") {+ await db.insert(issueThreadInteractions).values({+ id: interactionId,+ companyId,+ issueId,+ kind: "request_confirmation",+ status: "rejected",+ continuationPolicy: "wake_assignee",+ payload: {},+ result: { version: 1, outcome: "rejected", reason: "Needs more work" },+ createdByAgentId: agentId,+ resolvedAt: new Date(),+ });+ }+ const { runId } = await seedQueuedRun({ companyId, agentId, issueId, wakeReason: "issue_commented",+ contextExtras: { interactionId, interactionKind, interactionStatus, wakeCommentId,+ originCommentIds: [wakeCommentId],+ interactionResolvedAt: new Date().toISOString(), mutation: "interaction", source: `${interactionKind}.resolved`, forceFreshSession: true } });await heartbeat.resumeQueuedRuns();- await waitForCondition(async () => (await db.select({ status: heartbeatRuns.status }).from(heartbeatRuns).where(eq(heartbeatRuns.id, runId)))[0]?.status === "succeeded");- expect(countExecuteCallsForRun(runId)).toBe(1);+ await waitForCondition(async () => claimedIssue !== null);+ expect(claimedIssue).toEqual({ status: "in_progress", executionRunId: runId });});});diff --git a/server/src/modules/run-dispatch/domain/policy.test.ts b/server/src/modules/run-dispatch/domain/policy.test.tsindex 3d05ebf70b..d797a096bc 100644--- a/server/src/modules/run-dispatch/domain/policy.test.ts+++ b/server/src/modules/run-dispatch/domain/policy.test.ts@@ -389,6 +389,16 @@ describe("decideQueuedRunStaleness", () => {});});+ it("allows a resolved non-connection interaction to claim its review task", () => {+ expect(decideQueuedRunStaleness({+ ...baseStalenessFacts(),+ isResolvedInteractionContinuation: true,+ isConnectionContinuation: false,+ issueStatus: "in_review",+ reviewParticipant: { ...NO_PARTICIPANT, isInReview: true },+ }, NOW)).toEqual({ stale: false });+ });+it("does not cancel a parked continuation summary when the classifier says it does not park the executor", () => {const facts: QueuedRunFacts = {...baseStalenessFacts(),diff --git a/server/src/modules/run-dispatch/domain/policy.ts b/server/src/modules/run-dispatch/domain/policy.tsindex dcdf1c48fd..e591cbc0b9 100644--- a/server/src/modules/run-dispatch/domain/policy.ts+++ b/server/src/modules/run-dispatch/domain/policy.ts@@ -493,7 +493,7 @@ export function decideQueuedRunStaleness(if (facts.isResolvedInteractionContinuation || facts.isConnectionContinuation) {const earlyStatus = decideIssueStatus({status: facts.issueStatus,- requiresInProgress: !(facts.isConnectionContinuation && facts.issueStatus === "in_review"),+ requiresInProgress: facts.issueStatus !== "in_review",terminalBypass: true,});if (earlyStatus === "not_in_progress") {diff --git a/server/src/services/heartbeat.ts b/server/src/services/heartbeat.tsindex 09906d335c..65674fd3dc 100644--- a/server/src/services/heartbeat.ts+++ b/server/src/services/heartbeat.ts@@ -6771,6 +6771,13 @@ export function shouldAutoCheckoutIssueForWake(input: {return true;}+export function resolvedInteractionCheckoutExpectedStatuses() {+ // A resolved interaction authorizes a new provider turn. Review describes+ // the idle handoff state; once this turn acquires execution it must become+ // in_progress in the same guarded checkout update.+ return ["in_progress", "in_review"] as const;+}+export function shouldQueueFollowupForRunningIssueWake(input: {contextSnapshot: Record<string, unknown> | null | undefined;wakeCommentId: string | null;@@ -19529,9 +19536,7 @@ export function heartbeatService(await issuesSvc.checkout(issueId,agent.id,- context.interactionKind === "connection_intent"- ? ["in_progress", "in_review"]- : ["in_progress"],+ [...resolvedInteractionCheckoutExpectedStatuses()],run.id,);context[PAPERCLIP_HARNESS_CHECKOUT_KEY] = true;