Skip to content

Commit 14b37c7

Browse files
committed
fix(server): treat any rawOutput change as visible tool output
Grok sends { type: "Text", text } output, which the field list missed. Comparing the whole rawOutput covers every shape; streamed arguments never change it.
1 parent dbec3e2 commit 14b37c7

2 files changed

Lines changed: 32 additions & 29 deletions

File tree

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

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,14 @@ describe("AcpAdapterV2", () => {
10921092
status: "in_progress" as const,
10931093
rawOutput: `tick ${index + 1}`,
10941094
})),
1095+
...Array.from({ length: 5 }, (_, index) => ({
1096+
sessionUpdate: "tool_call_update" as const,
1097+
toolCallId: "text-ticker",
1098+
title: "Watch ticks",
1099+
kind: "execute" as const,
1100+
status: "in_progress" as const,
1101+
rawOutput: { type: "Text", text: `tock ${index + 1}` },
1102+
})),
10951103
{
10961104
sessionUpdate: "tool_call_update",
10971105
toolCallId: "child-a",
@@ -1153,12 +1161,17 @@ describe("AcpAdapterV2", () => {
11531161
assert.equal(writes.at(-1)?.status, "completed", toolCallId);
11541162
assert.include(JSON.stringify(writes.at(-1)), "END_OF_FILE", toolCallId);
11551163
}
1156-
const ticks = items.filter((item) => item.nativeItemRef?.nativeId?.endsWith("ticker"));
1157-
for (let tick = 1; tick <= 5; tick++) {
1158-
assert.isTrue(
1159-
ticks.some((item) => JSON.stringify(item).includes(`tick ${tick}`)),
1160-
`tick ${tick} must persist`,
1161-
);
1164+
for (const [toolCallId, word] of [
1165+
["ticker", "tick"],
1166+
["text-ticker", "tock"],
1167+
] as const) {
1168+
const ticks = items.filter((item) => item.nativeItemRef?.nativeId?.endsWith(toolCallId));
1169+
for (let tick = 1; tick <= 5; tick++) {
1170+
assert.isTrue(
1171+
ticks.some((item) => JSON.stringify(item).includes(`${word} ${tick}`)),
1172+
`${word} ${tick} must persist`,
1173+
);
1174+
}
11621175
}
11631176
}).pipe(Effect.provide(layerTest), Effect.scoped),
11641177
);

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

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,37 +1000,27 @@ export function toolCallProgressLength(state: AcpToolCallState): number {
10001000
return Math.max(state.detail?.length ?? 0, contentChars, rawOutputChars);
10011001
}
10021002

1003-
function toolCallVisibleOutput(state: AcpToolCallState): ReadonlyArray<string | undefined> {
1004-
const texts: Array<string | undefined> = [state.detail];
1003+
function toolCallContentTexts(state: AcpToolCallState): string {
10051004
const content = state.data.content;
1006-
if (Array.isArray(content)) {
1007-
for (const entry of content) {
1008-
texts.push(
1009-
isRecord(entry) ? toolCallContentText(entry as EffectAcpSchema.ToolCallContent) : undefined,
1010-
);
1011-
}
1012-
}
1013-
const rawOutput = state.data.rawOutput;
1014-
if (typeof rawOutput === "string") {
1015-
texts.push(rawOutput);
1016-
} else if (isRecord(rawOutput)) {
1017-
for (const field of RAW_OUTPUT_TEXT_FIELDS) {
1018-
const value = rawOutput[field];
1019-
texts.push(typeof value === "string" ? value : undefined);
1020-
}
1021-
}
1022-
return texts;
1005+
if (!Array.isArray(content)) return "";
1006+
return content
1007+
.map((entry) =>
1008+
isRecord(entry) ? (toolCallContentText(entry as EffectAcpSchema.ToolCallContent) ?? "") : "",
1009+
)
1010+
.join("\u0000");
10231011
}
10241012

1025-
// The text a user watches: detail, text content, and raw output text. A
1013+
// The output a user watches: detail, text content, and any `rawOutput`. A
10261014
// streamed diff or `rawInput` is not part of it.
10271015
export function toolCallVisibleOutputChanged(
10281016
previous: AcpToolCallState,
10291017
next: AcpToolCallState,
10301018
): boolean {
1031-
const before = toolCallVisibleOutput(previous);
1032-
const after = toolCallVisibleOutput(next);
1033-
return before.length !== after.length || before.some((text, index) => text !== after[index]);
1019+
return (
1020+
previous.detail !== next.detail ||
1021+
toolCallContentTexts(previous) !== toolCallContentTexts(next) ||
1022+
JSON.stringify(previous.data.rawOutput) !== JSON.stringify(next.data.rawOutput)
1023+
);
10341024
}
10351025

10361026
export function decideToolCallUpdateEmission(

0 commit comments

Comments
 (0)