Skip to content

Commit f2ac85f

Browse files
committed
fix(ui): pool reply-less wake activity into one chat rollup
Consecutive runs whose entire visible outcome is tool activity (heartbeat wakes, cron ticks) now collapse into a single expandable activity row instead of stacking identical rows down the transcript. Runs with a visible reply keep per-run activity separation. Group summaries reuse the standalone row's tool display label, so the rollup reads "Used Heartbeat Respond ×N". Splits tool call/result pairing out of chat-thread-grouping.ts into chat-tool-activity-coalesce.ts (max-lines).
1 parent 6bd6554 commit f2ac85f

7 files changed

Lines changed: 576 additions & 349 deletions
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// Control UI E2E covers pooling reply-less wake activity (heartbeats) into one rollup row.
2+
import fs from "node:fs/promises";
3+
import path from "node:path";
4+
import { expect, it } from "vitest";
5+
import { controlUiSessionUrl, installMockGateway } from "../test-helpers/control-ui-e2e.ts";
6+
import { waitForChatScrollIdle } from "./chat-flow.test-support.ts";
7+
import { createControlUiE2eSuite } from "./control-ui-e2e-suite.test-support.ts";
8+
9+
const suite = createControlUiE2eSuite({
10+
name: "Control UI heartbeat activity rollup",
11+
startServerBeforeBrowser: true,
12+
});
13+
14+
async function captureProof(page: import("playwright").Page, name: string) {
15+
const artifactDir = process.env.OPENCLAW_CONTROL_UI_E2E_ARTIFACT_DIR?.trim();
16+
if (!artifactDir) {
17+
return;
18+
}
19+
await fs.mkdir(artifactDir, { recursive: true });
20+
await page.screenshot({ path: path.join(artifactDir, `${name}.png`), fullPage: true });
21+
}
22+
23+
function heartbeatWake(index: number): Array<Record<string, unknown>> {
24+
const runId = `heartbeat-run-${index}`;
25+
const callId = `heartbeat-call-${index}`;
26+
const timestamp = 10_000 + index * 1_000;
27+
return [
28+
{
29+
role: "assistant",
30+
content: [
31+
{
32+
type: "toolCall",
33+
id: callId,
34+
name: "heartbeat_respond",
35+
arguments: { notify: false },
36+
},
37+
],
38+
runId,
39+
timestamp,
40+
},
41+
{
42+
role: "toolResult",
43+
toolCallId: callId,
44+
toolName: "heartbeat_respond",
45+
content: "ok",
46+
runId,
47+
timestamp: timestamp + 100,
48+
},
49+
];
50+
}
51+
52+
suite.define(() => {
53+
it("pools consecutive reply-less heartbeat wakes into one expandable rollup", async () => {
54+
await suite.withPage({ viewport: { height: 900, width: 1200 } }, async ({ page }) => {
55+
const sessionKey = "agent:main:dashboard:heartbeat-rollup";
56+
const wakeCount = 6;
57+
await installMockGateway(page, {
58+
sessionKey,
59+
historyMessages: [
60+
{ role: "user", content: "Watch the queue.", timestamp: 1_000, runId: "reply-run" },
61+
{
62+
role: "assistant",
63+
content: [{ type: "text", text: "Watching." }],
64+
timestamp: 2_000,
65+
runId: "reply-run",
66+
},
67+
...Array.from({ length: wakeCount }, (_, index) => heartbeatWake(index + 1)).flat(),
68+
],
69+
});
70+
71+
await page.goto(controlUiSessionUrl(suite.server.baseUrl, sessionKey));
72+
await page.getByText("Watching.", { exact: true }).waitFor();
73+
await waitForChatScrollIdle(page);
74+
75+
const rollup = page.locator(".chat-group--activity .chat-activity-group__summary");
76+
await rollup.waitFor();
77+
await expect
78+
.poll(async () => rollup.locator(".chat-activity-group__label").textContent())
79+
.toBe(`Used Heartbeat Respond ×${wakeCount}`);
80+
// One pooled row owns all wakes; no per-wake rows remain in the transcript.
81+
expect(await rollup.count()).toBe(1);
82+
expect(await page.locator(".chat-tool-row").count()).toBe(0);
83+
await captureProof(page, "heartbeat-rollup-collapsed");
84+
85+
await rollup.click();
86+
await expect
87+
.poll(async () => page.locator(".chat-activity-group__body .chat-tool-row").count())
88+
.toBe(wakeCount);
89+
await waitForChatScrollIdle(page);
90+
await captureProof(page, "heartbeat-rollup-expanded");
91+
});
92+
});
93+
});

