Skip to content

Conversation

@mzeng-openai
Copy link
Contributor

When headless environment is detected, show device login flow instead.

use codex_core::auth::CLIENT_ID;
use codex_core::auth::login_with_api_key;
use codex_core::auth::read_openai_api_key_from_env;
use codex_core::env::is_headless_environment;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that the diffs in this file is pretty much the same as in tui/src/onboarding/auth.rs and this is intentional since tui2 is a synced copy of tui

@mzeng-openai mzeng-openai marked this pull request as ready for review January 6, 2026 20:53
Copy link
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 983c2956d9

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

Comment on lines 716 to 720
match r {
Ok(()) => {
auth_manager.reload();
*sign_in_state.write().unwrap() =
SignInState::ChatGptSuccessMessage;
Copy link
Contributor

Choose a reason for hiding this comment

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

P2 Badge Guard fallback browser updates against stale login state

In the headless-device-code fallback path, this async task unconditionally overwrites sign_in_state after child.block_until_done().await. If the user presses Esc or switches to API key entry while the fallback browser flow is running (i.e., device code endpoint returned 404), the task can reset the UI back to PickMode or ChatGptSuccessMessage, clobbering the user’s new state. The rest of the device-code flow uses a cancel/Arc::ptr_eq guard to prevent stale updates; the fallback should do the same before writing. The same unguarded updates exist in codex-rs/tui2/src/onboarding/auth.rs.

Useful? React with 👍 / 👎.

});
self.request_frame.schedule_frame();

tokio::spawn(async move {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks complex (lots of nested behavior). Someone looking at this to validate it has to read every single line to understand whether it's correct as there's no grouping of parts of this that make it easy to understand small concrete pieces. Break it down into smaller pieces with documentation that captures the intent / context of each part of this and how each fits in the whole.

It's likely that each of the individual behaviors here have some property encoded that should always hold that is security sensitive, and it's important to make sure that is tested. Breaking it down smaller should facilitate that too.

Basically rewrite this 3 times:

  • documentation capturing intent
  • code capturing small understandable chunks
  • tests capturing assertable invariants

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, my bad for not pushing codex hard enough to make it more modular. Updated.

Copy link
Collaborator

@joshka-oai joshka-oai left a comment

Choose a reason for hiding this comment

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

These were a couple of small comments that I made the other day, but didn't hit submit - apologies

@mzeng-openai mzeng-openai merged commit 24d6e01 into main Jan 9, 2026
26 checks passed
@mzeng-openai mzeng-openai deleted the dev/mzeng/headless_detect branch January 9, 2026 05:48
@github-actions github-actions bot locked and limited conversation to collaborators Jan 9, 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.

3 participants