This commit is contained in:
Timothy Jaeryang Baek
2026-05-19 20:12:00 +04:00
parent 359590ca9d
commit d310a0777c
2 changed files with 79 additions and 23 deletions
+4 -23
View File
@@ -58,6 +58,7 @@
copyToClipboard,
getMessageContentParts,
createMessagesList,
sanitizeHistory,
getPromptVariables,
processDetails,
removeAllDetails,
@@ -1379,29 +1380,9 @@
? chatContent.history
: convertMessagesToHistory(chatContent.messages);
// Sanitize history: repair orphaned references from failed regenerations (#24424)
for (const message of Object.values(history.messages)) {
if (message.childrenIds) {
message.childrenIds = message.childrenIds.filter(
(childId) => history.messages[childId]
);
}
}
if (history.currentId && !history.messages[history.currentId]) {
const messageIds = Object.keys(history.messages);
let lastMessageId = null;
for (const messageId of messageIds) {
const message = history.messages[messageId];
if (
(message.childrenIds ?? []).length === 0 &&
(!lastMessageId ||
(message.timestamp ?? 0) > (history.messages[lastMessageId].timestamp ?? 0))
) {
lastMessageId = messageId;
}
}
history.currentId = lastMessageId ?? messageIds[0] ?? null;
}
// Sanitize history: repair orphaned references and structurally-malformed
// nodes from failed regenerations (#24424, #24157, #20474)
sanitizeHistory(history);
chatTitle.set(chatContent.title);