@devries-cameron20 / t3code Mirror · read-only / commits / 9d2db4b23f
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

fix(provider-acp): an ACP compaction no longer keeps a summary its agent cleared (#39151)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Soroush Baraouf committed Nov 19, 2026 at 10:14 UTC 9d2db4b23fe0449b0a652492ab734740e4aa08aa
4 files changed +183 -3
packages/provider-acp/src/server/adapter.ts
+3 -1
@@ -4571,7 +4571,9 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
4571 });
4572 let turnItem: OrchestrationV2TurnItem;
4573 if (toolCall.toolCallId.startsWith("acp-compaction:")) {
4574 - const summary = textFromUnknown(rawOutput);
4574 + const summary =
4575 + (status === "failed" ? textFromUnknown(toolCall.data.compactionError) : undefined) ||
4576 + textFromUnknown(rawOutput);
4577 turnItem = {
4578 ...base,
4579 type: "compaction",
packages/provider-acp/src/server/runtimeModel.test.ts
+59
@@ -1092,6 +1092,65 @@ describe("AcpRuntimeModel", () => {
1092 },
1093 });
1094 expect(idle.events).toEqual([]);
1095 +
1096 + const toolCall = (update: EffectAcpSchema.SessionUpdate) => {
1097 + const event = parseSessionUpdateEvent({ sessionId: "session-1", update }).events[0];
1098 + if (event?._tag !== "ToolCallUpdated") throw new Error("expected a compaction tool call");
1099 + return event.toolCall;
1100 + };
1101 + const draft = toolCall({
1102 + sessionUpdate: "compaction_summary_chunk",
1103 + compactionId: "compact-1",
1104 + content: { type: "text", text: "Draft summary" },
1105 + });
1106 + const finish = (summary?: ReadonlyArray<EffectAcpSchema.ContentBlock> | null) =>
1107 + mergeToolCallState(
1108 + draft,
1109 + toolCall({
1110 + sessionUpdate: "compaction_update",
1111 + compactionId: "compact-1",
1112 + status: "completed",
1113 + ...(summary === undefined ? {} : { summary }),
1114 + }),
1115 + ).data.rawOutput;
1116 +
1117 + expect(finish()).toBe("Draft summary");
1118 + expect([finish(null), finish([]), finish([{ type: "text", text: "" }])]).toEqual([
1119 + undefined,
1120 + undefined,
1121 + undefined,
1122 + ]);
1123 +
1124 + const fail = (
1125 + previous: ReturnType<typeof toolCall>,
1126 + patch: Pick<
1127 + Extract<EffectAcpSchema.SessionUpdate, { sessionUpdate: "compaction_update" }>,
1128 + "summary" | "error"
1129 + >,
1130 + ) =>
1131 + mergeToolCallState(
1132 + previous,
1133 + toolCall({
1134 + sessionUpdate: "compaction_update",
1135 + compactionId: "compact-1",
1136 + status: "failed",
1137 + ...patch,
1138 + }),
1139 + );
1140 + const failed = fail(draft, { error: "Budget exhausted" });
1141 + const summaryCleared = fail(failed, { summary: null });
1142 + const errorCleared = fail(summaryCleared, { error: null });
1143 + const fields = (state: ReturnType<typeof toolCall>) => [
1144 + state.data.rawOutput,
1145 + state.data.compactionError,
1146 + ];
1147 + expect(fields(failed)).toEqual(["Draft summary", "Budget exhausted"]);
1148 + expect(fields(summaryCleared)).toEqual([undefined, "Budget exhausted"]);
1149 + expect(fields(errorCleared)).toEqual([undefined, undefined]);
1150 + expect(fields(fail(draft, { summary: null, error: "Budget exhausted" }))).toEqual([
1151 + undefined,
1152 + "Budget exhausted",
1153 + ]);
1154 });
1155
1156 it("applies ACP v2 agent-owned terminal snapshots and output chunks", () => {
packages/provider-acp/src/server/runtimeModel.ts
+10 -2
@@ -1594,11 +1594,19 @@ export function parseSessionUpdateEvent(params: EffectAcpSchema.SessionNotificat
1594 title: "Compact context",
1595 kind: "think",
1596 status,
1597 - rawOutput: (upd.error ?? summary) || undefined,
1597 + rawOutput: upd.summary === undefined ? undefined : summary || null,
1598 _meta: upd._meta,
1599 });
1600 if (toolCall !== undefined) {
1601 - events.push({ _tag: "ToolCallUpdated", toolCall, rawPayload: params });
1601 + // Summary and error are independent patches; null clears only its own field.
1602 + events.push({
1603 + _tag: "ToolCallUpdated",
1604 + toolCall:
1605 + upd.error === undefined
1606 + ? toolCall
1607 + : { ...toolCall, data: { ...toolCall.data, compactionError: upd.error } },
1608 + rawPayload: params,
1609 + });
1610 }
1611 break;
1612 }
scripts/scenarios/acp-failed-compaction-drops-cleared-summary.e2e.ts new
+111
@@ -0,0 +1,111 @@
1 +// @effect-diagnostics nodeBuiltinImport:off -- The scenario stages a local ACP executable.
2 +import * as NodeFSP from "node:fs/promises";
3 +import * as NodePath from "node:path";
4 +
5 +import { expect } from "e2e";
6 +
7 +import { T3_HOME } from "../e2e.config.ts";
8 +import { makeState, runPromise, test, WEB } from "./t3.ts";
9 +
10 +const DRAFT = "Draft summary the agent discarded";
11 +const REPLY = "Compaction did not finish.";
12 +const ACP = `
13 +import { createInterface } from "node:readline";
14 +
15 +const sessionId = "compaction-scenario";
16 +const send = (message) => process.stdout.write(JSON.stringify({ jsonrpc: "2.0", ...message }) + "\\n");
17 +const respond = (id, result) => send({ id, result });
18 +const update = (update) => send({ method: "session/update", params: { sessionId, update } });
19 +for await (const line of createInterface({ input: process.stdin })) {
20 + const { id, method } = JSON.parse(line);
21 + if (id === undefined) continue;
22 + if (method === "initialize") {
23 + respond(id, { protocolVersion: 2, info: { name: "compaction-agent", version: "1.0.0" } });
24 + } else if (method === "session/new") {
25 + respond(id, { sessionId });
26 + } else if (method === "session/prompt") {
27 + update({ sessionUpdate: "compaction_update", compactionId: "compact-1", status: "in_progress" });
28 + update({
29 + sessionUpdate: "compaction_summary_chunk",
30 + compactionId: "compact-1",
31 + content: { type: "text", text: ${JSON.stringify(DRAFT)} },
32 + });
33 + // The agent discards its draft when the compaction fails.
34 + update({ sessionUpdate: "compaction_update", compactionId: "compact-1", status: "failed", summary: null });
35 + update({ sessionUpdate: "agent_message_chunk", content: { type: "text", text: ${JSON.stringify(REPLY)} } });
36 + update({ sessionUpdate: "state_update", state: "idle", stopReason: "end_turn" });
37 + respond(id, {});
38 + } else {
39 + send({ id, error: { code: -32601, message: "Method not found" } });
40 + }
41 +}
42 +`;
43 +
44 +test(
45 + "A failed ACP compaction does not show the draft summary its agent cleared",
46 + WEB,
47 + async ({ t3, app, screen }) => {
48 + const project = await t3.project("demo");
49 + const script = NodePath.join(project, "compaction-acp.mjs");
50 + const settingsPath = NodePath.join(T3_HOME, "userdata/settings.json");
51 + const originalSettings = await NodeFSP.readFile(settingsPath, "utf8");
52 + const settings = JSON.parse(originalSettings);
53 + await NodeFSP.writeFile(script, ACP);
54 + settings.providerInstances["compaction-agent"] = {
55 + driver: "acpRegistry",
56 + displayName: "Compaction Agent",
57 + enabled: true,
58 + config: { source: "local", commandPath: process.execPath, commandArgs: [script] },
59 + };
60 + try {
61 + await NodeFSP.writeFile(settingsPath, JSON.stringify(settings));
62 + const { cli } = makeState(T3_HOME);
63 + // The watcher reloads settings asynchronously. Retry only before a thread was created.
64 + let threadId: string | undefined;
65 + for (let attempt = 0; attempt < 8 && threadId === undefined; attempt++) {
66 + const started = await runPromise(
67 + cli(
68 + [
69 + "thread",
70 + "start",
71 + project,
72 + "Compact the context.",
73 + "--title",
74 + "Failed compaction",
75 + "--provider",
76 + "compaction-agent",
77 + "--model",
78 + "default",
79 + "--wait",
80 + "--json",
81 + ],
82 + [0, 1],
83 + ),
84 + );
85 + if (!started.stdout.includes("threadId")) continue;
86 + const result = JSON.parse(started.stdout) as {
87 + threadId: string;
88 + status: string;
89 + reply: string | null;
90 + };
91 + if (result.status !== "completed" || !result.reply?.includes(REPLY)) {
92 + throw new Error(`Compaction turn did not complete: ${started.stdout} ${started.stderr}`);
93 + }
94 + threadId = result.threadId;
95 + }
96 + if (threadId === undefined) throw new Error("Could not start the compaction turn.");
97 +
98 + await t3.open({ threadId });
99 + await screen.getByText(REPLY, { exact: true }).waitFor({ timeout: 60_000 });
100 + const separator = screen.getByRole("separator", /^Context compaction failed/);
101 + await separator.waitFor({ timeout: 15_000 });
102 + try {
103 + await expect(separator).toHaveText("Context compaction failed");
104 + } finally {
105 + await app.screenshot("failed-compaction-row");
106 + }
107 + } finally {
108 + await NodeFSP.writeFile(settingsPath, originalSettings);
109 + }
110 + },
111 +);