Repository navigation
fix(provider): settle model downloads cancelled before waiter attachment - #1640
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Threat model review — advisoryReviewed head Reviewers: anthropic/claude-sonnet-5.5: first pass completed; anthropic/claude-opus-5.5: selected depth completed (1 batches); openai/gpt-6.1-sol: not needed by escalation policy No actionable findings in the reviewed text. This is not a security approval. Models: budgeted Sonnet / selective Opus / selective Sol 6.1. Findings require human validation; this review never requests changes or blocks merging. Scan completed. Coverage: 23/23 source units; cross-file integration complete. 0 selected depth batch(es) pending. All threat definitions indexed; relevant full definitions selected. Unchanged callers are not scanned. Cost this run: $0.0000 reported, $0.0000 reserved with unknown cost; 0 paid request(s), 0 reused batch(es), 0 provider cache-hit tokens. Saved findings and earlier report · Historical findings are not confirmed resolved. Bedrock: 7 request(s), 292459 uncached + 0 cache-read + 0 cache-write input / 4603 output tokens; 0 request(s) with unknown usage. OpenRouter backup used 0 time(s). Dollar amounts above cover OpenRouter only; AWS billing is reconciled separately. |
Brings in the SSD cache changes merged since this branch's base (#1642, #1647, #1648, #1649, #1651) plus #1639, #1640 and #1646. The only conflict was the docs/reference/ssd-kv-cache.md table: keep this PR's victim selection row and master's updated maintenance sweep row. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cancelling a model download can finish its suspended
URLSessionDataTaskbeforestreamDownloadattaches the checked continuation. The delegate previously discarded completion when no continuation existed, leaving the later waiter suspended indefinitely.Retain the first terminal result under the existing lock.
attachimmediately receives an earlier result; completion clears and resumes an already-attached waiter. Both paths resume outside the lock. Writer closure, partial-file preservation, response/error precedence and cancellation's no-retry behavior stay unchanged.The reproducer uses a real ephemeral URLSession: cancel an unresumed task, wait for Foundation's actual completion callback, then attach the waiter. It opens no socket. Three regression tests fail on the original source and pass with this change; the ordinary partial-file cancellation control passes both versions.
Before
After
flowchart TD A["Cancel suspended download task"] --> B["finish: retain first result under lock"] B --> C{"Waiter attached?"} C -->|Yes| D["Clear waiter and resume outside lock"] C -->|No| E["Later attach receives retained result"] E --> F["Download receives CancellationError"] D --> F classDef input fill:#dbeafe,stroke:#2563eb,color:#172554; classDef code fill:#fef3c7,stroke:#b45309,color:#451a03; classDef done fill:#dcfce7,stroke:#15803d,color:#052e16; class A input; class B,C code; class D,E,F done;Validation:
Full provider-package build and 56 tests in seven selected download suites pass with native SwiftPM and the exact pinned MLX dependencies. Command:
swift test --package-path provider-swift --build-system native --scratch-path /private/tmp/darkbloom-lifecycle-full-01a1809c --jobs 4 --no-parallel --filter 'StreamingFileDownloadDelegateTests|ModelDownloadProgressTests|ModelDownloadCacheTests|HuggingFaceDownloadTests|ModelPrefetchDownloaderTests'.Five new component tests / seven parameter cases pass, including 100 attachment/completion races, both completion orders, duplicate terminal callbacks, exact partial-file byte preservation and rejection of late writes.
The baseline loses the early result in three tests. Its waiter is released by a cleanup callback after the failure is recorded, so regression tests remain bounded.
GitHub CI on this exact commit passed Provider Unit Tests (including isolated native lifecycle/memory/media/audio gates), Provider SDK Tests and Provider Prompt Parity. External deployment checks and the sandbox-receipt check remain separate unresolved gates.
Dedicated independent refactor review completed with no changes or unresolved findings. It traced downloader and Hugging Face fallback cancellation propagation, writer-close ordering and result precedence.
Docs-impact, docs lint (199 files), changelog check/preview and whitespace checks pass.
No API, configuration, on-disk format or migration changes. The delegate retains its existing single-attachment and serialized-delegate-callback assumptions. The fixture proves waiter settlement; whole-provider shutdown, real-network cancellation frequency and model/GPU serving are not measured.
Need help on this PR? Tag
@codesmith-botwith what you need.