Skip to content

Commit 5ff1482

Browse files
MarcoDotIOclaude
andauthored
fix(acp): cancelled plan steps no longer keep the plan running (pingdotgg#25564)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 1ad7861 commit 5ff1482

4 files changed

Lines changed: 50 additions & 14 deletions

File tree

‎apps/server/scripts/acp-mock-agent.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,18 @@ const program = Effect.gen(function* () {
11041104
entries: [{ content: "Ship B", priority: "high", status: "in_progress" }],
11051105
},
11061106
},
1107+
{
1108+
sessionUpdate: "plan_update",
1109+
plan: {
1110+
type: "items",
1111+
planId: "plan-c",
1112+
entries: [
1113+
{ content: "Write the fix", priority: "high", status: "completed" },
1114+
{ content: "Try another approach", priority: "low", status: "cancelled" },
1115+
{ content: "Add a test", priority: "medium", status: "completed" },
1116+
],
1117+
},
1118+
},
11071119
{ sessionUpdate: "plan_removed", planId: "plan-a" },
11081120
{
11091121
sessionUpdate: "terminal_update",

‎apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3046,6 +3046,19 @@ describe("AcpAdapterV2", () => {
30463046
assert.equal(planA[1]?.status, "superseded");
30473047
assert.isDefined(planB);
30483048
assert.notEqual(planA[0]?.id, planB?.id);
3049+
const planC = plans.find(
3050+
(plan) =>
3051+
plan.kind === "todo_list" && plan.steps.some((step) => step.text === "Write the fix"),
3052+
);
3053+
assert.ok(planC?.kind === "todo_list");
3054+
assert.deepEqual(
3055+
planC.steps.map((step) => ({ id: step.id, text: step.text, status: step.status })),
3056+
[
3057+
{ id: "acp-step-1", text: "Write the fix", status: "completed" },
3058+
{ id: "acp-step-3", text: "Add a test", status: "completed" },
3059+
],
3060+
);
3061+
assert.equal(planC.status, "completed");
30493062

30503063
const items = events.flatMap((event) =>
30513064
event.type === "turn_item.updated" ? [event.turnItem] : [],

‎packages/provider-acp/src/server/adapter.ts‎

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4033,20 +4033,27 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
40334033
if (planState.latest === null) return;
40344034
plan = { ...planState.latest, status: "superseded" };
40354035
} else if (update.kind === "items") {
4036-
const steps: ReadonlyArray<OrchestrationV2PlanStep> = update.plan.map(
4037-
(step, index) => ({
4038-
id: `acp-step-${index + 1}`,
4039-
text: nonEmptyText(step.step, `Step ${index + 1}`),
4040-
status:
4041-
step.status === "inProgress"
4042-
? "running"
4043-
: step.status === "completed"
4044-
? "completed"
4045-
: "pending",
4046-
}),
4036+
// A cancelled entry is not outstanding work, and plan steps have no
4037+
// cancelled status, so drop it rather than show it as pending.
4038+
const steps: ReadonlyArray<OrchestrationV2PlanStep> = update.plan.flatMap(
4039+
(step, index) =>
4040+
step.status === "cancelled"
4041+
? []
4042+
: [
4043+
{
4044+
id: `acp-step-${index + 1}`,
4045+
text: nonEmptyText(step.step, `Step ${index + 1}`),
4046+
status:
4047+
step.status === "inProgress"
4048+
? "running"
4049+
: step.status === "completed"
4050+
? "completed"
4051+
: "pending",
4052+
},
4053+
],
40474054
);
40484055
const completed =
4049-
steps.length > 0 && steps.every((step) => step.status === "completed");
4056+
update.plan.length > 0 && steps.every((step) => step.status === "completed");
40504057
plan = {
40514058
...base,
40524059
status: completed ? "completed" : "active",

‎packages/provider-acp/src/server/runtimeModel.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ export type AcpPlanUpdate =
220220
readonly explanation?: string | null;
221221
readonly plan: ReadonlyArray<{
222222
readonly step: string;
223-
readonly status: "pending" | "inProgress" | "completed";
223+
readonly status: "pending" | "inProgress" | "completed" | "cancelled";
224224
}>;
225225
}
226226
| { readonly nativePlanId: string; readonly kind: "markdown"; readonly markdown: string }
@@ -493,10 +493,14 @@ export function parseSessionModeState(
493493
};
494494
}
495495

496-
function normalizePlanStepStatus(raw: unknown): "pending" | "inProgress" | "completed" {
496+
function normalizePlanStepStatus(
497+
raw: unknown,
498+
): "pending" | "inProgress" | "completed" | "cancelled" {
497499
switch (raw) {
498500
case "completed":
499501
return "completed";
502+
case "cancelled":
503+
return "cancelled";
500504
case "in_progress":
501505
case "inProgress":
502506
return "inProgress";

0 commit comments

Comments
 (0)