Skip to content

perf(activate): skip redundant initial bash prompt hook - #11131

Merged
jdx merged 1 commit into
mainfrom
codex/bash-skip-first-prompt
Jul 20, 2026
Merged

jdx merged 1 commit into
mainfrom
codex/bash-skip-first-prompt

Conversation

@jdx

@jdx jdx commented Jul 20, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • skip Bash's first PROMPT_COMMAND hook after activation already refreshed the environment
  • clear the one-shot skip when a directory-change hook refreshes the environment first
  • remove the one-shot state during deactivation
  • update focused e2e coverage and Bash activation snapshots

Why

mise activate bash performs an immediate hook-env, then the first prompt invokes hook-env again. With an unchanged session, that second invocation exits early but still pays process and runtime startup costs.

In an isolated empty configuration using the debug build, a paired benchmark through the first Bash prompt improved from 36.91 ms to 29.30 ms on average across 30 runs, saving 7.60 ms. Absolute debug timings are machine-specific; the comparison isolates the redundant prompt dispatch.

Validation

  • cargo test shell::bash::tests
  • mise run test:e2e env/test_bash_first_prompt_after_activate env/test_bash_consecutive_prompt_runs cli/test_bash_duplicate_trust_warning
  • mise run lint-fix
  • pre-commit mise run lint

Note

Low Risk
Localized bash shell-hook timing change with explicit chpwd interaction and e2e coverage; no auth or data-path changes.

Overview
Bash activation now sets a one-shot __MISE_BASH_SKIP_FIRST_PROMPT after the initial _mise_hook / hook-env, so the first PROMPT_COMMAND does not invoke hook-env again. The flag is cleared on that skip (or when a chpwd hook already refreshed the env via __MISE_BASH_CHPWD_RAN), and deactivation unsets the variable.

The e2e script test_bash_first_prompt_after_activate is updated to assert the first prompt skips hook-env and the second runs it; Bash activate/deactivate snapshots match the new shell snippets.

Reviewed by Cursor Bugbot for commit 1100efb. Bugbot is set up for automated code reviews on this repo. Configure here.

Summary by CodeRabbit

  • Bug Fixes
    • Improved Bash shell activation so the first prompt avoids running redundant environment updates.
    • Ensured subsequent prompts continue to refresh the environment normally.
    • Added cleanup of temporary activation state when deactivating.
  • Tests
    • Added coverage verifying first-prompt behavior, state clearing, and normal hook execution on later prompts.

@coderabbitai

coderabbitai Bot commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Central YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: 2a26076a-4ccf-40b2-b426-faedd05f637d

📥 Commits

Reviewing files that changed from the base of the PR and between 996b1b9 and 1100efb.

⛔ Files ignored due to path filters (2)
  • src/shell/snapshots/mise__shell__bash__tests__activate.snap is excluded by !**/*.snap
  • src/shell/snapshots/mise__shell__bash__tests__deactivate.snap is excluded by !**/*.snap
📒 Files selected for processing (3)
  • e2e/env/test_bash_first_prompt_after_activate
  • src/assets/bash/activate.sh
  • src/assets/bash/deactivate.sh

📝 Walkthrough

Walkthrough

Bash activation now skips redundant hook-env execution on the first prompt, clears the skip state afterward, and removes it during deactivation. The end-to-end test verifies first- and second-prompt behavior.

Changes

Bash prompt flow

Layer / File(s) Summary
First prompt skip lifecycle
src/assets/bash/activate.sh, src/assets/bash/deactivate.sh, e2e/env/test_bash_first_prompt_after_activate
Activation initializes __MISE_BASH_SKIP_FIRST_PROMPT; the first prompt clears the flag and skips hook-env, the second prompt runs it, and deactivation removes the flag. End-to-end assertions cover this sequence.

Estimated code review effort: 2 (Simple) | ~10 minutes

Poem

