Skip to content

fix(bootstrap): preserve argv[0] for shim dispatch#8521

Merged
jdx merged 1 commit into
jdx:mainfrom
tak848:fix-bootstrap-argv0
Mar 20, 2026
Merged

fix(bootstrap): preserve argv[0] for shim dispatch#8521
jdx merged 1 commit into
jdx:mainfrom
tak848:fix-bootstrap-argv0

Conversation

@tak848

@tak848 tak848 commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

Summary

mise generate bootstrap currently emits:

exec "$MISE_INSTALL_PATH" "$@"

That drops the original invocation name.

When the generated bootstrap is used through a shim symlink such as claude -> /path/to/mise, the final mise process sees the cached binary path as argv[0] instead of claude, so shim dispatch breaks.

Direct usage of the generated bootstrap as mise itself should remain unchanged.

That direct usage is already documented and expected to work, for example:

mise generate bootstrap >./bin/mise
chmod +x ./bin/mise
PATH="./bin:$PATH" mise install

This change switches the generated exec line to:

exec -a "$0" "$MISE_INSTALL_PATH" "$@"

That preserves the shim name when invoked via symlink while still behaving like normal mise when the generated script itself is installed as mise.

Test plan

  • ./e2e/run_test generate/test_generate_bootstrap
  • verify direct ./bin/mise version still works
  • verify generated bootstrap output contains exec -a "$0"
  • verify localized bootstrap output still works

@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 addresses a critical issue in mise's bootstrap generation where the original invocation name (argv[0]) was dropped, causing shim dispatch to fail when mise was called through a symlink. The core change updates the generated bootstrap script to explicitly preserve argv[0] using exec -a "$0", ensuring correct behavior for both direct and symlinked invocations.

Highlights

  • Bootstrap script exec command: Modified the mise generate bootstrap output to use exec -a "$0" "$MISE_INSTALL_PATH" "$@" instead of exec "$MISE_INSTALL_PATH" "$@".
  • Shim dispatch fix: This change preserves the original invocation name (argv[0]), resolving an issue where shim dispatch would break when mise was invoked via a symlink.
  • Test coverage: Added new assertions to the e2e/generate/test_generate_bootstrap script to verify the presence of the exec -a "$0" command in generated bootstrap scripts.
Changelog
  • e2e/generate/test_generate_bootstrap
    • Added assertions to check for the exec -a "$0" command in the generated bootstrap scripts.
  • src/cli/generate/bootstrap.rs
    • Changed the exec command in the generated bootstrap script from exec "$MISE_INSTALL_PATH" "$@" to exec -a "$0" "$MISE_INSTALL_PATH" "$@".
Activity
  • Verified that direct usage of ./bin/mise version continues to function as expected.
  • Confirmed that the generated bootstrap output now correctly contains exec -a "$0".
  • Ensured that localized bootstrap output still works.
  • Executed the e2e/run_test generate/test_generate_bootstrap test suite.
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.

@tak848 tak848 force-pushed the fix-bootstrap-argv0 branch from 52088d8 to 442da75 Compare March 9, 2026 00:30

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request addresses an issue where the original invocation name (argv[0]) was not preserved when using a generated bootstrap script as a symlink. The fix is correct for the file changed. However, the same issue exists in other parts of the codebase that generate scripts. I've added a review comment with suggestions to fix these related issues for consistency, as I am unable to comment on files not included in this pull request's diff.

}}
__mise_bootstrap
exec "$MISE_INSTALL_PATH" "$@"
exec -a "$0" "$MISE_INSTALL_PATH" "$@"

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.

high

While this change correctly fixes the issue for the bootstrap script, the same problem exists in other script-generating commands. To ensure consistent behavior and fully resolve the argv[0] preservation issue, similar changes are needed in other files.

