Skip to content

fix(provider): settle model downloads cancelled before waiter attachment - #1640

Merged
Gajesh2007 merged 1 commit into
masterfrom
codex/provider-lifecycle-investigation-20261027
Oct 28, 2026
Merged

Gajesh2007 merged 1 commit into
masterfrom
codex/provider-lifecycle-investigation-20261027

Conversation

@jonathan308

@jonathan308 jonathan308 commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Cancelling a model download can finish its suspended URLSessionDataTask before streamDownload attaches 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. attach immediately 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

flowchart TD
  A["Cancel suspended download task"] --> B["URLSession sends terminal callback"]
  B --> C["finish: no continuation, discard result"]
  C --> D["streamDownload attaches waiter later"]
  D --> E["Waiter never receives completion"]
  classDef input fill:#dbeafe,stroke:#2563eb,color:#172554;
  classDef code fill:#fef3c7,stroke:#b45309,color:#451a03;
  classDef stuck fill:#fee2e2,stroke:#b91c1c,color:#450a0a;
  class A input;
  class B,C,D code;
  class E stuck;
Loading

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;
Loading

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.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

@vercel

vercel Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
d-inference Error Error Oct 28, 2026 4:20am UTC
d-inference-console-ui-dev Error Error Oct 28, 2026 4:20am UTC
d-inference-landing Ready Ready Preview Oct 28, 2026 4:20am UTC
darkbloom-status Ready Ready Preview Oct 28, 2026 4:20am UTC
eigen-homepages-darkbloom Ready Ready Preview Oct 28, 2026 4:20am UTC

Request Review

@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Threat model review — advisory

Reviewed head 1d05ef68d16c against base 8effff7f7067.

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.
Workload allowance: 8 native request(s), including one shared response repair; 500 emergency ceiling. Selected depth and integration rounds are admitted as their scope becomes known.

@Gajesh2007
Gajesh2007 merged commit 878cd25 into master Oct 28, 2026
28 of 31 checks passed
jonathan308 added a commit that referenced this pull request Oct 28, 2026
Freshness refresh: master gained #1637, #1639, #1640, #1646 and #1655. The merge has no conflicts and leaves the SDK pin unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jonathan308 added a commit that referenced this pull request Oct 28, 2026
Freshness refresh: master gained #1637, #1639, #1640, #1646 and #1655. The merge has no conflicts and leaves the SDK pin unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jonathan308 added a commit that referenced this pull request Oct 28, 2026
Freshness refresh: master gained #1637, #1639, #1640, #1646 and #1655. The merge has no conflicts and leaves the SDK pin unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jonathan308 added a commit that referenced this pull request Oct 28, 2026
Freshness refresh: master gained #1637, #1639, #1640, #1646 and #1655. The merge has no conflicts and leaves the SDK pin unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jonathan308 added a commit that referenced this pull request Oct 28, 2026
Freshness refresh: master gained #1637, #1639, #1640, #1646 and #1655. The merge has no conflicts and leaves the SDK pin unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jonathan308 added a commit that referenced this pull request Oct 28, 2026
Freshness refresh: master gained #1637, #1639, #1640, #1646 and #1655. The merge has no conflicts and leaves the SDK pin unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jonathan308 added a commit that referenced this pull request Oct 28, 2026
Freshness refresh: master gained #1637, #1639, #1640, #1646 and #1655. The merge has no conflicts and leaves the SDK pin unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jonathan308 added a commit that referenced this pull request Oct 29, 2026
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>

This branch had an error being deployed

2 failed and 3 active deployments
Preview – d-inference-landing — 1d05ef68 Deployed Oct 28, 2026 by vercel[bot]
Preview – eigen-homepages-darkbloom — 1d05ef68 Deployed Oct 28, 2026 by vercel[bot]
Preview – d-inference — 1d05ef68 Deployed Oct 28, 2026 by vercel[bot]
Preview – d-inference-console-ui-dev — 1d05ef68 Deployed Oct 28, 2026 by vercel[bot]
Preview – darkbloom-status — 1d05ef68 Deployed Oct 28, 2026 by vercel[bot]
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.

2 participants