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:
Eric Traut
2026-03-07 17:01:47 -07:00
committed by GitHub
parent 92f7541624
commit e8d7ede83c
3 changed files with 100 additions and 3 deletions

View File

@@ -1659,6 +1659,53 @@ async fn context_indicator_shows_used_tokens_when_window_unknown() {
);
}
#[tokio::test]
async fn turn_started_uses_runtime_context_window_before_first_token_count() {
let (mut chat, mut rx, _ops) = make_chatwidget_manual(None).await;
chat.config.model_context_window = Some(1_000_000);
chat.handle_codex_event(Event {
id: "turn-start".into(),
msg: EventMsg::TurnStarted(TurnStartedEvent {
turn_id: "turn-1".to_string(),
model_context_window: Some(950_000),
collaboration_mode_kind: ModeKind::Default,
}),
});
assert_eq!(
chat.status_line_value_for_item(&crate::bottom_pane::StatusLineItem::ContextWindowSize),
Some("950K window".to_string())
);
assert_eq!(chat.bottom_pane.context_window_percent(), Some(100));
chat.add_status_output();
let cells = drain_insert_history(&mut rx);
let context_line = cells
.last()
.expect("status output inserted")
.iter()
.map(|line| {
line.spans
.iter()
.map(|span| span.content.as_ref())
.collect::<String>()
})
.find(|line| line.contains("Context window"))
.expect("context window line");
assert!(
context_line.contains("950K"),
"expected /status to use TurnStarted context window, got: {context_line}"
);
assert!(
!context_line.contains("1M"),
"expected /status to avoid raw config context window, got: {context_line}"
);
}
#[cfg_attr(
target_os = "macos",
ignore = "system configuration APIs are blocked under macOS seatbelt"
@@ -1952,7 +1999,7 @@ fn lines_to_single_string(lines: &[ratatui::text::Line<'static>]) -> String {
}
fn status_line_text(chat: &ChatWidget) -> Option<String> {
chat.bottom_pane.status_line_text()
chat.status_line_text()
}
fn make_token_info(total_tokens: i64, context_window: i64) -> TokenUsageInfo {