e00965a7e8
Two corrections on top of the #71077 base (the whole bug class): 1. Turn boundary = last USER message, not last assistant message. A Codex turn spans several assistant messages (assistant+tool_calls -> tool -> ... -> final assistant) whose reasoning items must replay together; the last-assistant boundary would strip reasoning mid-chain from the active turn (the gap flagged in PR #71077 review). 2. type="compaction" checkpoints (native server-side compaction, PR #81747) are exempt: they carry already-pruned history, not per-turn reasoning. Pruning filters items instead of popping the sidecar key. Sibling site fixed in the same class: the Codex incomplete-continuation dedup path blind-overwrote codex_reasoning_items on visually-duplicate interim messages, which would drop the only copy of a checkpoint captured on the earlier response. Extracted merge_interim_reasoning_items() into agent/native_compaction.py; newer reasoning wins, prior checkpoints are preserved unless the newer payload carries its own.