Skip to content

fix(download): finalize completed range resumes - #9432

Merged
lstein merged 5 commits into
invoke-ai:mainfrom
ShiroKSH:fix/download-resume-finalization
Aug 8, 2026
Merged

lstein merged 5 commits into
invoke-ai:mainfrom
ShiroKSH:fix/download-resume-finalization

Conversation

@ShiroKSH

@ShiroKSH ShiroKSH commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Promote a completed .downloading file when HTTP 416 confirms the remote size.
  • Preserve a sidecar file when the reported remote size differs.
  • Cover both resume outcomes with regression tests.

Closes #9431

Testing

  • uvx [email protected] check invokeai/app/services/download/download_default.py tests/app/services/download/test_download_queue.py
  • Focused HTTP 416 regression checks: 2 passed.

@github-actions github-actions Bot added python PRs that change python files services PRs that change app services python-tests PRs that change python tests labels Aug 1, 2026
@lstein lstein self-assigned this Aug 3, 2026
@lstein lstein added the 6.14.0 label Aug 3, 2026
@lstein lstein moved this to 6.14.x Theme: USER EXPERIENCE in Invoke - Community Roadmap Aug 3, 2026

@lstein lstein left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the fix — this is exactly the right shape: the missing rename was the whole bug, and promoting the sidecar before signaling completion means on_complete consumers (including the model installer) now find a real file. I gave this an adversarial pass (traced every consumer of the new state, attacked the rename and the pause tail with interleavings, verified behavior empirically) and found no blockers. All 17 tests in the file pass locally, including your two new ones.

What I verified holds up:

  • The mismatch→PAUSED path is coherent end to end: the job is still WAITING so _signal_job_paused fires, _cleanup_cancelled_job skips paused jobs so the sidecar survives, and restart_failed's clear_partials=True deletes it — so "Restart required" genuinely restarts (no 416 loop).
  • resume_from > 0 always implies job.download_path is set (all three resume branches guarantee it), so the rename can never target a directory via the or job.dest arm.
  • The regex is safe against real-world 416 responses (S3/CloudFront/nginx/HF emit exactly bytes */N; bytes */* correctly falls through to pause), and the worker's status != COMPLETED guard prevents double-completion.

One non-blocking suggestion inline: when the 416 carries no parseable Content-Range (a SHOULD in RFC 9110, not a MUST), a genuinely complete file now dead-ends in "Restart required" and gets fully re-downloaded. Falling back to the recorded expected_total_bytes/total_bytes (never resume_from) keeps your strictness while rescuing that case — suggestion plus two regression tests attached, validated locally.

Two pre-existing issues this PR surfaces but shouldn't have to fix (follow-up material):

  • A marker-restored install whose first part pauses in this branch (before any started signal) leaves the install job's download_parts empty, so restart_failed no-ops (model_install_default.py:625) and the PAUSED marker rewrite persists files: [], discarding resume metadata.
  • If the sidecar vanishes between the resume stat and the rename (they're a network round-trip apart), the raised FileNotFoundError marks the part ERROR and the error callback rmtrees the whole install tmpdir, including other completed parts. Same exposure class as the pre-existing final rename.

Approving — the suggestion is optional polish, not a condition.

@lstein

lstein commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

I'll wait a couple of days to see if you want to act on either of the two nits in the review above. If I don't hear from you one way or another, I'll go ahead and merge for inclusion in 6.14.0.

@ShiroKSH

ShiroKSH commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

I'll wait a couple of days to see if you want to act on either of the two nits in the review above. If I don't hear from you one way or another, I'll go ahead and merge for inclusion in 6.14.0.

today

@ShiroKSH

ShiroKSH commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

Implemented the headerless 416 fallback in 77f053b. It uses only the originally recorded expected size, never the resumed byte count; added coverage for both the recorded-size and unknown-size paths. The two broader install-resume issues remain suitable for follow-up work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.14.0 python PRs that change python files python-tests PRs that change python tests services PRs that change app services

Projects

Status: 6.14.x Theme: USER EXPERIENCE

Development

Successfully merging this pull request may close these issues.

Bug: completed resumed downloads can remain as .downloading

3 participants