fix(webui): distinguish unknown history from exhaustion
This commit is contained in:
1 parent
fdd30e6dc9
commit
f5c359476b
7 files changed
+99
-9
No files matched your search
@@ -27,7 +27,8 @@ export function HistoryBoundaryFixture({ local = false, navigate = false, tasks
|
||||
<SubagentTasksProvider client={client} token={token} sessionKey={key} enabled={tasks} liveEvents={false}>
|
||||
<ThreadViewport messages={messages} isStreaming={false} conversationKey={key}
|
||||
messagesKey={local ? key : history.messagesKey}
|
||||
conversationReady={local || history.messagesReady && !history.loading} hasMoreBefore={history.hasMoreBefore}
|
||||
conversationReady={local || history.messagesReady} hasMoreBefore={history.hasMoreBefore}
|
||||
initialLoading={history.loading} initialError={history.error} onRetryInitial={history.refresh}
|
||||
loadingOlder={history.loadingOlder} olderError={history.olderError} onLoadOlder={history.loadOlder}
|
||||
navigation={navigate ? navigation : undefined} userMessageOffset={history.userMessageOffset}
|
||||
composer={<div className="border-t px-4 py-6" style={{ height: 96 }}>History boundary fixture</div>} />
|
||||
|
||||
@@ -222,6 +222,58 @@ test("pre-request compaction stays in place through retries and precedes the ans
|
||||
backend.healthy();
|
||||
});
|
||||
|
||||
for (const inputMethod of ["wheel", "touch"] as const) {
|
||||
test(`keeps unresolved history retryable after live-first delivery (${inputMethod})`, async ({ page }) => {
|
||||
const { backend, body } = await openFixture(page, inputMethod === "touch" ? 390 : 1440);
|
||||
const initial = await backend.read();
|
||||
await backend.send(delta(5, LIVE));
|
||||
await expect(body.getByText(LIVE, { exact: true })).toBeVisible();
|
||||
|
||||
if (inputMethod === "touch") {
|
||||
const cdp = await page.context().newCDPSession(page);
|
||||
await cdp.send("Emulation.setTouchEmulationEnabled", { enabled: true, maxTouchPoints: 1 });
|
||||
const bounds = (await body.boundingBox())!;
|
||||
const x = bounds.x + bounds.width / 2;
|
||||
const y = bounds.y + 80;
|
||||
await cdp.send("Input.dispatchTouchEvent", { type: "touchStart", touchPoints: [{ x, y }] });
|
||||
for (const travel of [40, 80, 120, 200]) {
|
||||
await cdp.send("Input.dispatchTouchEvent", { type: "touchMove", touchPoints: [{ x, y: y + travel }] });
|
||||
}
|
||||
await cdp.send("Input.dispatchTouchEvent", { type: "touchEnd", touchPoints: [] });
|
||||
await cdp.detach();
|
||||
} else {
|
||||
await body.hover();
|
||||
await page.mouse.wheel(0, -120);
|
||||
}
|
||||
await expect(page.getByText("No earlier messages", { exact: true })).toHaveCount(0);
|
||||
await expect(page.locator('.thread-history-status[data-state="loading"]')).toBeVisible();
|
||||
expect(backend.reads).toHaveLength(1);
|
||||
|
||||
await initial.route.fulfill({ status: 503, body: "Synthetic history unavailable" });
|
||||
const retry = page.getByRole("button", { name: "Loading failed. Retry" });
|
||||
await expect(retry).toBeVisible();
|
||||
await expect(page.getByText("No earlier messages", { exact: true })).toHaveCount(0);
|
||||
await expect(body.getByText(LIVE, { exact: true })).toBeVisible();
|
||||
await retry.click();
|
||||
const retried = await backend.read(A, null, 1);
|
||||
await expect(page.locator('.thread-history-status[data-state="loading"]')).toBeVisible();
|
||||
await backend.release(retried, liveFirstHistory());
|
||||
await expect(body.getByText("Historical prefix question", { exact: true })).toBeAttached();
|
||||
await expect(body.getByText(LIVE, { exact: true })).toHaveCount(1);
|
||||
await expect(page.getByText("No earlier messages", { exact: true })).toHaveCount(0);
|
||||
|
||||
const older = await requestOlder(page, backend, body, "nan311-before-2");
|
||||
await backend.release(older, history(closedTurn("first-turn", "First question", "First answer.")));
|
||||
await expect(body.getByText("First question", { exact: true })).toBeAttached();
|
||||
await body.hover();
|
||||
await page.mouse.wheel(0, -10_000);
|
||||
await expect.poll(() => body.evaluate((node) => node.scrollTop)).toBeLessThanOrEqual(1);
|
||||
await page.mouse.wheel(0, -120);
|
||||
await expect(page.getByText("No earlier messages", { exact: true })).toBeVisible();
|
||||
backend.healthy();
|
||||
});
|
||||
}
|
||||
|
||||
for (const width of [1440, 390]) {
|
||||
test(`synthetic live-first latest admits its prefix without refresh, then prepends two cursor pages (${width}px)`, async ({ page }) => {
|
||||
const { backend, body } = await openFixture(page, width);
|
||||
|
||||
@@ -1553,6 +1553,8 @@ export function ThreadShell({
|
||||
retryStatus={retryStatus}
|
||||
emptyState={emptyState}
|
||||
initialLoading={initialHistoryLoading}
|
||||
initialError={historyError}
|
||||
onRetryInitial={refreshHistory}
|
||||
composer={inlineComposer ? <div ref={setLocalComposerHost} /> : null}
|
||||
onComposerLayoutChange={alignSidebar}
|
||||
activeTurnId={viewportTurnId}
|
||||
|
||||
@@ -50,6 +50,8 @@ interface ThreadViewportProps {
|
||||
navigationFrame?: HTMLElement | null;
|
||||
emptyState?: ReactNode;
|
||||
initialLoading?: boolean;
|
||||
initialError?: string | null;
|
||||
onRetryInitial?: () => void;
|
||||
scrollToBottomSignal?: number;
|
||||
activeTurnId?: string | null;
|
||||
activeTurnStartedHere?: boolean;
|
||||
@@ -62,7 +64,7 @@ interface ThreadViewportProps {
|
||||
mcpPresets?: McpPresetInfo[];
|
||||
slashCommands?: SlashCommand[];
|
||||
forkBoundaryMessageCount?: number | null;
|
||||
hasMoreBefore?: boolean;
|
||||
hasMoreBefore?: boolean | null;
|
||||
loadingOlder?: boolean;
|
||||
olderError?: string | null;
|
||||
userMessageOffset?: number;
|
||||
@@ -264,6 +266,8 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
|
||||
navigationFrame,
|
||||
emptyState,
|
||||
initialLoading = false,
|
||||
initialError = null,
|
||||
onRetryInitial,
|
||||
scrollToBottomSignal = 0,
|
||||
activeTurnId: liveTurnId = null,
|
||||
activeTurnStartedHere = false,
|
||||
@@ -429,7 +433,8 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
|
||||
[messages, visibleMessageCount],
|
||||
);
|
||||
const hiddenMessageCount = messages.length - visibleMessages.length;
|
||||
const historyExhausted = !hasMoreBefore && hiddenMessageCount === 0;
|
||||
const historyUnknown = hasMoreBefore === null;
|
||||
const historyExhausted = hasMoreBefore === false && hiddenMessageCount === 0;
|
||||
const hiddenUserMessageCount =
|
||||
userMessageOffset
|
||||
+ (hiddenMessageCount > 0
|
||||
@@ -950,6 +955,11 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
|
||||
direction: ThreadScrollDirection | null,
|
||||
) => {
|
||||
if (!direction) return;
|
||||
if (direction === "backward" && atHistoryBoundary() && hasMoreBefore === null && hiddenMessageCount === 0) {
|
||||
captureHistoryScrollAnchor();
|
||||
yieldCameraToUser();
|
||||
return;
|
||||
}
|
||||
if (direction === "forward" && historyWindow?.hasMoreAfter
|
||||
&& el.scrollHeight - el.scrollTop - el.clientHeight < HISTORY_PREFETCH_MIN_PX
|
||||
&& !navigation?.loading) {
|
||||
@@ -983,7 +993,7 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
|
||||
return;
|
||||
}
|
||||
historyInputRef.current = "other";
|
||||
if (atHistoryBoundary()) {
|
||||
if (atHistoryBoundary() && hasMoreBefore !== null) {
|
||||
const unit = event.deltaMode === WheelEvent.DOM_DELTA_LINE ? 16
|
||||
: event.deltaMode === WheelEvent.DOM_DELTA_PAGE ? el.clientHeight : 1;
|
||||
if (event.deltaY < 0) {
|
||||
@@ -1043,7 +1053,7 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
|
||||
const verticalTravel = Math.abs(touch.clientY - gesture.startY);
|
||||
if (!gesture.pulling && horizontalTravel > verticalTravel) gesture.horizontal = true;
|
||||
if (gesture.horizontal) return;
|
||||
if (gesture.pulling || (atHistoryBoundary() && delta < 0 && hiddenMessageCount === 0)) {
|
||||
if (gesture.pulling || (atHistoryBoundary() && hasMoreBefore !== null && delta < 0 && hiddenMessageCount === 0)) {
|
||||
if (!gesture.pulling) {
|
||||
prepareHistoryPull();
|
||||
historySpringRef.current?.startTouch();
|
||||
@@ -1144,7 +1154,9 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
|
||||
]);
|
||||
|
||||
const navigationStatus = navigation?.operation !== "older" && Boolean(navigation?.loading || navigation?.error);
|
||||
const showHistoryStatus = !historySlotCompleted && !navigationStatus && messages.length > 0 && conversationReady
|
||||
const showInitialHistoryStatus = !navigationStatus && historyUnknown && hasMessages && conversationReady
|
||||
&& atHistoryTop && Boolean(initialLoading || initialError);
|
||||
const showHistoryStatus = !historyUnknown && !historySlotCompleted && !navigationStatus && messages.length > 0 && conversationReady
|
||||
&& (atHistoryTop && (!historyExhausted || showHistoryExhausted) || historyPhase !== "hidden" || loadingOlder);
|
||||
const historyStatus = showHistoryStatus ? (
|
||||
<ThreadHistoryStatus
|
||||
@@ -1286,6 +1298,8 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
|
||||
) : null}
|
||||
</div>
|
||||
{!retainedHistorySlotKey ? historyStatus : null}
|
||||
{showInitialHistoryStatus ? <ThreadHistoryStatus loading={initialLoading}
|
||||
error={initialError} onRetry={() => onRetryInitial?.()} /> : null}
|
||||
{navigationStatus && navigation ? <ThreadHistoryStatus loading={navigation.loading}
|
||||
error={navigation.error} onRetry={navigation.retry} /> : null}
|
||||
{!hasMessages ? <div ref={bottomRef} aria-hidden className="h-px" /> : null}
|
||||
|
||||
@@ -133,7 +133,8 @@ function appendProjectedSessionInput(
|
||||
function createTranscript(messages: UIMessage[], saved: ThreadTranscriptSnapshot | undefined, historyKey: string | null) {
|
||||
const owner = new ThreadTranscript(messages, saved);
|
||||
// The first paint must not enter the welcome layout while history is pending.
|
||||
owner.paging = { ...owner.paging, loading: !!historyKey && owner.paging.version === 0 };
|
||||
owner.paging = { ...owner.paging, loading: !!historyKey && owner.paging.version === 0,
|
||||
hasMoreBefore: historyKey ? owner.paging.hasMoreBefore : false };
|
||||
return owner;
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,8 @@ export interface ThreadPaging {
|
||||
error: string | null;
|
||||
olderError: string | null;
|
||||
beforeCursor: string | null;
|
||||
hasMoreBefore: boolean;
|
||||
/** Null until a history read establishes the oldest loaded boundary. */
|
||||
hasMoreBefore: boolean | null;
|
||||
userMessageOffset: number;
|
||||
forkBoundaryMessageCount: number | null;
|
||||
truncated: boolean;
|
||||
@@ -95,7 +96,7 @@ function copyText(value: TextSource): TextSource {
|
||||
}
|
||||
function emptyPaging(): ThreadPaging {
|
||||
return { loading: false, loadingOlder: false, error: null, olderError: null,
|
||||
beforeCursor: null, hasMoreBefore: false, userMessageOffset: 0,
|
||||
beforeCursor: null, hasMoreBefore: null, userMessageOffset: 0,
|
||||
forkBoundaryMessageCount: null, truncated: false, version: 0, lineage: 0,
|
||||
hasPendingToolCalls: false, completedTurnIds: [], completionIdsProvided: false, activeTurnId: null };
|
||||
}
|
||||
|
||||
@@ -41,6 +41,25 @@ function receive(thread: ThreadTranscript, ...events: ThreadProjectionEvent[]):
|
||||
}
|
||||
|
||||
describe("ThreadTranscript admission", () => {
|
||||
it("keeps the history boundary unknown through live delivery and a failed first read", () => {
|
||||
const thread = new ThreadTranscript();
|
||||
const read = thread.begin("initial");
|
||||
receive(thread, { ...at("turn-now", 5), event: "delta", stream_id: "answer-now", text: "Live tail" });
|
||||
expect(thread.paging).toMatchObject({ loading: true, hasMoreBefore: null });
|
||||
|
||||
thread.finishRead(read, "History unavailable");
|
||||
expect(thread.paging).toMatchObject({ loading: false, error: "History unavailable", hasMoreBefore: null });
|
||||
const restored = new ThreadTranscript([], thread.save());
|
||||
expect(restored.paging.hasMoreBefore).toBeNull();
|
||||
const retry = restored.begin("latest");
|
||||
expect(restored.accept(history([
|
||||
input("turn-now", "Earlier question"),
|
||||
{ ...at("turn-now", 6), event: "stream_end", stream_id: "answer-now", text: "Live tail", resuming: true, merge_next: true },
|
||||
]), retry)).toBe(true);
|
||||
expect(restored.messages.map((row) => row.content)).toEqual(["Earlier question", "Live tail"]);
|
||||
expect(restored.paging).toMatchObject({ loading: false, error: null, hasMoreBefore: false });
|
||||
});
|
||||
|
||||
it.each(["succeeded", "failed", "cancelled"] as const)("reconciles one idle compaction across live phases and history (%s)", (phase) => {
|
||||
const thread = new ThreadTranscript();
|
||||
const base = [
|
||||
|
||||
Reference in new issue
Block a user