fix(desktop): a live row short of the stored reply keeps the committed bubble
Taking the committed bubble's place is only safe when the live row already says everything the stored reply says. A live row still short of it may never get its tail (a completion lost to a reconnect), and replacing the committed bubble would leave the reply stuck on its first chunk; that case keeps both, as before. The race this fixes paints the whole reply into the live row before the REST page lands, so it is unaffected.
This commit is contained in:
@@ -49,11 +49,22 @@ describe('a re-attach page that commits the reply before its completion', () =>
|
||||
expect(overlaid.map(message => message.id)).toEqual(['18-user', 'assistant-stream-1-3'])
|
||||
})
|
||||
|
||||
// A live row still short of the stored reply may never get its tail (a
|
||||
// completion lost to a reconnect): only the committed bubble holds it all.
|
||||
it('keeps the committed bubble while the live row is still short of it', () => {
|
||||
const baseline = [steer, live('A6 ')]
|
||||
const current = [steer, live('A6 steered')]
|
||||
|
||||
const overlaid = overlayConcurrentMessageChanges(committedPage('change course'), baseline, current)
|
||||
|
||||
expect(assistants(overlaid).map(([id]) => id)).toEqual(['19-assistant', 'assistant-stream-1-3'])
|
||||
})
|
||||
|
||||
// A page whose newest prompt is not the live row's own is an earlier turn:
|
||||
// a new reply that happens to open with the same words is not that answer.
|
||||
it('leaves a page reply that follows another prompt alone', () => {
|
||||
const baseline = [steer, live('A6 ')]
|
||||
const current = [steer, live('A6 steered')]
|
||||
const current = [steer, live('A6 steered answer')]
|
||||
|
||||
const overlaid = overlayConcurrentMessageChanges(committedPage('an earlier prompt'), baseline, current)
|
||||
|
||||
|
||||
@@ -58,8 +58,11 @@ const promptText = (message: ChatMessage | undefined) =>
|
||||
* the turn: its late deltas and the completion still find it by id, while a
|
||||
* dropped live row would be re-seeded by the next delta. So it takes the
|
||||
* committed bubble's place. `committedNew` admits only page bubbles that are
|
||||
* new since the baseline and not themselves live, and the bubble must follow
|
||||
* the live row's own prompt and end in a reply covering the live text.
|
||||
* new since the baseline and not themselves live; the bubble must follow the
|
||||
* live row's own prompt, end in a reply, and say exactly what the live row
|
||||
* says. A live row still short of the stored text keeps both: its tail may
|
||||
* never arrive (a completion lost to a reconnect), and only the committed
|
||||
* bubble holds the whole reply.
|
||||
*/
|
||||
export function pageReplyCommittingLiveRow(
|
||||
page: ChatMessage[],
|
||||
@@ -78,13 +81,14 @@ export function pageReplyCommittingLiveRow(
|
||||
return -1
|
||||
}
|
||||
|
||||
const snapshot = spokenText(live)
|
||||
const said = spokenText(live).trim()
|
||||
|
||||
return page.findIndex(
|
||||
(message, index) =>
|
||||
index > pagePrompt &&
|
||||
message.role === 'assistant' &&
|
||||
committedNew(message) &&
|
||||
committedReplyCovers(message, snapshot)
|
||||
Boolean(replyAfterLastTool(message).trim()) &&
|
||||
spokenText(message).trim() === said
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user