mirror of
https://github.com/openai/codex.git
synced 2026-11-23 23:10:47 +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:
@@ -830,8 +830,7 @@ async fn drain_to_completed(
|
||||
prompt: &Prompt,
|
||||
phase: CompactionPhase,
|
||||
) -> CodexResult<CompactionResponse> {
|
||||
sess.set_server_reasoning_included(turn_context.model_info().use_responses_lite)
|
||||
.await;
|
||||
let mut includes_reasoning = turn_context.model_info().use_responses_lite;
|
||||
let mut stream = client_session
|
||||
.stream(
|
||||
prompt,
|
||||
@@ -862,7 +861,7 @@ async fn drain_to_completed(
|
||||
// Keep each attempt isolated until the response completes successfully.
|
||||
Ok(ResponseEvent::OutputItemDone(item)) => output.push(item),
|
||||
Ok(ResponseEvent::ServerReasoningIncluded(included)) => {
|
||||
sess.set_server_reasoning_included(included).await;
|
||||
includes_reasoning = included;
|
||||
}
|
||||
Ok(ResponseEvent::RateLimits(snapshot)) => {
|
||||
sess.update_rate_limits(turn_context, snapshot).await;
|
||||
@@ -896,8 +895,12 @@ async fn drain_to_completed(
|
||||
usage_metadata.as_ref(),
|
||||
)
|
||||
.await;
|
||||
sess.update_token_usage_info(turn_context, token_usage.as_ref())
|
||||
.await?;
|
||||
sess.update_token_usage_info(
|
||||
turn_context,
|
||||
token_usage.as_ref(),
|
||||
includes_reasoning,
|
||||
)
|
||||
.await?;
|
||||
return Ok(CompactionResponse {
|
||||
response_id,
|
||||
output,
|
||||
|
||||
Reference in New Issue
Block a user