mirror of
https://github.com/openai/codex.git
synced 2026-04-30 09:26:44 +00:00
Fix TUI context window display before first TokenCount (#13896)
The TUI was showing the raw configured `model_context_window` until the first `TokenCount` event arrived, even though core had already emitted the effective runtime window on `TurnStarted`. This made the footer, status-line context window, and `/status` output briefly inconsistent for models/configs where the effective window differs from the configured value, such as the `gpt-5.4` 1,000,000-token override reported in #13623. Update the TUI to cache `TurnStarted.model_context_window` immediately so pre-token-count displays use the runtime effective window, and add regression coverage for the startup path. --------- Co-authored-by: Charles Cunningham <ccunningham@openai.com> Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
@@ -1711,6 +1711,27 @@ impl ChatWidget {
|
||||
}
|
||||
}
|
||||
|
||||
fn apply_turn_started_context_window(&mut self, model_context_window: Option<i64>) {
|
||||
let info = match self.token_info.take() {
|
||||
Some(mut info) => {
|
||||
info.model_context_window = model_context_window;
|
||||
info
|
||||
}
|
||||
None => {
|
||||
let Some(model_context_window) = model_context_window else {
|
||||
return;
|
||||
};
|
||||
TokenUsageInfo {
|
||||
total_token_usage: TokenUsage::default(),
|
||||
last_token_usage: TokenUsage::default(),
|
||||
model_context_window: Some(model_context_window),
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
self.apply_token_info(info);
|
||||
}
|
||||
|
||||
fn apply_token_info(&mut self, info: TokenUsageInfo) {
|
||||
let percent = self.context_remaining_percent(&info);
|
||||
let used_tokens = self.context_used_tokens(&info, percent.is_some());
|
||||
@@ -4736,8 +4757,9 @@ impl ChatWidget {
|
||||
self.on_agent_reasoning_final();
|
||||
}
|
||||
EventMsg::AgentReasoningSectionBreak(_) => self.on_reasoning_section_break(),
|
||||
EventMsg::TurnStarted(_) => {
|
||||
EventMsg::TurnStarted(event) => {
|
||||
if !is_resume_initial_replay {
|
||||
self.apply_turn_started_context_window(event.model_context_window);
|
||||
self.on_task_started();
|
||||
}
|
||||
}
|
||||
@@ -8440,6 +8462,11 @@ impl ChatWidget {
|
||||
&self.config
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn status_line_text(&self) -> Option<String> {
|
||||
self.bottom_pane.status_line_text()
|
||||
}
|
||||
|
||||
pub(crate) fn clear_token_usage(&mut self) {
|
||||
self.token_info = None;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user