A rabbit hops where prompts begin,
The first hook waits, then lets one in.
The flag fades softly out of sight,
The second prompt runs just right.
Bash burrows cheerfully tonight!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main optimization: skipping the redundant initial Bash prompt hook during activation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR eliminates a redundant hook-env call that was occurring on the very first PROMPT_COMMAND invocation after mise activate bash, since activation already runs hook-env immediately via _mise_hook. The skip is implemented as a one-shot variable (__MISE_BASH_SKIP_FIRST_PROMPT) that is consumed and cleared on first prompt, with correct coordination when a cd fires before the first prompt.

  • activate.sh sets __MISE_BASH_SKIP_FIRST_PROMPT=1 after the initial _mise_hook call; the prompt hook checks for it and returns early exactly once, also clearing it from the chpwd branch to avoid silently skipping the next real prompt.
  • deactivate.sh adds the corresponding unset to keep the environment clean after deactivation.
  • The e2e test is updated to assert the skip-then-run sequence using a mock mise() sentinel file, and both shell snapshots are regenerated consistently.

Confidence Score: 5/5

Safe to merge — the change touches only the Bash activation/deactivation scripts and a focused e2e test, with no modifications to core Rust code or cross-shell behavior.

The one-shot skip flag is introduced, consumed, and cleaned up symmetrically across all code paths: normal first-prompt skip, chpwd-before-first-prompt, deactivation, and re-activation. Exit-status preservation is maintained in every branch of _mise_hook_prompt_command. The e2e test exercises both the skip path and the subsequent normal-run path.

No files require special attention; the e2e test leaves a bash-hook-ran sentinel file in $PWD that is never explicitly removed, but this is inconsequential in isolated test environments.

Important Files Changed

Filename Overview
src/assets/bash/activate.sh Adds __MISE_BASH_SKIP_FIRST_PROMPT one-shot flag to skip the redundant first PROMPT_COMMAND hook-env after activation; also clears it when the chpwd path fires first. Logic and exit-status preservation look correct.
src/assets/bash/deactivate.sh Adds unset __MISE_BASH_SKIP_FIRST_PROMPT to properly clean up the new one-shot flag on deactivation.
e2e/env/test_bash_first_prompt_after_activate Test updated to verify skip-on-first-prompt and run-on-second-prompt behavior using a mock mise() sentinel file; the marker file is never cleaned up but is likely harmless in isolated CI environments.
src/shell/snapshots/mise__shell__bash__tests__activate.snap Snapshot updated to match the new skip-flag logic in activate.sh; change is consistent with the source file.
src/shell/snapshots/mise__shell__bash__tests__deactivate.snap Snapshot updated to reflect the new unset __MISE_BASH_SKIP_FIRST_PROMPT line in deactivate.sh; consistent with the source.

Reviews (1): Last reviewed commit: "perf(activate): skip redundant initial b..." | Re-trigger Greptile

@github-actions

Copy link
Copy Markdown
Contributor

Hyperfine Performance

mise x -- echo

Command Mean [ms] Min [ms] Max [ms] Relative
mise-2026.7.7 x -- echo 21.7 ± 1.3 18.9 27.6 1.00
mise x -- echo 22.9 ± 2.4 18.2 31.7 1.05 ± 0.12

mise env

Command Mean [ms] Min [ms] Max [ms] Relative
mise-2026.7.7 env 23.3 ± 1.3 20.3 29.8 1.00
mise env 24.0 ± 1.7 19.5 32.1 1.03 ± 0.09

mise hook-env

Command Mean [ms] Min [ms] Max [ms] Relative
mise-2026.7.7 hook-env 25.2 ± 1.9 21.2 32.0 1.20 ± 0.12
mise hook-env 21.0 ± 1.5 17.5 26.8 1.00
✅ Performance improvement for hook-env is 20%

mise ls

Command Mean [ms] Min [ms] Max [ms] Relative
mise-2026.7.7 ls 17.9 ± 1.0 15.9 25.4 1.10 ± 0.09
mise ls 16.3 ± 1.0 14.6 23.9 1.00

xtasks/test/perf

Command mise-2026.7.7 mise Variance
install (cached) 165ms 170ms -2%
ls (cached) 65ms 61ms +6%
bin-paths (cached) 67ms 65ms +3%
task-ls (cached) 131ms 133ms -1%

@jdx
jdx merged commit 4a7f860 into main Jul 20, 2026
48 of 50 checks passed
@jdx
jdx deleted the codex/bash-skip-first-prompt branch July 20, 2026 20:05
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.

1 participant