diff --git a/server/src/__tests__/issue-continuation-summary.test.ts b/server/src/__tests__/issue-continuation-summary.test.ts index 0ec94518df7..7f11e2352c3 100644 --- a/server/src/__tests__/issue-continuation-summary.test.ts +++ b/server/src/__tests__/issue-continuation-summary.test.ts @@ -194,6 +194,54 @@ describe("issue continuation summaries", () => { expect(body).not.toContain(providerText); }); + it("stops parking the executor once the issue is back in progress", () => { + const previousSummaryBody = [ + "# Continuation Summary", + "", + "## Next Action", + "", + "- Wait for reviewer feedback or approval before continuing executor work.", + ].join("\n"); + const body = buildContinuationSummaryMarkdown({ + issue: { + id: "issue-1", identifier: "TEST-1", title: "Review loop", + description: null, status: "in_progress", priority: "medium", + }, + run: { id: "run-2", status: "succeeded", error: null, resultJson: null }, + agent: { id: "agent-1", name: "Agent", adapterType: "claude_local" }, + previousSummaryBody, + }); + + expect(continuationSummaryParksExecutor(body)).toBe(false); + expect(extractContinuationSummaryNextAction(body)).toBe( + "Resume implementation from the acceptance criteria, latest comments, and this summary.", + ); + }); + + it("keeps carrying a waiting next action other than the one generated for in_review", () => { + const previousSummaryBody = [ + "# Continuation Summary", + "", + "## Next Action", + "", + "- Wait for the board to approve the release plan before deploying.", + ].join("\n"); + const body = buildContinuationSummaryMarkdown({ + issue: { + id: "issue-1", identifier: "TEST-1", title: "Release", + description: null, status: "in_progress", priority: "medium", + }, + run: { id: "run-2", status: "succeeded", error: null, resultJson: null }, + agent: { id: "agent-1", name: "Agent", adapterType: "claude_local" }, + previousSummaryBody, + }); + + expect(extractContinuationSummaryNextAction(body)).toBe( + "Wait for the board to approve the release plan before deploying.", + ); + expect(continuationSummaryParksExecutor(body)).toBe(true); + }); + it("does not park executor work when the next action is still runnable", () => { const body = [ "# Continuation Summary", diff --git a/server/src/modules/run-dispatch/adapters/postgres.test.ts b/server/src/modules/run-dispatch/adapters/postgres.test.ts index 81c52459ff4..4c046dbf769 100644 --- a/server/src/modules/run-dispatch/adapters/postgres.test.ts +++ b/server/src/modules/run-dispatch/adapters/postgres.test.ts @@ -41,6 +41,7 @@ import { projectTaskInterruption } from "../../../services/task-interruption-pre import { reserveRunBudget } from "../../../services/budget-reservations.js"; import { budgetService, flushBudgetEvaluationWork, recheckAdmittedRunBudgetReadOnly } from "../../../services/budgets.js"; import { costService } from "../../../services/costs.js"; +import { refreshIssueContinuationSummary } from "../../../services/issue-continuation-summary.js"; // Proves the DB-to-facts mapping this adapter owns for each state the two // run-dispatch gates decide on. `application/use-cases.test.ts` and @@ -1440,6 +1441,40 @@ describeEmbeddedPostgres("run-dispatch postgres adapter", () => { errorCode: "issue_continuation_waiting_on_review", }); }); + + it("keeps a continuation queued after the summary was refreshed for an issue back in progress", async () => { + const { companyId, agentId } = await seedCompanyAndAgent(); + const issueId = randomUUID(); + await seedIssue({ companyId, issueId, status: "in_review", assigneeAgentId: agentId }); + const agent = { id: agentId, name: "Agent", adapterType: "claude_local" }; + + const finishRun = async () => { + const id = await seedRun({ companyId, agentId, contextSnapshot: { issueId } }); + await db.update(heartbeatRuns).set({ status: "succeeded", finishedAt: new Date() }).where(eq(heartbeatRuns.id, id)); + return { id, status: "succeeded", error: null }; + }; + await refreshIssueContinuationSummary({ db, issueId, agent, run: await finishRun() }); + await db.update(issues).set({ status: "in_progress" }).where(eq(issues.id, issueId)); + await refreshIssueContinuationSummary({ db, issueId, agent, run: await finishRun() }); + + const runId = await seedRun({ + companyId, + agentId, + contextSnapshot: { + issueId, + wakeReason: "issue_continuation_needed", + retryReason: "issue_continuation_needed", + }, + }); + const result = await createPostgresRunDispatchAdapter(db).cancelStaleQueuedRun({ + runId, + companyId, + expectedStatus: "queued", + now: new Date(), + }); + + expect(result).toMatchObject({ outcome: "not_stale" }); + }); }); describe("promoteOrCancelDueRetry", () => { diff --git a/server/src/services/issue-continuation-summary.ts b/server/src/services/issue-continuation-summary.ts index f92549ae4aa..8d1edc79ab5 100644 --- a/server/src/services/issue-continuation-summary.ts +++ b/server/src/services/issue-continuation-summary.ts @@ -10,6 +10,7 @@ export const ISSUE_CONTINUATION_SUMMARY_TITLE = "Continuation Summary"; export const ISSUE_CONTINUATION_SUMMARY_MAX_BODY_CHARS = 8_000; const SUMMARY_SECTION_MAX_CHARS = 1_200; const PATH_CANDIDATE_RE = /(?:^|[\s`"'(])((?:server|ui|packages|doc|scripts|\.github)\/[A-Za-z0-9._/-]+)/g; +const IN_REVIEW_NEXT_ACTION = "Wait for reviewer feedback or approval before continuing executor work."; const WAITING_FOR_REVIEW_OR_APPROVAL_RE = /\bwait(?:ing)? for\b.{0,160}\b(?:review(?:er)?(?: feedback)?|approval|board|human|user|operator)\b/i; @@ -134,12 +135,13 @@ function inferMode(issue: IssueSummaryInput, run: RunSummaryInput) { function inferNextAction(issue: IssueSummaryInput, run: RunSummaryInput, previousNextAction: string | null) { if (issue.status === "done") return "Review the completed issue output and close any remaining follow-up comments."; - if (issue.status === "in_review") return "Wait for reviewer feedback or approval before continuing executor work."; + if (issue.status === "in_review") return IN_REVIEW_NEXT_ACTION; if (run.status === "failed" || run.status === "timed_out") { return "Inspect the failed run, fix the cause, and resume from the most recent concrete action above."; } if (run.status === "cancelled") return "Confirm the cancellation reason before starting another run."; - return previousNextAction ?? "Resume implementation from the acceptance criteria, latest comments, and this summary."; + if (previousNextAction && previousNextAction !== IN_REVIEW_NEXT_ACTION) return previousNextAction; + return "Resume implementation from the acceptance criteria, latest comments, and this summary."; } function bulletList(items: string[], empty: string) {