Skip to content

Exec mise wrappers by resolved path, not by name - #9583

Open
mrdavidlaing wants to merge 4 commits into
omacom:quattrofrom
mrdavidlaing:fix-mise-wrapper-path-resolution
Open

mrdavidlaing wants to merge 4 commits into
omacom:quattrofrom
mrdavidlaing:fix-mise-wrapper-path-resolution

Conversation

@mrdavidlaing

@mrdavidlaing mrdavidlaing commented Sep 1, 2026 •

Copy link
Copy Markdown

4480a142 moved the generated stubs from exec "$bin" to
exec mise x "$package" -- "$bin" so the tool would resolve from mise's install
dir rather than by name through PATH. That narrowed the loop but did not close
it: mise still looks the bare name up in PATH, so it can find the stub again
and exec itself forever, in the same PID, pinning a core.

Reproducing

Four conditions, all required:

  1. ~/.local/bin precedes the tool's mise install dir on PATH;
  2. that install dir is already on PATH — otherwise mise x prepends it and
    the name resolves correctly;
  3. ~/.local/share/mise/shims is on PATH;
  4. the environment carries none of mise's session variables (__MISE_DIFF,
    __MISE_SESSION, MISE_SHELL).
omarchy-mise-install gh

GH=$(dirname "$(mise which gh)")
SH="$HOME/.local/share/mise/shims"

env -i HOME="$HOME" PATH="$HOME/.local/bin:$GH:$SH:/bin" timeout 5 gh --version
echo "rc=$?"   # rc=124 — hangs, ~100% CPU, never prints a version

Condition 4 is why this hides: from an interactive shell (session vars set) the
same command returns in ~50ms. Only non-interactive children hit it — a systemd
service, a git subprocess, an agent runner.

Verified minimal by delta-debugging a 31-entry PATH captured from a real stuck
process; dropping any one of conditions 1-3 fixes it:

PATH result
wrapper : install : shims loops (killed at 5s)
wrapper : install (no shims) ok, 55ms
wrapper : shims (no install dir) ok, 64ms
wrapper alone ok, 61ms
install : shims : … : wrapper (wrapper last) ok, 54ms

Impact

Hit on Omarchy 4.0.2-1 as gh auth git-credential get spinning for 85 minutes
and burning 35 minutes of CPU, with the git operation behind it hung the whole
time — git had invoked the gh stub as its credential.helper. The same loop
broke an agent runner's tool probes: each probe spawned a stub, spun, and was
killed on timeout, so it dropped all three of its providers.

argv alternates on a single PID, no children, state flipping S/R:

/bin/bash /home/<user>/.local/bin/gh auth git-credential get
...
mise x gh -- gh auth git-credential get          <-- same PID, mid-exec

The change

Resolve the binary with mise which and exec that absolute path, so the name is
never handed back for lookup. When resolution fails the stub falls back to the
previous line, keeping today's behavior rather than breaking a tool mise cannot
locate.

Generating a stub from the patched script in an identical sandbox: 62ms
instead of hanging. Generating one from main in that same sandbox still loops,
so the before/after is attributable to this change alone.

Tests

test/shell.d/default-agent-test.sh asserted the stub called mise exactly twice,
which encoded the old contract; updated for the mise which call, with the mise
mock taught to answer which. Added assert_stub_execs_resolved_path, which
fails against main and passes here.

./test/all shows the same 4 failures before and after this change
(omarchy-pkgs checkout missing ×3, and a widget IPC handler count) — all
environmental on my machine, none related.

4480a14 moved the stubs from `exec "$bin"` to `exec mise x "$package" --
"$bin"` so the tool would resolve from mise's install dir rather than by
name through PATH. It narrowed the loop but did not close it: mise still
looks the bare name up in PATH, so it can find the stub again and exec
itself forever, in the same PID, pinning a core.

Four conditions have to line up, and they routinely do: ~/.local/bin
precedes the tool's install dir, that install dir is already on PATH (so
mise has nothing to prepend), the shims directory is on PATH, and the
environment carries none of mise's session variables. That last one is
why this hides — an interactive shell has them set and returns in ~50ms,
while a systemd service, a git subprocess, or an agent runner does not.

Seen in the wild as `gh auth git-credential get` spinning for 85 minutes
and burning 35 minutes of CPU, with the git operation behind it hung the
whole time, after git invoked the gh stub as its credential helper.

Resolve the binary with `mise which` and exec that absolute path, so the
name is never handed back for lookup. When resolution fails the stub
falls back to the previous line, keeping today's behavior rather than
breaking a tool mise cannot locate.

