Skip to content

Resolve mise wrapper binaries before execution - #8692

Closed
imadtg wants to merge 4 commits into
omacom:quattrofrom
imadtg:fix/mise-wrapper-resolution
Closed

imadtg wants to merge 4 commits into
omacom:quattrofrom
imadtg:fix/mise-wrapper-resolution

Conversation

@imadtg

@imadtg imadtg commented Aug 28, 2026 •

Copy link
Copy Markdown

Fixes #7234.

Problem

When ~/.local/bin comes before mise's binaries in PATH, a generated wrapper can execute itself through mise x and hang forever.

Fix

The fix is resolving the command's absolute binary path and using that instead.

A straightforward (but naive) way to resolve the command would be:

bin_path=$(mise which "$bin" --tool="$package") || exit 1

Here, --tool="$package" tells mise which tool/version to use while resolving "$bin". It does not guarantee that the returned executable comes from that package's own install directory. Another active package can provide the same executable name.

Instead, the wrapper now asks for the requested package's runtime directories and searches them directly:

bin_paths=$(mise bin-paths "$package") || exit 1

It passes the first matching absolute path to mise x and reports an error when no match exists.

Migration 1787809285.sh regenerates wrappers matching the old template. It preserves custom wrappers and symlinks and leaves repaired wrappers alone.

Testing

All tests in ./test/all pass: CLI and all 237 shell test files.

The new test coverage verifies that:

  • mise bin-paths "$package" stays within the requested package;
  • a same-named executable from another package is rejected;
  • package runtime variables and argument boundaries survive mise x;
  • shell metacharacters in bin names remain literal, and bin names containing paths are rejected;
  • missing or failing bin-paths stops before execution;
  • migration remains safe and idempotent.

Copilot AI balanced review requested due to automatic review settings August 28, 2026 00:24

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@chatgpt-codex-connector

Copy link
Copy Markdown

To use Codex here, create a Codex account and connect to github.

@imadtg
imadtg force-pushed the fix/mise-wrapper-resolution branch from ee42826 to 0a66d9e Compare September 8, 2026 17:08
@imadtg
imadtg force-pushed the fix/mise-wrapper-resolution branch from 0a66d9e to 011c837 Compare September 8, 2026 17:15
@davidavasalcai

Copy link
Copy Markdown

Field-tested on a real install — this fix is the right shape

I hit this exact loop (mise x re-resolving the bare command name back to the wrapper in ~/.local/bin, exec-looping in a single PID until timeout, flooding stderr with mise ~/.config/mise/config.toml tools: <pkg>@<version> lines) on Omarchy today, for gh, claude, codex, opencode and gemini at once.

My local workaround landed on the same principle as this PR: resolve the real binary first, then exec it directly —

mise use -g --quiet "$pkg" || exit 1
exec "$(mise which "$pkg")" "$@"

Verified on this machine:

  • mise which gh → ~/.local/share/mise/installs/gh/latest/gh_2.100.0_linux_amd64/bin/gh (real binary, not the wrapper)
  • gh --version, gh auth status, gh api user — all return instantly, no loop, no flood
  • claude --version (2.1.266), codex --version (0.153.4), opencode --version (1.18.30), gemini --version (0.59.0) — all instant

So resolving to an absolute path before executing is confirmed working in production. Appreciate the --tool scoping in this PR (plain mise which "$bin" can pick a same-named binary from another package — that's why resolving from the package's bin-paths is the better shape). Happy to test the branch here if helpful.

@imadtg
imadtg marked this pull request as ready for review September 12, 2026 08:30
@imadtg

imadtg commented Sep 12, 2026 •

Copy link
Copy Markdown
Author

Field-tested on a real install — this fix is the right shape

I hit this exact loop (mise x re-resolving the bare command name back to the wrapper in ~/.local/bin, exec-looping in a single PID until timeout, flooding stderr with mise ~/.config/mise/config.toml tools: <pkg>@<version> lines) on Omarchy today, for gh, claude, codex, opencode and gemini at once.

