Skip to content

Run Codex async main on a sized stack#25847

Merged
jif-oai merged 4 commits into
mainfrom
jif/stack-size-of-arg0
Jun 2, 2026
Merged

Run Codex async main on a sized stack#25847
jif-oai merged 4 commits into
mainfrom
jif/stack-size-of-arg0

Conversation

@jif-oai

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

Copy link
Copy Markdown
Collaborator

Why

Runtime::block_on executes the top-level future on the caller's OS thread, not on one of Tokio's worker threads. That matters for the interactive CLI because the Tokio runtime already configures larger worker stacks, while the process main thread can still have a smaller platform default stack.

This showed up as a /clear crash on macOS: starting a fresh TUI thread reloads config, and the stack-heavy TOML deserialization path can overflow before the new session is actually started.

What Changed

  • Run the regular arg0_dispatch_or_else async entrypoint on a named codex-main thread.
  • Give that thread the same TOKIO_WORKER_STACK_SIZE_BYTES stack budget already used for Tokio worker threads.
  • Keep Arg0DispatchPaths and the arg0 alias guard lifetime behavior the same.
  • Resume panics from the spawned main thread so panic behavior is preserved.

Verification

  • cargo check -p codex-cli currently fails because the top-level CLI/TUI future is not Send under the new thread boundary.

@jif-oai jif-oai changed the title fix: stack size of arg0 Run Codex async main on a sized stack Jun 2, 2026
@jif-oai

jif-oai commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

Codex Review: Didn't find any major issues. Bravo.

ℹ️ 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".

@anp-oai anp-oai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, one alternative might be to set the initial thread stack size with linker args but this has the advantage of being spelled the same for bazel and cargo and the expense of an extra thread is probably not a big deal.

@jif-oai jif-oai merged commit 3766941 into main Jun 2, 2026
30 of 31 checks passed
@jif-oai jif-oai deleted the jif/stack-size-of-arg0 branch June 2, 2026 14:34
@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.

2 participants