fix(env): merge SDK envs in deterministic order to stabilize PATH and env-state cache - #691
Open
xooooooooox wants to merge 1 commit into
Open
Conversation
… env-state cache Same-scope PATH entries were ordered by goroutine completion, which is scheduling-dependent. The emitted PATH therefore almost never matched the cached_path recorded in env-state.json once the shell hook eval'd the output, so every 'vfox env' took the slow rebuild path. Collect per-SDK results first and merge them sorted by SDK name after g.Wait(); scope priority is unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #690
Problem
envFlagmerges each SDK's envs inside its own goroutine, so same-scope PATH entries end up in goroutine completion order — scheduling-dependent and different on every rebuild. Cache validity (internal/env/state.go,HasChanged) compares the current$PATHagainstcached_path, so once the shell hook evals the emitted output,$PATHnever matches again and everyvfox envtakes the slow rebuild path (0.3–3s with a handful of SDKs). With theprecmd/chpwdhook fromvfox activate, that stalls every prompt /cd.Fix
Collect the per-SDK results during the concurrent phase and merge them after
g.Wait()in sorted-by-SDK-name order.user-injected > Project > Session > Global > system,MergeByScopePriority) is untouched — only the ordering of same-scope entries, which was previously random, becomes stable.Verification
go build ./...,go test ./internal/env/... ./internal/sdk/... ./cmd/...pass.eval "$(vfox env -s zsh)"once → the next rebuild records the fixed point → every subsequentvfox envis a cache hit (~10ms,env-state.jsonno longer rewritten). Live zsh with the activate hook:cdcost drops from 0.4–0.5s per directory change to ~20ms.Note: the ordering of
export VAR=...statements still varies between rebuilds (map iteration inShell.Export). That is cosmetic — only PATH participates in cache validity — and is deliberately left out of this PR to keep the diff minimal.