Skip to content

Commit d6be4f3

Browse files
authored
fix(ui): fill short transcripts with earlier history (#125080)
1 parent b2709ce commit d6be4f3

7 files changed

Lines changed: 151 additions & 61 deletions

‎ui/src/e2e/chat-flow.history-recovery.e2e.test.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,6 @@ suite.define(() => {
498498
expect(returnedSamples.every((sample) => sample.minOpacity === 1)).toBe(true);
499499
expect(returnedSamples.every((sample) => !sample.hiddenNotice)).toBe(true);
500500
expect(returnedSamples.every((sample) => !sample.loading)).toBe(true);
501-
expect(await page.getByRole("button", { name: "Load older" }).count()).toBe(0);
502501
await expectRequestCountStable(gateway, "chat.history", historyRequestsBeforeReturn);
503502
if (artifactDir) {
504503
await page.screenshot({

‎ui/src/e2e/claude-sessions.e2e.test.ts‎

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,156 @@ suite.define(() => {
661661
await page.close();
662662
});
663663

664+
it("auto-pages an underfilled native transcript until it becomes scrollable", async () => {
665+
const artifactDir = process.env.OPENCLAW_UI_E2E_ARTIFACT_DIR?.trim();
666+
if (artifactDir) {
667+
await fs.mkdir(artifactDir, { recursive: true });
668+
}
669+
const viewport = { width: 1280, height: 900 };
670+
const context = await suite.newBrowserContext({
671+
locale: "en-US",
672+
serviceWorkers: "block",
673+
viewport,
674+
...(artifactDir ? { recordVideo: { dir: artifactDir, size: viewport } } : {}),
675+
});
676+
const page = await context.newPage();
677+
const proofVideo = page.video();
678+
const historyMessage = (seq: number, role: "assistant" | "user", text: string) => ({
679+
__openclaw: { seq },
680+
content: [{ type: role === "assistant" ? "output_text" : "input_text", text }],
681+
role,
682+
timestamp: 1_800_000_000_000 + seq,
683+
});
684+
const recent = [
685+
historyMessage(21, "user", "Recent question"),
686+
historyMessage(22, "assistant", "Recent answer"),
687+
];
688+
// Consecutive assistant records collapse into one rendered group, so this
689+
// page advances the raw offset without filling the real transcript viewport.
690+
const firstOlderPage = Array.from({ length: 4 }, (_, index) =>
691+
historyMessage(index + 17, "assistant", `Short older answer ${index + 17}`),
692+
);
693+
const secondOlderPage = Array.from({ length: 16 }, (_, index) => {
694+
const seq = index + 1;
695+
const role = seq % 2 === 0 ? "assistant" : "user";
696+
return historyMessage(
697+
seq,
698+
role,
699+
`Scrollable older ${role} message ${seq}\n${"Transcript detail line\n".repeat(3)}`,
700+
);
701+
});
702+
const gateway = await installMockGateway(page, {
703+
deferredMethods: ["chat.history"],
704+
featureMethods: ["chat.metadata", "chat.startup"],
705+
methodResponses: {
706+
"chat.startup": {
707+
messages: recent,
708+
hasMore: true,
709+
nextOffset: 2,
710+
totalMessages: 30,
711+
sessionId: "native-underfill-pagination",
712+
thinkingLevel: null,
713+
},
714+
"chat.history": {
715+
cases: [
716+
{
717+
match: { offset: 2 },
718+
response: {
719+
messages: firstOlderPage,
720+
hasMore: true,
721+
nextOffset: 6,
722+
totalMessages: 30,
723+
sessionId: "native-underfill-pagination",
724+
thinkingLevel: null,
725+
},
726+
},
727+
{
728+
match: { offset: 6 },
729+
response: {
730+
messages: secondOlderPage,
731+
hasMore: true,
732+
nextOffset: 22,
733+
totalMessages: 30,
734+
sessionId: "native-underfill-pagination",
735+
thinkingLevel: null,
736+
},
737+
},
738+
],
739+
},
740+
},
741+
});
742+
743+
try {
744+
await page.goto(`${suite.server.baseUrl}chat`);
745+
const pane = page.locator('openclaw-chat-pane[aria-hidden="false"]');
746+
const thread = pane.locator(".chat-thread");
747+
await page.getByText("Recent answer", { exact: true }).waitFor();
748+
await expect
749+
.poll(async () =>
750+
(await gateway.getRequests("chat.history")).map(
751+
(request) => (request.params as { offset?: number } | undefined)?.offset,
752+
),
753+
)
754+
.toEqual([2]);
755+
await pane.locator(".chat-history-loading").waitFor();
756+
expect(await thread.evaluate((element) => element.scrollHeight <= element.clientHeight)).toBe(
757+
true,
758+
);
759+
if (artifactDir) {
760+
await page.screenshot({
761+
path: path.join(artifactDir, "00-native-history-initial-underfill-loading.png"),
762+
fullPage: true,
763+
});
764+
}
765+
766+
await gateway.deferNext("chat.history", { offset: 6 });
767+
await gateway.resolveDeferred("chat.history");
768+
await expect
769+
.poll(async () =>
770+
(await gateway.getRequests("chat.history")).map(
771+
(request) => (request.params as { offset?: number } | undefined)?.offset,
772+
),
773+
)
774+
.toEqual([2, 6]);
775+
await pane.locator(".chat-history-loading").waitFor();
776+
expect(await thread.evaluate((element) => element.scrollHeight <= element.clientHeight)).toBe(
777+
true,
778+
);
779+
if (artifactDir) {
780+
await page.screenshot({
781+
path: path.join(artifactDir, "01-native-history-continued-auto-load.png"),
782+
fullPage: true,
783+
});
784+
}
785+
786+
await gateway.resolveDeferred("chat.history");
787+
await expect
788+
.poll(() => thread.evaluate((element) => element.scrollHeight > element.clientHeight))
789+
.toBe(true);
790+
await expect.poll(() => pane.locator(".chat-history-loading").count()).toBe(0);
791+
expect(await pane.locator(".chat-history-sentinel").count()).toBe(1);
792+
if (artifactDir) {
793+
await page.screenshot({
794+
path: path.join(artifactDir, "02-native-history-final-scrollable.png"),
795+
fullPage: true,
796+
});
797+
}
798+
await new Promise<void>((resolve) => {
799+
setTimeout(resolve, 300);
800+
});
801+
expect(
802+
(await gateway.getRequests("chat.history")).map(
803+
(request) => (request.params as { offset?: number } | undefined)?.offset,
804+
),
805+
).toEqual([2, 6]);
806+
} finally {
807+
await suite.closeBrowserContext(context);
808+
if (artifactDir && proofVideo) {
809+
await proofVideo.saveAs(path.join(artifactDir, "native-history-auto-pagination.webm"));
810+
}
811+
}
812+
});
813+
664814
it("shows loaded native history before fetching and revealing an earlier page", async () => {
665815
const page = await suite.browser.newPage({ viewport: { width: 1280, height: 800 } });
666816
const artifactDir = process.env.OPENCLAW_UI_E2E_ARTIFACT_DIR?.trim();

‎ui/src/pages/chat/chat-pane-base.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,6 @@ export abstract class ChatPaneBase extends OpenClawLightDomElement {
373373
protected historyObserverBootstrap = false;
374374
protected historyObserverArmed = false;
375375
protected historyAutoLoadBlocked = false;
376-
protected historyBootstrapPagesLoaded = 0;
377376
protected historyIntentConsumed = false;
378377
protected historyIntentTimer: number | null = null;
379378
protected historyTouchY: number | null = null;

‎ui/src/pages/chat/chat-pane-history.test.ts‎

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -471,52 +471,6 @@ describe("chat pane native history pagination", () => {
471471
expect(pane.historyAutoLoadBlocked).toBe(false);
472472
});
473473

474-
it("stops non-scrollable bootstrap after one older page", async () => {
475-
const request = vi.fn(async () => ({
476-
messages: [nativeHistoryMessage(3), nativeHistoryMessage(4)],
477-
hasMore: true,
478-
nextOffset: 4,
479-
totalMessages: 6,
480-
}));
481-
const client = { request } as unknown as GatewayBrowserClient;
482-
const { pane, state } = createTestChatPane({ client, sessions: {} as SessionCapability });
483-
state.chatMessages = [nativeHistoryMessage(5), nativeHistoryMessage(6)];
484-
state.chatHistoryPagination = { hasMore: true, nextOffset: 2, totalMessages: 6 };
485-
const thread = document.createElement("div");
486-
thread.className = "chat-thread";
487-
Object.defineProperty(thread, "scrollHeight", { value: 100 });
488-
Object.defineProperty(thread, "clientHeight", { value: 200 });
489-
const sentinel = document.createElement("div");
490-
sentinel.className = "chat-history-sentinel";
491-
thread.append(sentinel);
492-
pane.append(thread);
493-
class FakeIntersectionObserver {
494-
constructor(private readonly callback: IntersectionObserverCallback) {}
495-
disconnect() {}
496-
observe() {
497-
this.callback(
498-
[{ isIntersecting: true } as IntersectionObserverEntry],
499-
this as unknown as IntersectionObserver,
500-
);
501-
}
502-
}
503-
vi.stubGlobal("IntersectionObserver", FakeIntersectionObserver);
504-
try {
505-
pane.syncHistoryObserver();
506-
await vi.waitFor(() => expect(request).toHaveBeenCalledOnce());
507-
await vi.waitFor(() =>
508-
expect(state.chatMessages.map(nativeHistorySeq)).toEqual([3, 4, 5, 6]),
509-
);
510-
511-
pane.syncHistoryObserver();
512-
513-
expect(request).toHaveBeenCalledOnce();
514-
expect(pane.historyAutoLoadBlocked).toBe(true);
515-
} finally {
516-
vi.unstubAllGlobals();
517-
}
518-
});
519-
520474
it("reuses an unchanged armed history observer across pane updates", () => {
521475
const client = { request: vi.fn() } as unknown as GatewayBrowserClient;
522476
const { pane, state } = createTestChatPane({ client, sessions: {} as SessionCapability });

‎ui/src/pages/chat/chat-pane-history.ts‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import {
2828
} from "./chat-history.ts";
2929
import { ChatPaneReplyNavigation } from "./chat-pane-reply-navigation.ts";
3030
import {
31-
CHAT_HISTORY_BOOTSTRAP_PAGE_LIMIT,
3231
CHAT_HISTORY_INTENT_EDGE_PX,
3332
CHAT_HISTORY_INTENT_IDLE_MS,
3433
CHAT_HISTORY_TOUCH_INTENT_PX,
@@ -66,7 +65,6 @@ export abstract class ChatPaneHistory extends ChatPaneReplyNavigation {
6665
this.loadingOlder = false;
6766
this.historyObserverArmed = false;
6867
this.historyAutoLoadBlocked = false;
69-
this.historyBootstrapPagesLoaded = 0;
7068
this.historyIntentConsumed = false;
7169
this.historyTouchY = null;
7270
if (this.historyIntentTimer !== null) {
@@ -114,10 +112,7 @@ export abstract class ChatPaneHistory extends ChatPaneReplyNavigation {
114112
}
115113
this.transcriptScrollTop ??= root.scrollTop;
116114
const threadIsScrollable = root.scrollHeight > root.clientHeight;
117-
const bootstrap =
118-
!this.historyObserverArmed &&
119-
!threadIsScrollable &&
120-
this.historyBootstrapPagesLoaded < CHAT_HISTORY_BOOTSTRAP_PAGE_LIMIT;
115+
const bootstrap = !this.historyObserverArmed && !threadIsScrollable;
121116
if (this.historyAutoLoadBlocked) {
122117
this.clearHistoryObserver();
123118
return;
@@ -143,9 +138,6 @@ export abstract class ChatPaneHistory extends ChatPaneReplyNavigation {
143138
(entries) => {
144139
if (entries.some((entry) => entry.isIntersecting)) {
145140
this.historyObserverArmed = false;
146-
if (bootstrap) {
147-
this.historyBootstrapPagesLoaded += 1;
148-
}
149141
void this.loadOlderMessages();
150142
}
151143
},

‎ui/src/pages/chat/chat-pane-session.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,6 @@ export abstract class ChatPaneSession extends ChatPaneTaskSuggestions {
397397
this.catalogCursor = undefined;
398398
this.olderCursorsSeen.clear();
399399
this.historyObserverArmed = false;
400-
this.historyBootstrapPagesLoaded = 0;
401400
this.transcriptScrollTop = null;
402401
this.historyObserver?.disconnect();
403402
this.historyObserver = null;

‎ui/src/pages/chat/chat-pane-shared.ts‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,6 @@ export const CHAT_AUTOTYPE_EXEMPT_SELECTOR =
238238
export const CHAT_SPACE_ACTIVATION_SELECTOR =
239239
"a[href], button, summary, [role='button'], [role='checkbox'], [role='link'], [role='radio'], [role='switch']";
240240
export const CHAT_MODAL_SELECTOR = "dialog[open], [aria-modal='true']";
241-
// One automatic page can fill a short initial tail without serially walking a
242-
// collapsed or sparse transcript to exhaustion.
243-
export const CHAT_HISTORY_BOOTSTRAP_PAGE_LIMIT = 1;
244241

245242
export const NEW_SESSION_ACTIVE_RUN_MESSAGE =
246243
"Start a new session after the active run or queued messages finish.";

0 commit comments

Comments
 (0)