mirror of
https://github.com/openai/codex.git
synced 2026-11-05 20:10:33 +00:00
fix(next-prompt): keep hidden usage out of context state
This commit is contained in:
@@ -28,6 +28,7 @@ use codex_protocol::openai_models::ReasoningEffort;
|
||||
use codex_protocol::protocol::Event;
|
||||
use codex_protocol::protocol::EventMsg;
|
||||
use codex_protocol::protocol::TokenCountEvent;
|
||||
use codex_protocol::protocol::TokenUsageInfo;
|
||||
use codex_rollout_trace::InferenceTraceContext;
|
||||
use futures::StreamExt;
|
||||
use std::collections::HashSet;
|
||||
@@ -181,11 +182,14 @@ pub(crate) async fn suggest_next_prompt(
|
||||
token_usage,
|
||||
..
|
||||
} => {
|
||||
let should_emit_token_count = token_usage.is_some() || latest_rate_limits.is_some();
|
||||
sess.record_token_usage_info(&turn_context, token_usage.as_ref())
|
||||
.await;
|
||||
let token_usage_info = TokenUsageInfo::new_or_append(
|
||||
&sess.token_usage_info().await,
|
||||
&token_usage,
|
||||
turn_context.model_context_window(),
|
||||
);
|
||||
let should_emit_token_count =
|
||||
token_usage_info.is_some() || latest_rate_limits.is_some();
|
||||
if should_emit_token_count {
|
||||
let token_usage_info = sess.token_usage_info().await;
|
||||
// App-server clients key usage updates by turn id. Attribute hidden
|
||||
// suggestion sampling to the latest real turn instead of the ephemeral
|
||||
// lightweight turn used to configure the request.
|
||||
|
||||
@@ -96,6 +96,32 @@ async fn suggest_next_prompt_samples_history_without_tools() -> Result<()> {
|
||||
.used_percent,
|
||||
42.0
|
||||
);
|
||||
assert_eq!(test.codex.token_usage_info().await, None);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn suggest_next_prompt_skips_early_history_without_request() -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
let server = MockServer::start().await;
|
||||
let first_turn_response = sse(vec![
|
||||
ev_response_created("resp-1"),
|
||||
ev_assistant_message("msg-1", "first turn complete"),
|
||||
ev_completed("resp-1"),
|
||||
]);
|
||||
let responses = mount_sse_sequence(&server, vec![first_turn_response]).await;
|
||||
|
||||
let test = test_codex().build(&server).await?;
|
||||
test.submit_turn("first task").await?;
|
||||
|
||||
let suggestion = test
|
||||
.codex
|
||||
.suggest_next_prompt(CancellationToken::new())
|
||||
.await?;
|
||||
assert_eq!(suggestion, None);
|
||||
assert_eq!(responses.requests().len(), 1);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user