‎ui/src/lib/chat/tool-call-grouping.test.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ describe("summarizeToolGroup", () => {
6565
{ name: "str_replace_editor", args: { path: "/repo/a.ts" } },
6666
{ name: "str_replace_based_edit_tool", args: { command: "rename" } },
6767
],
68-
"Used str_replace_editor, str_replace_based_edit_tool",
68+
"Used Str Replace Editor, Str Replace Based Edit Tool",
6969
],
7070
[
7171
"multi-file apply_patch targets",
@@ -115,11 +115,11 @@ describe("summarizeToolGroup", () => {
115115
],
116116
"Deleted a file",
117117
],
118-
["one generic tool by name", [{ name: "mcp__linear" }], "Used mcp__linear"],
118+
["one generic tool by name", [{ name: "mcp__linear" }], "Used Mcp Linear"],
119119
[
120120
"repeat generic tool with a multiplier",
121-
[{ name: "mcp__linear" }, { name: "mcp__linear" }],
122-
"Used mcp__linear ×2",
121+
[{ name: "heartbeat_respond" }, { name: "heartbeat_respond" }],
122+
"Used Heartbeat Respond ×2",
123123
],
124124
[
125125
"many distinct generic tools as a count",

‎ui/src/lib/chat/tool-call-grouping.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
resolveToolCallTargetPaths,
1111
type ToolCallKind,
1212
} from "./tool-call-view.ts";
13+
import { resolveToolDisplay } from "./tool-display.ts";
1314

1415
type ToolGroupSummaryInput = {
1516
name: string;
@@ -73,7 +74,9 @@ function countCard(counts: GroupCounts, card: ToolGroupSummaryInput): void {
7374
break;
7475
default:
7576
counts.others += 1;
76-
counts.otherNames.add(card.name);
77+
// Same display label as the standalone row, so a collapsed rollup of
78+
// e.g. heartbeat_respond reads "Heartbeat Respond" in both shapes.
79+
counts.otherNames.add(resolveToolDisplay({ name: card.name, args: card.args }).label);
7780
}
7881
}
7982
}

‎ui/src/pages/chat/chat-thread-build.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {
3030
shouldRenderQueuedSendInThread,
3131
} from "./chat-progress.ts";
3232
import { chatMessagesContainQueuedSend } from "./chat-send-support.ts";
33-
import { coalesceToolActivityMessages, groupMessages } from "./chat-thread-grouping.ts";
33+
import { groupMessages } from "./chat-thread-grouping.ts";
3434
import {
3535
appendCanvasBlockToAssistantMessage,
3636
buildMessageKeys,
@@ -61,6 +61,7 @@ import {
6161
optionalRunIdentity,
6262
resolveRunInsertionBounds,
6363
} from "./chat-thread-run-identity.ts";
64+
import { coalesceToolActivityMessages } from "./chat-tool-activity-coalesce.ts";
6465
import { safeNormalizeMessage } from "./chat-turn-boundary.ts";
6566
import { resolveSystemNoticeKind } from "./system-notice-kinds.ts";
6667
import { isLiveTerminalForRun } from "./terminal-message-identity.ts";

0 commit comments

Comments
 (0)