Repository navigation
perf(vercheck): switch devbox versions before startup for devbox_version auto - #3023
Merged
Merged
Conversation
…ion auto With devbox_version on_mismatch "auto", devbox only noticed the mismatch inside devbox.Open, after the command's PreRunE hooks (nix install check, telemetry setup, etc.), and then re-exec'd through the bash launcher. Every invocation paid for two devbox startups plus the launcher. - Add a ProjectVersion middleware that runs first. It resolves the subcommand, reads its --config flag (or DEVBOX_CONFIG) into a separate flag set, loads devbox.json, and calls vercheck.SwitchProjectVersion. It skips devbox global, --all-projects, and commands without --config; those still switch when they open the project. - SwitchProjectVersion only re-execs when CheckProjectVersion would, and otherwise stays silent so CheckProjectVersion still reports warnings and errors. - When the launcher already downloaded the target version (~/.cache/devbox/bin/<version>_<os>_<arch>/devbox), exec it directly instead of going through the launcher. Otherwise fall back to the launcher, which downloads it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
Collaborator
Author
|
@claude ptal |
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
PR #3023 was updated after the trigger (2026-10-25T21:46:39Z >= 2026-10-25T21:44:37Z). Mention Claude again to run on the latest version. |
Collaborator
Author
|
@claude ptal |
|
Claude finished @mikeland73's task in 27s —— View job Review of #3023I read the full diff of the new middleware,
Looks right
Things to consider
The spec deviation, skipping the version cache because --- · branch |
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.
Summary
Implements item 7 of
specs/perf-improvements.md. Withdevbox_version: {"version": "X", "on_mismatch": "auto"}, devbox only noticed the mismatch insidedevbox.Open, after the command'sPreRunEhooks (nix install check, etc.) had run. Then it re-exec'd through the bash launcher. So every invocation in a pinned project paid for two devbox startups plus the launcher.Design
midcobra.ProjectVersion, registered first inExecute): finds the subcommand, reads only its--config/-cflag (defaultDEVBOX_CONFIG) into a separatepflag.FlagSetso cobra's later parse isn't affected, loadsdevbox.jsonwithdevconfig.Find/Open, and callsvercheck.SwitchProjectVersion. It skipsdevbox global ...(its config path is set in a PreRunE),--all-projects, and commands without--config. Those cases still switch fromdevbox.Openas before.vercheck.SwitchProjectVersionre-execs only whenCheckProjectVersionwould. In every other case (warn/error policy,DEVBOX_USE_VERSIONset by the user, no launcher, already switched) it returns without printing anything, soCheckProjectVersionstill reports the same warnings and errors when the project is opened. The policy, satisfaction, and user-version checks are shared helpers.$HOME/.cache/devbox/bin/<version>_<os>_<arch>/devbox, which matchesINSTALL_DIRinlaunch.sh), we exec that binary directly. TheLAUNCHER_*andDEVBOX_LATEST_VERSIONenv vars are inherited. If it hasn't been downloaded, we fall back to the launcher, which downloads it. The existing__DEVBOX_AUTO_VERSIONguard still prevents exec loops. This also applies when the switch happens fromdevbox.Open.Deviation from the spec
The spec also suggests caching the resolved version. I didn't add a cache because
autorequires an exact version (devbox.json validation rejectsautowith a range), so there's nothing to resolve. The decision comes from parsing devbox.json and one semver compare, both well under a millisecond. The expensive part was the launcher, which direct exec now skips.Testing
go test ./internal/vercheck/... ./internal/boxcli/... ./internal/devbox/...passes.SwitchProjectVersion: switches, and doesn't switch (and doesn't suppress the warning) in each skip case.HOME.projectConfigPath: flag forms, unknown flags,--handling, global,--all-projects, commands without--config, and a check that the command's real flags aren't touched.shell --pure -c <proj>withdevbox_version9.9.9/auto and a fakeLAUNCHER_PATH. It re-exec'd before any nix check withDEVBOX_USE_VERSION=9.9.9.golangci-lintreports no issues on the changed packages.🤖 Generated with Claude Code