Skip to content

fix(windows): correctly identify mise binary without extension#8496

Closed
salim-b wants to merge 2 commits intojdx:mainfrom
salim-b:fix-win-shim-check
Closed

fix(windows): correctly identify mise binary without extension#8496
salim-b wants to merge 2 commits intojdx:mainfrom
salim-b:fix-win-shim-check

Conversation

@salim-b
Copy link
Copy Markdown
Contributor

@salim-b salim-b commented Mar 7, 2026

On Windows, mise expects argv[0] to resolve to a filename of mise.exe to consider itself as not running as a shim. However, under certain conditions (e.g. on the conda-forge Windows CI build environment), running mise --help or mise --version directly results in argv[0] resolving to just mise (without the .exe extension, or perhaps mise.bat if it gets wrapped in some instances).

Because "mise" != "mise.exe", the condition bin_name != mise_bin evaluates to true, and mise mistakenly thinks it is running as a shim. When mise runs as a shim, it completely ignores CLI flags (like --help) and tries to execute the shimmed tool. Since no such tool is found or configured, it just silently exits with a non-zero exit code (exit(1)).

This PR fixes the logic so that variations of mise on Windows (like mise without extension or mise.bat/mise.cmd) aren't considered shims.

On Windows, mise expects argv[0] to resolve to a filename of mise.exe to consider itself as not running as a shim. However, under certain conditions (e.g. on the conda-forge Windows CI build environment), running mise --help or mise --version directly results in argv[0] resolving to just mise (without the .exe extension, or perhaps mise.bat if it gets wrapped in some instances).

Because "mise" != "mise.exe", the condition bin_name != mise_bin evaluates to true, and mise mistakenly thinks it is running as a shim. When mise runs as a shim, it completely ignores CLI flags (like --help) and tries to execute the shimmed tool. Since no such tool is found or configured, it just silently exits with a non-zero exit code (exit(1)).

This patch fixes the logic so that variations of mise on Windows (like mise without extension or mise.bat/mise.cmd) aren't considered shims.
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a critical issue on Windows where the mise binary was incorrectly identified as a shim under specific conditions, such as when executed without the .exe extension or via wrapper scripts. The fix updates the shim detection logic to accurately recognize the main mise executable, ensuring that command-line arguments are processed correctly and preventing unintended silent exits.

Highlights

  • Windows Binary Identification: Modified the IS_RUNNING_AS_SHIM logic on Windows to correctly identify the mise binary, even when the .exe extension is missing or when wrapped by scripts like mise.bat or mise.cmd.
  • Shim Detection Fix: Prevented mise from mistakenly identifying itself as a shim in these scenarios, which previously caused CLI flags to be ignored and silent exits.
Changelog
  • src/env.rs
    • Updated the IS_RUNNING_AS_SHIM logic to include checks for bin_name being "mise" (without extension) and not starting with "mise." (e.g., "mise.bat", "mise.cmd") when running on Windows.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request fixes an issue on Windows where the mise binary could be misidentified as a shim if invoked without the .exe extension. The change correctly identifies mise, mise.exe, and mise.* as non-shim invocations on Windows. My review includes a suggestion to refactor the conditional logic to improve clarity and remove redundancy, making it more maintainable across different platforms.

src/env.rs Outdated
let mise_bin = "mise.exe";
let bin_name = *MISE_BIN_NAME;
bin_name != mise_bin && !bin_name.starts_with("mise-")
bin_name != "mise" && bin_name != mise_bin && !bin_name.starts_with("mise-") && !bin_name.starts_with("mise.")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This logic is correct, but it introduces a small redundancy on Unix where mise_bin is "mise", leading to bin_name != "mise" && bin_name != "mise". This could be confusing for future readers.

For better clarity and to avoid this redundancy, consider refactoring the condition to be more explicit about the platform-specific checks. Here is a suggestion that achieves the same logic in a more readable way:

Suggested change
bin_name != "mise" && bin_name != mise_bin && !bin_name.starts_with("mise-") && !bin_name.starts_with("mise.")
!(bin_name == mise_bin || (cfg!(windows) && bin_name == "mise")) && !bin_name.starts_with("mise-") && !bin_name.starts_with("mise.")

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 7, 2026

Greptile Summary

This PR correctly fixes a Windows-specific bug in the IS_RUNNING_AS_SHIM detection logic. On Windows, argv[0] can resolve to mise (without .exe extension) or wrapper scripts like mise.bat, but these were incorrectly identified as shim invocations, causing CLI flags like --help and --version to be silently ignored in affected environments (e.g. conda-forge Windows CI).

Changes made:

  • Added bin_name != "mise" to handle Windows where argv[0] omits the .exe extension
  • Added !bin_name.starts_with("mise.") to treat wrapper scripts (mise.bat, mise.cmd, etc.) as direct invocations

Verification:
The fix is correct and safe. The changes are minimal, targeted, and address the specific reported issue without affecting existing behavior on Unix or other platforms.

Confidence Score: 5/5

  • This PR is safe to merge. The fix correctly addresses the described Windows shim-detection bug with no risk to existing behavior.
  • The PR makes a small, targeted change to fix a concrete Windows bug where argv[0] lacks the .exe extension or uses wrapper scripts. The logic is verified to work correctly on both Unix and Windows. The changes are minimal, focused, and address the exact issue described in the PR.
  • No files require special attention

Last reviewed commit: e782d54

@@ -281,7 +281,10 @@ pub static IS_RUNNING_AS_SHIM: Lazy<bool> = Lazy::new(|| {
#[cfg(windows)]
let mise_bin = "mise.exe";
let bin_name = *MISE_BIN_NAME;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I think we should only do this for windows and also probably clean this logic up since there's some unnecessary conditions

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Like the the gemini-code-assist suggestion above? Feel free to adapt the PR as you see fit (I'm not really experienced in Rust) :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes, jdx's feedback aligns with the idea of simplifying the shim detection logic. The current logic in the PR, while addressing the Windows-specific mise vs mise.exe issue, inadvertently introduces a new problem: it incorrectly identifies actual shims (like mise-node) as not being shims.

The most robust and straightforward way to determine if the current executable is a shim is to check if its name starts with mise-. This correctly identifies binaries like mise-node as shims, while correctly identifying mise, mise.exe, mise.bat, and mise.cmd as the main executable (not shims).

This approach also naturally handles the Windows-specific nuances without requiring explicit #[cfg(windows)] blocks within the IS_RUNNING_AS_SHIM calculation, thus cleaning up the logic as suggested.

I recommend replacing the entire Lazy::new block's content (lines 281-287 in the current PR) with the simplified logic below.

Suggested change
let bin_name = *MISE_BIN_NAME;
let bin_name = *MISE_BIN_NAME;
bin_name.starts_with("mise-")

jdx added a commit that referenced this pull request Mar 7, 2026
## Summary
- Fixes the same issue as #8496 with the cleanup requested by @jdx
- On Windows, `argv[0]` can resolve to `mise` (without `.exe`),
`mise.bat`, or `mise.cmd`, all of which were incorrectly identified as
shims
- Simplifies the `IS_RUNNING_AS_SHIM` logic by removing
`#[cfg(unix)]`/`#[cfg(windows)]` blocks and using a single unified check
- Extracts a shared `is_mise_binary()` helper used by both
`IS_RUNNING_AS_SHIM` and `handle_shim()` to keep the logic in one place

Credit to @salim-b for identifying and reporting the issue in #8496.

Co-Authored-By: Salim B <git@salim.space>

## Test plan
- Verify `mise --help` and `mise --version` work correctly on Windows
when `argv[0]` is `mise` (without extension)
- Verify shim behavior still works (e.g., `node` shim correctly
identified as a shim)
- Verify `mise-` prefixed subcommands are not treated as shims

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Low Risk**
> Small, localized change to binary-name detection; main risk is
misclassifying edge-case executable names and altering shim behavior in
those cases.
> 
> **Overview**
> Fixes Windows shim detection when `argv[0]` resolves to `mise` without
an extension (or to `mise.bat`/`mise.cmd`), which previously caused real
`mise` invocations to be treated as shims.
> 
> This replaces the platform-specific comparison logic in
`IS_RUNNING_AS_SHIM` with a shared `env::is_mise_binary()` helper and
updates `handle_shim()` to use the same check, ensuring consistent
behavior for `mise`, `mise.*`, and `mise-...` binaries.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
566183a. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

Co-authored-by: Salim B <git@salim.space>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
@jdx jdx closed this Mar 7, 2026
@salim-b salim-b deleted the fix-win-shim-check branch March 7, 2026 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants