fix(app): yield before session history ingestion

This commit is contained in:
LukeParkerDev
2026-08-04 16:47:24 +10:00
parent 115e689723
commit 8c8492ef97
@@ -45,6 +45,12 @@ function projectMessageSource(message: Message): SessionMessageInfo[] {
]
}
function yieldToMain() {
const scheduler = (globalThis as { scheduler?: { yield: () => Promise<void> } }).scheduler
if (scheduler) return scheduler.yield()
return new Promise<void>((resolve) => setTimeout(resolve, 0))
}
function needsOlderTurnRoot(source: readonly SessionMessageInfo[]) {
const boundary = source.find(
(message) =>
@@ -530,6 +536,7 @@ export function createServerSession(
if (!response.data.length) break
}
const response = pages.at(-1)!
await yieldToMain()
const source = pages.flatMap((page) => page.data).toReversed()
const normalized = normalizeSessionMessages(sessionID, source)
return {