Co-Authored-By: Claude Opus 5 <[email protected]>
@mrdavidlaing
mrdavidlaing changed the base branch from master to quattro September 1, 2026 09:46

@getaaron getaaron left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems reasonable - comments seem a little verbose (especially in tests)

quattro now writes the wrapper's package and bin through %q-quoted $package_arg and $bin_arg, so the resolved-path lines take the same quoting, mise which included. The new resolved-path assertion sits beside quattro's Cursor and Muse stub checks.

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 1, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed and reproduced on a disposable Omarchy worker; the bug is real and this fixes it for newly written wrappers.

Merged quattro into the branch (23b8366) to clear the conflict. quattro now writes the wrapper's package and bin through %q-quoted $package_arg/$bin_arg, so the new mise which and both exec lines take the same quoting. Your new assertion sits beside quattro's Cursor and Muse stub checks. No other change to your code.

Reproduction (your recipe, gh, mise 2026.9.11): with PATH=~/.local/bin:<gh install dir>:<shims> and no mise session variables, the wrapper quattro writes never returns (killed by timeout at 10s, every run). The wrapper this branch writes prints gh version 2.102.0 in about 55ms. Putting quattro's bin/omarchy-mise-install back under this branch's tests makes default-agent-test.sh fail, so the new test does cover the change.

Tests on the worker: default-agent-test.sh, mise-wrapper-quiet-migration-test.sh, hermes-mise-migration-test.sh, mise-install-test.sh, mise-work-path-test.sh and update-mise-grok-test.sh all pass. ./test/cli has one failure, "vscode generated theme references current theme file", which fails the same way on quattro and is unrelated.

Second opinion: Codex Medium reviewed the same head. It agreed that the loop is real, explaining it from mise's exec lookup: an install dir already on PATH gets no priority, so the wrapper ahead of it wins again under the same PID. It agreed the quoting is right and that the wrapper's new shape doesn't break anything that reads wrapper files (omarchy-remove-preinstalls, the mise use -g greps in migrations). Its independence is not guaranteed. It also raised two things I hadn't covered:

  • Wrappers already installed keep looping. This changes only the generator. Every wrapper install/user/mise.sh already wrote on a user's machine keeps the bare-name exec until something regenerates it, and migrations/1787573629.sh deliberately skips wrappers that already carry --quiet. So the machines that hit this bug don't get the fix on update. Fixing that needs a migration that regenerates wrappers of the current form, along the lines of 1787573629. That decides what gets rewritten on every install, so I've left it to the maintainer rather than adding it here.
  • The fallback still execs the bare name when mise which fails, which is the old behaviour and can still loop under the same PATH. It is no worse than today.

It also pointed out that mise which ignores a version pinned in the package argument (node@22 inside a project pinning Node 20). No wrapper Omarchy writes passes a version, so this affects no wrapper Omarchy installs, and I've set it aside.

Waiting on the maintainer: whether this lands as is, or with a migration for the wrappers already installed.

@greptile-apps

greptile-apps Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium risk] Changes how tool wrappers find and execute binaries.

The PR does not appear safe to merge while failed binary resolution can still take the bare-name execution path.

Findings

  1. P1 Fallback restores the loop ▶
  2. P2 Test cannot catch self-execution ▶

Summary

The PR changes generated mise wrappers to resolve a binary path before execution and updates the wrapper tests to check the resulting mise calls.

  • The change addresses bare-name lookup when resolution succeeds.
  • The existing fallback and test-coverage findings remain outstanding.

Reviews (2) · Last reviewed commit: "Merge quattro into fix-mise-wrapper-path..."

Comment thread bin/omarchy-mise-install Resolved
Comment thread bin/omarchy-mise-install
Comment on lines +63 to +64
else
exec mise x $package_arg -- $bin_arg "\$@"

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.

P1 Fallback restores the loop
If mise which returns no path, this branch passes the bare binary name to mise x again. When the wrapper precedes mise's install directory on PATH, that is the same invocation that can select the wrapper and run indefinitely. A failed resolution should not return to the self-recursing path.

Comment on lines +160 to +165
"$ROOT/bin/omarchy-mise-install" "$package" "$command"
OMARCHY_TEST_MISE_WHICH="/opt/resolved/$command" "$test_home/.local/bin/$command" --version
mapfile -t mise_calls <"$mise_history"

[[ ${mise_calls[2]} == "x $package -- /opt/resolved/$command --version" ]] ||
fail "$command lazy stub execs the resolved path, not the bare name"

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.

