Skip to content

Commit 3c00ca3

Browse files
Radu028claude
andcommitted
fix(acp): a compaction left open at turn end still counts when it really finishes
When a turn ended with its compaction still in progress, settling projected the compaction as completed and recorded its id, so the agent's real completion later was ignored and the next prompt skipped T3's instructions. Record compaction ids only for the agent's own updates. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 6757893 commit 3c00ca3

3 files changed

Lines changed: 33 additions & 1 deletion

File tree

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ const failPromptOrdinal = Number(process.env.T3_ACP_FAIL_PROMPT_ORDINAL);
5454
const compactionPromptOrdinals = new Set(
5555
(process.env.T3_ACP_COMPACTION_PROMPT_ORDINALS ?? "").split(",").map(Number),
5656
);
57+
// These prompts end while their compaction is still in progress.
58+
const openCompactionPromptOrdinals = new Set(
59+
(process.env.T3_ACP_OPEN_COMPACTION_PROMPT_ORDINALS ?? "").split(",").map(Number),
60+
);
5761
const failSetModeConfigOption = process.env.T3_ACP_FAIL_SET_MODE_CONFIG_OPTION === "1";
5862
const emitEmptyDefaultAgentOption = process.env.T3_ACP_EMIT_EMPTY_DEFAULT_AGENT_OPTION === "1";
5963
const promptResponseText = process.env.T3_ACP_PROMPT_RESPONSE_TEXT;
@@ -1249,6 +1253,16 @@ const program = Effect.gen(function* () {
12491253
yield* Effect.sleep(`${promptDelayMs} millis`);
12501254
}
12511255

1256+
if (openCompactionPromptOrdinals.has(promptCount)) {
1257+
yield* agent.client.sessionUpdate({
1258+
sessionId: requestedSessionId,
1259+
update: {
1260+
sessionUpdate: "compaction_update",
1261+
compactionId: `compact-${promptCount}`,
1262+
status: "in_progress",
1263+
},
1264+
});
1265+
}
12521266
if (compactionPromptOrdinals.has(promptCount)) {
12531267
for (const status of ["in_progress", "completed"] as const) {
12541268
yield* agent.client.sessionUpdate({

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,7 @@ describe("AcpAdapterV2", () => {
10841084
const { runTurn, idleSessionUpdate, idleCopilotSessionEvent } =
10851085
yield* makeInstructionCompactionHarness({
10861086
T3_ACP_COMPACTION_PROMPT_ORDINALS: "2,4",
1087+
T3_ACP_OPEN_COMPACTION_PROMPT_ORDINALS: "13",
10871088
});
10881089
yield* runTurn("Start work.");
10891090
yield* runTurn("Continue until context compacts.");
@@ -1151,6 +1152,20 @@ describe("AcpAdapterV2", () => {
11511152
assert.deepEqual(yield* runTurn("Continue after child compaction."), [
11521153
{ type: "text", text: "Continue after child compaction." },
11531154
]);
1155+
yield* runTurn("End this turn while compaction is still running.");
1156+
assertReinjectedInstructions(
1157+
yield* runTurn("Continue after the turn ended mid-compaction."),
1158+
"Continue after the turn ended mid-compaction.",
1159+
);
1160+
yield* idleSessionUpdate({
1161+
sessionUpdate: "compaction_update",
1162+
compactionId: "compact-13",
1163+
status: "completed",
1164+
});
1165+
assertReinjectedInstructions(
1166+
yield* runTurn("Continue after the compaction really finished."),
1167+
"Continue after the compaction really finished.",
1168+
);
11541169
}).pipe(Effect.provide(layerTest), Effect.scoped),
11551170
);
11561171

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3693,9 +3693,12 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
36933693
updated.delete(context.nativeThreadId);
36943694
return updated;
36953695
});
3696+
// A completion projected at turn end must not swallow the agent's later real one.
36963697
yield* markSessionCompacted(
36973698
context.nativeThreadId,
3698-
toolCall.toolCallId.slice("acp-compaction:".length),
3699+
projectedStatus === undefined
3700+
? toolCall.toolCallId.slice("acp-compaction:".length)
3701+
: undefined,
36993702
);
37003703
}
37013704
} else if (mcpIdentity !== undefined) {

0 commit comments

Comments
 (0)