Skip to content

Commit 30dd7e6

Browse files
authored
fix(ui): keep restart-resumed tool activity together (#128726)
Preserve restart recovery’s existing send identity through the Control UI notice projection so subsequent tool activity stays in one response frame. Co-authored-by: Ayaan Zaidi <[email protected]>
1 parent 9f58030 commit 30dd7e6

6 files changed

Lines changed: 106 additions & 2 deletions

File tree

‎ui/src/e2e/chat-agent-run-transcript.e2e.test.ts‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,76 @@ function transcriptMessage(
2525
}
2626

2727
suite.define(() => {
28+
it("keeps restart-recovered live tool batches in one transcript row", async () => {
29+
const context = await suite.browser.newContext({ viewport: { height: 900, width: 1200 } });
30+
const page = await context.newPage();
31+
const runId = "run-restart-recovery";
32+
const toolResult = (id: string, seq: number, name: string) => ({
33+
...transcriptMessage(
34+
"toolResult",
35+
[{ type: "text", text: `${name} completed` }],
36+
runId,
37+
id,
38+
seq,
39+
),
40+
toolCallId: id,
41+
toolName: name,
42+
});
43+
await installMockGateway(page, {
44+
historyMessages: [
45+
{
46+
...transcriptMessage(
47+
"user",
48+
"[System] Continue the interrupted turn.",
49+
`${runId}:user`,
50+
"restart-recovery",
51+
1,
52+
),
53+
provenance: {
54+
kind: "internal_system",
55+
sourceSessionKey: "main",
56+
sourceTool: "main_session_restart_recovery",
57+
},
58+
},
59+
toolResult("process-1", 2, "process"),
60+
toolResult("process-2", 3, "process"),
61+
transcriptMessage("assistant", "Checking the next batch.", runId, "gap-1", 4),
62+
toolResult("exec-1", 5, "exec"),
63+
toolResult("exec-2", 6, "exec"),
64+
transcriptMessage("assistant", "Checking the final batch.", runId, "gap-2", 7),
65+
toolResult("process-3", 8, "process"),
66+
toolResult("process-4", 9, "process"),
67+
],
68+
inFlightRun: { runId, text: "" },
69+
sessionInfo: {
70+
activeRunIds: [runId],
71+
hasActiveRun: true,
72+
key: "main",
73+
},
74+
});
75+
76+
await page.goto(`${suite.server.baseUrl}chat`);
77+
const summaries = page.locator(".chat-activity-group__summary");
78+
await expect.poll(() => summaries.count()).toBe(3);
79+
const rowKeys = await summaries.evaluateAll((elements) =>
80+
elements.map(
81+
(element) => element.closest<HTMLElement>(".chat-virtual-row")?.dataset.virtualRowKey,
82+
),
83+
);
84+
85+
expect(rowKeys[0]).toMatch(/^agent-run:/u);
86+
expect(rowKeys).toEqual([rowKeys[0], rowKeys[0], rowKeys[0]]);
87+
const artifactDir = process.env.OPENCLAW_CONTROL_UI_E2E_ARTIFACT_DIR?.trim();
88+
if (artifactDir) {
89+
await fs.mkdir(artifactDir, { recursive: true });
90+
await page.locator(".chat-thread-inner").screenshot({
91+
path: path.join(artifactDir, "restart-recovery-run-frame.png"),
92+
});
93+
}
94+
95+
await context.close();
96+
});
97+
2898
it("renders each run as one linear response with actions only on its terminal text", async () => {
2999
const context = await suite.browser.newContext({ viewport: { height: 900, width: 1200 } });
30100
const page = await context.newPage();

‎ui/src/lib/chat/chat-types.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ export type ChatItem =
103103
icon?: keyof typeof toolIcons;
104104
label?: string;
105105
startsTurn?: true;
106+
boundaryId?: string;
106107
tone?: "danger";
107108
}
108109
| {

‎ui/src/pages/chat/chat-agent-run-grouping.test.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,34 @@ describe("coalesceAgentRunFrames", () => {
132132
expect(history.key).toBe(live.key);
133133
});
134134

135+
it("keeps a restart-recovered tool-only run in one stable frame", () => {
136+
const runId = "run-recovered";
137+
const boundaryId = `send:${runId}`;
138+
const recoveryNotice = {
139+
kind: "notice" as const,
140+
key: "notice:restart-recovery",
141+
text: "Turn interrupted by a gateway restart.",
142+
timestamp: 1,
143+
startsTurn: true as const,
144+
boundaryId,
145+
};
146+
const first = group("tool", "recovered-tool-1", runId);
147+
const second = group("tool", "recovered-tool-2", runId);
148+
const historyActivity: ActivityRunRenderItem = {
149+
kind: "activity-run",
150+
key: "activity:recovered-tools",
151+
groups: [first, second],
152+
};
153+
154+
const live = requireFrame(coalesceAgentRunFrames([recoveryNotice, first, second])[1]);
155+
const history = requireFrame(coalesceAgentRunFrames([recoveryNotice, historyActivity])[1]);
156+
157+
expect(live.parts).toEqual([first, second]);
158+
expect(history.parts).toEqual([historyActivity]);
159+
expect(live.boundaryId).toBe(boundaryId);
160+
expect(history.key).toBe(live.key);
161+
});
162+
135163
it("remounts a large live stream after steer without destabilizing ordinary frames", () => {
136164
const runId = "run-steered";
137165
const boundaryId = "send:steer-run";

‎ui/src/pages/chat/chat-agent-run-grouping.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ export function coalesceAgentRunFrames(
231231
if (!isAgentRunFramePart(item)) {
232232
flush();
233233
result.push(item);
234-
boundaryId = undefined;
235-
segmentId = item.key;
234+
boundaryId = item.kind === "notice" && item.startsTurn ? item.boundaryId : undefined;
235+
segmentId = boundaryId ? undefined : item.key;
236236
continue;
237237
}
238238
const candidate = item;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import {
5252
transcriptPositionTimestamp,
5353
turnHasMatchingAssistant,
5454
type TurnInsertionBounds,
55+
userTurnSendIdentity,
5556
} from "./chat-thread-items.ts";
5657
import {
5758
findCurrentTurnBounds,
@@ -192,6 +193,7 @@ export function buildChatItems(props: BuildChatItemsProps): Array<ChatItem | Mes
192193
? t(noticeKind.summaryKey)
193194
: extractTextCached(msg)?.replace(/^\[System\] /u, "");
194195
if (text?.trim()) {
196+
const boundaryId = userTurnSendIdentity(msg);
195197
items.push({
196198
kind: "notice",
197199
key: itemKey,
@@ -200,6 +202,7 @@ export function buildChatItems(props: BuildChatItemsProps): Array<ChatItem | Mes
200202
startsTurn: true,
201203
text,
202204
timestamp: normalized.timestamp,
205+
...(boundaryId ? { boundaryId } : {}),
203206
});
204207
}
205208
continue;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,6 +1829,7 @@ describe("buildCachedChatItems", () => {
18291829
userMessage("before", 999),
18301830
userMessage("[System] Continue the interrupted turn.", 1000, {
18311831
provenance: { kind: "internal_system", sourceTool: "main_session_restart_recovery" },
1832+
__openclaw: { id: "restart-recovery", idempotencyKey: "run-recovered:user" },
18321833
}),
18331834
userMessage("[System] Gateway restarted during update 2026.8.2 -> 2026.8.3.", 1001, {
18341835
provenance: { kind: "internal_system", sourceTool: "restart-sentinel" },
@@ -1853,6 +1854,7 @@ describe("buildCachedChatItems", () => {
18531854
label: "System · restart recovery",
18541855
text: "Turn interrupted by a gateway restart — asked the agent to resume and finish the response.",
18551856
timestamp: 1000,
1857+
boundaryId: "send:run-recovered",
18561858
});
18571859
// Summary-less kinds keep the producer's informative text under the label.
18581860
expect(items[2]).toMatchObject({

0 commit comments

Comments
 (0)