fix(tui): avoid update loops for mismatched npm installs#21956
Open
fcoury-oai wants to merge 3 commits intomainfrom
Open
fix(tui): avoid update loops for mismatched npm installs#21956fcoury-oai wants to merge 3 commits intomainfrom
fcoury-oai wants to merge 3 commits intomainfrom
Conversation
8f3eed5 to
1c6e063
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Users with more than one Codex install can get stuck in a misleading update loop: the running CLI offers an update, but the updater mutates a different install than the executable their shell will launch next. For npm-managed installs, a successful
npm install -g @openai/codexis not enough to prove that the activecodexcommand now points at the updated package.And when the user chooses Help me fix this it starts a new session with:
What changed
Preserve npm launch provenance from the JS shim via
CODEX_MANAGED_PACKAGE_ROOT, then compare that running package root with the package rootnpm install -gwould update.When Codex can prove those roots differ, replace the misleading update flow with remediation UX:
bare launches show an actionable popup with
Help me fix this,Later, andDon't remind me about this versionprompt-bearing launches show a subdued inline warning instead of interrupting the user's task
Help me fix thisstarts a Codex session with a prefilled diagnostic prompt that asks before destructive changesWhen a prompt-driven update reports success but the next launch is still the same old executable, treat that as a likely no-op update:
bare launches show the richer remediation popup
prompt-bearing launches show a one-time inline warning while preserving the later popup opportunity
Reuse the same mismatch detection in
codex update, and persist just enough state to avoid repeated no-op inline warnings for the same target version.How to Test
Set up two npm-managed Codex installs in different prefixes, with an older install first on
PATHwhilenpm root -gpoints at the other prefix.Start bare
codexfrom the older install and confirm the remediation popup identifies both package roots instead of offering a misleading update.Choose
Help me fix thisand confirm Codex starts a session with a prefilled repair prompt that asks it to inspectPATH/ install state before changing anything.Start
codex "summarize recent commits"in the same mismatched environment and confirm startup stays non-blocking while showing the subdued inline warning.Trigger a prompt-driven update that completes without changing the executable used on the next launch:
on the next prompt-bearing launch, confirm Codex shows the one-time inline no-op warning
on the next bare launch, confirm Codex still shows the remediation popup
Run
codex updatefrom the mismatched shell and confirm it exits with remediation text instead of running the wrong updater.Manual validation performed:
Reproduced the original loop with two disposable npm prefixes in tmux:
the launched CLI stayed on
0.129.0npm install -gupdated the other prefix to0.130.0relaunching the same
codexcommand showed the same update prompt againLocally smoke-tested the new mismatch path by temporarily making the debug build eligible for startup update checks:
changed the workspace version from
0.0.0to0.129.0temporarily widened the debug-only update gates so the debug binary included the startup flow
launched the branch build with:
CODEX_MANAGED_BY_NPM=1 \ CODEX_MANAGED_PACKAGE_ROOT="$HOME/.local/bin" \ ./target/debug/codex resume --lastwith npm still rooted at the mise-managed install, this exercised the remediation path against the real local mismatch between
$HOME/.local/binand the npm global package rootThe fake-version and debug-gate edits were smoke-only local changes and are not part of this PR.
Targeted tests:
cargo test -p codex-tui update_actioncargo test -p codex-tui update_cargo test -p codex-tui no_op_inline_notice_marker_is_persisted_without_clearing_remediationcargo test -p codex-cli update_