Skip to content

Recover uploads abandoned by preparation exceptions - #1559

Merged
bmehta001 merged 5 commits into
microsoft:mainfrom
bmehta001:fix/upload-exception-recovery
Nov 6, 2026
Merged

bmehta001 merged 5 commits into
microsoft:mainfrom
bmehta001:fix/upload-exception-recovery

Conversation

@bmehta001

Copy link
Copy Markdown
Contributor

Summary

Port all SDK-relevant changes from bmehta001/onnxruntime#11 (source commit 611834d7eafd18ea0d4ca9ab28dfa3b539b3c61b) directly into the SDK, with regression tests adapted to this repository's harness.

  • Share exception recovery between scheduled uploads and immediate events. Release reserved records before retiring an unregistered upload, and still retire it if cleanup throws.
  • Preserve terminal completion ownership once an HTTP callback is registered, including synchronous completion followed by an exception; ignore already-finished uploads.
  • Own pending callbacks with RAII until registry insertion succeeds, and move potentially throwing request-log formatting before registration.
  • Add the source PR's 14 scheduled/immediate component cases and six native-transport fault modes, plus a request-log formatting regression and ownership assertions in existing HTTP tests.

The native tests use a private collector URL on IPv4 loopback and the actual platform HTTP transport. They verify retry of the original reserved event, subsequent uploads, immediate teardown without retry after standard/nonstandard preparation failures, throwing HTTP handoff, and completion-then-throw. Each mode has a 30-second CTest timeout.

ORT-specific dependency-patch plumbing, telemetry wrapper/build integration, enable/disable behavior, and ORT documentation are intentionally not copied. The SDK now contains the fix itself rather than an external patch.

Validation

Fresh Debug builds with MATSDK_WARNINGS_AS_ERRORS=ON, vendored SQLite/zlib, and the repository's pinned GoogleTest submodule:

Check Windows x64, Visual Studio 2026 Ubuntu 24.04 / WSL, GCC 13
Build UnitTests and UploadExceptionTests Passed Passed
TPM, upload-exception, and all HTTP-manager component suites 82 passed 84 passed
All six upload-* native CTests 6 passed (WinHTTP) 6 passed (curl)
Existing full-SDK no-exceptions-smoke build and CTest Passed Passed

Component selector: TransmissionPolicyManagerTests.*:*UploadExceptionTests.*:HttpClientManager*.*. No selected tests were skipped or excluded; the two extra Linux cases exercise response-dispatcher fallback paths compiled only outside Windows.

Formatting checks passed for the new native test and changed C++ implementation/test lines. Existing aligned header declarations were preserved. git diff --cached --check passed before committing. No public package registries were used.

This is targeted SDK/lifecycle validation, not a full SDK test-suite run or a reproduction of the reporter's COLMAP workload. No new sanitizer run was performed for this port. As in the source PR, microsoft/onnxruntime#33923's configuration-map SIGSEGV remains unconfirmed and is not claimed fixed.

Related: microsoft/onnxruntime#33929, microsoft/onnxruntime#33923 (non-closing references).

Port the SDK recovery from bmehta001/onnxruntime#11 so failed upload
preparation cannot leave teardown waiting for a callback that was never
registered. Release reserved records before retiring an upload, contain
cleanup exceptions, and preserve HTTP ownership after registration.

Protect pending callback allocation with RAII and evaluate request logging
before handing ownership to the registry. Adapt all 14 component cases and
six native fault modes to the SDK harness, plus a request-log failure test.

Files changed:
- lib/http/HttpClientManager.cpp
- lib/system/Contexts.hpp
- lib/system/TelemetrySystem.cpp
- lib/tpm/TransmissionPolicyManager.cpp
- lib/tpm/TransmissionPolicyManager.hpp
- tests/functests/CMakeLists.txt
- tests/functests/upload-exception-tests.cpp
- tests/unittests/HttpClientManagerTests.cpp
- tests/unittests/TransmissionPolicyManagerTests.cpp

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 6982f030-2ce2-47a3-b52b-9d8a1cdb05d9
@bmehta001
bmehta001 requested a balanced review from Copilot November 6, 2026 19:31
@bmehta001 bmehta001 self-assigned this Nov 6, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Exception cleanup can target disk instead of RAM after partial retrieval, leaving RAM records reserved, while a task-lifetime race can make preparation-mode tests fail nondeterministically.

