From 3d47dc40be53a2b7729443cf89cfa8d058830aa1 Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Tue, 18 Aug 2026 06:15:54 +0000 Subject: [PATCH] Box the TUI future to bound CLI stack usage (#39154) ## Why The TUI startup future is large enough to inflate the CLI dispatcher's stack frame. ## What changed - Heap-pin the TUI startup future before awaiting it. - Add a regression test that keeps the `run_interactive_tui` future below 64 KiB. GitOrigin-RevId: 1f977928117537a5188c4d801517fb4a42e39e15 --- codex-rs/cli/src/main.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/codex-rs/cli/src/main.rs b/codex-rs/cli/src/main.rs index 516028f169..94aa119bab 100644 --- a/codex-rs/cli/src/main.rs +++ b/codex-rs/cli/src/main.rs @@ -2567,7 +2567,8 @@ async fn run_interactive_tui( }; let mut attempted_backups = HashSet::new(); loop { - let err = match start_tui().await { + // Keep the large TUI future out of the CLI dispatcher's stack frame. + let err = match Box::pin(start_tui()).await { Ok(exit_info) => return Ok(exit_info), Err(err) => err, }; @@ -2795,6 +2796,19 @@ mod tests { use codex_tui::TokenUsage; use pretty_assertions::assert_eq; + #[test] + fn interactive_tui_future_stays_bounded() { + let future = run_interactive_tui( + TuiCli::parse_from(["codex"]), + /*remote*/ None, + /*remote_auth_token_env*/ None, + Arg0DispatchPaths::default(), + ); + let size = std::mem::size_of_val(&future); + + assert!(size < 64 * 1024, "interactive TUI future is {size} bytes"); + } + #[tokio::test] async fn updater_http_client_factory_honors_respect_system_proxy() { let codex_home = tempfile::tempdir().expect("temporary Codex home");