Skip to content
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

feat: CLI can self-update when there is a new version and properly continue proving #62

Merged
merged 62 commits into from
Nov 27, 2024

Conversation

dprats
Copy link
Collaborator

@dprats dprats commented Nov 23, 2024

Auto-updating CLI

This PR implements automatic updates for the CLI, allowing users to always run the latest version without manual intervention.

User Flow

  1. User installs CLI via install.sh
  2. CLI starts proving
  3. CLI spins up a background thread periodically checks for updates (every 30 seconds in test mode, 5 minutes in production mode, all configurable via UpdaterConfig)
  4. When a new version is detected:
    • Downloads and builds the new version
    • Seamlessly restarts the CLI process
    • User's proving session continues uninterrupted

Modes

The auto updater has two modes: as seen here:

#[derive(Debug, Clone, Copy, PartialEq, clap::ValueEnum)]
pub enum AutoUpdaterMode {
    Production,
    Test,
}
  1. Production mode runs every 5 minutes and checks the git remote for the latest tags and versions.
  2. Test runs every 30 seconds and checks the local git repo for latest tags. This is used for testing.

Implementation and notable changes

├── analytics.rs
├── config.rs
├── connection.rs
├── generated
│   ├── fast-fib
│   ├── mod.rs
│   └── nexus.orchestrator.rs
├── prover.rs.       <--- this is the same file slightly modified at top to instantiate the auto updater
├── prover_id_manager.rs
├── updater.rs.     <--- this is a new file that is entry point for auto updater
├── utils
│   ├── mod.rs.         <--- this is a new file for the new `/utils` folder
│   └── updater.rs.   <--- this is a new file with helper functions for auto updater
└── websocket.rs
  • /prover.rs: Integration with main CLI <-- this is the main file we always use

    • Spawns update checker thread
    • Configurable update intervals
    • Some of the print statements were modified for easier reading (newlines)
  • /updater.rs: Core update logic <-- this is a new file

    • spawns the thread for the auto updater
  • utils/updater.rs: Core update logic <-- this is a new file with helper function

    • Monitors local git tags for version changes
    • Handles version comparison and process management
    • Manages graceful process handoff during updates
  • tests/test_updater.sh: End-to-end testing <-- this is a new file which is a bash script used for testing

    • Verifies update detection
    • Confirms process restart
    • Validates version transitions

Threads/Processes Logic

The auto-updater manages updates through threads and processes:

  1. Main CLI Process (contains two threads):
    • Main Thread: Runs proving operations
    • Auto-updater Thread: Checks for updates periodically
      • When update found:
        • Builds new version with cargo
        • Spawns new CLI process with updated code
        • Exits old CLI process cleanly

Goal: Enable automatic updates that does interrupt proving operations, but restarts them with the new code running.

Color Printing (and other similar updates)

To make things easier to understand here are the highlights of the changes:

  • Yellow fonts are the print statements by a bash script (test_updater.sh) I created that pretends to be a user, starts up the CLI, changes git tag, waits to see if the CLI notices the updates and checks if the CLI re-updated and CLI restarted itself
  • White font is the classic prover.rs logic in the main thread
  • Blue font is a second thread (updater.rs which is called by prover.rs) that checks for any new updates
  • Additionally some print statements were updated to have newlines to make them easier to read like this:
 println!("\n\nWaiting for a new program to prove...");
Screenshot 2024-11-22 at 7 42 03 PM Screenshot 2024-11-22 at 7 41 54 PM

Copy link

github-actions bot commented Nov 23, 2024

Visit the preview URL for this PR (updated for commit 487a6fc):

https://nexus-cli--pr62-dprats-cli-self-upda-xbzt1ko0.web.app

(expires Wed, 04 Dec 2024 00:20:13 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 815ec4c632754f56eccfacfc0919559f5a85a0f1

@dprats dprats marked this pull request as ready for review November 26, 2024 21:43
@collinjackson collinjackson self-requested a review November 26, 2024 23:44
@stupidmelon stupidmelon self-requested a review November 26, 2024 23:44
Copy link
Contributor

@stupidmelon stupidmelon left a comment

Choose a reason for hiding this comment

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

left a few comments, but nonblocking

@dprats dprats merged commit f2adb21 into main Nov 27, 2024
3 checks passed
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