fix(python): avoid closed loop completion callbacks - #676
Conversation
Signed-off-by: Will Killian <wkillian@nvidia.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Enterprise Run ID: 📒 Files selected for processing (1)
📜 Recent review details🧰 Additional context used📓 Path-based instructions (11)**/*.rs📄 CodeRabbit inference engine (.agents/skills/prepare-pr/SKILL.md)
Files:
**/*.{rs,py}📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.{rs,py,js,mjs,cjs,ts,tsx}📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.{rs,py,go,js,ts,c,h}📄 CodeRabbit inference engine (CONTRIBUTING.md)
Files:
**/*.{rs,go,js,ts}📄 CodeRabbit inference engine (CONTRIBUTING.md)
Files:
{crates/python/src/py_api/mod.rs,python/nemo_relay/**/*.py,python/nemo_relay/**/*.pyi,go/nemo_relay/**/*.go,crates/node/src/api/**/*.rs}📄 CodeRabbit inference engine (.agents/skills/add-binding-feature/SKILL.md)
Files:
{crates/**/src/**/*.rs,python/**/*.py}📄 CodeRabbit inference engine (.agents/skills/maintain-dynamic-plugins/SKILL.md)
Files:
**/*📄 CodeRabbit inference engine (.agents/skills/validate-change/SKILL.md)
Files:
**/*.{rs,py,go,js,ts}📄 CodeRabbit inference engine (.agents/skills/validate-change/SKILL.md)
Files:
**/*.{rs,py,js,ts,tsx,go,java,kt,swift}📄 CodeRabbit inference engine (.agents/skills/add-middleware/SKILL.md)
Files:
crates/{python,ffi,node}/**/*⚙️ CodeRabbit configuration file
Files:
🧠 Learnings (1)📚 Learning: 2026-08-03T19:55:03.931ZApplied to files:
🔇 Additional comments (3)
WalkthroughThe Python API adds a cancellation-aware bridge for Rust futures. It creates native asyncio futures, cancels Rust tasks when Python futures are cancelled, and safely propagates results or exceptions. Tool execution uses the new bridge. ChangesPython future bridge
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant PythonFuture
participant SafeFutureCanceller
participant RustTask
participant EventLoop
PythonFuture->>SafeFutureCanceller: cancellation callback
SafeFutureCanceller->>RustTask: cancellation signal
RustTask->>EventLoop: result or exception
EventLoop->>PythonFuture: complete future
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
/merge |
#### Overview Preserve `future_into_py` panic settlement for the closed-loop-safe tool execution bridge. - [x] I confirm this contribution is my own work, or I have the right to submit it under this project's license. - [x] I searched existing issues and open pull requests, and this does not duplicate existing work. #### Details - Use the closed-loop-safe completion bridge for `tool_call_execute`. - Convert panicking Rust tasks into `pyo3_async_runtimes.RustPanic`, matching `future_into_py`. - Add regression coverage for Python future settlement after a Rust panic. #### Where should the reviewer start? Start with `safe_future_into_py` in `crates/python/src/py_api/mod.rs` and `safe_future_into_py_settles_rust_panics` in the adjacent coverage test. #### Related Issues: (use one of the action keywords Closes / Fixes / Resolves / Relates to) - Relates to #676 ## Summary by CodeRabbit * **Bug Fixes** * Improved reliability when running asynchronous operations from Python. * Rust panics and task failures are now converted into Python exceptions with readable error messages. * Preserved successful results and cancellation behavior during asynchronous execution. * Prevented completion callbacks from being scheduled after the Python event loop closes. * **Tests** * Added coverage for panic handling, cancellation of pending operations, and closed event-loop behavior. Authors: - Will Killian (https://github.com/willkill07) Approvers: - Maryam Najafian (https://github.com/mnajafian-nv) URL: #682
Overview
Prevents Python tool execution from queuing a completion callback after its owning asyncio event loop has closed during cancellation.
Details
Where should the reviewer start?
Start with
crates/python/src/py_api/mod.rs, especiallysafe_future_into_pyand its cancellation/completion callbacks.Related Issues: (use one of the action keywords Closes / Fixes / Resolves / Relates to)
Summary by CodeRabbit