fix(ai): avoid duplicate Codex replay message ids closes #5148

This commit is contained in:
Mario Zechner
2026-05-28 23:06:47 +02:00
parent f9832ccb82
commit 3f1ce9b6e9
3 changed files with 54 additions and 1 deletions

View File

@@ -166,6 +166,7 @@ export function convertResponsesMessages<TApi extends Api>(
assistantMsg.model !== model.id &&
assistantMsg.provider === model.provider &&
assistantMsg.api === model.api;
let textBlockIndex = 0;
for (const block of msg.content) {
if (block.type === "thinking") {
@@ -176,10 +177,13 @@ export function convertResponsesMessages<TApi extends Api>(
} else if (block.type === "text") {
const textBlock = block as TextContent;
const parsedSignature = parseTextSignature(textBlock.textSignature);
const fallbackMessageId =
textBlockIndex === 0 ? `pi_msg_${msgIndex}` : `pi_msg_${msgIndex}_${textBlockIndex}`;
textBlockIndex++;
// OpenAI requires id to be max 64 characters
let msgId = parsedSignature?.id;
if (!msgId) {
msgId = `msg_${msgIndex}`;
msgId = fallbackMessageId;
} else if (msgId.length > 64) {
msgId = `msg_${shortHash(msgId)}`;
}