fix(session): prevent double auto-compaction from filterCompacted reorder (#27545)
This commit is contained in:
@@ -1654,19 +1654,7 @@ NOTE: At any point in time through this workflow you should feel free to ask the
|
||||
|
||||
let msgs = yield* MessageV2.filterCompactedEffect(sessionID)
|
||||
|
||||
let lastUser: MessageV2.User | undefined
|
||||
let lastAssistant: MessageV2.Assistant | undefined
|
||||
let lastFinished: MessageV2.Assistant | undefined
|
||||
let tasks: (MessageV2.CompactionPart | MessageV2.SubtaskPart)[] = []
|
||||
for (let i = msgs.length - 1; i >= 0; i--) {
|
||||
const msg = msgs[i]
|
||||
if (!lastUser && msg.info.role === "user") lastUser = msg.info
|
||||
if (!lastAssistant && msg.info.role === "assistant") lastAssistant = msg.info
|
||||
if (!lastFinished && msg.info.role === "assistant" && msg.info.finish) lastFinished = msg.info
|
||||
if (lastUser && lastFinished) break
|
||||
const task = msg.parts.filter((part) => part.type === "compaction" || part.type === "subtask")
|
||||
if (task && !lastFinished) tasks.push(...task)
|
||||
}
|
||||
const { user: lastUser, assistant: lastAssistant, finished: lastFinished, tasks } = MessageV2.latest(msgs)
|
||||
|
||||
if (!lastUser) throw new Error("No user message found in stream. This should never happen.")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user