P2 Test cannot catch self-execution
The new test supplies a fixed resolved path and checks only what the mise x mock logs. The mock never executes the target, and the wrapper directory is not on the test PATH. A self-exec loop under the PATH ordering this change targets would therefore go undetected. A bounded execution test with the wrapper ahead of the install directory would cover that risk.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@omarchybot

Copy link
Copy Markdown
Collaborator

Checked Greptile's three inline findings against the source at the same head (23b8366), and Codex Medium reviewed them separately. Nothing on the branch has changed since the review above, so the worker results there still stand.

  • Existing wrappers remain unchanged: correct, and the same gap as the first point above. migrations/1787573629.sh only parses mise use -g "<pkg>" without --quiet, so it cannot pick up the current form, and it has already run on updated machines. The wrappers that hit this bug need a new migration to get the fix.
  • Fallback restores the loop: correct. When mise which prints nothing, bin/omarchy-mise-install line 64 writes the bare-name exec mise x, which is the call that loops. It is no worse than quattro, but Codex now thinks it should be fixed before this lands rather than left. There are two ways to fix it, and they behave differently. One is to print an error and exit, which stops the hang but breaks any tool that mise x can run and mise which cannot find. The other is to drop ~/.local/bin from PATH for that one exec, which keeps such tools running but hides the other wrappers from them. Choosing between them changes what users see, so I have not pushed either.
  • Test cannot catch self-execution: correct as far as it goes. The mise mock records its arguments and never runs the target. The new assertion still fails if the resolved branch goes back to the bare name, but it cannot show that a real run finishes. The real loop was reproduced on the worker instead (see above). A bounded run with the wrapper directory on PATH would cover it in the suite.

Still waiting on the maintainer: whether this lands as it is, or with a migration for installed wrappers and a different fallback.

@omarchybot omarchybot removed the verified Omarchy Triage has verified that this issue is ready for final review label Oct 2, 2026
quattro's default-agent test gained an `ls` branch in its mise mock for the npm Grok migration, beside this branch's `which` branch; both are kept. quattro now installs Grok as mise's first-party `grok`, which the resolved-path assertion already uses.

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

quattro moved again and this stopped merging cleanly, so I merged quattro into the branch once more (32a83d9). The only conflict was the mise mock in test/shell.d/default-agent-test.sh: quattro added an ls branch for the Grok migration next to this branch's which branch, and both are kept. quattro now installs Grok as mise's own grok package, which the new resolved-path assertion already uses. Your code is unchanged.

Re-checked on a disposable Omarchy worker at 32a83d9. I reran the reproduction with real mise (2026.9.11) and gh, with PATH=~/.local/bin:<gh install dir>:<shims> and no mise session variables. The wrapper quattro writes still hangs until timeout kills it at 10s. The wrapper this branch writes prints gh version 2.102.0 in about 55ms. Putting quattro's generator back in brings the hang back, and makes default-agent-test.sh fail. These all pass: default-agent-test.sh, mise-wrapper-quiet-migration-test.sh, hermes-mise-migration-test.sh, mise-install-test.sh, mise-work-path-test.sh, agent-account-test.sh and agent-usage-grok-test.sh. ./test/cli has one failure, "vscode generated theme references current theme file", and it fails the same way on quattro itself.

Second opinion: Codex Medium reviewed the merge and found nothing new. Its independence is not guaranteed. It confirmed that both mock branches survive. It found that nothing quattro added since the last merge breaks on the new wrapper shape: migrations/1790863209.sh, omarchy-default-agent and omarchy-remove-preinstalls all look for the package text or the mise use -g line, and both are still there.

The two points from the earlier review are still open and unchanged by this merge. Wrappers already on users' machines are not regenerated. When mise which prints nothing, the fallback still execs the bare name.

Waiting on the maintainer: whether this lands as it is, or with a migration for installed wrappers and a different fallback.

