fix(parser): skip external-session-import sentinel in agent_message (#221) - #228
Merged
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_meta. codex-trace's existing(mtime, size)cache invalidation incache.rsalready re-parses on any change to that file, so no duplicate/orphaned session entries can appear anddiscover.rsneeds no change here.agent_messageevent with the sentinel text<EXTERNAL SESSION IMPORTED>as the last message of an imported thread (seeEXTERNAL_SESSION_IMPORTED_MARKERincodex-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.rsrendered any non-emptyagent_messagetext 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_msgso it's never rendered as a message or picked up as afinal_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 passedcargo clippy --manifest-path src-tauri/Cargo.toml -- -D warnings— cleancargo fmt --manifest-path src-tauri/Cargo.toml --check— cleannpx vitest run— 148 passednpx tsc --noEmit— cleannpx oxlint— clean (one pre-existing, unrelated warning inMarkdownRenderer.tsx)Fixes #221