GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(acp): keep one answer when a running tool reports progress (#13386) · IanWorley/t3code@e144732

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/server
    • scripts
      • acp-mock-agent.ts
    • src/provider/acp
      • AcpJsonRpcConnection.test.ts
      • AcpSessionRuntime.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: apps/server/scripts/acp-mock-agent.ts
+43Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ const emitToolCalls = process.env.T3_ACP_EMIT_TOOL_CALLS === "1";
1919
const emitInterleavedAssistantToolCalls =
2020
process.env.T3_ACP_EMIT_INTERLEAVED_ASSISTANT_TOOL_CALLS === "1";
2121
const emitGenericToolPlaceholders = process.env.T3_ACP_EMIT_GENERIC_TOOL_PLACEHOLDERS === "1";
22+
const emitBackgroundToolDuringAnswer =
23+
process.env.T3_ACP_EMIT_BACKGROUND_TOOL_DURING_ANSWER === "1";
2224
const emitAskQuestion = process.env.T3_ACP_EMIT_ASK_QUESTION === "1";
2325
const emitXAiAskUserQuestion = process.env.T3_ACP_EMIT_XAI_ASK_USER_QUESTION === "1";
2426
const emitXAiExitPlanMode = process.env.T3_ACP_EMIT_XAI_EXIT_PLAN_MODE === "1";
@@ -952,6 +954,47 @@ const program = Effect.gen(function* () {
952954
return yield* Effect.never;
953955
}
954956

957+
if (emitBackgroundToolDuringAnswer) {
958+
// A command backgrounded earlier reports progress and then finishes
959+
// while the next answer is still streaming.
960+
const toolCallId = "background-1";
961+
const say = (text: string) =>
962+
agent.client.sessionUpdate({
963+
sessionId: requestedSessionId,
964+
update: { sessionUpdate: "agent_message_chunk", content: { type: "text", text } },
965+
});
966+
const progress = (status: "in_progress" | "completed", stdout: string) =>
967+
agent.client.sessionUpdate({
968+
sessionId: requestedSessionId,
969+
update: {
970+
sessionUpdate: "tool_call_update",
971+
toolCallId,
972+
status,
973+
rawOutput: { stdout },
974+
},
975+
});
976+
yield* agent.client.sessionUpdate({
977+
sessionId: requestedSessionId,
978+
update: {
979+
sessionUpdate: "tool_call",
980+
toolCallId,
981+
title: "Terminal",
982+
kind: "execute",
983+
status: "in_progress",
984+
rawInput: { command: "sleep 3 && echo done" },
985+
},
986+
});
987+
yield* say("| a | b |\n|---|---|\n| 1 ");
988+
yield* progress("in_progress", ".");
989+
yield* say("| x |\n");
990+
yield* progress("completed", "done");
991+
yield* say("| 2 | y |\n");
992+
// Agents can repeat a terminal update after the call finished.
993+
yield* progress("completed", "done");
994+
yield* say("| 3 | z |");
995+
return { stopReason: "end_turn" };
996+
}
997+
955998
if (emitInterleavedAssistantToolCalls) {
956999
const toolCallId = "tool-call-1";
9571000

Collapse file

‎apps/server/src/provider/acp/AcpJsonRpcConnection.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/provider/acp/AcpJsonRpcConnection.test.ts
+48Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,54 @@ describe("AcpSessionRuntime", () => {
882882
),
883883
);
884884

885+
it.effect("keeps one answer when an earlier tool reports progress mid-stream", () =>
886+
Effect.gen(function* () {
887+
const runtime = yield* AcpSessionRuntime.AcpSessionRuntime;
888+
yield* runtime.start();
889+
yield* runtime.prompt({ prompt: [{ type: "text", text: "hi" }] });
890+
891+
const notes = Array.from(yield* Stream.runCollect(Stream.take(runtime.getEvents(), 9)));
892+
// The coalesced progress tick emits nothing, and neither the completion
893+
// nor a repeated one splits the markdown table across items.
894+
expect(notes.map((note) => note._tag)).toEqual([
895+
"ToolCallUpdated",
896+
"AssistantItemStarted",
897+
"ContentDelta",
898+
"ContentDelta",
899+
"ToolCallUpdated",
900+
"ContentDelta",
901+
"ToolCallUpdated",
902+
"ContentDelta",
903+
"AssistantItemCompleted",
904+
]);
905+
const itemIds = new Set(
906+
notes.flatMap((note) =>
907+
note._tag === "ContentDelta" ||
908+
note._tag === "AssistantItemStarted" ||
909+
note._tag === "AssistantItemCompleted"
910+
? [note.itemId]
911+
: [],
912+
),
913+
);
914+
expect(itemIds.size).toBe(1);
915+
}).pipe(
916+
Effect.provide(
917+
AcpSessionRuntime.layer({
918+
spawn: {
919+
command: mockAgentCommand,
920+
args: mockAgentArgs,
921+
env: { T3_ACP_EMIT_BACKGROUND_TOOL_DURING_ANSWER: "1" },
922+
},
923+
cwd: process.cwd(),
924+
clientInfo: { name: "t3-test", version: "0.0.0" },
925+
authMethodId: "test",
926+
}),
927+
),
928+
Effect.scoped,
929+
Effect.provide(NodeServices.layer),
930+
),
931+
);
932+
885933
it.effect("emits status-only tool updates through completion", () =>
886934
Effect.gen(function* () {
887935
const runtime = yield* AcpSessionRuntime.AcpSessionRuntime;
Collapse file

‎apps/server/src/provider/acp/AcpSessionRuntime.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/provider/acp/AcpSessionRuntime.ts
+21-6Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ import {
4040
type AcpToolCallState,
4141
} from "./AcpRuntimeModel.ts";
4242

43+
const MAX_SHOWN_TOOL_CALL_IDS = 256;
44+
4345
interface AcpToolCallTrackedState {
4446
readonly state: AcpToolCallState;
4547
readonly lastEmittedDetailLength: number | undefined;
@@ -343,6 +345,9 @@ export const make = (
343345
const eventQueue = yield* Queue.unbounded<AcpSessionRuntimeEvent>();
344346
const modeStateRef = yield* Ref.make<AcpSessionModeState | undefined>(undefined);
345347
const toolCallsRef = yield* Ref.make(new Map<string, AcpToolCallTrackedState>());
348+
// Recently shown tool calls. A late update to a finished call is not a new
349+
// boundary in the answer, although its progress state is gone.
350+
const shownToolCallIds = new Set<string>();
346351
const assistantItemRuntimeId = yield* crypto.randomUUIDv4.pipe(
347352
Effect.mapError(
348353
(cause) =>
@@ -540,6 +545,7 @@ export const make = (
540545
modeStateRef,
541546
configOptionsRef,
542547
toolCallsRef,
548+
shownToolCallIds,
543549
assistantSegmentRef,
544550
assistantItemRuntimeId,
545551
params: notification,
@@ -1182,6 +1188,7 @@ const handleSessionUpdate = ({
11821188
availableCommandsReady,
11831189
configOptionsRef,
11841190
toolCallsRef,
1191+
shownToolCallIds,
11851192
assistantSegmentRef,
11861193
assistantItemRuntimeId,
11871194
params,
@@ -1194,6 +1201,7 @@ const handleSessionUpdate = ({
11941201
>;
11951202
readonly configOptionsRef: Ref.Ref<ReadonlyArray<EffectAcpSchema.SessionConfigOption>>;
11961203
readonly toolCallsRef: Ref.Ref<Map<string, AcpToolCallTrackedState>>;
1204+
readonly shownToolCallIds: Set<string>;
11971205
readonly assistantSegmentRef: Ref.Ref<AcpAssistantSegmentState>;
11981206
readonly assistantItemRuntimeId: string;
11991207
readonly params: EffectAcpSchema.SessionNotification;
@@ -1215,11 +1223,7 @@ const handleSessionUpdate = ({
12151223
}
12161224
for (const event of parsed.events) {
12171225
if (event._tag === "ToolCallUpdated") {
1218-
yield* closeActiveAssistantSegment({
1219-
queue,
1220-
assistantSegmentRef,
1221-
});
1222-
const { merged, decision } = yield* Ref.modify(toolCallsRef, (current) => {
1226+
const { merged, decision, active } = yield* Ref.modify(toolCallsRef, (current) => {
12231227
const tracked = current.get(event.toolCall.toolCallId);
12241228
const previous = tracked?.state;
12251229
const nextToolCall = mergeToolCallState(previous, event.toolCall);
@@ -1241,11 +1245,22 @@ const handleSessionUpdate = ({
12411245
skippedSinceEmit: decision.skippedSinceEmit,
12421246
});
12431247
}
1244-
return [{ merged: nextToolCall, decision }, next] as const;
1248+
return [{ merged: nextToolCall, decision, active: tracked !== undefined }, next] as const;
12451249
});
12461250
if (!decision.emit) {
12471251
continue;
12481252
}
1253+
// A new tool call is a boundary in the prose. Progress on a call that
1254+
// is already shown, such as a background command finishing, is not.
1255+
if (!shownToolCallIds.has(merged.toolCallId)) {
1256+
shownToolCallIds.add(merged.toolCallId);
1257+
// Only recent calls get late updates; keep a long session bounded.
1258+
if (shownToolCallIds.size > MAX_SHOWN_TOOL_CALL_IDS) {
1259+
shownToolCallIds.delete(shownToolCallIds.values().next().value!);
1260+
}
1261+
// A call still running is already on screen, even if it aged out.
1262+
if (!active) yield* closeActiveAssistantSegment({ queue, assistantSegmentRef });
1263+
}
12491264
yield* Queue.offer(queue, {
12501265
_tag: "ToolCallUpdated",
12511266
toolCall: merged,

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.