Skip to content

Guard mise stubs against PATH recursion when a tool is missing - #13614

Open
AnPod wants to merge 5 commits into
omacom:quattrofrom
AnPod:cursor/fix-mise-stub-recursion-e0d3
Open

AnPod wants to merge 5 commits into
omacom:quattrofrom
AnPod:cursor/fix-mise-stub-recursion-e0d3

Conversation

@AnPod

@AnPod AnPod commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #13177

mise x … -- bin falls back to PATH when the tool has no matching binary, which re-executes the ~/.local/bin stub until the machine stalls.

Change

  • Resolve installed binaries via mise which (absolute path) instead of PATH fallback
  • Add a per-command re-entry guard and migrate unguarded quiet wrappers
  • Cover install wrappers and migrations in shell tests

Test plan

  • bash test/shell.d/mise-install-test.sh
  • bash test/shell.d/mise-stub-recursion-migration-test.sh

cursoragent and others added 2 commits September 29, 2026 21:07
mise x falls back to PATH when a tool has no matching binary, so the
stub in ~/.local/bin re-executes itself until the machine stalls.
Use mise which and exec the real path instead (omacom#13177).

Co-authored-by: AnPod <[email protected]>
mise x falls back to PATH when the tool has no matching binary, which
re-executes the ~/.local/bin stub until the machine stalls. Add a
per-command re-entry guard and regenerate unguarded quiet wrappers.

Co-authored-by: AnPod <[email protected]>
@cursor
cursor Bot force-pushed the cursor/fix-mise-stub-recursion-e0d3 branch from 7b02c43 to af64637 Compare September 29, 2026 21:10

@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 keep package and command arguments inert in the generated wrapper.

Comment thread bin/omarchy-mise-install Outdated
# which finds this stub again. Fail fast rather than recursing until the machine
# runs out of processes.
if [ -n "\$$guard" ]; then
printf '%s: mise could not provide "%s" from tool "%s" (is it installed?)\\n' "$command" "$bin" "$package" >&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 shell-quote the values interpolated into this diagnostic as well: $command, $bin and $package are written raw into the generated shell source, undoing the escaping above. a package argument containing a literal $(...) remains inert on the base revision but executes that substitution on the new re-entry error path; reuse the escaped arguments when generating the printf call.

@greptile-apps

greptile-apps Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[High risk] Changes how tool wrappers resolve and execute binaries.

The PR appears safe to merge; no actionable new failure was established in the changed code.

Summary

The PR replaces PATH-based mise wrapper execution with resolution of an executable from the requested tool and adds a migration for older unguarded wrappers. Tests cover missing binaries, path validation, nested invocation, and migration behavior.

Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Invoke wrapper] --> B[mise use]
  B --> C[mise which and mise where]
  C --> D{Executable inside tool install?}
  D -->|Yes| E[mise x with absolute path]
  D -->|No| F[Exit 127]
Loading

Reviews (2) · Last reviewed commit: "Merge remote-tracking branch 'upstream/q..." · Reviewed by Greptile

Comment thread bin/omarchy-mise-install Resolved
Comment thread bin/omarchy-mise-install Resolved
@jandrusk

jandrusk commented Oct 7, 2026

Copy link
Copy Markdown

Thanks for this. One behavior problem with the guard that I don't think has been raised yet:

The guard is inherited by the real tool. The stub runs export _OMARCHY_MISE_GUARD_<CMD>=1 and then exec mise x … -- <bin>, so the actual program and everything it spawns keeps that variable. Any later, legitimate run of the same command from inside it hits the stub with the guard set and gets exit 127 "mise could not provide …". Examples: an agent running codex exec inside a codex session, a shell or tmux pane opened from the tool, or a tool that re-execs itself by name. That turns a rare missing-tool case into a common false failure.

A fix that doesn't leak state is to resolve the binary from the tool itself and exec it by absolute path, which is what the PR description says it does, though the diff still uses mise x … -- $bin_arg:

bin_path=$(mise which --tool <package> <bin>) || {
  printf '%s: mise could not provide "%s" from tool "%s"\n' <command> <bin> <package> >&2
  exit 127
}
exec "$bin_path" "$@"

That also covers greptile's point about PATH picking up an unrelated executable. Also, #13470 is your earlier PR for the same issue, so one of the two should be closed.

@omarchybot

Copy link
Copy Markdown
Collaborator

I reviewed this at 4d972c8 against quattro by reading the diff alongside the four other open pull requests for the same wrapper recursion: #8692, #9583, #9596 and #13470. Nothing ran on a worker, because this is not the pull request recommended to land.

At this head the exported guard @jandrusk described is gone. The wrapper now resolves the binary from the tool and executes it by absolute path, so nested calls through the same wrapper work, and a missing binary exits 127 instead of falling back to PATH. That fixes both #13177 and #7234. Three problems remain:

  • An existing test breaks. test/shell.d/default-agent-test.sh was not updated. Its mock mise prints nothing for which, so every generated wrapper in that test now exits 127. Its assertion also still expects x to be the second mise call, straight after use, while the wrapper now calls which and where first.
  • The binary runs under its canonical name. The wrapper readlink -fs the resolved binary and executes the target, so a tool that is a symlink runs under its target's name, not the name it was installed as. That breaks any tool that dispatches on its own name. A tool whose symlink points outside mise where is refused outright.
  • mise which --tool does not limit the search to that package. The containment check against mise where rejects a result from another package rather than finding the right one. Resolve mise wrapper binaries before execution #8692 searches only the package's own mise bin-paths.

#8692 is the oldest of these fixes. It resolves the binary from the package's mise bin-paths, stops with an error when the package has no such executable, has no inherited guard, migrates existing wrappers and updates default-agent-test.sh. The fixes are similar, and this one is not clearly better, so #8692 is the one recommended to land. This pull request also rejects a binary that resolves back to the wrapper itself. That only matters if a package's own bin directory links back into ~/.local/bin, so I am not carrying it across.

The second opinion, Codex Medium, compared the five diffs separately and also recommends #8692. It found the default-agent-test.sh failure and the symlink behaviour above, and I checked both against the source. It would carry the self-resolution check into #8692, where I would not. On the choice itself it agreed with a conclusion already written down on #13470, so its independence is not guaranteed.

Which of these lands is the maintainer's call. This one is waiting on that decision.

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