Since I can only comment on changed files, I'm leaving this feedback here. Please consider applying fixes to the following:

  1. src/cli/generate/tool_stub.rs:
    In the wrap_with_bootstrap function, the exec call does not preserve argv[0]. It should be changed from:

    exec "$MISE_BIN" tool-stub "$0" "$@"

    to:

    exec -a "$0" "$MISE_BIN" tool-stub "$0" "$@"
  2. src/cli/generate/task_stubs.rs:
    The generated script in the generate function uses #!/bin/sh and an exec call that doesn't preserve argv[0]. This should be updated to use bash and exec -a.
    Change from:

    #!/bin/sh
    exec {mise_bin} run {display_name} "$@"

    to:

    #!/usr/bin/env bash
    exec -a "$0" {mise_bin} run {display_name} "$@"

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.

This is out of scope for this PR.

This change is limited to mise generate bootstrap. Other generators should be evaluated separately.

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.

Correction: this is not the same issue.

This PR is limited to mise generate bootstrap, where preserving argv[0] is required for shim dispatch.

tool_stub.rs passes the original path explicitly to tool-stub, and task_stubs.rs invokes mise run {display_name} directly, so they do not depend on argv[0] in the same way.

@tak848 tak848 force-pushed the fix-bootstrap-argv0 branch 2 times, most recently from a4fec89 to 2089ed5 Compare March 9, 2026 00:59
@tak848 tak848 force-pushed the fix-bootstrap-argv0 branch 3 times, most recently from 07005f2 to ff67a09 Compare March 18, 2026 21:22
@tak848 tak848 marked this pull request as ready for review March 18, 2026 21:44
@greptile-apps

greptile-apps Bot commented Mar 18, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a one-liner in the generated bootstrap script so that argv[0] is preserved when the script is invoked via a shim symlink (e.g. claude -> /path/to/bootstrap). The change swaps exec "$MISE_INSTALL_PATH" "$@" for exec -a "$0" "$MISE_INSTALL_PATH" "$@", which is the standard POSIX-adjacent idiom for forwarding the caller's name through a shell wrapper.

Key points:

  • Correctnessexec -a name is supported by bash (the shebang requires #!/usr/bin/env bash) including macOS's default bash 3.2, so there are no portability regressions.
  • Backward compatibility – when the script is invoked directly as ./bin/mise, $0 equals ./bin/mise, so mise still sees itself as mise and behaves identically to before.
  • Test coverage – both the regular (-w) and localized (-l -w) bootstrap paths now assert the new exec -a "$0" line is present in the generated file; SC2016 suppression is correctly applied to avoid false shellcheck warnings on the single-quoted $0.

Confidence Score: 5/5

  • This PR is safe to merge — the change is a one-line, well-understood shell idiom with no side-effects on existing usage.
  • The fix is minimal and targeted, uses a well-supported bash built-in flag (exec -a), preserves all existing behaviour for direct invocations, and is covered by updated e2e tests for both bootstrap modes.
  • No files require special attention.

Important Files Changed

Filename Overview
src/cli/generate/bootstrap.rs Single-line fix replacing exec "$MISE_INSTALL_PATH" "$@" with exec -a "$0" "$MISE_INSTALL_PATH" "$@" to preserve argv[0] through shim dispatch; change is minimal and correct.
e2e/generate/test_generate_bootstrap Test updated to assert the new exec -a "$0" line appears in the generated bootstrap for both regular and localized modes; SC2016 suppression is appropriate for single-quoted shell variables.

Sequence Diagram

sequenceDiagram
    participant User as User / Shell
    participant Symlink as claude (symlink)
    participant Bootstrap as Bootstrap Script ($0="claude")
    participant Mise as mise binary

    Note over User,Mise: Shim dispatch via symlink (new behaviour)
    User->>Symlink: invoke claude
    Symlink->>Bootstrap: exec bootstrap ($0 = "claude")
    Bootstrap->>Bootstrap: __mise_bootstrap() — install if needed
    Bootstrap->>Mise: exec -a "claude" $MISE_INSTALL_PATH "$@"
    Note right of Mise: argv[0] == "claude" → shim dispatch works ✓

    Note over User,Mise: Direct invocation (unchanged behaviour)
    User->>Bootstrap: ./bin/mise install ($0 = "./bin/mise")
    Bootstrap->>Bootstrap: __mise_bootstrap() — install if needed
    Bootstrap->>Mise: exec -a "./bin/mise" $MISE_INSTALL_PATH "$@"
    Note right of Mise: argv[0] == "./bin/mise" → normal mise ✓
Loading

Last reviewed commit: "fix(bootstrap): pres..."

@tak848

tak848 commented Mar 18, 2026

Copy link
Copy Markdown
Contributor Author

coverage-7 failure is unrelated to this PR — caused by Java EA version bump (26 → 27). Fix is tracked in #8634

Signed-off-by: tak848 <pairs_char0j@icloud.com>
@tak848 tak848 force-pushed the fix-bootstrap-argv0 branch from ff67a09 to 01bce2f Compare March 20, 2026 05:41

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 01bce2fc3c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

}}
__mise_bootstrap
exec "$MISE_INSTALL_PATH" "$@"
exec -a "$0" "$MISE_INSTALL_PATH" "$@"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve absolute argv0 when re-executing bootstrap binary

Using exec -a "$0" "$MISE_INSTALL_PATH" "$@" forwards relative invocation names (for example ./bin/mise) into argv[0]. On Linux, activate intentionally uses ARGV0 as the executable path (src/cli/activate.rs), so eval "$(./bin/mise activate bash)" now emits hooks that call ./bin/mise and those hooks fail after changing directories away from the project root. Before this change, argv[0] was the absolute install path, so the generated activation hooks remained valid across directories.

Useful? React with 👍 / 👎.

@jdx jdx merged commit 9c9514c into jdx:main Mar 20, 2026
34 checks passed
This was referenced Mar 20, 2026
tak848 added a commit to tak848/dotfiles that referenced this pull request Mar 22, 2026
upstream PR jdx/mise#8521 で修正されたため、
sed による後処理が不要になった。
tak848 added a commit to tak848/dotfiles that referenced this pull request Mar 22, 2026
…eep・パーミッション追加 (#491)

## Summary

- **mise bootstrap**: upstream PR jdx/mise#8521 で `exec -a "$0"`
が修正されたため、Taskfile.yaml と mise-bootstrap.yaml の sed ワークアラウンドを削除
- **Claude Code statusline**: rate limit (5h/7d) の使用率表示を追加。Pro/Max
サブスクライバー向け、rate_limits が無い場合は非表示
- **Codex config.toml**: experimental 機能 `prevent_idle_sleep`
を有効化(実行中のアイドルスリープ防止)
- **Claude Code settings**: 不足・推奨パーミッションを追加
  - 汎用コマンド: `wc`, `diff`, `file`, `date`
  - mise: `latest`, `search`, `--version`, `ls`, `current`, `plugins ls`
  - gh: `issue view`, `search`, `release view`, `pr status`, `repo view`
  - WebFetch: `docs.anthropic.com`, `docs.devin.ai`, `devin.ai`
  - MCP: `mcp__devin__read_wiki_contents`

## Test plan

- [ ] `task mise:bootstrap` で sed なしに bootstrap スクリプトが正しく生成されることを確認
- [ ] Claude Code statusline で rate limit が表示されることを確認
- [ ] `chezmoi apply` 後に Codex の `/experimental` で prevent_idle_sleep
が有効になっていることを確認
- [ ] 追加パーミッションが正しく動作することを確認

(by Claude Code)
<!-- devin-review-badge-begin -->

---

<a href="https://app.devin.ai/review/tak848/dotfiles/pull/491"
target="_blank">
  <picture>
<source media="(prefers-color-scheme: dark)"
srcset="https://static.devin.ai/assets/gh-open-in-devin-review-dark.svg?v=1">
<img
src="https://static.devin.ai/assets/gh-open-in-devin-review-light.svg?v=1"
alt="Open with Devin">
  </picture>
</a>
<!-- devin-review-badge-end -->
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