Skip to content

Reduce stack pressure in session startup and config rebuilds#25844

Merged
jif-oai merged 3 commits into
mainfrom
jif/boxing
Jun 2, 2026
Merged

Reduce stack pressure in session startup and config rebuilds#25844
jif-oai merged 3 commits into
mainfrom
jif/boxing

Conversation

@jif-oai
Copy link
Copy Markdown
Collaborator

@jif-oai jif-oai commented Jun 2, 2026

Why

/clear starts a fresh thread with InitialHistory::Cleared, which re-enters the thread/session startup path. That path now builds large async futures through ThreadManagerState::spawn_thread_with_source, Codex::spawn, and Session::new. Separately, TUI config rebuilds for cwd and permission-profile changes build a similarly heavy ConfigBuilder::build() future inside the app task. In debug and Bazel runs, those call chains can put enough state on the caller stack to abort before startup or config refresh completes.

This change keeps the behavior the same while moving the heaviest future frames off the caller stack.

What changed

  • Box Codex::spawn(...) in codex-rs/core/src/thread_manager.rs before awaiting it from spawn_thread_with_source.
  • Box Session::new(...) in codex-rs/core/src/session/mod.rs before awaiting it from Codex::spawn_internal.
  • Route ConfigBuilder::build() through a small tokio::spawn helper in codex-rs/tui/src/app/config_persistence.rs so cwd and permission-profile config rebuilds run on a runtime worker stack while preserving error context.

Verification

CI is running on the PR.

No new targeted tests were added. This is a mechanical stack-pressure reduction that keeps the existing behavior and error propagation intact.

@jif-oai jif-oai requested a review from a team as a code owner June 2, 2026 13:02
@jif-oai
Copy link
Copy Markdown
Collaborator Author

jif-oai commented Jun 2, 2026

@codex review

@jif-oai jif-oai changed the title nit: boxing to reduce the stack size Box session startup futures to reduce stack usage Jun 2, 2026
@chatgpt-codex-connector
Copy link
Copy Markdown
Contributor

Codex Review: Didn't find any major issues. Keep it up!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@jif-oai
Copy link
Copy Markdown
Collaborator Author

jif-oai commented Jun 2, 2026

@codex review

@jif-oai jif-oai changed the title Box session startup futures to reduce stack usage Reduce stack pressure in session startup and config rebuilds Jun 2, 2026
@jif-oai
Copy link
Copy Markdown
Collaborator Author

jif-oai commented Jun 2, 2026

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown
Contributor

Codex Review: Didn't find any major issues. Keep them coming!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@jif-oai
Copy link
Copy Markdown
Collaborator Author

jif-oai commented Jun 2, 2026

CI failures are unrelated and due to plugin test issues

@jif-oai jif-oai merged commit 1dd7313 into main Jun 2, 2026
29 of 31 checks passed
@jif-oai jif-oai deleted the jif/boxing branch June 2, 2026 13:42
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 2, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant