Skip to content

fix(core): harden diffusion strategy callbacks - #925

Open
shubhamsinnh wants to merge 1 commit into
RunanywhereAI:mainfrom
shubhamsinnh:bugfix/diffusion-registry-callback-safety
Open

shubhamsinnh wants to merge 1 commit into
RunanywhereAI:mainfrom
shubhamsinnh:bugfix/diffusion-registry-callback-safety

Conversation

@shubhamsinnh

@shubhamsinnh shubhamsinnh commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Description

Completes the hardening follow-up from #715:

  • documents that RAC_ERROR_NOT_FOUND is the only strategy result that defers to later strategies;
  • contains exceptions from can_handle, get_model_def, and select_backend at the public C ABI boundary;
  • maps std::bad_alloc to RAC_ERROR_OUT_OF_MEMORY and unexpected exceptions to RAC_ERROR_INTERNAL where an error channel exists;
  • preserves the existing CoreML fallback for backend selection;
  • adds a backend-independent native regression test for returned errors and throwing callbacks.

Fixes #851.

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Refactoring

Testing

  • Lint passes locally — clang-format is not installed on this Windows host
  • Added/updated tests for changes

Validation performed:

  • cmake --build build-issue851 --target test_diffusion_model_registry --parallel 4 — passed with MinGW/Ninja.
  • ctest --test-dir build-issue851 -R '^diffusion_model_registry_tests$' --output-on-failure — passed, 17 checks and 0 failures.
  • git diff --check — passed.

Platform-Specific Testing

Not applicable. This changes the shared native registry contract and adds a backend-independent native test; no application UI or device behavior changed.

Labels

  • core — C++ commons core (core/)

Checklist

  • Changes are limited to the diffusion registry contract and callback boundary
  • Mirrored public headers use identical wording
  • Self-review completed
  • Documentation updated

Screenshots

Not applicable; no UI changes.

Summary by CodeRabbit

  • Bug Fixes

    • Corrected Core ML diffusion model metadata, including scheduler selection, image-to-image support, model paths, and asset sizes.
    • Improved error handling so failures from diffusion model providers are reported consistently instead of escaping unexpectedly.
    • Preserved fallback behavior when a model or backend is unavailable.
  • Documentation

    • Clarified how model lookup and listing errors are handled, including fallback behavior for unavailable models.
  • Tests

    • Added coverage for provider errors, exceptions, memory failures, fallback behavior, and empty results on failure.

@coderabbitai

coderabbitai Bot commented Sep 11, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 0023d7ca-f56a-4a93-b236-20e7f4b1e6df

📥 Commits

Reviewing files that changed from the base of the PR and between 7d5a168 and 010fd5c.

📒 Files selected for processing (5)
  • bindings/swift/Sources/RunAnywhere/CRACommons/include/rac_diffusion_model_registry.h
  • core/include/rac/features/diffusion/rac_diffusion_model_registry.h
  • core/src/features/diffusion/diffusion_model_registry.cpp
  • core/tests/CMakeLists.txt
  • core/tests/test_diffusion_model_registry.cpp

Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The diffusion registry now documents strategy error propagation, catches exceptions from registry callbacks, corrects CoreML model definitions, and adds tests for returned errors, thrown exceptions, empty outputs, and backend fallback behavior.

Changes

Diffusion registry hardening

Layer / File(s) Summary
Callback error contract
bindings/swift/.../rac_diffusion_model_registry.h, core/include/.../rac_diffusion_model_registry.h
Both mirrored headers document that RAC_ERROR_NOT_FOUND defers to other strategies. Other errors abort the registry call and reach the caller.
Registry exception handling
core/src/features/diffusion/diffusion_model_registry.cpp
get maps callback exceptions to RAC_ERROR_OUT_OF_MEMORY or RAC_ERROR_INTERNAL. select_backend logs callback exceptions and returns the CoreML fallback. CoreML model definitions use the corrected scheduler, image-to-image support flag, path, and asset sizes.
Failure-path test coverage
core/tests/CMakeLists.txt, core/tests/test_diffusion_model_registry.cpp
Adds a CTest target that verifies returned strategy errors, exception mappings, empty outputs, and CoreML fallback behavior.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Suggested reviewers: sanchitmonga22

Merge Risk: ⚪ Minimal · up to 010fd

No concrete current-head issue remains; the callback exception handling, fallback behavior, documentation, and regression coverage are merge-ready.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 6.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 4 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: hardening diffusion strategy callbacks in the core registry.
Description check ✅ Passed The description covers the required sections, explains the callback hardening, identifies the bug-fix and documentation changes, reports test results, notes platform-specific testing is not applicable…
Linked Issues check ✅ Passed Issue #851 coding requirements are met. Both public headers document that only RAC_ERROR_NOT_FOUND defers to later strategies for get_model_def and list_models. rac_diffusion_model_registry_get() catc…
Out of Scope Changes check ✅ Passed The changes stay within Issue #851. Header documentation, callback exception guards, CoreML fallback handling, and the CMake and regression-test additions directly support the issue requirements. No u…
Full details: Docstring Coverage

Explanation

Docstring coverage is 6.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 4 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@shubhamsinnh
shubhamsinnh marked this pull request as ready for review September 11, 2026 21:49
@shubhamsinnh

Copy link
Copy Markdown
Contributor Author

Hi @sanchitmonga22 ,
Please have a look when you get a chance.
It addresses the hardening follow-up from #715
Thanks!

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.

Diffusion registry: document strategy return codes, guard remaining callbacks

1 participant