My local workaround landed on the same principle as this PR: resolve the real binary first, then exec it directly —

mise use -g --quiet "$pkg" || exit 1
exec "$(mise which "$pkg")" "$@"

Verified on this machine:

* `mise which gh` → `~/.local/share/mise/installs/gh/latest/gh_2.100.0_linux_amd64/bin/gh` (real binary, not the wrapper)

* `gh --version`, `gh auth status`, `gh api user` — all return instantly, no loop, no flood

* `claude --version` (2.1.266), `codex --version` (0.153.4), `opencode --version` (1.18.30), `gemini --version` (0.59.0) — all instant

So resolving to an absolute path before executing is confirmed working in production. Appreciate the --tool scoping in this PR (plain mise which "$bin" can pick a same-named binary from another package — that's why resolving from the package's bin-paths is the better shape). Happy to test the branch here if helpful.

Thanks for taking the time to try this fix. but i need to point out one thing, this is no longer using the mise which --tool approach, since that could still confuse same named binaries. it's using a more robust approach as described in the PR body (introduced in #8798)

Keep command-name rejection and path-escape coverage in mise-install-test.sh, which already exercises the generator guard and verifies that an escaping name leaves files outside the wrapper directory intact.

Remove the overlapping command-name block from mise-wrapper-resolution-test.sh. Retain the bin-name rejection tests, which cover the new package-directory lookup, along with wrapper execution and migration coverage.

Validation: mise-install-test.sh and mise-wrapper-resolution-test.sh pass; git diff --check passes.
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed by Claude Opus 5.5 and verified on a disposable Omarchy worker (mise 2026.9.11) against quattro at c05d901. The second opinion (Codex Medium) did not run: its daily review quota was spent, so this review has only one reviewer.

Reproduction. I regenerated the gh wrapper and ran gh --version with an activated mise PATH and ~/.local/bin first, minus __MISE_DIFF. That is the environment a GUI app or service passes on, as described in #7234. With quattro's template the wrapper re-execs itself until timeout kills it at 15 s. With this head it returns at once. With the template reverted it loops again. A wrapper whose package lacks the named binary also loops forever on quattro, and on this head it exits 1 with mise package 'gh' provides no executable '…'. Arguments containing spaces and $(…) reach gh intact.

Suite. I ran ./test/all on the worker at this head. CLI passed, and 3 of 237 shell test files failed. None of them is caused by this change. ascii-test.sh and branding-about-animation-test.sh fail on current quattro too. locate-test.sh fails only at this branch's base, 277 commits behind, and passes on quattro. I also ran a local merge with quattro on the worker: the mise tests (mise-install, mise-work-path, mise-wrapper-quiet-migration, mise-wrapper-resolution) and default-agent all pass, and GitHub reports the branch merges cleanly.

Design. Resolving through mise bin-paths "$package" holds up against mise's source. bin-paths keeps only the requested tool's versions, whereas mise which --tool adds the tool to the full configured toolset and searches all of it, so a same-named binary from another tool can win. The migration only rewrites wrappers that exactly match the stock template, and no later migration on quattro parses that template, so its older timestamp is harmless.

Competing fixes. Several open pull requests fix the same loop: #13090, #13677 and #13769 use mise which --tool, #13470 and #13614 add a re-entry guard that turns the loop into an error, and #9175 and #9583 conflict with quattro. Of these, this one fixes the cause most precisely. Choosing between them is the maintainer's call.

Nothing is needed from you. This now waits on the maintainer, and on a second-opinion review once one can run.

@omarchybot omarchybot removed the verified Omarchy Triage has verified that this issue is ready for final review label Oct 2, 2026
Keep the bin-paths stub beside quattro's new mise ls stub for the Grok registry migration; they answer different subcommands.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Oct 2, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

This branch had stopped merging with quattro. The only conflict was the mise mock in test/shell.d/default-agent-test.sh, where quattro's Grok registry change (#14004) added an ls branch next to this PR's bin-paths branch. I merged quattro into the branch and kept both branches, since they answer different subcommands. That is f941379, pushed here. Nothing else in the PR changed.

Reviewed by Claude Opus 5.5 and by Codex Medium as a second opinion, which ran this time. Its independence is not guaranteed. Tests ran on a disposable Omarchy worker (mise 2026.9.11) against quattro at 821ae58.

Reproduction, at the merge. I regenerated the gh wrapper and ran it with the PATH an activated shell passes on, minus __MISE_*, with ~/.local/bin first. On quattro it loops until timeout kills it at 15 s. At f941379 it returns at once. With the template reverted it loops again. A wrapper for a binary the package does not ship exits 1 with mise package 'gh' provides no executable '…'.

Suite. The mise tests (mise-install, mise-wrapper-resolution, mise-wrapper-quiet-migration, mise-work-path) and default-agent all pass. ./test/cli fails on vscode generated theme references current theme file, and 8 shell test files fail: ascii, branding-about-animation, kernel-headers-migration, launch-browser, network-captive-portal, omarchy-kernel-migration, passwordless-grant-lifecycle and video-background. Every one of those fails the same way on quattro itself, so this PR does not cause them. They do mean the suite is not green.

Second opinion. Codex Medium was given this PR and the seven competing fixes without my conclusion, and it picked this one. It found that mise bin-paths keeps only the requested tool, whereas mise which --tool (used by #13090, #13677 and #13769) searches the whole configured toolset and can run another tool's binary of the same name. #13470 and #13614 only turn the loop into an error, and #9583 falls back to the looping command. It also checked the merge: this PR's migration and quattro's migrations/1790863209.sh work in either order, because the regenerated wrapper still names npm:@xai-official/grok. It raised one minor gap: migrations/1787809285.sh only recognises double-quoted wrappers, so a wrapper the generator writes with %q quoting is not regenerated. That only happens for a package or binary name containing characters like !, $ or \. No Omarchy install path generates one, so I left it alone.

Nothing is needed from you. This waits on the maintainer, who has the competing fixes to choose between.

@greptile-apps

greptile-apps Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[High risk] Changes how wrapper scripts resolve and execute package binaries.

The PR appears safe to merge; no actionable issue was identified.

Summary

The PR changes generated mise wrappers to resolve an executable from the requested package’s bin directories before passing its absolute path to mise x. It also migrates existing wrappers that match the previous template and adds resolution and migration tests.

Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Invoke wrapper] --> B[mise use -g]
  B --> C[mise bin-paths for package]
  C --> D{Executable found?}
  D -- Yes --> E[mise x with absolute path]
  D -- No --> F[Report error and exit]
Loading

Reviews (1) · Last reviewed commit: "Merge quattro into fix/mise-wrapper-reso..."

@jdx

jdx commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

fyi we should not merge this, #9596 is a better fix that removes the wrappers

@imadtg

imadtg commented Oct 7, 2026

Copy link
Copy Markdown
Author

fyi we should not merge this, #9596 is a better fix that removes the wrappers

Agreed. Subscribed to it and will close this PR when it merges

@imadtg
imadtg marked this pull request as draft October 7, 2026 15:44
@omarchybot omarchybot removed the verified Omarchy Triage has verified that this issue is ready for final review label Oct 7, 2026
Zeus-Deus added a commit to Zeus-Deus/omarchy-setup that referenced this pull request Oct 12, 2026
The old fix shadowed omarchy-mise-install in ~/.local/bin, which would
silently outlive any upstream change. The guard instead rewrites only exact
stock wrappers after each update, backs them up first, and never shadows the
packaged generator. A byte-identical legacy override is moved out of PATH;
anything unknown is left alone and reported.

Once the packaged generator resolves binaries itself (omacom/omarchy#8692),
the guard changes nothing and asks to be removed. Wrappers upstream
generates are never flagged, and its migration skips guarded ones.

The feature is opt-in through ./install.sh --mise-wrapper-resolution.
@imadtg imadtg closed this Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mise wrappers still exec-loop when mise x falls back to a PATH lookup (residual case of #6349)

6 participants