mirror of
https://github.com/openai/codex.git
synced 2026-10-31 19:28:49 +00:00
fix
This commit is contained in:
@@ -830,7 +830,7 @@ impl Session {
|
||||
|
||||
async fn get_total_token_usage(&self) -> i64 {
|
||||
let state = self.state.lock().await;
|
||||
state.get_total_token_usage(state.server_reasoning_included())
|
||||
state.get_total_token_usage()
|
||||
}
|
||||
|
||||
pub(crate) async fn get_base_instructions(&self) -> BaseInstructions {
|
||||
|
||||
@@ -25,6 +25,7 @@ pub(crate) struct ContextManager {
|
||||
/// The oldest items are at the beginning of the vector.
|
||||
items: Vec<ResponseItem>,
|
||||
token_info: Option<TokenUsageInfo>,
|
||||
server_reasoning_included: bool,
|
||||
codex_home: PathBuf,
|
||||
}
|
||||
|
||||
@@ -33,6 +34,7 @@ impl ContextManager {
|
||||
Self {
|
||||
items: Vec::new(),
|
||||
token_info: TokenUsageInfo::new_or_append(&None, &None, None),
|
||||
server_reasoning_included: false,
|
||||
codex_home: codex_home.to_path_buf(),
|
||||
}
|
||||
}
|
||||
@@ -54,6 +56,14 @@ impl ContextManager {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn set_server_reasoning_included(&mut self, included: bool) {
|
||||
self.server_reasoning_included = included;
|
||||
}
|
||||
|
||||
pub(crate) fn total_token_usage(&self) -> i64 {
|
||||
self.get_total_token_usage(self.server_reasoning_included)
|
||||
}
|
||||
|
||||
/// `items` is ordered from oldest to newest.
|
||||
pub(crate) fn record_items<I>(&mut self, items: I, policy: TruncationPolicy)
|
||||
where
|
||||
@@ -321,7 +331,8 @@ impl ContextManager {
|
||||
return item.clone();
|
||||
};
|
||||
|
||||
let mut remaining = context_window.saturating_sub(self.get_total_token_usage());
|
||||
let mut remaining = context_window
|
||||
.saturating_sub(self.get_total_token_usage(self.server_reasoning_included));
|
||||
let offloader = ContextOffloader::new(&self.codex_home);
|
||||
let mut new_content = Vec::with_capacity(content.len().saturating_add(1));
|
||||
for item in content {
|
||||
|
||||
@@ -14,7 +14,6 @@ pub(crate) struct SessionState {
|
||||
pub(crate) session_configuration: SessionConfiguration,
|
||||
pub(crate) history: ContextManager,
|
||||
pub(crate) latest_rate_limits: Option<RateLimitSnapshot>,
|
||||
pub(crate) server_reasoning_included: bool,
|
||||
}
|
||||
|
||||
impl SessionState {
|
||||
@@ -25,7 +24,6 @@ impl SessionState {
|
||||
session_configuration,
|
||||
history,
|
||||
latest_rate_limits: None,
|
||||
server_reasoning_included: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,17 +78,12 @@ impl SessionState {
|
||||
self.history.set_token_usage_full(context_window);
|
||||
}
|
||||
|
||||
pub(crate) fn get_total_token_usage(&self, server_reasoning_included: bool) -> i64 {
|
||||
self.history
|
||||
.get_total_token_usage(server_reasoning_included)
|
||||
pub(crate) fn get_total_token_usage(&self) -> i64 {
|
||||
self.history.total_token_usage()
|
||||
}
|
||||
|
||||
pub(crate) fn set_server_reasoning_included(&mut self, included: bool) {
|
||||
self.server_reasoning_included = included;
|
||||
}
|
||||
|
||||
pub(crate) fn server_reasoning_included(&self) -> bool {
|
||||
self.server_reasoning_included
|
||||
self.history.set_server_reasoning_included(included);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user