Files
codex/codex-rs/ext/extension-api/src/capabilities/conversation_history.rs
T
felixxia-oai 5971d42847 Preserve verified answers across history compaction (#42293)
## Why

Compaction replaces the model history window, but host-verified user answers may
still be needed for the rest of the owning thread.

## What changed

- Add bounded, model-invisible retained context for verified
  `request_user_input` answers.
- Persist retained context in rollout events and compaction checkpoints, and
  restore it when a thread resumes.
- Remove answers when their source turns are rolled back, and prevent
  parent-local answers from being inherited by child forks.

## Testing

Add lifecycle coverage for deduplication and size limits, compaction and resume,
rollback, rollout migration, and child forks.

GitOrigin-RevId: c32900d3e8120a9899b71f0576683acd67a4b898
2026-09-02 15:07:11 +00:00

36 lines
1.4 KiB
Rust

use codex_history::RetainedContext;
use codex_protocol::models::ResponseItem;
/// Read-only conversation-history snapshot supplied by the extension host.
///
/// Implementations should retain the host's existing snapshot storage rather than
/// copying response payloads into an extension-owned collection.
pub trait ConversationHistorySnapshot: Send + Sync {
/// Returns the generation of the history captured by this snapshot.
fn history_version(&self) -> u64;
/// Host-owned revision captured with this snapshot. Advances on user messages and
/// history resets, but stays unchanged for compaction and internal context.
fn user_message_revision(&self) -> u64;
/// Returns the snapshot's response items in conversation order.
fn items(&self) -> Box<dyn Iterator<Item = &ResponseItem> + Send + '_>;
/// Host-owned retained facts captured atomically with the parent model window.
fn retained_context(&self) -> Option<&RetainedContext> {
None
}
/// Original review evidence retained across parent compaction, in conversation order.
/// Hosts without separate retention provide their current history.
fn review_items(&self) -> Box<dyn Iterator<Item = &ResponseItem> + Send + '_> {
self.items()
}
/// Changes whenever offsets into the retained review evidence become invalid.
fn review_history_version(&self) -> u64 {
self.history_version()
}
}