Fix: Download with progress callback fails with 'Operation was cancel…#693
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR fixes the C++ SDK/native-core callback ABI mismatch that caused downloads with a progress callback to be interpreted as cancelled.
Changes:
- Updated native callback typedefs from
voidtointto match the core DLL contract. - Adjusted download and streaming callback lambdas to return
0so the core continues instead of cancelling. - Added a regression test for the download callback path.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
sdk/cpp/test/model_variant_test.cpp |
Adds a regression test for the download callback return value. |
sdk/cpp/src/model.cpp |
Updates the download progress callback lambda to return int. |
sdk/cpp/src/foundry_local_internal_core.h |
Changes the internal native callback typedef to int. |
sdk/cpp/src/flcore_native.h |
Changes the exported callback typedef/comment to the int contract. |
sdk/cpp/src/core_helpers.h |
Updates the streaming callback lambda to return int. |
Comments suppressed due to low confidence (1)
sdk/cpp/src/core_helpers.h:1
- Once
onChunkthrows, this callback stores the exception but still returns0(continue) both immediately after the failure and on every subsequent invocation. With the new callback contract, that means the native core will keep streaming data even though the caller has already failed, wasting work and potentially delaying error propagation until the full stream finishes. Return the cancel value after capturing an exception, and whenst->exceptionis already set.
// Copyright (c) Microsoft Corporation. All rights reserved.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
baijumeswani
approved these changes
May 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix: Download with progress callback fails with "Operation was cancelled by user"
Problem
Calling
model->Download()with a progress callback causes the native core to abort with:The same call without a callback works correctly.
Root Cause
The C++ SDK declared
NativeCallbackFnas returningvoid, while the native core DLL (C#) expects the callback to returnint(0= continue,1= cancel). Since thevoidcallback never sets the return register, the C# marshalling reads an indeterminate value (garbage), interprets it as non-zero (cancel), and aborts the download.All other SDKs correctly define the callback as returning
int:voidintint32_tc_inti32Fix
Changed
NativeCallbackFnandUserCallbackFnfromvoid(*)()toint(*)()and updated all callback lambdas to return0(continue).Files Changed
sdk/cpp/src/foundry_local_internal_core.h—NativeCallbackFnreturn typevoid→intsdk/cpp/src/flcore_native.h—UserCallbackFnreturn typevoid→intsdk/cpp/src/model.cpp— download progress callback lambda returns0sdk/cpp/src/core_helpers.h— streaming callback lambda returns0sdk/cpp/test/model_variant_test.cpp— added regression testDownload_WithCallback_ReturnsZeroToContinueTesting
All 163 unit tests pass, including a new regression test that invokes the callback and asserts the return value is
0.