Skip to content

Add version update checker for worker CLI #501

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

lgingerich
Copy link
Contributor

Context

This PR addresses #413

Implementation

  • Add automatic version checking that runs once per day on first CLI usage (checks every 24 hours)
  • Check GitHub API for latest releases and compare with current version
  • Display user-friendly update notifications with installation command
  • Cache check results to prevent duplicate notifications and API calls
  • Store cache in user home directory (~/.prime_worker_version_check)

Example

Below is the message shown to users when a new update is available:

╔════════════════════════════════════════════════════════════════════════════════╗
║                              📦 UPDATE AVAILABLE                               ║
╚════════════════════════════════════════════════════════════════════════════════╝
⚠ A newer version of Prime Worker is available!
Current Version: 0.2.10
Latest Version: 0.2.11
Update Command: curl -sSL https://raw.githubusercontent.com/PrimeIntellect-ai/protocol/main/crates/worker/scripts/install.sh | bash
Release Notes: https://github.com/PrimeIntellect-ai/protocol/releases/tag/v0.2.11

@JannikSt JannikSt requested a review from Copilot July 7, 2025 07:23
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Adds a daily version update checker to the worker CLI that fetches the latest release from GitHub, compares it against the current version, caches the result in the user’s home directory, and prints a notification with install instructions if an update is available.

  • Introduce VersionChecker service for fetching, comparing, and caching version info
  • Register and invoke VersionChecker in the CLI entrypoint
  • Store and load a JSON cache at ~/.prime_worker_version_check

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
crates/worker/src/services/version_checker.rs New service implementing version fetching, comparison, caching, and notification
crates/worker/src/services/mod.rs Expose version_checker module
crates/worker/src/cli/command.rs Instantiate and run daily version check in execute_command
Comments suppressed due to low confidence (1)

crates/worker/src/services/version_checker.rs:71

  • There are no tests covering the caching logic or should_check_today() behavior. Adding tests for scenarios like a cache older than 24 hours versus recent cache would improve reliability.
    fn should_check_today(&self) -> bool {

Comment on lines +157 to +164
.map(|s| s.parse().unwrap_or(0))
.collect();

let latest_parts: Vec<u32> = latest
.split('.')
.take(3)
.map(|s| s.parse().unwrap_or(0))
.collect();
Copy link
Preview

Copilot AI Jul 7, 2025

Choose a reason for hiding this comment

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

Parsing version components with unwrap_or(0) swallows errors and never triggers the fallback in is_newer_version. Consider returning a parse error instead of defaulting to zero so that non‐numeric or pre-release tags use the intended fallback logic.

Suggested change
.map(|s| s.parse().unwrap_or(0))
.collect();
let latest_parts: Vec<u32> = latest
.split('.')
.take(3)
.map(|s| s.parse().unwrap_or(0))
.collect();
.map(|s| s.parse())
.collect::<Result<Vec<u32>, _>>()?;
let latest_parts: Vec<u32> = latest
.split('.')
.take(3)
.map(|s| s.parse())
.collect::<Result<Vec<u32>, _>>()?;

Copilot uses AI. Check for mistakes.

Comment on lines +194 to +195
fn load_cache(&self) -> Result<VersionCheckCache> {
let content = fs::read_to_string(&self.cache_file_path)?;
Copy link
Preview

Copilot AI Jul 7, 2025

Choose a reason for hiding this comment

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

This synchronous std::fs::read_to_string call runs on the async Tokio runtime and may block the executor. Consider using tokio::fs::read_to_string or spawning a blocking task.

Suggested change
fn load_cache(&self) -> Result<VersionCheckCache> {
let content = fs::read_to_string(&self.cache_file_path)?;
async fn load_cache(&self) -> Result<VersionCheckCache> {
let content = tokio::fs::read_to_string(&self.cache_file_path).await?;

Copilot uses AI. Check for mistakes.

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.

1 participant