Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mise run, mise exec: uses previous value of removed env var on first run after var removal #2895

Open
powerman opened this issue Nov 2, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@powerman
Copy link
Contributor

powerman commented Nov 2, 2024

Describe the bug
This is clearly a shell "activate" mode issue. Maybe it's even not a bug, but an UX issue. Maybe it's good enough to just document it instead of fixing.

If mise config is edited not in the current shell (e.g. in IDE) and some env.var is removed (using any way: commented, set to false, deleted), and first executed command after this edit is mise run or mise exec, then they'll use previous (deleted) value for this variable. This happens because current shell had no chance to execute mise hook-env after edit thus current shell still have this var set to old value and mise run/exec gets it in same way as any manually set in a shell variable.

To Reproduce
Use two shells:

sh1$ mkdir mise-del-var-bug
sh1$ cd mise-del-var-bug
sh1$ env | grep VAR
sh1$ mise set VAR=val
sh1$ mise exec -- env | grep VAR; echo; cat .mise.toml
VAR=val

[env]
VAR = "val"
sh1$ 

sh2$ cd mise-del-var-bug
sh2$ sed -i -e 's/"val"/"modified"/' .mise.toml
sh2$

sh1$ mise exec -- env | grep VAR; echo; cat .mise.toml
VAR=modified

[env]
VAR = "modified"
sh1$

sh2$ sed -i -e 's/"modified"/false/' .mise.toml
sh2$ # NEXT COMMAND WILL USE REMOVED VALUE:

sh1$ mise exec -- env | grep VAR; echo; cat .mise.toml
VAR=modified

[env]
VAR = false
sh1$ mise exec -- env | grep VAR; echo; cat .mise.toml

[env]
VAR = false
sh1$

Expected behavior
Well, in an ideal world, I'd like to avoid mise exec/run execution with variables which doesn't match current config. After all, doc states "Of course, tasks launched with mise will include the mise environment—your tools and env vars defined in mise.toml." and this is violated here.

mise doctor output

version: 2024.11.0 linux-x64 (eae29db 2024-11-01)
activated: yes
shims_on_path: no

build_info:
  Target: x86_64-unknown-linux-gnu
  Features: DEFAULT, NATIVE_TLS, OPENSSL
  Built: Fri, 1 Nov 2024 11:36:23 +0000
  Rust Version: rustc 1.81.0 (eeb90cda1 2024-09-04)
  Profile: release

shell:
  /bin/zsh
  zsh 5.9 (x86_64-pc-linux-gnu)

dirs:
  data: ~/.local/share/mise
  config: ~/.config/mise
  cache: ~/.cache/mise
  state: ~/.local/state/mise
  shims: ~/.local/share/mise/shims

config_files:
  ~/.config/mise/config.toml
  ~/tmp/mise-del-var-bug/.mise.toml

backends:
  cargo
  core
  go
  npm
  pipx
  spm
  ubi
  vfox

plugins:
  jq       ssh://git@github.com/mise-plugins/asdf-jq.git#6d86d19
  yamlfmt  ssh://git@github.com/mise-plugins/asdf-yamlfmt.git#c5760c1

toolset:
  ubi:jdx/usage@1.0.1
  ubi:watchexec/watchexec@2.2.0
  ubi:aquaproj/aqua@2.37.0
  ubi:go-task/task@3.39.2
  go:github.com/oklog/ulid/v2/cmd/ulid@2.1.0
  ubi:santhosh-tekuri/jsonschema@6.0.1
  ubi:bronze1man/yaml2json@1.3.3
  ubi:mikefarah/yq@4.44.3
  ubi:fullstorydev/grpcui@1.4.1
  ubi:fullstorydev/grpcurl@1.9.1
  ubi:ktr0731/evans@0.10.11
  pipx:a13xp0p0v/kernel-hardening-checker@latest
  go:golang.org/x/review/git-codereview@1.12.0
  ubi:ankitpokhrel/jira-cli@1.5.2
  ubi:noahgorstein/jqp@0.7.0
  ubi:cespare/reflex@0.3.1
  ubi:jondot/goweight@1.0.5
  ubi:kubernetes-sigs/kind@0.24.0
  ubi:kubernetes/minikube@1.34.0
  go:github.com/bernardo-bruning/ollama-copilot@0.2.0
  ubi:plandex-ai/plandex@cli/v1.1.1
  npm:rag-crawler@1.5.0
  ubi:magefile/mage@1.15.0
  go:github.com/erning/gorun@latest
  go:golang.org/x/pkgsite/cmd/pkgsite@latest
  go:golang.org/x/tools/cmd/godoc@0.26.0
  go:golang.org/x/tools/cmd/gonew@0.26.0
  go:github.com/rogpeppe/gohack@1.0.2
  ubi:oligot/go-mod-upgrade@0.10.0
  ubi:psampaz/go-mod-outdated@0.9.0
  ubi:uber-go/gopatch@0.4.0
  go:golang.org/x/tools/cmd/eg@0.26.0
  go:rsc.io/rf@latest
  go:github.com/quasilyte/gogrep/cmd/gogrep@0.5.0
  go:golang.org/x/tools/cmd/go-contrib-init@0.26.0
  go:github.com/josharian/impl@1.4.0
  go:github.com/koron/iferr@latest
  go:github.com/fatih/gomodifytags@1.17.0
  go:github.com/davidrjenni/reftools/cmd/fillswitch@latest
  go:github.com/davidrjenni/reftools/cmd/fillstruct@latest
  go:github.com/maruel/panicparse/v2/cmd/pp@2.3.1
  go:github.com/smartystreets/goconvey@1.8.1
  go:golang.org/x/perf/cmd/benchstat@latest

