Skip to content

fix(codex): stop merging multi-turn assistant replies into one message - #15

Merged
ClaudiaFang merged 1 commit into
masterfrom
worktree-codex-turn-split-fix
Jul 21, 2026
Merged

fix(codex): stop merging multi-turn assistant replies into one message#15
ClaudiaFang merged 1 commit into
masterfrom
worktree-codex-turn-split-fix

Conversation

@ClaudiaFang

Copy link
Copy Markdown
Member

Summary

  • Codex CLI sessions where the model replied multiple times in a row before the next user prompt (or task_complete) were being merged into a single assistant message, since flushAssistantTurn() only triggered on a new user message or turn completion.
  • That collapsed genuinely substantial sessions down to messageCount === 2, which trips the "trivial session (≤2 messages)" skip filter in sync.ts — the session was parsed correctly but silently never written to the DB.
  • Confirmed via 2 real sessions from today (2026-07-21) that were missing from the local dashboard: both had 60-165 lines of real conversation (multiple tool calls, reasoning, several assistant replies) but were dropped because they parsed down to exactly 2 messages.

Fix

cli/src/providers/codex.ts: flush the in-progress assistant turn whenever a new response_item/message (role=assistant) block starts, instead of only on user_message/task_complete. Each output_text block from Codex is a full reply, not a streaming delta, so this correctly produces one message per assistant turn.

Session boundaries are unaffected — one rollout file is still one session; this only changes how messages within a session are split.

Test plan

  • pnpm build (tsc) passes
  • pnpm test — all 902 existing tests pass, including codex.test.ts
  • Re-parsed the two real sessions that were dropped: message counts went from 2 → 3 and 2 → 6
  • Ran code-insights sync --source codex-cli --force locally — both previously-missing 2026-07-21 sessions now appear in the DB (today's codex-cli count: 9 → 11)

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 <noreply@anthropic.com>
@ClaudiaFang
ClaudiaFang marked this pull request as ready for review July 21, 2026 12:39
@ClaudiaFang
ClaudiaFang merged commit 32a6540 into master Jul 21, 2026
1 check passed
@ClaudiaFang
ClaudiaFang deleted the worktree-codex-turn-split-fix branch July 21, 2026 12:39
ClaudiaFang pushed a commit that referenced this pull request Jul 23, 2026
feat: capture thinking content, tool results, and per-message usage
ClaudiaFang added a commit that referenced this pull request Jul 23, 2026
fix(codex): stop merging multi-turn assistant replies into one message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant