Reduce TUI stack usage during session transitions (#44176)

## Why

Session transitions need stack headroom to rebuild configuration and the chat widget. Tokio stores task outputs inline even when it boxes the task future, so returning a large `Config` adds stack pressure during task allocation.

## What changed

Box the configuration build result inside the runtime worker and unbox it after joining. Box the `App::run` future to keep the large event loop out of enclosing startup futures.

## Testing

Extend the production-stack TUI integration test to enter `/side`, verify the process remains running, and return to the saved conversation with Ctrl+C.

GitOrigin-RevId: 44975300bb837bf3645ff762cf7bcdc44a277f41
This commit is contained in:
Eric Traut authored and copyberry committed 2026-09-09 15:20:47 +00:00
1 parent 0df1daf526
commit c77c34ed33
3 files changed
+15 -5

No files matched your search

+4 -2
View File
@@ -19,8 +19,10 @@ async fn build_config_on_runtime_worker(
builder: ConfigBuilder,
error_context: String,
) -> Result<Config> {
match tokio::spawn(async move { builder.build().await }).await {
Ok(build_result) => build_result.wrap_err(error_context),
// Tokio stores the task output inline even when it boxes the future. Keep the large
// Config off the caller's stack while Tokio allocates the task during session switches.
match tokio::spawn(async move { builder.build().await.map(Box::new) }).await {
Ok(build_result) => build_result.map(|config| *config).wrap_err(error_context),
Err(err) if err.is_panic() => std::panic::resume_unwind(err.into_panic()),
Err(err) => Err(err).wrap_err_with(|| format!("{error_context} task failed")),
}