Skip to content

Add recursion guard to omarchy-mise-install wrappers - #13470

Open
AnPod wants to merge 2 commits into
omacom:quattrofrom
AnPod:fix/mise-install-recursion-guard
Open

AnPod wants to merge 2 commits into
omacom:quattrofrom
AnPod:fix/mise-install-recursion-guard

Conversation

@AnPod

@AnPod AnPod commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

Summary

When a tool is not installed or mise fails to provide the requested binary, mise x <tool> -- <bin> falls back to searching PATH. Because the wrapper itself is installed in ~/.local/bin, mise re-executes the wrapper script. Without a recursion guard, this creates an unbounded fork loop (~1,000 forks/sec) that saturates the machine until it exhausts process limits.

This emits a tool-specific environment guard variable (_OMARCHY_MISE_GUARD_<COMMAND>) at the top of the generated wrapper so recursive invocations fail fast with exit code 127 and a clear stderr message instead of hanging the machine.

Fixes #13177

Testing

  • Updated test/shell.d/mise-install-test.sh with a test simulating mise x falling back to PATH when an executable is missing.
  • Verified that the wrapper catches the recursion, writes the error to stderr, and exits 127.
  • Ran bash test/shell.d/mise-install-test.sh (all 5 assertions passed).

@chessing234 chessing234 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.

please escape the diagnostic before writing it into the wrapper.

Comment thread bin/omarchy-mise-install Outdated
cat >"$HOME/.local/bin/$command" <<EOF
#!/bin/bash
if [[ -n \${$guard:-} ]]; then
echo "omarchy-mise-install: '$command' recursed; mise could not provide $bin_arg" >&2

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.

please quote the generated diagnostic as shell data too: command is inserted raw inside its double-quoted echo, so an accepted literal command name such as tool$(touch marker) runs that substitution when the recursion guard fires. the actual generator and wrapper create the marker in an isolated fixture; the existing %q escaping on the execution lines does not protect this new line.

AnPod and others added 2 commits October 1, 2026 00:28
When a tool is missing or mise fails to provide the requested binary,
`mise x <tool> -- <bin>` falls back to searching PATH. Because the wrapper
itself lives in `~/.local/bin`, mise finds and re-executes the wrapper,
recursing indefinitely and forking thousands of processes until the
machine exhausts resources.

Emit an environment guard variable (`_OMARCHY_MISE_GUARD_<COMMAND>`) in the
generated wrapper script so recursive executions fail fast with exit code 127
instead of hanging the system.

Fixes omacom#13177
@AnPod
AnPod force-pushed the fix/mise-install-recursion-guard branch from 9fb3bc9 to 8e30031 Compare September 30, 2026 22:28
@greptile-apps

greptile-apps Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium risk] Adds recursion guard to tool installation wrapper script.

Not safe to merge until existing installed wrappers receive the recursion guard.

Findings

  1. P1 Existing wrappers remain unguarded ▶
  2. P2 Distinct commands share guards ▶

Summary

The PR adds a per-command environment guard to generated mise wrappers and tests the missing-binary PATH fallback and diagnostic.

  • The guard stops recursion in newly generated wrappers, but installed wrappers need a rollout path.
  • Lossy command-name normalization can make distinct wrappers share a guard.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Invoke installed wrapper] --> B{Guard present?}
  B -->|Yes| C[Exit 127]
  B -->|No| D[mise use and mise x]
  D --> E{Binary provided?}
  E -->|Yes| F[Run tool]
  E -->|No; PATH finds wrapper| A
Loading

Reviews (1) · Last reviewed commit: "Shell-quote the mise recursion-guard dia..."

Comment thread bin/omarchy-mise-install
Comment on lines 59 to +65
cat >"$HOME/.local/bin/$command" <<EOF
#!/bin/bash
if [[ -n \${$guard:-} ]]; then
printf '%s\n' $diagnostic_arg >&2
exit 127
fi
export $guard=1

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 Existing wrappers remain unguarded

This check is written only when omarchy-mise-install generates a wrapper. Updating Omarchy leaves wrappers already installed in ~/.local/bin unchanged, and this PR adds no migration to rewrite them. If an existing wrapper's tool is missing or does not provide its binary, mise x can still find that wrapper through PATH and recurse until the machine exhausts its process limit. Existing wrappers need a rollout path for the guard.

Comment thread bin/omarchy-mise-install
*) bin_arg="\"$bin\"" ;;
esac