env_vars:
  MISE_LOG_FILE=~/.local/share/mise.log
  MISE_LOG_FILE_LEVEL=info
  MISE_SHELL=zsh

settings:
  activate_aggressive = false
  all_compile = false
  always_keep_download = false
  always_keep_install = false
  asdf_compat = false
  cache_prune_age = "30d"
  ci = false
  color = true
  debug = false
  disable_backends = []
  disable_default_registry = false
  disable_hints = []
  disable_tools = []
  experimental = true
  fetch_remote_versions_cache = "1h"
  fetch_remote_versions_timeout = "10s"
  go_default_packages_file = "~/.default-go-packages"
  go_download_mirror = "https://dl.google.com/go"
  go_repo = "https://github.com/golang/go"
  go_set_gopath = false
  go_set_goroot = true
  go_skip_checksum = false
  http_timeout = "30s"
  jobs = 4
  legacy_version_file = true
  legacy_version_file_disable_tools = []
  libgit2 = true
  lockfile = false
  log_level = "info"
  not_found_auto_install = true
  paranoid = true
  pin = false
  plugin_autoupdate_last_check_duration = "7d"
  quiet = false
  raw = false
  trace = false
  trusted_config_paths = [
      "~/.config/mise/config.toml",
      "~/.mise.toml",
      "~/proj/soft/golangci-lint-strict/",
      "~/tmp/mise-del-var-bug/",
  ]
  use_versions_host = true
  verbose = false
  yes = false

  [cargo]
  binstall = true

  [node]

  [pipx]
  uvx = true

  [python]
  default_packages_file = "~/.default-python-packages"
  pyenv_repo = "https://github.com/pyenv/pyenv.git"
  venv_auto_create = false
  venv_stdlib = false

  [ruby]
  default_packages_file = "~/.default-gems"
  ruby_build_repo = "https://github.com/rbenv/ruby-build.git"
  ruby_install = false
  ruby_install_repo = "https://github.com/postmodern/ruby-install.git"

  [status]
  missing_tools = "if_other_versions_installed"
  show_env = false
  show_tools = false
No warnings found
No problems found
@powerman powerman added the bug Something isn't working label Nov 2, 2024
@jdx
Copy link
Owner

jdx commented Nov 6, 2024

idk how it works but I think fish shell has the ability to run async daemons that could watch for things which could be used for this. I'm not sure what the state is for other shells.

Something running as a daemon would be a prerequisite for this I think.

That said, I don't really want to be managing a daemon if I can help it so even if it was possible I'm not sure I would want to maintain it.

@powerman
Copy link
Contributor Author

powerman commented Nov 6, 2024

Something running as a daemon would be a prerequisite for this I think.

I agree it will be non-trivial to fix, but daemon sounds like overkill!

I may be wrong about some Mise internals, but I support it already knows which env vars it has set and to which values. So, all these vars with unchanged values may be ignored by mise exec/run and removed from their process environment before they'll start reading configs and update env vars. This way this issue will be fixed without a daemon.

But there will be another corner case: if user will do EXISTING_VAR_FROM_CONFIG=it_current_value muse run ... then this manually set variable will be ignored on first run. But this corner case IMO will happens less often.

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

No branches or pull requests

2 participants