Skip to content

fix(parser): skip external-session-import sentinel in agent_message (#221) - #228

Merged
delexw merged 1 commit into
mainfrom
fix-issue-221
Aug 12, 2026
Merged

fix(parser): skip external-session-import sentinel in agent_message (#221)#228
delexw merged 1 commit into
mainfrom
fix-issue-221

Conversation

@delexw

@delexw delexw commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

What changed

Codex v0.147.0 (openai/codex PR #36356, part of #36361/#35623) lets Codex sync further edits into an already-imported Claude/Cursor conversation by appending new turns to the existing thread, instead of only ever finishing an import once.

I checked the real upstream diff (openai/codex#36356) rather than guessing:

  • Session-identity concern (the issue's main "open question"): the sync path appends directly into the same rollout file for the same thread id — it never writes a new file or a new session_meta. codex-trace's existing (mtime, size) cache invalidation in cache.rs already re-parses on any change to that file, so no duplicate/orphaned session entries can appear and discover.rs needs no change here.
  • Real bug found instead: Codex inserts a synthetic agent_message event with the sentinel text <EXTERNAL SESSION IMPORTED> as the last message of an imported thread (see EXTERNAL_SESSION_IMPORTED_MARKER in codex-rs/external-agent-migration/src/sessions/export.rs). Previously this sentinel only ever trailed a finished import. With v0.147.0's sync, it can now sit mid-transcript, right before newly-synced turns, since the append logic filters it out of the appended suffix but leaves the original one in place. turn.rs rendered any non-empty agent_message text as a real message, so this sentinel would show up as a fake assistant reply sitting between two real turns.

Fix

Skip the exact sentinel string in handle_event_msg so it's never rendered as a message or picked up as a final_answer.

Tests

Added two tests in src-tauri/src/parser/turn.rs:

  • v0147_external_session_imported_marker_is_not_rendered_as_agent_message — the marker is suppressed and doesn't become the turn's final answer.
  • v0147_synced_turn_after_import_marker_parses_as_its_own_turn — a turn appended after the marker (simulating a sync) still parses correctly as its own turn.

Verification

  • cargo test --lib --manifest-path src-tauri/Cargo.toml — 362 passed
  • cargo clippy --manifest-path src-tauri/Cargo.toml -- -D warnings — clean
  • cargo fmt --manifest-path src-tauri/Cargo.toml --check — clean
  • npx vitest run — 148 passed
  • npx tsc --noEmit — clean
  • npx oxlint — clean (one pre-existing, unrelated warning in MarkdownRenderer.tsx)

Fixes #221

…221)

Codex v0.147.0 (openai/codex PR #36356) can now sync further edits into
an already-imported Claude/Cursor conversation by appending new turns
to the existing thread, instead of only ever finishing an import once.

Codex inserts a synthetic agent_message with the sentinel text
"<EXTERNAL SESSION IMPORTED>" as the last message of an imported
thread. Previously this sentinel only ever trailed a finished import;
with v0.147.0 it can now sit mid-transcript, right before newly-synced
turns. turn.rs rendered any non-empty agent_message text as a real
message, so this sentinel would show up as a fake assistant reply.

Skip that exact sentinel text in handle_event_msg so it is never
rendered as a message or picked up as a final answer.

The issue also speculated codex-trace's session list could show
duplicate entries once sync lands, since a new rollout file or
session id might be created. Checked against the real PR #36356 diff:
sync appends directly into the existing rollout file for the same
thread id, so the existing (mtime, size) cache invalidation already
picks it up correctly and no discover.rs change is needed.

Fixes #221
@delexw
delexw merged commit 70411ab into main Aug 12, 2026
1 check passed
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.

[Compat] Codex v0.147.0: Cursor skill import and Claude/Cursor conversation sync without duplicates

1 participant