From 5b9108ac187889c82162e492d861f9484c11fd02 Mon Sep 17 00:00:00 2001 From: Haileyesus <118998054+blackmammoth@users.noreply.github.com> Date: Wed, 29 Apr 2026 18:23:14 +0300 Subject: [PATCH] fix(codex): preserve reasoning entries as thinking blocks Codex history normalization was downgrading reasoning into plain assistant text because of branch ordering, not because the raw data was missing. Why this mattered: - Codex reasoning JSONL entries are intentionally mapped to history items with type thinking, but they also carry message.role assistant. - normalizeHistoryEntry evaluated the assistant-role branch before the thinking branch. - As a result, reasoning content matched the assistant-text path first and was emitted as kind text instead of kind thinking. - This collapses semantic intent, so UI and downstream features that rely on thinking blocks (separate rendering, filtering, and interpretation of model thought process vs final answer) receive the wrong message kind. What changed: - Prioritized thinking detection (raw.type === thinking or raw.isReasoning) before role-based assistant normalization. - Kept a non-empty content guard for thinking payloads to avoid emitting empty artifacts. Impact: - Reasoning entries from persisted Codex JSONL now remain thinking blocks end-to-end. - Regular assistant text normalization behavior remains unchanged. --- .../list/codex/codex-sessions.provider.ts | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/server/modules/providers/list/codex/codex-sessions.provider.ts b/server/modules/providers/list/codex/codex-sessions.provider.ts index 8540d27a..a7fe8129 100644 --- a/server/modules/providers/list/codex/codex-sessions.provider.ts +++ b/server/modules/providers/list/codex/codex-sessions.provider.ts @@ -270,6 +270,23 @@ export class CodexSessionsProvider implements IProviderSessions { const ts = raw.timestamp || new Date().toISOString(); const baseId = raw.uuid || generateMessageId('codex'); + if (raw.type === 'thinking' || raw.isReasoning) { + const thinkingContent = typeof raw.message?.content === 'string' + ? raw.message.content + : ''; + if (!thinkingContent.trim()) { + return []; + } + return [createNormalizedMessage({ + id: baseId, + sessionId, + timestamp: ts, + provider: PROVIDER, + kind: 'thinking', + content: thinkingContent, + })]; + } + if (raw.message?.role === 'user') { const content = typeof raw.message.content === 'string' ? raw.message.content @@ -316,17 +333,6 @@ export class CodexSessionsProvider implements IProviderSessions { })]; } - if (raw.type === 'thinking' || raw.isReasoning) { - return [createNormalizedMessage({ - id: baseId, - sessionId, - timestamp: ts, - provider: PROVIDER, - kind: 'thinking', - content: raw.message?.content || '', - })]; - } - if (raw.type === 'tool_use' || raw.toolName) { return [createNormalizedMessage({ id: baseId,