Skip to content

refactor(auto-update): make auto-update non-interactive and run in background#718

Merged
kajogo777 merged 2 commits intomainfrom
refactor/non-interactive-background-auto-update
May 8, 2026
Merged

refactor(auto-update): make auto-update non-interactive and run in background#718
kajogo777 merged 2 commits intomainfrom
refactor/non-interactive-background-auto-update

Conversation

@ahmedhesham6
Copy link
Copy Markdown
Collaborator

Description

Refactors the auto-update system from a blocking interactive prompt to a non-interactive background task spawned at startup. This eliminates the y/n prompt that previously blocked the CLI from starting and removes all process::exec()/process::exit() calls from the update success path.

Changes Made

  • main.rs: Auto-update now runs via tokio::spawn in the background. Added should_spawn_auto_update() gate that skips update in warden, async, print, or command-modes. Restructured config loading to separate initialization from auto-update gating.
  • auto_update.rs: Extracted apply_downloaded_binary_update() from update_binary_atomic() to isolate the file-swap logic for testability. Extracted update_via_brew_with_command() for injectable brew path. Removed process::exec()/exit() — update now returns Ok(()) and prints a restart message. Added update_success_message() for consistent messaging.
  • check_update.rs: Removed interactive y/n stdin prompt. Extracted run_auto_update_if_newer() with an injectable async callback for testing.
  • warden.rs: Extracted run_stakpak_in_warden_with_path() for testability. Added test verifying STAKPAK_SKIP_WARDEN=1 env propagation to inner process.
  • Docs: Updated system prompt and README to say "restart long-running processes" instead of implying auto-restart/re-exec.
  • Tests: Unit tests for update gate logic, newer-version skip, brew path injection, atomic binary swap without process exit, and warden env propagation.

Testing

  • All tests pass locally (cargo test --workspace)
  • No clippy warnings (cargo clippy --all-targets)
  • Code is formatted (cargo fmt --check)
  • New unit tests cover: update gate conditions, version comparison callback injection, brew update path injection, atomic binary swap lifecycle, warden env propagation

Breaking Changes

None. The update behavior is transparent to users — the only visible change is that updates no longer block startup or prompt for confirmation.

…ckground

- Spawn auto-update via tokio::spawn instead of blocking main startup
- Remove interactive y/n prompt from auto_update() in check_update.rs
- Extract run_auto_update_if_newer() with injectable callback for testing
- Extract apply_downloaded_binary_update() from update_binary_atomic() for testability
- Extract update_via_brew_with_command() for testable brew update path
- Remove process::exec()/exit() from binary update success path; update now returns Ok
- Add should_spawn_auto_update() gate that skips update in warden/async/print/command modes
- Extract run_stakpak_in_warden_with_path() for testability; add env propagation test
- Unify update success messages to prompt restart rather than auto-re-exec
- Update system prompt and README with restart guidance
- Add unit tests for: update gate, newer-version check, brew path injection,
  atomic binary swap without process exit, warden env propagation
Introduces several improvements to the binary update process:

- **`restart_current_process`**: A new function that handles restarting
  the current process, essential for applying updates atomically.
- **Atomic Replacement**: Ensures that the new binary is copied to a
  temporary location, permissions are set, and then atomically replaced
  with the current executable. This minimizes downtime and potential
  corruption.
- **Error Handling and Cleanup**: Enhanced error handling throughout the
  update process, including cleanup of temporary files if an error
  occurs.
- **Verification Test**: A new verification test is run on the
  downloaded binary before applying it.
- **Background Updates**: The `stakpak update` command now supports a
  `--background` flag, allowing updates to be performed without
  interrupting the current session. This is used by
@ahmedhesham6 ahmedhesham6 self-assigned this May 7, 2026
@kajogo777 kajogo777 merged commit 00085e7 into main May 8, 2026
1 check 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