2 open issues
What changed in this PR

This PR adds upload-preparation exception recovery to the SDK, releasing abandoned reservations while preserving HTTP callback ownership of registered uploads.

Changes:

  • Share recovery logic between scheduled and immediate uploads.
  • Protect pending callbacks with RAII and move request-log formatting before registration.
  • Add component regressions and six native-transport fault modes with bounded test timeouts.
File Description
tests/​unittests/​TransmissionPolicyManagerTests.cpp Adds scheduled and immediate upload exception cases.
tests/​unittests/​HttpClientManagerTests.cpp Tests logging failures and callback ownership.
tests/​functests/​upload-exception-tests.cpp Adds native-transport recovery and teardown tests.
tests/​functests/​CMakeLists.txt Registers six fault modes with 30-second timeouts.
lib/​tpm/​TransmissionPolicyManager.hpp Declares shared recovery helpers and a record-release route.
lib/​tpm/​TransmissionPolicyManager.cpp Handles preparation exceptions and retires abandoned uploads.
lib/​system/​TelemetrySystem.cpp Connects failed-upload recovery to storage record release.
lib/​system/​Contexts.hpp Tracks HTTP callback registration ownership.
lib/​http/​HttpClientManager.cpp Guards pending callbacks and reorders request logging.

Review effort: Balanced

Comment thread lib/tpm/TransmissionPolicyManager.cpp Resolved
@bmehta001
bmehta001 enabled auto-merge (squash) November 6, 2026 19:38
bmehta001 and others added 2 commits November 6, 2026 13:38
Address Copilot round 1 on microsoft#1559.

4496757055: Mark the active memory/disk backend before retrieval can throw and copy that provenance to the upload context during unwinding, so partial RAM reservations return to RAM rather than being stranded. Verified at lib/offline/OfflineStorageHandler.cpp:654 and lib/offline/StorageObserver.cpp:66. Add four standard/nonstandard RAM/disk regressions in tests/unittests/OfflineStorageTests.cpp.

4496757163: Verify the zero-delay barrier through its future rather than a task pointer that is cleared on completion. Verified at lib/pal/TaskDispatcher.hpp:73; update tests/functests/upload-exception-tests.cpp.

Files: lib/offline/OfflineStorageHandler.cpp, lib/offline/StorageObserver.cpp, tests/unittests/OfflineStorageTests.cpp, tests/functests/upload-exception-tests.cpp.

Validation: Windows 195 and Linux 199 targeted unit tests; six native upload cases and no-exceptions smoke on both platforms; 20 repetitions of all four Windows preparation barriers. Changed-code clang-format and git diff --check passed; no selected tests were skipped or excluded.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: ffecbc0a-951e-4cae-9e94-49ddce94c050

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

An oversized RAM event can be incorrectly marked as disk-backed when the disk read consumes no records, leaving it queued for repeated uploads after successful completion.

1 open issue
2 resolved since last review

Review effort: Balanced

Comment thread lib/offline/OfflineStorageHandler.cpp Resolved
Address Copilot round 2, comment 4496977358: preserve pre-call disk exception provenance, but restore the previous source when a successful disk read consumes no records. This prevents an oversized first RAM event from being mislabeled as disk-backed and uploaded repeatedly after successful completion.

Verified at lib/offline/MemoryStorage.cpp:163-168 and lib/packager/Packager.cpp:31-41. Files changed: lib/offline/OfflineStorageHandler.cpp and tests/unittests/OfflineStorageTests.cpp.

The new regression failed before the fix, leaving the acknowledged RAM event queued, and passes afterward. Windows and Linux: 25 storage tests, six native upload CTests, and no-exceptions smoke passed without skipped or excluded selected tests. Changed-code clang-format and git diff --check passed.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: ffecbc0a-951e-4cae-9e94-49ddce94c050

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified for the upload exception-recovery changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@bmehta001
bmehta001 merged commit c7761eb into microsoft:main Nov 6, 2026
95 checks passed
@bmehta001
bmehta001 deleted the fix/upload-exception-recovery branch November 6, 2026 21:02
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.

3 participants