guard="_OMARCHY_MISE_GUARD_$(printf '%s' "$command" | tr -c 'A-Za-z0-9_' '_' | tr '[:lower:]' '[:upper:]')"

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 Distinct commands share guards

The accepted command names my-tool and my_tool both produce _OMARCHY_MISE_GUARD_MY_TOOL. If a tool launched by one wrapper invokes the other wrapper through PATH, the second sees the inherited guard and exits 127 instead of running. This can break a valid combination of user-installed tools.

@jandrusk

jandrusk commented Oct 7, 2026

Copy link
Copy Markdown

Thanks for tackling #13177. The %q quoting of the diagnostic addresses the escaping request. There's one blocking problem with the guard itself, though:

The guard leaks into the real tool's environment. export $guard=1 runs before exec mise x … -- $bin, so the real gh/claude/codex/… process and everything it spawns inherit _OMARCHY_MISE_GUARD_<CMD>=1. Any legitimate nested call through the wrapper then exits 127 with "recursed":

  • gh alias set co --shell 'gh pr checkout "$1"', then gh co 123: the inner gh hits the guard
  • an agent CLI running itself from its own shell tool (claude -p … inside Claude Code, codex inside Codex)

All of the wrappers in install/user/mise.sh are affected. A way out that needs no env var is to resolve the binary through mise and never fall back to PATH. Roughly, the generated wrapper would become (untested sketch, using gh as the example):

#!/bin/bash
export MISE_MINIMUM_RELEASE_AGE=0
mise use -g --quiet "gh" || exit 1
tool=$(mise which "gh" 2>/dev/null)
if [[ -z $tool || $tool == "$HOME/.local/bin/"* ]]; then
  echo "omarchy-mise-install: 'gh' recursed; mise could not provide gh" >&2
  exit 127
fi
exec mise x "gh" -- "$tool" "$@"

Wrappers that are already installed also need a migration to pick up the fix, as Greptile noted. Note that #9583 and #8692 already propose exec-by-resolved-path. Your later #13614 also moves toward mise which and adds the migration, but it still exports the same guard. Folding everything into one PR, and closing this one, would keep a single candidate for #13177.

@jdx

jdx commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

see #9596, that should be the correct fix

@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at 8e30031 against quattro by reading the diff next to the four other open pull requests that fix the same wrapper recursion: #8692, #9583, #9596 and #13614. Nothing was run on a worker, because this pull request is not the one recommended to land.

Two defects in the guard, both visible in the generated wrapper:

  • Nested calls break. export _OMARCHY_MISE_GUARD_<CMD>=1 runs before exec mise x, so the real tool and every process it starts inherit the variable. Any legitimate call back through the same wrapper then exits 127 with "recursed": a gh shell alias that runs gh, or an agent CLI that calls itself from its own shell tool. @jandrusk raised this above, and it holds.
  • The mise wrappers still exec-loop when mise x falls back to a PATH lookup (residual case of #6349) #7234 case stops working instead of running. The wrapper still hands the bare name to mise x. When the tool is installed but ~/.local/bin comes before its install directory on PATH, mise finds the wrapper again, and the guard ends the call with 127, so the tool never runs. The loop stops, but so does the tool. The cause, resolving by name through PATH, is untouched.

Also, foo-bar and foo_bar normalise to the same guard name, and wrappers already installed keep the unguarded template, since there is no migration.

#8692 is the oldest of these fixes. It resolves the binary from the package's own mise bin-paths, exits with an error when the package provides no such binary rather than falling back to PATH, has no inherited guard, and migrates existing wrappers. That covers both #13177 and #7234. Nothing here is missing from it, so there is nothing to carry across. Your later #13614 drops the exported guard and resolves an absolute path, so it does not have the first defect either. #9596 replaces the wrappers with mise's own lazy shims, which is a larger change for the maintainer to weigh separately.

The second opinion, Codex Medium, compared the five diffs separately and also recommends #8692. It found the #7234 failure above. Otherwise it agreed with a conclusion already written down, so its independence is not guaranteed.

The choice between these pull requests is the maintainer's. This one waits on that decision.

@jdx

jdx commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

my 2 cents: if we continue adding complex bash to the wrappers we're going to continue to run into edge-cases. mise's lazy tools i built specifically for omarchy to be able to get rid of them and it has non-omarchy users already validating it

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.

omarchy-mise-install stubs recurse into themselves when the tool is not installed, forking until the machine stalls

5 participants