Commit 598fc19
authored
Fix: Download with progress callback fails with 'Operation was cancel… (#693)
## 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:
```
[Foundry][Error] Error downloading model [qwen3.5-2b-generic-gpu]:
Operation was cancelled by user
```
The same call without a callback works correctly.
### Root Cause
The C++ SDK declared `NativeCallbackFn` as returning `void`, while the
native core DLL (C#) expects the callback to return `int` (`0` =
continue, `1` = cancel). Since the `void` callback 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`:
| SDK | Callback return type | Correct? |
|-----|---------------------|----------|
| **C++ (before fix)** | **`void`** | **No** |
| C# | `int` | Yes |
| JavaScript | `int32_t` | Yes |
| Python | `c_int` | Yes |
| Rust | `i32` | Yes |
### Fix
Changed `NativeCallbackFn` and `UserCallbackFn` from `void(*)()` to
`int(*)()` and updated all callback lambdas to return `0` (continue).
### Files Changed
- **`sdk/cpp/src/foundry_local_internal_core.h`** — `NativeCallbackFn`
return type `void` → `int`
- **`sdk/cpp/src/flcore_native.h`** — `UserCallbackFn` return type
`void` → `int`
- **`sdk/cpp/src/model.cpp`** — download progress callback lambda
returns `0`
- **`sdk/cpp/src/core_helpers.h`** — streaming callback lambda returns
`0`
- **`sdk/cpp/test/model_variant_test.cpp`** — added regression test
`Download_WithCallback_ReturnsZeroToContinue`
### Testing
All 163 unit tests pass, including a new regression test that invokes
the callback and asserts the return value is `0`.1 parent b379679 commit 598fc19
5 files changed
Lines changed: 28 additions & 8 deletions
File tree
- sdk/cpp
- src
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
| 63 | + | |
64 | 64 | | |
65 | | - | |
| 65 | + | |
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
| 69 | + | |
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| 78 | + | |
78 | 79 | | |
79 | 80 | | |
80 | 81 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
27 | | - | |
| 26 | + | |
| 27 | + | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
| 82 | + | |
83 | 83 | | |
84 | | - | |
| 84 | + | |
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| 94 | + | |
94 | 95 | | |
95 | 96 | | |
96 | 97 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
131 | 149 | | |
132 | 150 | | |
133 | 151 | | |
| |||
0 commit comments