quattro dropped OMARCHY_TEST_MISSING_COMMAND from the install/user/mise.sh source line in default-agent-test.sh when Kimi became a selectable agent (omacom#7261); take its line and keep this branch's resolved-path assertion above it.

quattro's new kimi-agent-test.sh expects the wrapper to call mise twice; the wrapper now asks `mise which kimi` in between, so the expected sequence includes it.

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

Copy link
Copy Markdown
Collaborator

quattro moved again and this stopped merging cleanly, so I merged quattro into the branch (9f29a48). Two things needed adjusting, both in tests:

  • test/shell.d/default-agent-test.sh: quattro now sources install/user/mise.sh without OMARCHY_TEST_MISSING_COMMAND=cursor-agent (from Add Kimi as a selectable default coding agent #7261, which added Kimi). I took quattro's line and kept your resolved-path assertion above it.
  • test/shell.d/kimi-agent-test.sh: this test is new on quattro. Its mise mock logs every call and expected the wrapper to call mise twice. Your wrapper asks mise which kimi in between, so the test failed after the merge. The expected sequence now includes that call. Codex caught this one.

Your code in bin/omarchy-mise-install is unchanged.

Re-checked on a disposable Omarchy worker at 9f29a48. The reproduction used real mise (2026.9.11) and gh, with PATH=~/.local/bin:<gh install dir>:<shims> and no mise session variables. The wrapper quattro writes still hangs until timeout kills it at 10s. The wrapper this branch writes prints gh version 2.102.0 in about 150ms. Putting quattro's generator back makes default-agent-test.sh fail. These all pass, along with ./test/cli: default-agent-test.sh, kimi-agent-test.sh, every mise-* test, the Hermes mise tests, agent-account-test.sh, agent-account-exec-test.sh, agent-usage-grok-test.sh and agent-usage-codex-scanner-test.sh.

Second opinion: Codex Medium reviewed the merge over two rounds. In the first it found the Kimi test failure above. In the second it found nothing more. It checked the scripts and tests on quattro that read wrapper files: the exec mise x checks in mise-wrapper-quiet-migration-test.sh look for a substring and still match, and omarchy-agent-usage-codex still finds mise use in the wrapper.

The two points from the earlier reviews are still open, and this merge does not change them. Wrappers already installed on users' machines are not regenerated. When mise which prints nothing, the fallback still execs the bare name.

Waiting on the maintainer: whether this lands as it is, or with a migration for installed wrappers and a different fallback.

@omarchybot omarchybot removed the verified Omarchy Triage has verified that this issue is ready for final review label Oct 28, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

quattro moved again and this conflicts once more, but I have not merged it in this time: since my last comment, #9596 (merged 2026-10-18, closing #7234) fixed the loop a different way, and merging this on top of it now would cause a problem of its own.

What #9596 changed. Omarchy's default CLI tools are now declared as mise lazy tools in etc/mise/conf.d/omarchy-tools.toml, so install/user/mise.sh no longer writes wrappers into ~/.local/bin at all, and migrations/1791382872.sh deletes the wrappers already on disk. Nothing on quattro outside old migrations and tests calls bin/omarchy-mise-install any more.

Checked on a disposable Omarchy worker against quattro at d367a56, with mise 2026.10.24, using your recipe (env -i, PATH=~/.local/bin:<gh install dir>:<shims>:/bin):

  • As quattro sets things up, there is no ~/.local/bin/gh, and gh --version returns in 19ms.
  • A wrapper written by quattro's generator still loops until timeout kills it at 10s. One written by this branch's generator returns in 74ms. So your fix still works for the wrappers it writes, but quattro no longer writes any for the defaults.

Why it shouldn't land as it is. Migrations still pending on a 4.0.x machine (1787215824 for hey, 1787573629's regeneration and others, none of them in v4.0.6) call the generator during the upgrade to 4.5, and then 1791382872 removes only wrappers that match its five known templates byte for byte. On the worker, I ran 1787215824 and 1787573629 over a pre---quiet gh wrapper. With quattro's generator, 1791382872 recognises and removes both the gh and the hey wrappers. With this branch's generator it recognises neither. Those wrappers would stay in ~/.local/bin and run mise use -g on every call, putting back the latest entries the migration removes so the tools can update themselves.

Second opinion: Codex Medium and muse-wonder (via pi, thinking high) reviewed this with the same questions, statically. Both confirmed the cleanup regression from the migration code. Codex recommends closing this as superseded by #9596. muse-wonder pointed out two cases #9596 does not cover. First, kimi is declared as a lazy tool, but it is missing from 1791382872's removal list, so a kimi wrapper written by migrations/1786967403.sh survives in the looping form. Second, anyone who still runs omarchy-mise-install by hand gets the old wrapper. Their independence is not guaranteed.

Nothing was pushed to your branch this time. Waiting on the maintainer to decide between closing this as superseded by #9596, with the kimi gap fixed in #9596's cleanup, or keeping it with this wrapper shape added to 1791382872's templates. Thanks, @mrdavidlaing, for the precise reproduction; it is still the recipe used to check this.

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.

3 participants