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, 18:30 UTC
fix(acp): linked terminal output no longer reopens a completed tool call (#35844)
Julius Marminge committed
Nov 12, 2026 at 19:31 UTC
c967d98cea57c6a2245c29115086b42ba5d0f60d
2 files changed
+109
-5
apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts
+103
@@ -1074,6 +1074,109 @@ const optionValues = (question: OrchestrationV2UserInputQuestion | undefined) =>
1074
describe("AcpAdapterV2", () => {
1075
beforeAll(() => bundleAgents);
1076
1077
+ it.live("keeps a completed tool's status when its linked ACP terminal streams output", () =>
1078
+ Effect.gen(function* () {
1079
+ const instanceId = ProviderInstanceId.make("acp-test-terminal-linked-tool");
1080
+ const threadId = ThreadId.make("thread-acp-terminal-linked-tool");
1081
+ let notify: Parameters<
1082
+ AcpSessionRuntime.AcpSessionRuntime["Service"]["handleSessionUpdate"]
1083
+ >[0];
1084
+ const adapter = yield* makeAcpAdapterV2({
1085
+ instanceId,
1086
+ selfInvocation: yield* resolveSelfInvocation(),
1087
+ flavor: {
1088
+ driver: ACP_TEST_DRIVER,
1089
+ capabilities: AcpProviderCapabilitiesV2,
1090
+ makeRuntime: makeMockRuntime({
1091
+ childProcessSpawner: yield* ChildProcessSpawner.ChildProcessSpawner,
1092
+ mockAgentPath: yield* bundledMockAgentPath,
1093
+ wrapRuntime: (runtime) => ({
1094
+ ...runtime,
1095
+ handleSessionUpdate: (handler) =>
1096
+ Effect.sync(() => {
1097
+ notify = handler;
1098
+ }).pipe(Effect.andThen(runtime.handleSessionUpdate(handler))),
1099
+ prompt: () =>
1100
+ Effect.gen(function* () {
1101
+ const send = (update: EffectAcpSchema.SessionUpdate) =>
1102
+ notify({ sessionId: "mock-session-1", update });
1103
+ yield* send({ sessionUpdate: "state_update", state: "running" });
1104
+ yield* send({
1105
+ sessionUpdate: "terminal_update",
1106
+ terminalId: "term",
1107
+ command: "npm run dev",
1108
+ });
1109
+ yield* send({
1110
+ sessionUpdate: "tool_call_update",
1111
+ toolCallId: "linked",
1112
+ kind: "execute",
1113
+ title: "Start dev server",
1114
+ status: "completed",
1115
+ content: [{ type: "terminal", terminalId: "term" }],
1116
+ });
1117
+ yield* send({
1118
+ sessionUpdate: "terminal_output_chunk",
1119
+ terminalId: "term",
1120
+ data: Buffer.from("still running").toString("base64"),
1121
+ });
1122
+ yield* send({
1123
+ sessionUpdate: "state_update",
1124
+ state: "idle",
1125
+ stopReason: "end_turn",
1126
+ });
1127
+ return { stopReason: "end_turn" as const };
1128
+ }),
1129
+ }),
1130
+ }),
1131
+ },
1132
+ });
1133
+ const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
1134
+ runtimeMode: "full-access",
1135
+ interactionMode: "default",
1136
+ cwd: process.cwd(),
1137
+ });
1138
+ const modelSelection = { instanceId, model: "default" } as const;
1139
+ const runtime = yield* adapter.openSession({
1140
+ threadId,
1141
+ providerSessionId: ProviderSessionId.make("provider-session-acp-terminal-linked-tool"),
1142
+ modelSelection,
1143
+ runtimePolicy,
1144
+ });
1145
+ const providerThread = yield* runtime.ensureThread({
1146
+ threadId,
1147
+ modelSelection,
1148
+ runtimePolicy,
1149
+ });
1150
+ yield* runtime.startTurn(
1151
+ makeTurnInput({
1152
+ threadId,
1153
+ providerThread,
1154
+ instanceId,
1155
+ runtimePolicy,
1156
+ now: yield* DateTime.now,
1157
+ ordinal: 1,
1158
+ }),
1159
+ );
1160
+ const items = Array.from(
1161
+ yield* runtime.events.pipe(
1162
+ Stream.takeUntil((event) => event.type === "turn.terminal"),
1163
+ Stream.runCollect,
1164
+ ),
1165
+ ).flatMap((event) =>
1166
+ event.type === "turn_item.updated" && event.turnItem.nativeItemRef?.nativeId === "linked"
1167
+ ? [event.turnItem]
1168
+ : [],
1169
+ );
1170
+ const last = items.at(-1);
1171
+ assert.equal(last?.type === "command_execution" ? last.output : null, "still running");
1172
+ assert.deepEqual(
1173
+ items.map((item) => item.status),
1174
+ items.map(() => "completed"),
1175
+ "terminal output must not reopen a tool the agent completed",
1176
+ );
1177
+ }).pipe(Effect.provide(layerTest), Effect.scoped),
1178
+ );
1179
+
1180
it.live("reports per-turn usage unavailable on a continuation turn that never prompts", () =>
1181
Effect.gen(function* () {
1182
const instanceId = ProviderInstanceId.make("acp-test-usage-continuation");
packages/provider-acp/src/server/adapter.ts
+6
-5
@@ -4973,10 +4973,10 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
4973
? ("completed" as const)
4974
: ("failed" as const);
4975
const embeddedToolCallIds = toolCallIdsByAgentTerminalId.get(terminalKey);
4976
- const projectedToolCallIds =
4977
- embeddedToolCallIds === undefined || embeddedToolCallIds.size === 0
4978
- ? [`acp-agent-terminal:${update.terminalId}`]
4979
- : [...embeddedToolCallIds];
4976
+ const linked = embeddedToolCallIds !== undefined && embeddedToolCallIds.size > 0;
4977
+ const projectedToolCallIds = linked
4978
+ ? [...embeddedToolCallIds]
4979
+ : [`acp-agent-terminal:${update.terminalId}`];
4980
const output = next.output.slice(-MAX_AGENT_TERMINAL_OUTPUT_CHARS);
4981
for (const toolCallId of projectedToolCallIds) {
4982
const existing = context.tools.get(toolCallId);
@@ -4995,7 +4995,8 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
4995
setToolOutputText(
4996
{
4997
...seeded,
4998
- status,
4998
+ // An agent-reported tool owns its status; terminal state only drives the synthetic one.
4999
+ status: (linked ? existing?.status : undefined) ?? status,
5000
...(next.command === undefined ? {} : { command: next.command }),
5001
},
5002
output,