fix(chat): keep page.tsx at the 1951-line freeze after lookup wiring
Independent Staging Quality Gate / validate (push) Failing after 6m40s
Independent Staging Quality Gate / publish (push) Skipped

Move BUG-705 bootstrap selection + session lookup into
resolveLookupBootstrap so Home only awaits once. The 1951 cap in
chart-view-route.test.ts is unchanged.
This commit is contained in:
jesse-ux
2026-09-15 17:40:17 +08:00
parent fadb64fbcf
commit 6bb892b826
5 changed files with 84 additions and 22 deletions
+2 -15
View File
@@ -125,9 +125,6 @@ import { writeChatSession } from "@/lib/chat-session-write-contract";
import {
SESSION_MISSING_NOTICE,
clearLoginSessionReturn,
parseSessionUrlQuery,
readLoginSessionReturn,
resolveBootstrapSessionSelection,
writeSessionUrl,
} from "@/lib/chat-session-url";
import { consultationReportMarkdown } from "@/lib/consultation-report-export";
@@ -994,20 +991,10 @@ export default function Home() {
}
if (controller.signal.aborted) return;
const listedSelection = resolveBootstrapSessionSelection({
listedIds: nextSessions.map((session) => session.id),
defaultSessionId: nextSessions[0].id,
search: window.location.search,
storedReturnId: readLoginSessionReturn(),
});
const lookedUp = await resolveLookupBootstrap({
selection: listedSelection,
sessions: nextSessions,
defaultSessionId: nextSessions[0].id,
catalog: nextModelCatalog,
signal: controller.signal,
sessions: nextSessions, catalog: nextModelCatalog,
defaultSessionId: nextSessions[0].id, signal: controller.signal,
});
if (controller.signal.aborted) return;
nextSessions = lookedUp.sessions;
const bootstrapSelection = lookedUp.selection;
let landingSessionId = resolveStarterHomeLandingSessionId(
+22 -6
View File
@@ -2,6 +2,8 @@ import { writeChatSession } from "@/lib/chat-session-write-contract";
import {
bootstrapSelectionFromLookup,
persistLoginSessionReturn,
readLoginSessionReturn,
resolveBootstrapSessionSelection,
SESSION_LOOKUP_FAILED_NOTICE,
type BootstrapSessionSelection,
} from "@/lib/chat-session-url";
@@ -496,8 +498,14 @@ export async function lookupSessionById(
return { status: "found", session };
}
function throwIfAborted(signal?: AbortSignal) {
if (!signal?.aborted) return;
const error = new Error("Aborted");
error.name = "AbortError";
throw error;
}
export async function resolveLookupBootstrap(input: {
selection: BootstrapSessionSelection;
sessions: ChatSession[];
defaultSessionId: string;
catalog: PublicLanguageModelCatalog | null;
@@ -507,10 +515,18 @@ export async function resolveLookupBootstrap(input: {
sessions: ChatSession[];
notice: string | null;
}> {
if (input.selection.urlAction !== "lookup") {
return { selection: input.selection, sessions: input.sessions, notice: null };
throwIfAborted(input.signal);
const selection = resolveBootstrapSessionSelection({
listedIds: input.sessions.map((session) => session.id),
defaultSessionId: input.defaultSessionId,
search: window.location.search,
storedReturnId: readLoginSessionReturn(),
});
if (selection.urlAction !== "lookup") {
return { selection, sessions: input.sessions, notice: null };
}
const looked = await lookupSessionById(input.selection.sessionId, input.catalog, input.signal);
const looked = await lookupSessionById(selection.sessionId, input.catalog, input.signal);
throwIfAborted(input.signal);
if (looked.status === "found") {
return {
selection: bootstrapSelectionFromLookup("found", looked.session.id, input.defaultSessionId),
@@ -520,13 +536,13 @@ export async function resolveLookupBootstrap(input: {
}
if (looked.status === "missing") {
return {
selection: bootstrapSelectionFromLookup("missing", input.selection.sessionId, input.defaultSessionId),
selection: bootstrapSelectionFromLookup("missing", selection.sessionId, input.defaultSessionId),
sessions: input.sessions,
notice: null,
};
}
return {
selection: bootstrapSelectionFromLookup("unavailable", input.selection.sessionId, input.defaultSessionId),
selection: bootstrapSelectionFromLookup("unavailable", selection.sessionId, input.defaultSessionId),
sessions: input.sessions,
notice: SESSION_LOOKUP_FAILED_NOTICE,
};