Skip to content

Conversation

@shijie-oai
Copy link
Collaborator

Summary

  • Use https://github.com/Homebrew/homebrew-cask/blob/main/Casks/c/codex.rb to get the latest available version for brew usage.

@shijie-oai shijie-oai marked this pull request as ready for review November 5, 2025 14:34
@shijie-oai shijie-oai requested a review from bolinfest November 5, 2025 14:34
@shijie-oai shijie-oai marked this pull request as draft November 5, 2025 17:09
@shijie-oai shijie-oai force-pushed the shijie/update-brew-auto-update branch from e493207 to 2fa833e Compare November 7, 2025 20:09
BrewUpgrade,
}

#[cfg(any(not(debug_assertions), test))]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

All the usage of this is guarded - without removing this I have string #[cfg(any(not(debug_assertions), test))] through get_upgrade_version which triggers a lot more changes. Alternatively I can create another get_update_action which returns None for debug_assertions cfg only but that is not super clean.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is here so that we don't get the message all the time in dev mode. I think it's important to make this work.

match self {
UpdateAction::NpmGlobalLatest => ("npm", &["install", "-g", "@openai/codex@latest"]),
UpdateAction::BunGlobalLatest => ("bun", &["install", "-g", "@openai/codex@latest"]),
UpdateAction::BrewUpgrade => ("brew", &["upgrade", "--cask", "codex"]),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Remove --cask flag because it is not necessary.


use crate::version::CODEX_CLI_VERSION;

pub fn get_upgrade_version(config: &Config) -> Option<String> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Both the history cell (displaying upgrade message) and update_prompt (auto update) use this value for showing and calculating the correct update message.

Comment on lines 47 to 48
#[serde(default)]
latest_brew_version: String,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Optional because the existing version.json does not contain this and parsing it would error (hidden but still).

@shijie-oai shijie-oai force-pushed the shijie/update-brew-auto-update branch from 4a198c4 to a7ba34c Compare November 8, 2025 00:02
} else {
None
}
latest_version_for_action(&info, update_action).and_then(|latest_version| {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Get the latest version based on installation method.

Comment on lines 140 to 143
Some(UpdateAction::BrewUpgrade) if !info.latest_brew_version.is_empty() => {
Some(&info.latest_brew_version)
}
Some(UpdateAction::BrewUpgrade) => None,
Copy link
Collaborator Author

@shijie-oai shijie-oai Nov 8, 2025

Choose a reason for hiding this comment

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

The case which you have a version.json but it is not updated (i.e. not outside the window for updating) and therefore brew version is missing. Instead of using the latest version number from github we will wait until we can get the value from brew.

@shijie-oai shijie-oai requested a review from bolinfest November 8, 2025 00:05
@shijie-oai shijie-oai marked this pull request as ready for review November 8, 2025 00:06
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.

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

@shijie-oai
Copy link
Collaborator Author

@codex review it

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.

ℹ️ 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 208 to 212
match self {
UpdateAction::NpmGlobalLatest => ("npm", &["install", "-g", "@openai/codex@latest"]),
UpdateAction::BunGlobalLatest => ("bun", &["install", "-g", "@openai/codex@latest"]),
UpdateAction::BrewUpgrade => ("brew", &["upgrade", "--cask", "codex"]),
UpdateAction::BrewUpgrade => ("brew", &["upgrade", "codex"]),
}
Copy link
Contributor

Choose a reason for hiding this comment

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

P1 Badge Restore --cask flag for Brew upgrades

The update action now invokes brew upgrade codex, but Codex is published as a Homebrew cask, not a formula. Our own FAQ (docs/faq.md lines 46‑55) explicitly tells users to run brew upgrade --cask codex after the migration from a formula, because omitting --cask causes Homebrew to look for a formula named codex and fail with “No available formula with the name ‘codex’”. With this change the automatic update the CLI runs (and the command string shown to the user) will always fail for Brew installs, preventing updates for that channel. The UpdateAction::BrewUpgrade branch should continue to pass the --cask flag.

Useful? React with 👍 / 👎.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Upgrade is actually fine and --cask is not necessary.

@shijie-oai shijie-oai force-pushed the shijie/update-brew-auto-update branch from c7bf6cc to 76c5897 Compare November 8, 2025 07:14
@shijie-oai shijie-oai force-pushed the shijie/update-brew-auto-update branch from 76c5897 to 7ea7f34 Compare November 8, 2025 07:25
mod text_formatting;
mod tui;
mod ui_consts;
pub mod update_action;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this need to be pub?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes - this is used in the the cli crate for typing https://github.com/openai/codex/blob/main/codex-rs/cli/src/main.rs#L23.

/// Returns string representation of the command-line arguments for invoking the update.
pub fn command_str(self) -> String {
let (command, args) = self.command_args();
let args_str = args.join(" ");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use shlex.join

let prev = std::env::var_os("CODEX_MANAGED_BY_NPM");

// First: no npm var -> expect None (we do not run from brew in CI)
unsafe { std::env::remove_var("CODEX_MANAGED_BY_NPM") };
Copy link
Collaborator

Choose a reason for hiding this comment

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

You need to test using dependency injection/pass from above for the env: setvar can cause undefined behavior, which is why it is marked unsafe.

@shijie-oai shijie-oai marked this pull request as draft November 8, 2025 23:06
@shijie-oai shijie-oai force-pushed the shijie/update-brew-auto-update branch from 0883d10 to 99a6734 Compare November 9, 2025 03:20
Comment on lines 18 to 23
detect_update_action(
cfg!(target_os = "macos"),
&exe,
managed_by_npm,
managed_by_bun,
)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@bolinfest let me know your thoughts on this - it is pretty scalable and we can moved away from setting env variables in tests.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks, yes, this is what I meant by "pass from above."

Comment on lines 18 to 23
detect_update_action(
cfg!(target_os = "macos"),
&exe,
managed_by_npm,
managed_by_bun,
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks, yes, this is what I meant by "pass from above."

/// Returns the list of command-line arguments for invoking the update.
pub fn command_args(self) -> (&'static str, &'static [&'static str]) {
match self {
UpdateAction::NpmGlobalLatest => ("npm", &["install", "-g", "@openai/codex@latest"]),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would drop the @latest for now. At least, I wasn't aware that maintaining that tag was part of our contract with the user.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Dropped latest tag for bun install too.

/// Returns string representation of the command-line arguments for invoking the update.
pub fn command_str(self) -> String {
let (command, args) = self.command_args();
shlex::try_join(std::iter::once(command).chain(args.iter().copied()))
Copy link
Collaborator

Choose a reason for hiding this comment

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

That copied() seems a bit suspicious to me. try_join() takes by reference: https://docs.rs/shlex/latest/shlex/fn.try_join.html

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Aha this statement has a bit too much of a nesting - .copied() is applied on the args.iter() and not the overall iter object. .chain expects an iterator and not an itr which is why we need to use copied.

Comment on lines 51 to 62
if managed_by_npm {
return Some(UpdateAction::NpmGlobalLatest);
}
if managed_by_bun {
return Some(UpdateAction::BunGlobalLatest);
}
if is_macos
&& (current_exe.starts_with("/opt/homebrew") || current_exe.starts_with("/usr/local"))
{
return Some(UpdateAction::BrewUpgrade);
}
None
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unnecessary use of return is not canonical Rust. Prefer:

Suggested change
if managed_by_npm {
return Some(UpdateAction::NpmGlobalLatest);
}
if managed_by_bun {
return Some(UpdateAction::BunGlobalLatest);
}
if is_macos
&& (current_exe.starts_with("/opt/homebrew") || current_exe.starts_with("/usr/local"))
{
return Some(UpdateAction::BrewUpgrade);
}
None
if managed_by_npm {
Some(UpdateAction::NpmGlobalLatest);
} else if managed_by_bun {
Some(UpdateAction::BunGlobalLatest);
} else if is_macos
&& (current_exe.starts_with("/opt/homebrew") || current_exe.starts_with("/usr/local"))
{
Some(UpdateAction::BrewUpgrade);
} else {
None
}

}
}

#[cfg(any(not(debug_assertions), test))]
Copy link
Collaborator

Choose a reason for hiding this comment

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

This isn't pub, so I don't think you need this cfg line, do you?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think we should keep it - removing it leads to a dead_code warning for dev build. We can add #[allow(dead_code)] but a strongly defined cfg makes it feel more intentional.

@bolinfest bolinfest marked this pull request as ready for review November 10, 2025 00:24
@bolinfest bolinfest self-requested a review November 10, 2025 00:25
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.

ℹ️ 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 26 to 33
impl UpdateAction {
/// Returns the list of command-line arguments for invoking the update.
pub fn command_args(self) -> (&'static str, &'static [&'static str]) {
match self {
UpdateAction::NpmGlobalLatest => ("npm", &["install", "-g", "@openai/codex@latest"]),
UpdateAction::BunGlobalLatest => ("bun", &["install", "-g", "@openai/codex@latest"]),
UpdateAction::BrewUpgrade => ("brew", &["upgrade", "codex"]),
}
Copy link
Contributor

Choose a reason for hiding this comment

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

P1 Badge Restore --cask in brew upgrade command

The new UpdateAction::BrewUpgrade now emits brew upgrade codex. Homebrew upgrades formulae by default and requires --cask to upgrade casks, so this command fails with “No available formula with the name ‘codex’” when the user confirms the update prompt or when the CLI auto‑runs the update after exit. The previous implementation correctly used brew upgrade --cask codex. Please reintroduce the flag so Brew installations actually update.

Useful? React with 👍 / 👎.

@shijie-oai shijie-oai merged commit 788badd into main Nov 10, 2025
25 checks passed
@shijie-oai shijie-oai deleted the shijie/update-brew-auto-update branch November 10, 2025 17:05
@github-actions github-actions bot locked and limited conversation to collaborators Nov 10, 2025
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.

4 participants