You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
vfox env cache never hits when the shell hook evals the output: same-scope PATH order changes between rebuilds #690
Several SDKs installed in global scope (golang, gradle, java, maven, nodejs, python, ruby)
Symptom
With the standard hook installed by eval "$(vfox activate zsh)", every _vfox_hook invocation takes the slow rebuild path (0.3–3s here) instead of the env-state cache fast path. Since the hook runs on precmd/chpwd, every prompt / cd stalls.
Root cause
Cache validity requires the current $PATH to equal cached_path — the input PATH recorded at the last rebuild (internal/env/state.go, HasChanged). For the cache to ever hit, the emitted PATH must converge with the input PATH once the shell evals the output.
But envFlag (cmd/commands/env.go) merges each SDK's envs inside its own goroutine:
Paths is an insertion-ordered set, so the ordering of same-scope PATH entries is goroutine completion order — scheduling-dependent. The emitted PATH shuffles between rebuilds, therefore:
shell evals the output → $PATH = emitted PATH
next vfox env: $PATH != cached_path → slow rebuild
the rebuild emits yet another ordering → repeat forever; the cache never hits
Reproduction
Nondeterminism (same input, fresh state, two runs):
export __VFOX_CURTMPPATH=$HOME/.version-fox/tmp/repro-$$
rm -rf "$__VFOX_CURTMPPATH"; vfox env -s zsh | grep -o 'PATH="[^"]*"'| tr :'\n'> /tmp/p1
rm -rf "$__VFOX_CURTMPPATH"; vfox env -s zsh | grep -o 'PATH="[^"]*"'| tr :'\n'> /tmp/p2
diff /tmp/p1 /tmp/p2 # frequently non-empty, e.g. sdks/gradle/bin at a different position
Cache never hits once the output is eval'd:
eval"$(vfox env -s zsh)"time vfox env -s zsh >/dev/null # slow rebuild again — every time, in a loop
Impact
Every prompt/cd pays the full rebuild cost (lua plugin evaluation) — 0.3–3s per invocation on this machine — defeating the purpose of the env-state cache.
Fix
Collect per-SDK results and merge them after g.Wait() in a stable (sorted-by-SDK-name) order; concurrency and scope priority (user-injected > Project > Session > Global > system) untouched. Verified: output PATH is deterministic, idempotent, and the cache hits after one converging rebuild (subsequent vfox env ≈ 10ms).
Side note: the order of export VAR=... statements also varies between rebuilds (map iteration in Shell.Export). That one is cosmetic — only PATH participates in cache validity — so it is left untouched.
Activity