Repository navigation
fix: honor cancellation after model download completes #9
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -888,6 +888,29 @@ fn change_setting(app: &mut App, forward: bool) { | |
| fn finish_model_download(app: &mut App, outcome: DownloadOutcome) { | ||
| match outcome { | ||
| DownloadOutcome::Ready => { | ||
| if app.download_discard { | ||
| let result = app | ||
| .download_models | ||
| .iter() | ||
| .find(|model| model.file == app.download_file) | ||
| .ok_or_else(|| "downloaded model is no longer in the catalog".to_string()) | ||
| .and_then(model::remove_model); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium · Completed model survives cancellation When another process acquires the model’s cache lock after the downloader returns and before cleanup acquires it, Keep the download lock held through cancellation cleanup, or retry cleanup after a transient lock conflict. Prompt for AI agentsIn `src/main.rs` at line 897:
**Completed model survives cancellation**
When another process acquires the model’s cache lock after the downloader returns and before cleanup acquires it, `model::remove_model` cannot acquire the cache lock, so the completed file remains and the UI reports failure instead of honoring the discard request.
Keep the download lock held through cancellation cleanup, or retry cleanup after a transient lock conflict. |
||
| app.download_discard = false; | ||
| app.download_paused = false; | ||
| match result { | ||
| Ok(()) => { | ||
| app.download = app::DownloadState::Idle; | ||
| app.download_info = "download canceled · completed file removed".into(); | ||
| app.toast("download canceled", ToastKind::Warn); | ||
| } | ||
| Err(err) => { | ||
| app.download = app::DownloadState::Failed; | ||
| app.download_info = err.clone(); | ||
| app.set_message(err); | ||
| } | ||
| } | ||
| return; | ||
| } | ||
| app.download = app::DownloadState::Done; | ||
| app.download_paused = false; | ||
| app.download_frac = 1.0; | ||
|
|
@@ -1081,6 +1104,33 @@ mod tests { | |
| assert_eq!(failed.unwrap_err(), "decoder failed"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn cancel_after_download_commit_removes_the_completed_model() { | ||
| let dir = std::env::temp_dir().join(format!("scribe-discard-{}", std::process::id())); | ||
| let _ = std::fs::remove_dir_all(&dir); | ||
| std::fs::create_dir_all(&dir).unwrap(); | ||
| crate::model::set_test_cache_dir(Some(dir.clone())); | ||
|
|
||
| let info = crate::model::find("tiny").unwrap(); | ||
| let path = dir.join(info.file); | ||
| std::fs::write(&path, b"completed model").unwrap(); | ||
|
|
||
| let mut app = App::new(&crate::cli::Args::default()); | ||
| app.download_models = crate::model::CATALOG.to_vec(); | ||
| app.download_file = info.file.to_string(); | ||
| app.download_discard = true; | ||
| app.download_paused = true; | ||
|
|
||
| finish_model_download(&mut app, DownloadOutcome::Ready); | ||
|
|
||
| assert!(!path.exists()); | ||
| assert!(!app.download_discard); | ||
| assert!(!app.download_paused); | ||
| assert_eq!(app.download, app::DownloadState::Idle); | ||
| crate::model::set_test_cache_dir(None); | ||
| std::fs::remove_dir_all(&dir).unwrap(); | ||
| } | ||
|
|
||
| #[test] | ||
| fn terminal_cleanup_continues_after_a_failed_step() { | ||
| use std::cell::RefCell; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Medium · Selected model points to a removed file
When the worker commits the file while discard is pending and Enter is processed before completion is handled,
start_downloadcan select the committed file before checking whether a downloader is active, thenfinish_model_downloadremoves it without clearingapp.model_name; the next transcription uses a missing model file and fails.Prevent the committed file from being selected while discard is pending, or clear the selection when removing it.
Prompt for AI agents