mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-01 15:35:12 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Issue comment wake handoffs are part of the control-plane execution loop that decides when agents resume work after comments and issue updates. > - PR #7678 changed that wake handoff behavior in server issue routes, heartbeat context, and related tests. > - The change broke an important workflow after merge, so the safest immediate fix is to restore the pre-#7678 wake behavior. > - This pull request reverts the wake-handoff behavior from PR #7678 while keeping narrow review-requested safeguards that prevent known runtime/test regressions. > - The benefit is that Paperclip returns to the last known working wake behavior without reintroducing avoidable UUID skill lookup and annotation-resolution test gaps. ## Linked Issues or Issue Description Refs: #7678 Bug context: - What happened: PR #7678 was reported to have broken an important Paperclip workflow after it merged. - Expected behavior: Paperclip should preserve the prior issue comment wake handoff behavior until a corrected change is ready. - Steps to reproduce: Use the workflow affected by PR #7678's issue comment wake handoff changes. - Paperclip version/commit: `master` after merge commit `4da79a88c67e54084d40bd18cada5ee5c8be23da`. - Deployment mode: Paperclip control-plane server behavior. ## What Changed - Reverted merge commit `4da79a88c67e54084d40bd18cada5ee5c8be23da` from PR #7678 to restore pre-#7678 wake-handoff behavior. - Preserved the safe accepted-plan routing check so `parseObject(...)` is not used as a boolean. - Preserved UUID filtering for run-scoped skill mentions so legacy non-UUID skill IDs do not reach a Postgres UUID lookup. - Restored the annotation thread-resolution test guard that verifies resolving a thread does not wake the assignee. ## Verification - `pnpm run preflight:workspace-links && NODE_ENV=test PAPERCLIP_HOME=/tmp/... PAPERCLIP_INSTANCE_ID=pap10614-revert TMPDIR=/tmp/... pnpm exec vitest run --project @paperclipai/server --no-file-parallelism --maxWorkers=1 server/src/__tests__/document-annotation-routes.test.ts server/src/__tests__/heartbeat-project-env.test.ts server/src/__tests__/heartbeat-accepted-plan-workspace-refresh.test.ts server/src/__tests__/heartbeat-context-summary.test.ts` - Result: 4 test files passed, 26 tests passed. - Earlier targeted revert verification also passed: 4 test files, 50 tests. ## Risks - This intentionally restores behavior from before PR #7678, so intended wake-handoff improvements from that PR are removed. - The PR is no longer a byte-for-byte revert because Greptile identified two narrow safeguards worth preserving. - Low migration risk: no schema or dependency changes are included. - Follow-up work may still be needed to reintroduce the desired wake handoff behavior without the regression. ## Model Used OpenAI Codex, GPT-5 coding agent in this Paperclip heartbeat, with shell/tool execution and repository write access. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [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 run tests locally and they pass - [x] I have added or updated tests where applicable - [x] If this change affects the UI, I have included before/after screenshots - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge
225 lines
6.6 KiB
TypeScript
225 lines
6.6 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
buildPaperclipTaskMarkdown,
|
|
mergeCoalescedContextSnapshot,
|
|
summarizeHeartbeatRunContextSnapshot,
|
|
summarizeHeartbeatRunListResultJson,
|
|
} from "../services/heartbeat.js";
|
|
|
|
describe("buildPaperclipTaskMarkdown", () => {
|
|
it("adds planning directives for assignment and comment task context", () => {
|
|
const assignment = buildPaperclipTaskMarkdown({
|
|
issue: {
|
|
id: "issue-1",
|
|
identifier: "PAP-3404",
|
|
title: "Plan first",
|
|
workMode: "planning",
|
|
description: null,
|
|
},
|
|
});
|
|
|
|
expect(assignment).toContain("- Work mode: \"planning\"");
|
|
expect(assignment).toContain("Make the plan only. Do not write code or perform implementation work.");
|
|
|
|
const commentWake = buildPaperclipTaskMarkdown({
|
|
issue: {
|
|
id: "issue-1",
|
|
identifier: "PAP-3404",
|
|
title: "Plan first",
|
|
workMode: "planning",
|
|
description: null,
|
|
},
|
|
wakeComment: {
|
|
id: "comment-1",
|
|
body: "Please revise the plan.",
|
|
},
|
|
});
|
|
|
|
expect(commentWake).toContain("Update the plan only. Do not write code or perform implementation work.");
|
|
|
|
const acceptedConfirmation = buildPaperclipTaskMarkdown({
|
|
issue: {
|
|
id: "issue-1",
|
|
identifier: "PAP-3404",
|
|
title: "Plan first",
|
|
workMode: "planning",
|
|
description: null,
|
|
},
|
|
interaction: {
|
|
kind: "request_confirmation",
|
|
status: "accepted",
|
|
},
|
|
});
|
|
|
|
expect(acceptedConfirmation).toContain("Create child issues from the approved plan only");
|
|
expect(acceptedConfirmation).not.toContain("Make the plan only.");
|
|
});
|
|
|
|
it("adds accepted-plan continuation guidance for standard-work issues when the wake is flagged as a plan continuation", () => {
|
|
const acceptedConfirmation = buildPaperclipTaskMarkdown({
|
|
issue: {
|
|
id: "issue-2",
|
|
identifier: "PAP-415",
|
|
title: "Implement the fix",
|
|
workMode: "standard",
|
|
description: null,
|
|
},
|
|
acceptedPlanContinuation: true,
|
|
});
|
|
|
|
expect(acceptedConfirmation).toContain("Accepted plan directive:");
|
|
expect(acceptedConfirmation).toContain("Create child issues from the approved plan only");
|
|
expect(acceptedConfirmation).not.toContain("- Work mode: \"planning\"");
|
|
});
|
|
|
|
it("prefers ordinary comment planning guidance over stale accepted confirmation state", () => {
|
|
const commentWake = buildPaperclipTaskMarkdown({
|
|
issue: {
|
|
id: "issue-1",
|
|
identifier: "PAP-3404",
|
|
title: "Plan first",
|
|
workMode: "planning",
|
|
description: null,
|
|
},
|
|
wakeComment: {
|
|
id: "comment-1",
|
|
body: "Please revise the plan.",
|
|
},
|
|
interaction: {
|
|
kind: "request_confirmation",
|
|
status: "accepted",
|
|
},
|
|
});
|
|
|
|
expect(commentWake).toContain("Update the plan only. Do not write code or perform implementation work.");
|
|
expect(commentWake).not.toContain("Create child issues from the approved plan only");
|
|
});
|
|
});
|
|
|
|
describe("mergeCoalescedContextSnapshot", () => {
|
|
it("clears stale accepted-plan interaction state when merging a later ordinary comment wake", () => {
|
|
const merged = mergeCoalescedContextSnapshot(
|
|
{
|
|
issueId: "issue-1",
|
|
interactionId: "interaction-1",
|
|
interactionKind: "request_confirmation",
|
|
interactionStatus: "accepted",
|
|
continuationPolicy: "wake_assignee_on_accept",
|
|
wakeReason: "issue_commented",
|
|
},
|
|
{
|
|
issueId: "issue-1",
|
|
commentId: "comment-1",
|
|
wakeCommentId: "comment-1",
|
|
wakeReason: "issue_commented",
|
|
},
|
|
);
|
|
|
|
expect(merged.interactionId).toBeUndefined();
|
|
expect(merged.interactionKind).toBeUndefined();
|
|
expect(merged.interactionStatus).toBeUndefined();
|
|
expect(merged.continuationPolicy).toBeUndefined();
|
|
expect(merged.commentId).toBe("comment-1");
|
|
expect(merged.wakeCommentId).toBe("comment-1");
|
|
});
|
|
|
|
it("preserves accepted-plan interaction state for the interaction wake itself", () => {
|
|
const merged = mergeCoalescedContextSnapshot(
|
|
{
|
|
issueId: "issue-1",
|
|
},
|
|
{
|
|
issueId: "issue-1",
|
|
interactionId: "interaction-1",
|
|
interactionKind: "request_confirmation",
|
|
interactionStatus: "accepted",
|
|
continuationPolicy: "wake_assignee_on_accept",
|
|
wakeReason: "issue_commented",
|
|
},
|
|
);
|
|
|
|
expect(merged.interactionId).toBe("interaction-1");
|
|
expect(merged.interactionKind).toBe("request_confirmation");
|
|
expect(merged.interactionStatus).toBe("accepted");
|
|
expect(merged.continuationPolicy).toBe("wake_assignee_on_accept");
|
|
});
|
|
});
|
|
|
|
describe("summarizeHeartbeatRunContextSnapshot", () => {
|
|
it("keeps only the small retry/linking fields needed by the client", () => {
|
|
const summarized = summarizeHeartbeatRunContextSnapshot({
|
|
issueId: "issue-1",
|
|
taskId: "task-1",
|
|
taskKey: "PAP-1",
|
|
commentId: "comment-1",
|
|
wakeCommentId: "comment-2",
|
|
wakeReason: "retry_failed_run",
|
|
wakeSource: "on_demand",
|
|
wakeTriggerDetail: "manual",
|
|
paperclipWake: {
|
|
comments: [
|
|
{
|
|
body: "x".repeat(50_000),
|
|
},
|
|
],
|
|
},
|
|
executionStage: {
|
|
summary: "large nested object that should not be sent back in run lists",
|
|
},
|
|
});
|
|
|
|
expect(summarized).toEqual({
|
|
issueId: "issue-1",
|
|
taskId: "task-1",
|
|
taskKey: "PAP-1",
|
|
commentId: "comment-1",
|
|
wakeCommentId: "comment-2",
|
|
wakeReason: "retry_failed_run",
|
|
wakeSource: "on_demand",
|
|
wakeTriggerDetail: "manual",
|
|
});
|
|
});
|
|
|
|
it("returns null when no allowed fields are present", () => {
|
|
expect(
|
|
summarizeHeartbeatRunContextSnapshot({
|
|
paperclipWake: { comments: [{ body: "hello" }] },
|
|
}),
|
|
).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe("summarizeHeartbeatRunListResultJson", () => {
|
|
it("keeps only summary fields and parses numeric cost aliases", () => {
|
|
expect(
|
|
summarizeHeartbeatRunListResultJson({
|
|
summary: "Completed the task",
|
|
result: "Updated three files",
|
|
message: "",
|
|
error: null,
|
|
totalCostUsd: "1.25",
|
|
costUsd: "0.75",
|
|
costUsdCamel: "0.5",
|
|
}),
|
|
).toEqual({
|
|
summary: "Completed the task",
|
|
result: "Updated three files",
|
|
total_cost_usd: 1.25,
|
|
cost_usd: 0.75,
|
|
costUsd: 0.5,
|
|
});
|
|
});
|
|
|
|
it("returns null when projected fields are empty", () => {
|
|
expect(
|
|
summarizeHeartbeatRunListResultJson({
|
|
summary: "",
|
|
result: null,
|
|
message: undefined,
|
|
error: " ",
|
|
totalCostUsd: "abc",
|
|
}),
|
|
).toBeNull();
|
|
});
|
|
});
|