mirror of
https://github.com/openai/codex.git
synced 2026-11-01 19:33:35 +00:00
Preserve reasoning token accounting across resume and fork (#57839)
## Why Resuming or forking a thread loses the session flag indicating that reported token usage already includes retained reasoning. Counting that reasoning again can trigger automatic compaction too early. ## What changed Persist `last_usage_includes_reasoning` with `TokenUsageInfo` and use it when estimating context usage. Record the flag with completed sampling and compaction usage, and mark local estimates as including reasoning. Older records without the field retain the existing accounting behavior. ## Testing Add coverage for saved inclusive, exclusive, and legacy token counts. Extend the encrypted-reasoning compaction test to verify the compaction threshold for live, forked, and cold-resumed threads. GitOrigin-RevId: 9f22262a693111ec0406dce11804eb4844ad8983
This commit is contained in:
@@ -3721,6 +3721,7 @@ mod tests {
|
||||
total_tokens: 200,
|
||||
codex_rollout_budget_units: None,
|
||||
},
|
||||
last_usage_includes_reasoning: None,
|
||||
last_token_usage: TokenUsage {
|
||||
input_tokens: 10,
|
||||
cached_input_tokens: 5,
|
||||
|
||||
@@ -125,6 +125,7 @@ pub fn create_fake_rollout_with_token_usage(
|
||||
total_tokens: 150,
|
||||
codex_rollout_budget_units: None,
|
||||
},
|
||||
last_usage_includes_reasoning: None,
|
||||
last_token_usage: TokenUsage {
|
||||
input_tokens: 70,
|
||||
cached_input_tokens: 10,
|
||||
|
||||
@@ -4250,6 +4250,7 @@ async fn cold_paginated_resume_restores_usage_without_loading_turns() -> Result<
|
||||
total_tokens: 150,
|
||||
..Default::default()
|
||||
},
|
||||
last_usage_includes_reasoning: None,
|
||||
last_token_usage: TokenUsage {
|
||||
input_tokens: 70,
|
||||
output_tokens: 20,
|
||||
@@ -4361,6 +4362,7 @@ async fn cold_paginated_resume_omits_usage_when_its_turn_is_ambiguous() -> Resul
|
||||
total_tokens: 150,
|
||||
..Default::default()
|
||||
},
|
||||
last_usage_includes_reasoning: None,
|
||||
last_token_usage: TokenUsage {
|
||||
total_tokens: 90,
|
||||
..Default::default()
|
||||
@@ -4645,6 +4647,7 @@ async fn thread_resume_token_usage_replay_can_belong_to_interrupted_turn() -> Re
|
||||
total_tokens: 230,
|
||||
codex_rollout_budget_units: None,
|
||||
},
|
||||
last_usage_includes_reasoning: None,
|
||||
last_token_usage: TokenUsage {
|
||||
input_tokens: 90,
|
||||
cached_input_tokens: 30,
|
||||
|
||||
Reference in New Issue
Block a user