Skip to content

feat: add command to check for updates#706

Open
cspath1 wants to merge 2 commits into
mainfrom
cspath/add-update-checker
Open

feat: add command to check for updates#706
cspath1 wants to merge 2 commits into
mainfrom
cspath/add-update-checker

Conversation

@cspath1
Copy link
Copy Markdown
Contributor

@cspath1 cspath1 commented May 11, 2026

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

Related issues

Provide links to any issues in this repository or elsewhere relating to this pull request.

Describe the solution you've provided

Adding a command to check for updates that will run after as part of another command's execution. Just a friendly little way to prompt the user to install a new version


Note

Medium Risk
Introduces a new background network request and cache file write on normal CLI execution, which could affect startup behavior and stderr output. Risk is mitigated by timeouts, caching, and an explicit update-check-opt-out setting.

Overview
Adds an automatic update notification: cmd/root.go now starts a background update check during command execution and, if a newer version is found, prints a message to stderr (skipped for non-TTY stderr or when opted out).

Introduces internal/update to fetch the latest GitHub release with a short timeout and a 24-hour on-disk cache, plus tests for version parsing/comparison and caching behavior. Exposes a new update-check-opt-out config/flag (wired into cliflags, config.Config.Update, and help golden output).

Reviewed by Cursor Bugbot for commit 90f093e. Bugbot is set up for automated code reviews on this repo. Configure here.

@cspath1 cspath1 requested a review from nieblara May 11, 2026 19:11
@cspath1 cspath1 changed the title add command to check for updates feat: add command to check for updates May 11, 2026
@cspath1 cspath1 requested a review from a team May 11, 2026 19:13
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default mode and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 9217b8b. Configure here.

Comment thread internal/update/update.go
Copy link
Copy Markdown
Contributor

@LindseyB LindseyB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, I just have some suggestions about how we can quickly handle rate limiting

Comment thread cmd/root.go
if result.info != nil && result.info.IsNewer {
fmt.Fprint(os.Stderr, update.NotificationMessage(result.info))
}
case <-time.After(500 * time.Millisecond):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Can we move this timeout into a constant

Comment thread internal/update/update.go

const (
defaultGitHubReleasesURL = "https://api.github.com/repos/launchdarkly/ldcli/releases/latest"
cacheTTL = 24 * time.Hour
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cacheTTL = 24 * time.Hour
cacheTTL = 24 * time.Hour
errorCacheTTL = 1 * time.Hour

Comment thread internal/update/update.go
writeCache(&cacheEntry{
LatestVersion: latest,
CheckedAt: time.Now(),
})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking we need to update this to make sure we don't hammer the GitHUb API if it's down or rate limiting us:

Suggested change
})
client := &http.Client{Timeout: httpTimeout}
latest, err := fetchLatestVersion(client)
if err != nil {
writeCache(&cacheEntry{
LatestVersion: currentVersion,
CheckedAt: time.Now().Add(errorCacheTTL - cacheTTL), // -23h, expires in 1h
})
return nil
}
writeCache(&cacheEntry{
LatestVersion: latest,
CheckedAt: time.Now(),
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The suggested change box got funky but you should get the idea

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants