fix(app): stop history enrichment at the original turn (#57700)

This commit is contained in:
Kit Langton
2026-10-21 09:49:18 -07:00
committed by GitHub
Unverified
parent b2ade6389c
commit 2f7b93ee95
2 changed files with 21 additions and 6 deletions
@@ -63,7 +63,12 @@ describe("timeline model", () => {
})
test("pauses between history pages and stops once the leading turn has its parent", async () => {
const pages: SessionMessageInfo[][] = [[assistant("msg_older")], [user("msg_parent")], [user("msg_earlier")]]
const pages: SessionMessageInfo[][] = [
[assistant("msg_older")],
[assistant("msg_previous_turn"), user("msg_parent")],
[user("msg_earlier")],
]
const messages: SessionMessageInfo[] = [assistant("msg_latest"), user("msg_next")]
const calls: string[] = []
@@ -83,7 +88,7 @@ describe("timeline model", () => {
maxPages: 3,
})
expect(calls).toEqual(["pause", "load:msg_older", "pause", "load:msg_parent"])
expect(calls).toEqual(["pause", "load:msg_older", "pause", "load:msg_previous_turn"])
expect(pages).toHaveLength(1)
})
})
+14 -4
View File
@@ -86,12 +86,21 @@ export async function enrichLeadingTurn(input: {
pause: () => Promise<void>
maxPages: number
}) {
const assistant = input.messages().find((message) => message.type === "assistant")?.id
if (!assistant) return
const load = async (pages: number): Promise<void> => {
if (!input.current() || pages >= input.maxPages || !leadingTurnNeedsParent(input.messages()) || !input.more())
if (
!input.current() ||
pages >= input.maxPages ||
!leadingTurnNeedsParent(input.messages(), assistant) ||
!input.more()
)
return
await input.pause()
if (!input.current() || !leadingTurnNeedsParent(input.messages()) || !input.more()) return
if (!input.current() || !leadingTurnNeedsParent(input.messages(), assistant) || !input.more()) return
if (input.loading()) return load(pages)
await input.loadMore()
@@ -102,8 +111,9 @@ export async function enrichLeadingTurn(input: {
return load(0)
}
function leadingTurnNeedsParent(messages: SessionMessageInfo[]) {
const assistant = messages.findIndex((message) => message.type === "assistant")
function leadingTurnNeedsParent(messages: SessionMessageInfo[], id: string) {
// Older pages can start mid-turn too; only complete the turn that was visible on entry.
const assistant = messages.findIndex((message) => message.id === id)
if (assistant === -1) return false
const boundary = messages.findIndex((message) => message.type === "user" || message.type === "shell")