From b7096897b4c3b785d3eadf6054e12e68ea017059 Mon Sep 17 00:00:00 2001 From: tianyao Date: Tue, 21 Jul 2026 12:37:11 +0000 Subject: [PATCH] fix(codex): stop merging multi-turn assistant replies into one message Codex sessions where the model replied multiple times before the next user prompt (or task_complete) collapsed all those replies into a single assistant message. That pushed messageCount down to 2, which tripped the "trivial session" filter in sync and silently dropped otherwise substantial sessions from the database. Flush the accumulated assistant turn whenever a new assistant text block starts, so each reply becomes its own message. Co-Authored-By: Claude Sonnet 5 --- cli/src/providers/codex.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cli/src/providers/codex.ts b/cli/src/providers/codex.ts index 4186bdc6..84edb06e 100644 --- a/cli/src/providers/codex.ts +++ b/cli/src/providers/codex.ts @@ -278,7 +278,14 @@ function parseFormatA(content: string): ParsedSession | null { } if (role === 'assistant') { - // response_item assistant message: content has output_text items + // response_item assistant message: content has output_text items. + // Each such block is a distinct model reply (not a streaming delta) — + // if one is already pending, flush it first so multi-turn tasks (several + // agent replies before the next user prompt) don't collapse into a single + // assistant message and get miscounted as a trivial (<=2 message) session. + if (currentAssistantText.trim()) { + flushAssistantTurn(); + } const assistantContent = extractContent(payload); if (assistantContent) { currentAssistantText += assistantContent + '\n';