Repository navigation
perf(telemetry): reuse opened project, cache device ID, throttle uploads - #3021
Merged
Merged
Conversation
- Skip the telemetry post-run hook entirely when telemetry is disabled. - Reuse the project the command already opened instead of calling devbox.Open a second time after every command. This also drops the broken --config lookup, which was done on the root command and so never found the flag. - Cache the device ID in the XDG state dir. Computing it runs ioreg on macOS (~20ms). - Only spawn the `upload-telemetry` process at most every 30 minutes, unless an error was reported or 50+ events are buffered. Sentry events now record their own timestamp since they may be uploaded later. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
mikeland73
added a commit
that referenced
this pull request
Oct 25, 2026
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Collaborator
Author
|
@claude ptal |
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
PR #3021 was updated after the trigger (2026-10-25T21:46:34Z >= 2026-10-25T21:44:01Z). Mention Claude again to run on the latest version. |
Collaborator
Author
|
@claude ptal |
|
Claude finished @mikeland73's task in 23s —— View job Review of #3021I read the diff and traced the changed code paths. I didn't run the tests or the linter. The PR description says both pass, but I haven't confirmed that. I found no blocking issues, only a few small points below. What looks right
Points to consider (non-blocking)
Verdict: looks good to me. The behavior change (commands that open no project report no packages) is clearly documented in the PR description. |
mikeland73
added a commit
that referenced
this pull request
Oct 26, 2026
…#3022) ## Summary Implements item 5 of `specs/perf-improvements.md`. direnv runs `devbox generate direnv --print-envrc` on every reload. It only prints a fixed `.envrc` template, but it still: - inherited `ensureNixInstalled` from `generate`'s `PersistentPreRunE`, which runs `nix --version`, and - recorded a telemetry event, which also spawned the `devbox upload-telemetry` process. Changes: - `generate`'s `PersistentPreRunE` skips the nix check when `--print-envrc` is set. The root uses `cobra.EnableTraverseRunHooks`, so overriding the hook on the `direnv` subcommand wouldn't stop the parent's hook from running. That's why the check goes in the parent. - New `midcobra.SkipTelemetry(cmd)` lets a command opt out of being recorded for the current run. The telemetry post-run hook checks for it. The `--print-envrc` path calls it. ## Testing - New `TestGenerateDirenvPrintEnvrcSkipsNixCheck` runs the command through `RootCmd()` and checks the output and that `nix.Ensured()` stays false. Without the fix it fails. - New `TestSkipTelemetry`. - `go test ./internal/boxcli/...` passes. `golangci-lint run ./internal/boxcli/...` reports 0 issues. - Output is byte-for-byte the same as on `main`. - Timing for `generate direnv --print-envrc` on macOS, averaged over 20 runs. Binaries were built with fake telemetry keys and network was blocked by a proxy. | | main | this PR | |---|---|---| | telemetry on | 131.0ms | 33.7ms | | `DO_NOT_TRACK=1` | 92.7ms | 10.6ms | With telemetry on, almost all of the remaining ~23ms is `telemetry.Start()` running `ioreg` for the machine ID. #3021 caches that. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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 items 2–4 of
specs/perf-improvements.md, which together remove fixed telemetry costs from every command (including everydevbox global shellenvand every direnv reload).2. Don't re-open the project after every command
DO_NOT_TRACK, or builds without keys). Before, it still randevbox.Open.devbox.Opennow records the project it returned (devbox.LastOpened()), and telemetry reads packages and the nixpkgs commit from that project instead of opening it again (which re-parsed devbox.json/devbox.lock and reloaded plugins).--configbug: the old code looked the flag up on the root command, so it never found it.version,search) now report no packages. Before, they reported whatever project was in the cwd.3. Cache the device ID
machineid.ProtectedIDis written to$XDG_STATE_HOME/devbox/telemetry/device-idand read from there on later runs. This skipsioregon macOS (~20ms).4. Throttle
devbox upload-telemetry$XDG_STATE_HOME/devbox/telemetry/last-uploadbefore the child starts, so commands running at the same time don't all spawn one. A timestamp in the future is ignored.Timestampwhen they're created, since they may be uploaded later.Testing
go test ./internal/telemetry/ ./internal/boxcli/midcobra/: new tests for the device ID cache (hit and miss) andshouldUpload(never uploaded, recent, stale, future timestamp, error, threshold). Updated thegetPackagesAndCommitHashtest.golangci-lint runon the changed packages: 0 issues.devbox versiondevbox listMost of the remaining cost is
nix --version(~75ms), whichnewTrackMessagecalls throughnix.Version(). Item 1 (a separate PR) caches it.🤖 Generated with Claude Code