fix(heartbeat): stop carrying the in_review wait into later summaries (#15544)

## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - After each run, Paperclip refreshes the issue's continuation
summary. In review, its Next Action says to wait for reviewer feedback
> - Later refreshes copy that line into in-progress issues, so the
dispatcher cancels the queued continuation
> - This pull request stops that copy

## Linked Issues or Issue Description

Refs #14424. Agents on an issue that came back from review get their
queued continuation runs cancelled with
`issue_continuation_waiting_on_review`. Builds on the repro and check
from @mnazirp-finity. Related: #11614.

## What Changed

- `inferNextAction` no longer carries the Next Action it writes for an
in_review issue into another status.
- Tests: the issue's repro, a kept waiting Next Action, and a Postgres
test for the queued continuation.

## Verification

- `pnpm exec vitest run issue-continuation-summary.test.ts
run-dispatch/adapters/postgres.test.ts`

## Risks

Low. Stored summaries with the wait line change after the next run.

## Model Used

The AI assistance note is at the end.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [ ] I have specified the model used (with version and capability
details)
- [x] ROADMAP.md lists no planned core work that overlaps this PR
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [ ] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [ ] All Paperclip CI gates are green
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [ ] I will address all Greptile and reviewer comments before
requesting merge

Assisted by Claude/Codex.

Co-authored-by: mnazirp-finity
<317764857+mnazirp-finity@users.noreply.github.com>

Co-authored-by: mnazirp-finity <317764857+mnazirp-finity@users.noreply.github.com>
This commit is contained in:
Arthurandmnazirp-finity authored and GitHub committed 2026-12-04 21:23:21 -08:00
1 parent 6520046f35
commit 2eea950c2e
3 files changed
+87 -2

No files matched your search

@@ -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",
@@ -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", () => {
@@ -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) {