Skip to content

Commit 73c4582

Browse files
refactor(ui): remove unreachable assistant message expanded flag (#124263)
Loaded full assistant messages always render in full, so the loaded state's expanded boolean and its toggle branch could never be reached by the automatic loader or the exhausted-retry action. Drop the dead field and branch, and shrink the browser E2E fixture from an 8,000-plus character architectural essay describing the removed field to a compact deterministic Markdown sample that still exceeds the transport preview limit. Fixes #124235
1 parent 99766cb commit 73c4582

4 files changed

Lines changed: 41 additions & 158 deletions

File tree

‎ui/src/e2e/chat-message-actions.e2e.test.ts‎

Lines changed: 29 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -19,135 +19,39 @@ const captureUiProof = process.env.OPENCLAW_CAPTURE_UI_PROOF === "1";
1919
const artifactDir = path.resolve(process.cwd(), ".artifacts/control-ui-e2e/chat-message-actions");
2020
const transportPreviewLimit = 8_000;
2121

22-
const realisticFullAssistantContent = `# Refactor complete: one transcript-loading path
22+
// Neutral filler line repeated to push the fixture past the transport
23+
// preview limit without embedding stale implementation narrative; the
24+
// heading, list, code block, and path sample below exercise Markdown
25+
// rendering, while the repeated line only pads length.
26+
const FULL_ASSISTANT_CONTENT_FILLER_LINE =
27+
"Repeat neutral filler text to exceed the transport preview limit while staying deterministic and readable.\n";
2328

24-
I finished the Control UI transcript refactor. Ordinary messages render exactly as before, but a long assistant response no longer leaves the operator behind a disclosure control when the complete Markdown is available.
29+
const realisticFullAssistantContent = `# Deployment report
2530
26-
## What was wrong
31+
## Summary
2732
28-
The transcript list already knew the session key and stable message id, while each message group separately derived enough state to render Markdown, copy text, and build reply context. When history contained a transport-limited preview, those consumers could disagree: the bubble showed the preview, Copy used cached text, and Reply rebuilt text from the original transcript entry.
33+
- service: payment-gateway
34+
- environment: production
35+
- status: completed
2936
30-
The underlying problem was ownership. Full-message loading already belonged to the thread, but visibility was controlled farther down the render tree. That meant the UI could possess the complete response and still choose to show only the preview until someone clicked Show more.
37+
## Rollout steps
3138
32-
## Files reviewed
33-
34-
### ui/src/pages/chat/chat-thread.ts
35-
36-
The page owns the session-scoped map of assistant message expansions. Each entry records a revision and a loading, loaded, or failed result. The revision participates in row memoization, so completing a request invalidates the affected row without rebuilding the entire transcript.
37-
38-
The cache key combines the active session and message id. Switching sessions therefore cannot leak loaded text into another conversation, even when deterministic fixtures reuse a local id.
39-
40-
~~~ts
41-
type AssistantMessageExpansionState =
42-
| { status: "loading"; revision: number }
43-
| { status: "error"; revision: number }
44-
| { status: "loaded"; expanded: boolean; markdown: string; revision: number };
45-
~~~
46-
47-
This state and the existing chat.message.get request remain unchanged. The UI adjustment only removes the separate assistant disclosure decision after the loaded Markdown is present.
48-
49-
### ui/src/pages/chat/components/chat-message-group.ts
50-
51-
The group is the shared boundary for bubble content and message actions. It already checks the gateway suffix and transcriptMeta.truncated, looks up the stable message id, and receives the existing full-message callback from the thread.
52-
53-
The group now starts that existing callback when it first sees an eligible entry instead of waiting for a button click. It does not introduce another cache, request type, retry timer, or transport flag. A loading or failed entry is left alone, which prevents render-driven request loops.
39+
1. Build the release artifact and run smoke tests.
40+
2. Deploy to the canary pool and watch the error budget.
41+
3. Promote to the full fleet.
5442
5543
~~~ts
56-
for (const details of messageActionDetails) {
57-
if (
58-
details?.shouldFetchFullMessage &&
59-
details.messageId &&
60-
!getAssistantMessageExpansion(details.messageId)
61-
) {
62-
onToggleAssistantMessageExpanded(details.messageId);
63-
}
44+
export function verifyRollout(serviceName: string): Promise<boolean> {
45+
return healthCheck(serviceName);
6446
}
6547
~~~
6648
67-
Once the existing loader resolves, the same selected Markdown flows to the bubble, inline Copy action, Reply action, and context menu. No consumer has to infer whether a loaded response should still look collapsed.
68-
69-
### ui/src/pages/chat/components/chat-message-markdown.ts
49+
Reference: src/services/payment-gateway/deploy.ts:88
7050
71-
Assistant Markdown now renders directly. If the existing expansion record contains loaded text, that text is selected regardless of the old expanded boolean. Otherwise the transcript text is shown exactly as received.
51+
${FULL_ASSISTANT_CONTENT_FILLER_LINE.repeat(75)}
52+
## Final verification
7253
73-
Loaded text uses document rendering mode so the chat renderer does not apply its regular large-message preview limit to a response that was explicitly recovered in full. User-authored messages keep their separate local disclosure behavior; this change only removes the assistant control.
74-
75-
~~~ts
76-
const markdown = disclosure?.expanded
77-
? disclosure.markdown ?? previewMarkdown
78-
: previewMarkdown;
79-
80-
return renderMarkdownText(markdown, isStreaming, renderOptions);
81-
~~~
82-
83-
There is no assistant footer, loading label, Show more button, Show less button, or inline failure banner. During the existing request, the transport text remains readable. When complete text arrives, the same bubble grows naturally to fit it.
84-
85-
## Request lifecycle
86-
87-
1. History supplies the transport representation of the assistant message.
88-
2. The existing truncation check determines whether a stored full copy can be requested.
89-
3. The group invokes the already-shipped full-message callback once.
90-
4. The thread sends chat.message.get with the stable session and message identifiers.
91-
5. A successful result replaces the visible Markdown in the existing bubble.
92-
6. Copy and Reply immediately use the same complete Markdown.
93-
94-
The request shape remains the one already supported by the gateway:
95-
96-
~~~json
97-
{
98-
"sessionKey": "main",
99-
"messageId": "assistant-refactor-report",
100-
"maxChars": 500000
101-
}
102-
~~~
103-
104-
Those names are deterministic fixture values. This scenario contains no production session identifiers, account data, credentials, channel addresses, provider keys, or access tokens.
105-
106-
## Failure behavior
107-
108-
If no complete stored message is available, the UI keeps the transcript text. It does not replace useful content with an error card or leave a dead control on screen. The existing failed state prevents the render pass from immediately issuing the same request again.
109-
110-
This matters during reconnects and partial history imports: the operator still sees the information that actually reached the browser. The UI does not invent missing prose, infer a synthetic ending, or claim that a transport-limited message is complete.
111-
112-
## Observable behavior covered
113-
114-
The focused component tests protect the user-facing boundary rather than the internal call order:
115-
116-
- eligible assistant text starts the existing full-message load without a click;
117-
- loaded Markdown is visible even if an older cached expanded flag is false;
118-
- the assistant bubble contains no Show more or Show less control;
119-
- Copy and Reply use the complete loaded response;
120-
- loading and failure continue to display the transcript text;
121-
- mirrored tool replies and messages without a loader remain unchanged;
122-
- user-message disclosure behavior stays separate and intact.
123-
124-
The thread test verifies that one render starts one request, that the complete response replaces the preview, and that later renders do not fetch it again. A second case rejects the request and confirms that the transport text stays readable with no disclosure or error UI.
125-
126-
## Browser proof
127-
128-
The browser scenario boots the real Control UI against a mocked Gateway WebSocket. History contains the first 8,000 characters of this report plus the existing truncation state, while chat.message.get returns this complete Markdown document.
129-
130-
The test waits for the final heading, checks the exact request parameters, confirms that no disclosure buttons exist, and exercises both inline and context-menu actions. Screenshots use a normal 1440×900 viewport in dark and light themes rather than zooming out to make the response look artificially short.
131-
132-
The before view ends in the middle of the refactor explanation because that is where the transport preview stops. The after view reaches the remaining failure notes, test coverage, scope checks, and final result in the same message bubble.
133-
134-
## Scope checks
135-
136-
No gateway handler, protocol type, persistence model, or transport limit changed. The full-message request, expansion cache, identifiers, and response extraction all predate this change. The production diff removes presentation branches instead of adding a second way to retrieve content.
137-
138-
The change also leaves user-authored long messages alone. Their local disclosure is a presentation choice for text the user submitted, while this assistant path is about showing the complete response once the existing loader has made it available.
139-
140-
## Manual review notes
141-
142-
I reviewed the transition at a normal desktop viewport and followed the text rather than relying only on request assertions. The preview remains selectable while loading, the existing headings and code blocks stay mounted, and the message grows in place when the remaining Markdown arrives.
143-
144-
In both themes, code blocks retain their contrast, long paths wrap without covering the message actions, and the final section remains reachable with ordinary scrolling. No spinner or temporary card shifts the reading position between the preview and the full response.
145-
146-
I also rejected the mocked full-message request and confirmed that the last received sentence stayed visible. A later host render did not create a tight retry loop, duplicate the message group, or expose an inactive assistant disclosure control.
147-
148-
## Verification result
149-
150-
The focused component suite and real-browser mocked-gateway scenario pass with the same structured response. The complete answer is always visible when available, message actions agree with the bubble, both themes remain readable, and the assistant UI exposes no manual expansion control.`;
54+
All health checks passed and the rollout is complete.`;
15155

15256
let browser: Browser;
15357
let server: ControlUiE2eServer;
@@ -318,7 +222,7 @@ describeControlUiE2e("Control UI chat message actions", () => {
318222
role: "assistant",
319223
content: [{ type: "text", text: truncatedPreview }],
320224
timestamp: Date.now() + 4,
321-
__openclaw: { id: "assistant-refactor-report", seq: 5 },
225+
__openclaw: { id: "assistant-full-message", seq: 5 },
322226
},
323227
],
324228
methodResponses: {
@@ -474,24 +378,22 @@ describeControlUiE2e("Control UI chat message actions", () => {
474378
.poll(() => page.evaluate(() => navigator.clipboard.readText()))
475379
.toBe(messageText);
476380

477-
const fullTextBubble = page.locator(
478-
'.chat-bubble[data-entry-id="assistant-refactor-report"]',
479-
);
381+
const fullTextBubble = page.locator('.chat-bubble[data-entry-id="assistant-full-message"]');
480382
const fullTextGroup = fullTextBubble.locator(
481383
"xpath=ancestor::*[contains(concat(' ', normalize-space(@class), ' '), ' chat-group ')]",
482384
);
483385
const fullMessageRequest = await gateway.waitForRequest("chat.message.get");
484386
expect(fullMessageRequest.params).toMatchObject({
485387
sessionKey: "main",
486-
messageId: "assistant-refactor-report",
388+
messageId: "assistant-full-message",
487389
maxChars: 500_000,
488390
});
489-
const fullTail = fullTextBubble.getByRole("heading", { name: "Verification result" });
391+
const fullTail = fullTextBubble.getByRole("heading", { name: "Final verification" });
490392
await fullTail.waitFor({ state: "visible" });
491393
expect(await fullTextBubble.getByRole("button", { name: "Show more" }).count()).toBe(0);
492394
expect(await fullTextBubble.getByRole("button", { name: "Show less" }).count()).toBe(0);
493395
await fullTail.scrollIntoViewIfNeeded();
494-
await screenshot(page, "07-realistic-refactor-dark.png");
396+
await screenshot(page, "07-full-message-dark.png");
495397

496398
await fullTextGroup.hover();
497399
await fullTextGroup.getByRole("button", { name: "Copy as markdown" }).click();
@@ -502,7 +404,7 @@ describeControlUiE2e("Control UI chat message actions", () => {
502404
const fullTextReplyPreview = page.locator(".chat-reply-preview");
503405
await expect
504406
.poll(() => fullTextReplyPreview.locator(".chat-reply-preview__text").textContent())
505-
.toContain("# Refactor complete: one transcript-loading path");
407+
.toContain("# Deployment report");
506408
await fullTextReplyPreview.getByRole("button", { name: "Cancel reply" }).click();
507409

508410
await fullTextBubble.click({ button: "right" });
@@ -514,12 +416,12 @@ describeControlUiE2e("Control UI chat message actions", () => {
514416
await menu.getByRole("menuitem", { name: "Reply to message" }).click();
515417
await expect
516418
.poll(() => fullTextReplyPreview.locator(".chat-reply-preview__text").textContent())
517-
.toContain("# Refactor complete: one transcript-loading path");
419+
.toContain("# Deployment report");
518420
await fullTextReplyPreview.getByRole("button", { name: "Cancel reply" }).click();
519421

520422
await setThemeMode(page, "light");
521423
await fullTail.scrollIntoViewIfNeeded();
522-
await screenshot(page, "08-realistic-refactor-light.png");
424+
await screenshot(page, "08-full-message-light.png");
523425
expect(await gateway.getRequests("chat.message.get")).toHaveLength(1);
524426
} finally {
525427
await context.close();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ export function getExpandedUserMessages(sessionKey: string): Map<string, boolean
390390
export type AssistantMessageExpansionState =
391391
| { status: "loading"; revision: number }
392392
| { status: "error"; revision: number }
393-
| { status: "loaded"; expanded: boolean; markdown: string; revision: number };
393+
| { status: "loaded"; markdown: string; revision: number };
394394

395395
export function getExpandedAssistantMessages(
396396
sessionKey: string,

‎ui/src/pages/chat/components/chat-message.test.ts‎

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5292,7 +5292,6 @@ describe("grouped chat rendering", () => {
52925292
});
52935293

52945294
function renderAssistantDisclosureActionFixture(
5295-
expanded: boolean,
52965295
options: Partial<RenderMessageGroupOptions> = {},
52975296
) {
52985297
const container = document.createElement("div");
@@ -5310,7 +5309,6 @@ describe("grouped chat rendering", () => {
53105309
loadFullAssistantMessage: async () => null,
53115310
getAssistantMessageExpansion: () => ({
53125311
status: "loaded",
5313-
expanded,
53145312
markdown: fullMessage,
53155313
revision: 1,
53165314
}),
@@ -5321,13 +5319,10 @@ describe("grouped chat rendering", () => {
53215319
return { container, fullMessage, preview };
53225320
}
53235321

5324-
it.each([
5325-
{ expanded: false, label: "previously collapsed" },
5326-
{ expanded: true, label: "expanded" },
5327-
])("copies the full $label assistant message", async ({ expanded }) => {
5322+
it("copies the full loaded assistant message", async () => {
53285323
const writeText = vi.fn().mockResolvedValue(undefined);
53295324
vi.stubGlobal("navigator", { clipboard: { writeText } } as unknown as Navigator);
5330-
const { container, fullMessage } = renderAssistantDisclosureActionFixture(expanded);
5325+
const { container, fullMessage } = renderAssistantDisclosureActionFixture();
53315326

53325327
expect(container.querySelector(".chat-text")?.textContent).toContain(fullMessage);
53335328
expect(container.querySelector(".chat-message-disclosure__toggle")).toBeNull();
@@ -5338,12 +5333,9 @@ describe("grouped chat rendering", () => {
53385333
await vi.waitFor(() => expect(writeText).toHaveBeenCalledWith(fullMessage));
53395334
});
53405335

5341-
it.each([
5342-
{ expanded: false, label: "previously collapsed" },
5343-
{ expanded: true, label: "expanded" },
5344-
])("replies with the full $label assistant message", ({ expanded }) => {
5336+
it("replies with the full loaded assistant message", () => {
53455337
const onReply = vi.fn();
5346-
const { container, fullMessage } = renderAssistantDisclosureActionFixture(expanded, {
5338+
const { container, fullMessage } = renderAssistantDisclosureActionFixture({
53475339
onReply,
53485340
});
53495341

@@ -5363,7 +5355,7 @@ describe("grouped chat rendering", () => {
53635355
"keeps the transcript preview in %s assistant-message actions",
53645356
(status) => {
53655357
const onReply = vi.fn();
5366-
const { container, preview } = renderAssistantDisclosureActionFixture(false, {
5358+
const { container, preview } = renderAssistantDisclosureActionFixture({
53675359
onReply,
53685360
getAssistantMessageExpansion: () => ({ status, revision: 1 }),
53695361
});
@@ -5380,17 +5372,16 @@ describe("grouped chat rendering", () => {
53805372
},
53815373
);
53825374

5383-
it("keeps expanded assistant thinking private while bounding reply context", async () => {
5375+
it("keeps loaded assistant thinking private while bounding reply context", async () => {
53845376
const writeText = vi.fn().mockResolvedValue(undefined);
53855377
vi.stubGlobal("navigator", { clipboard: { writeText } } as unknown as Navigator);
53865378
const onReply = vi.fn();
5387-
const visibleMessage = `${"a".repeat(499)}😀 full expanded answer`;
5388-
const { container } = renderAssistantDisclosureActionFixture(true, {
5379+
const visibleMessage = `${"a".repeat(499)}😀 full loaded answer`;
5380+
const { container } = renderAssistantDisclosureActionFixture({
53895381
onReply,
53905382
getAssistantMessageExpansion: () => ({
53915383
status: "loaded",
5392-
expanded: true,
5393-
markdown: `<thinking>private expanded reasoning</thinking>${visibleMessage}`,
5384+
markdown: `<thinking>private loaded reasoning</thinking>${visibleMessage}`,
53945385
revision: 1,
53955386
}),
53965387
});
@@ -5415,12 +5406,11 @@ describe("grouped chat rendering", () => {
54155406
const onReply = vi.fn();
54165407
const onToggleAssistantMessageExpanded = vi.fn();
54175408
const privateThinking = "private expanded reasoning only";
5418-
const { container, preview } = renderAssistantDisclosureActionFixture(false, {
5409+
const { container, preview } = renderAssistantDisclosureActionFixture({
54195410
onReply,
54205411
onToggleAssistantMessageExpanded,
54215412
getAssistantMessageExpansion: () => ({
54225413
status: "loaded",
5423-
expanded: false,
54245414
markdown: `<thinking>${privateThinking}</thinking>`,
54255415
revision: 1,
54265416
}),

‎ui/src/pages/chat/components/chat-transcript-projection.ts‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -243,15 +243,6 @@ export function projectChatTranscript(
243243
};
244244
const toggleAssistantMessageExpanded = (messageId: string) => {
245245
const current = expandedAssistantMessages.get(messageId);
246-
if (current?.status === "loaded") {
247-
expandedAssistantMessages.set(messageId, {
248-
...current,
249-
expanded: !current.expanded,
250-
revision: current.revision + 1,
251-
});
252-
requestUpdate();
253-
return;
254-
}
255246
const loader = props.loadFullAssistantMessage;
256247
if (!loader || current?.status === "loading") {
257248
return;
@@ -278,7 +269,7 @@ export function projectChatTranscript(
278269
messageId,
279270
markdown === null
280271
? { status: "error", revision: revision + 1 }
281-
: { status: "loaded", expanded: true, markdown, revision: revision + 1 },
272+
: { status: "loaded", markdown, revision: revision + 1 },
282273
);
283274
requestUpdate();
284275
},

0 commit comments

Comments
 (0)