mirror of
https://github.com/openai/codex.git
synced 2026-11-10 21:00:47 +00:00
Avoid cloning thread history for token usage replay (#34361)
## What changed - Resolve the turn ID for restored token usage before sending resume and fork responses, avoiding a clone of the full thread history. - Add `ThreadHistoryBuilder::active_turn_id` so attribution can inspect the active turn without materializing its items. - Stop history reconstruction at the latest persisted `TokenCount` and verify that a later tail turn does not receive the replayed usage. GitOrigin-RevId: 69c4a9fe04770d1a938470afc933431e61670094
This commit is contained in:
@@ -274,6 +274,14 @@ impl ThreadHistoryBuilder {
|
||||
.or_else(|| self.turns.last().cloned())
|
||||
}
|
||||
|
||||
/// Returns the id of the active turn without materializing its items.
|
||||
pub fn active_turn_id(&self) -> Option<&str> {
|
||||
self.current_turn
|
||||
.as_ref()
|
||||
.map(|turn| turn.id.as_str())
|
||||
.or_else(|| self.turns.last().map(|turn| turn.id.as_str()))
|
||||
}
|
||||
|
||||
pub fn turn_snapshot(&self, turn_id: &str) -> Option<Turn> {
|
||||
self.current_turn
|
||||
.as_ref()
|
||||
|
||||
Reference in New Issue
Block a user