diff --git a/server/modules/providers/services/session-conversations-search.service.ts b/server/modules/providers/services/session-conversations-search.service.ts index 1c046666..65883e5e 100644 --- a/server/modules/providers/services/session-conversations-search.service.ts +++ b/server/modules/providers/services/session-conversations-search.service.ts @@ -100,6 +100,15 @@ const INTERNAL_CONTENT_PREFIXES = [ '[Request interrupted', ] as const; +/** + * Codex includes extra internal metadata tags that should not surface as + * user-facing searchable conversation content. + */ +const CODEX_INTERNAL_CONTENT_PREFIXES = [ + '', + '', +] as const; + function normalizeComparablePath(inputPath: string): string { if (!inputPath || typeof inputPath !== 'string') { return ''; @@ -156,6 +165,11 @@ function isInternalContent(content: string): boolean { return INTERNAL_CONTENT_PREFIXES.some((prefix) => content.startsWith(prefix)); } +function isInternalCodexContent(content: string): boolean { + const normalized = content.trimStart(); + return CODEX_INTERNAL_CONTENT_PREFIXES.some((prefix) => normalized.startsWith(prefix)); +} + function escapeRegex(value: string): string { return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); } @@ -807,7 +821,6 @@ async function parseCodexSessionMatches( if (entry.type === 'event_msg' && isVisibleCodexUserMessage(entry.payload as AnyRecord)) { text = String(entry.payload.message); role = 'user'; - latestUserMessageText = text; } else if ( entry.type === 'event_msg' && entry.payload?.type === 'agent_reasoning' @@ -820,9 +833,6 @@ async function parseCodexSessionMatches( if (payload.role === 'user') { text = extractCodexText(payload.content); role = 'user'; - if (text) { - latestUserMessageText = text; - } } else if (payload.role === 'assistant') { text = extractCodexText(payload.content); role = 'assistant'; @@ -844,6 +854,12 @@ async function parseCodexSessionMatches( if (!text || !role) { continue; } + if (isInternalCodexContent(text)) { + continue; + } + if (role === 'user') { + latestUserMessageText = text; + } const fingerprint = `${role}:${text.trim().toLowerCase()}`; if (seenMessageFingerprints.has(fingerprint)) {