Skip to content

fix: honor cancellation after model download completes - #9

Merged
programmersd21 merged 3 commits into
mainfrom
fix/cancel-completed-model-download
Nov 28, 2026
Merged

programmersd21 merged 3 commits into
mainfrom
fix/cancel-completed-model-download

Conversation

@programmersd21

@programmersd21 programmersd21 commented Nov 28, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • handle the race where a model finishes verification and is committed just as the user cancels it
  • remove the completed cache entry when cancellation requested discard, instead of reporting success and keeping it
  • reset discard and pause state consistently

Verification

  • CI will run formatting, Clippy, tests and MSRV checks

Summary by Sourcery

Ensure canceled model downloads do not leave completed cache entries or report success after cancellation.

Bug Fixes:

  • Honor cancellation when a model completes downloading concurrently by removing the committed model instead of reporting a successful download.

Enhancements:

  • Reset discard and pause state consistently after cancellation handling.

Tests:

  • Add coverage for removing a completed model when cancellation is requested after commit.

@sourcery-ai

sourcery-ai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Implementation

When a download finishes after cancellation requested discard, remove the committed model and reset cancellation state instead of reporting success.

  • src/main.rs L891-913

Tests

Add an isolated cache fixture and regression coverage for removing a model when cancellation races with download completion.

  • src/main.rs L1107-1133
  • src/model.rs L427-431

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9731b67d-afd5-4974-9b79-847eea2db80d
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread src/main.rs
.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);

Copy link
Copy Markdown

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_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.

Comment thread src/main.rs
.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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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, 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.

@programmersd21
programmersd21 merged commit 414efad into main Nov 28, 2026
5 checks passed
@programmersd21
programmersd21 deleted the fix/cancel-completed-model-download branch November 28, 2026 03:55
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