Repository navigation
fix: honor cancellation after model download completes - #9
Conversation
Reviewer's GuideImplementationWhen a download finishes after cancellation requested discard, remove the committed model and reset cancellation state instead of reporting success.
TestsAdd an isolated cache fixture and regression coverage for removing a model when cancellation races with download completion.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/main.rs" line_range="897" />
<code_context>
+ .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);
+ app.download_discard = false;
+ app.download_paused = false;
</code_context>
<issue_to_address>
**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_download` can select the committed file before checking whether a downloader is active, then `finish_model_download` removes it without clearing `app.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.
</issue_to_address>
### Comment 2
<location path="src/main.rs" line_range="897" />
<code_context>
+ .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);
+ app.download_discard = false;
+ app.download_paused = false;
</code_context>
<issue_to_address>
**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.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 2 findings to address first, and if the cancellation state is wrong, this can remove the completed model file even though the user intended to keep it. Reverting will not restore the file, but the loss is bounded and the model can be downloaded again.
Blocking findings: src/main.rs:897, src/main.rs:897
| .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.
🟡 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_download can select the committed file before checking whether a downloader is active, then finish_model_download removes it without clearing app.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
In `src/main.rs` at line 897:
**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_download` can select the committed file before checking whether a downloader is active, then `finish_model_download` removes it without clearing `app.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.| .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.
🟡 Medium · 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.
Prompt for AI agents
In `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.
Summary
Verification
Summary by Sourcery
Ensure canceled model downloads do not leave completed cache entries or report success after cancellation.
Bug Fixes:
Enhancements:
Tests: