Skip to content

fix(python): preserve panic settlement after loop shutdown fix - #682

Merged
rapids-bot[bot] merged 2 commits into
NVIDIA:release/0.7from
willkill07:fix/relay-676-panic-settlement
Aug 4, 2026
Merged

fix(python): preserve panic settlement after loop shutdown fix#682
rapids-bot[bot] merged 2 commits into
NVIDIA:release/0.7from
willkill07:fix/relay-676-panic-settlement

Conversation

@willkill07

@willkill07 willkill07 commented Aug 4, 2026

Copy link
Copy Markdown
Member

Overview

Preserve future_into_py panic settlement for the closed-loop-safe tool execution bridge.

  • I confirm this contribution is my own work, or I have the right to submit it under this project's license.
  • 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)

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.

@willkill07
willkill07 requested a review from a team as a code owner August 4, 2026 01:58
@github-actions github-actions Bot added size:M PR is medium Bug issue describes bug; PR fixes bug lang:rust PR changes/introduces Rust code labels Aug 4, 2026
@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Enterprise

Run ID: 70dda61f-9e15-4b73-b899-842ba64a88f2

📥 Commits

Reviewing files that changed from the base of the PR and between a8dcb8c and ee6d71d.

📒 Files selected for processing (2)
  • crates/python/src/py_api/mod.rs
  • crates/python/tests/coverage/py_api_coverage_tests.rs
📜 Recent review details
⏰ Context from checks skipped due to timeout. (1)
  • GitHub Check: Preview docs
🧰 Additional context used
📓 Path-based instructions (15)
**/*.rs

📄 CodeRabbit inference engine (.agents/skills/prepare-pr/SKILL.md)

**/*.rs: Any Rust change must run just test-rust
Any Rust change must run cargo fmt --all
Any Rust change must run cargo clippy --workspace --all-targets -- -D warnings

**/*.rs: Run cargo fmt --all for all FFI work since it is Rust work
Run just test-rust to validate FFI changes
Run cargo clippy --workspace --all-targets -- -D warnings to enforce strict linting on FFI work

When Rust files changed as part of Go work, also run cargo fmt --all, just test-rust, and cargo clippy --workspace --all-targets -- -D warnings

**/*.rs: Run cargo fmt --all when Rust files are changed as part of Node work
Run cargo clippy --workspace --all-targets -- -D warnings when Rust files are changed as part of Node work
Run just test-rust when Rust files are changed as part of Node work

**/*.rs: If any Rust code changed, always run just test-rust.
If any Rust code changed, also run cargo fmt --all.
If any Rust code changed, also run cargo clippy --workspace --all-targets -- -D warnings.
For Rust changes headed for review, run cargo fmt --all and cargo clippy --workspace --all-targets -- -D warnings even if relying on pre-commit.

**/*.rs: Format Rust code with rustfmt defaults using cargo fmt.
Run cargo clippy -- -D warnings; all Rust warnings must be treated as errors.
Use Rust snake_case naming conventions.

Files:

  • crates/python/src/py_api/mod.rs
  • crates/python/tests/coverage/py_api_coverage_tests.rs
{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)

Update the language-native bindings for every exposed surface in Python, Go, and Node.js.

Files:

  • crates/python/src/py_api/mod.rs
{crates/**/src/**/*.rs,python/**/*.py}

📄 CodeRabbit inference engine (.agents/skills/maintain-dynamic-plugins/SKILL.md)

Do not add tests under src; Rust tests belong in crate tests/ trees, and Python SDK tests belong under python/tests.

Files:

  • crates/python/src/py_api/mod.rs
**/*

📄 CodeRabbit inference engine (.agents/skills/validate-change/SKILL.md)

**/*: Format changed files with the language-native formatter before the final lint/test pass.
If dynamic plugin behavior changed, use maintain-dynamic-plugins and include the native SDK, worker protocol, Python SDK, docs, packaging, and Codecov surfaces in the validation plan.
If code changes alter APIs, bindings, commands, paths, packaging behavior, observability/adaptive semantics, or documented best practices, update any dependent maintainer or consumer skills in the same branch.
During iteration, prefer uv run pre-commit run --files <changed files...>.
Before review or handoff, run uv run pre-commit run --all-files.

**/*: Use release tags in raw Rust-compatible SemVer without a leading v; tags such as v0.1.0 are prohibited.
Use branch prefixes feat/, fix/, docs/, test/, or refactor/ according to the change purpose.
Every commit in a pull request must include a DCO Signed-off-by: sign-off.
Before submitting a pull request, ensure pre-commit hooks, relevant tests, target-specific builds, documentation updates, and a rebase on the latest main are complete.
Use commit messages in the form type: short description, with a valid type and a first line under 72 characters.

Files:

  • crates/python/src/py_api/mod.rs
  • crates/python/tests/coverage/py_api_coverage_tests.rs
**/*.{rs,py,go,js,ts}

📄 CodeRabbit inference engine (.agents/skills/validate-change/SKILL.md)

If a language surface changed, always run that language's test target even when Rust core did not change.

**/*.{rs,py,go,js,ts}: When observability configuration or lifecycle is exposed, keep FFI and Python, Go, and Node.js binding-native config objects and subscriber/exporter methods aligned in logical knobs and semantics.
Require every OpenTelemetry endpoint to have a type and nonblank destination; resolve header_env values at activation and reject missing, blank, or duplicate headers.
Concatenate layered ATOF sink, ATIF storage, and OpenTelemetry endpoint lists with higher-precedence entries first.
Preserve correct handling of mark events, start/end events, orphan cases, and span or trajectory fields derived from intended event data.
Run affected Rust tests and just test-rust when event fields change; run just test-python, just test-go, and just test-node when binding-native configuration or lifecycle changes.

Files:

  • crates/python/src/py_api/mod.rs
  • crates/python/tests/coverage/py_api_coverage_tests.rs
**/*.{rs,py,js,ts,tsx,go,java,kt,swift}

📄 CodeRabbit inference engine (.agents/skills/add-middleware/SKILL.md)

Add tests covering registration and duplicate names, deregistration and missing names, priority ordering, callback failure policy, scope-local inheritance and cleanup, event payload semantics, immutable mark and scope fields, and parity across affected bindings.

Files:

  • crates/python/src/py_api/mod.rs
  • crates/python/tests/coverage/py_api_coverage_tests.rs
**/*.{rs,py,js,jsx,ts,tsx,go,c,h,cc,cpp,md,toml,yml,yaml,sh}

📄 CodeRabbit inference engine (AGENTS.md)

Keep SPDX headers on source, documentation, scripts, and configuration files; the project is Apache-2.0.

Files:

  • crates/python/src/py_api/mod.rs
  • crates/python/tests/coverage/py_api_coverage_tests.rs
**/*.{rs,py}

📄 CodeRabbit inference engine (AGENTS.md)

Use snake_case naming in Rust and Python.

Files:

  • crates/python/src/py_api/mod.rs
  • crates/python/tests/coverage/py_api_coverage_tests.rs
crates/**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

crates/**/*.rs: Use Json = serde_json::Value in Rust-facing runtime APIs where existing code expects JSON payloads.
Treat Rust as the source of truth for runtime behavior; binding APIs should mirror Rust semantics unless a language-specific wrapper intentionally improves ergonomics.

Files:

  • crates/python/src/py_api/mod.rs
  • crates/python/tests/coverage/py_api_coverage_tests.rs
**/*.{rs,py,js,mjs,ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Preserve the existing Tokio-based asynchronous model and callback/future lifetimes; do not unexpectedly block or hide async work in bindings.

Files:

  • crates/python/src/py_api/mod.rs
  • crates/python/tests/coverage/py_api_coverage_tests.rs
**/*.{rs,py,go,js,jsx,ts,tsx,c,h}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

**/*.{rs,py,go,js,jsx,ts,tsx,c,h}: Run tests for every language affected by a change; changes to the core Rust crate require tests across all bindings.
Use SONAR_IGNORE_START / SONAR_IGNORE_END only for documented false positives, keep ignored blocks minimal, explain them with a comment, and obtain reviewer sign-off.
Preserve the layered architecture in which Rust provides the core runtime and C FFI, PyO3, and NAPI provide bindings that mirror the full API surface.

Files:

  • crates/python/src/py_api/mod.rs
  • crates/python/tests/coverage/py_api_coverage_tests.rs
**/*.{rs,py,go,js,jsx,ts,tsx,c,h,html,md,mdx,toml}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Include the appropriate SPDX copyright and Apache-2.0 license header in every source file.

Files:

  • crates/python/src/py_api/mod.rs
  • crates/python/tests/coverage/py_api_coverage_tests.rs
crates/{python,ffi,node}/**/*

⚙️ CodeRabbit configuration file

crates/{python,ffi,node}/**/*: Treat binding changes as public API changes. Check for parity with the other language bindings, FFI ownership/lifetime safety,
callback error propagation, stable type conversion, and consistent async/stream semantics.
Flag changes that update one binding without corresponding tests or documentation for the same surface elsewhere.

Files:

  • crates/python/src/py_api/mod.rs
  • crates/python/tests/coverage/py_api_coverage_tests.rs
**/{test,tests}/**/*

📄 CodeRabbit inference engine (CONTRIBUTING.md)

When adding functionality, include tests in the appropriate test files for each affected language binding.

Files:

  • crates/python/tests/coverage/py_api_coverage_tests.rs
{crates/**/tests/**,python/tests/**,go/nemo_relay/**/*_test.go}

⚙️ CodeRabbit configuration file

{crates/**/tests/**,python/tests/**,go/nemo_relay/**/*_test.go}: Tests should cover the behavior promised by the changed API surface, including error paths and cross-request isolation where relevant.
Prefer assertions on lifecycle events, scope stacks, middleware ordering, and binding parity over shallow smoke tests.

Files:

  • crates/python/tests/coverage/py_api_coverage_tests.rs
🧠 Learnings (1)
📚 Learning: 2026-08-03T19:55:03.931Z
Learnt from: afourniernv
Repo: NVIDIA/NeMo-Relay PR: 558
File: crates/pii-redaction/src/rampart/mod.rs:265-274
Timestamp: 2026-08-03T19:55:03.931Z
Learning: In NeMo Relay first-party plugin registration helpers, treat the documented duplicate-registration `PluginError::RegistrationFailed` result from `register_plugin` as success when registration is intended to be idempotent. Do not locally reclassify this as `PluginError::Conflict`; changing the classification requires a core-wide review of the public API and FFI behavior.

Applied to files:

  • crates/python/src/py_api/mod.rs
  • crates/python/tests/coverage/py_api_coverage_tests.rs
🔇 Additional comments (5)
crates/python/src/py_api/mod.rs (1)

138-153: 📐 Maintainability & Code Quality

Run the required Rust validation.

Run cargo fmt --all, cargo clippy --workspace --all-targets -- -D warnings, and just test-rust before merge. Provide the results with this change.

As per coding guidelines, Rust changes must run cargo fmt --all, cargo clippy --workspace --all-targets -- -D warnings, and just test-rust.

Source: Coding guidelines

crates/python/tests/coverage/py_api_coverage_tests.rs (4)

9-10: LGTM!


43-92: LGTM!


118-143: LGTM!


145-177: LGTM!


Walkthrough

The PR updates safe_future_into_py to run bridged futures in spawned Tokio tasks. It converts Rust panics and task join failures into Python exceptions. Tests cover panic messages, cancellation, and closed event loops.

Changes

Safe future bridge

Layer / File(s) Summary
Future bridge and panic handling
crates/python/src/py_api/mod.rs
safe_future_into_py formats panic payloads, handles spawned-task panics and join failures, and preserves successful results and cancellation behavior.
Future lifecycle coverage
crates/python/tests/coverage/py_api_coverage_tests.rs
Tests verify panic conversion, cancellation of pending Rust work, and skipped completion scheduling for closed loops.

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

Sequence Diagram(s)

sequenceDiagram
  participant PythonEventLoop
  participant TokioTask
  participant RustFuture
  PythonEventLoop->>TokioTask: Start safe_future_into_py
  TokioTask->>RustFuture: Execute bridged future
  RustFuture-->>TokioTask: Return result or panic
  TokioTask-->>PythonEventLoop: Return result or RustPanic
Loading

Possibly related PRs

  • NVIDIA/NeMo-Relay#676: Modifies the same Python async future bridge for cancellation and closed-event-loop handling.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title follows Conventional Commits format, uses an allowed type and lowercase scope, stays under 72 characters, and has no trailing period.
Description check ✅ Passed The description includes all required sections, completed checklist items, implementation details, reviewer guidance, and a related issue reference.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Signed-off-by: Will Killian <wkillian@nvidia.com>
@willkill07
willkill07 force-pushed the fix/relay-676-panic-settlement branch from 47d1bbf to a8dcb8c Compare August 4, 2026 02:00
@github-actions github-actions Bot added size:S PR is small and removed size:M PR is medium labels Aug 4, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/python/src/py_api/mod.rs`:
- Around line 137-150: Update the async task handling around the
`tokio::select!` in the Python API so the spawned `JoinHandle` is stored and
selected by mutable reference rather than detached. When `cancel_receiver` wins,
explicitly call `handle.abort()` before returning; preserve the existing result
and panic conversion for completed tasks, and add a regression test proving
cancellation prevents the Rust-side tool work from completing.

In `@crates/python/tests/coverage/py_api_coverage_tests.rs`:
- Around line 41-63: Add a regression test alongside
safe_future_into_py_settles_rust_panics that closes the event loop before the
Rust future settles, then drive or await the task as appropriate. Verify
safe_future_into_py completes without scheduling post-closure completion and
does not produce an unraisable callback error, covering the closed-loop error
path.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Enterprise

Run ID: 693737a3-e1dc-4f4d-a014-aec5b71d51ca

📥 Commits

Reviewing files that changed from the base of the PR and between 0ed87c7 and 47d1bbf.

📒 Files selected for processing (2)
  • crates/python/src/py_api/mod.rs
  • crates/python/tests/coverage/py_api_coverage_tests.rs
📜 Review details
🧰 Additional context used
📓 Path-based instructions (15)
**/*.rs

📄 CodeRabbit inference engine (.agents/skills/prepare-pr/SKILL.md)

**/*.rs: Any Rust change must run just test-rust
Any Rust change must run cargo fmt --all
Any Rust change must run cargo clippy --workspace --all-targets -- -D warnings

**/*.rs: Run cargo fmt --all for all FFI work since it is Rust work
Run just test-rust to validate FFI changes
Run cargo clippy --workspace --all-targets -- -D warnings to enforce strict linting on FFI work

When Rust files changed as part of Go work, also run cargo fmt --all, just test-rust, and cargo clippy --workspace --all-targets -- -D warnings

**/*.rs: Run cargo fmt --all when Rust files are changed as part of Node work
Run cargo clippy --workspace --all-targets -- -D warnings when Rust files are changed as part of Node work
Run just test-rust when Rust files are changed as part of Node work

**/*.rs: If any Rust code changed, always run just test-rust.
If any Rust code changed, also run cargo fmt --all.
If any Rust code changed, also run cargo clippy --workspace --all-targets -- -D warnings.
For Rust changes headed for review, run cargo fmt --all and cargo clippy --workspace --all-targets -- -D warnings even if relying on pre-commit.

**/*.rs: Format Rust code with rustfmt defaults using cargo fmt.
Run cargo clippy -- -D warnings; all Rust warnings must be treated as errors.
Use Rust snake_case naming conventions.

Files:

  • crates/python/tests/coverage/py_api_coverage_tests.rs
  • crates/python/src/py_api/mod.rs
**/*

📄 CodeRabbit inference engine (.agents/skills/validate-change/SKILL.md)

**/*: Format changed files with the language-native formatter before the final lint/test pass.
If dynamic plugin behavior changed, use maintain-dynamic-plugins and include the native SDK, worker protocol, Python SDK, docs, packaging, and Codecov surfaces in the validation plan.
If code changes alter APIs, bindings, commands, paths, packaging behavior, observability/adaptive semantics, or documented best practices, update any dependent maintainer or consumer skills in the same branch.
During iteration, prefer uv run pre-commit run --files <changed files...>.
Before review or handoff, run uv run pre-commit run --all-files.

**/*: Use release tags in raw Rust-compatible SemVer without a leading v; tags such as v0.1.0 are prohibited.
Use branch prefixes feat/, fix/, docs/, test/, or refactor/ according to the change purpose.
Every commit in a pull request must include a DCO Signed-off-by: sign-off.
Before submitting a pull request, ensure pre-commit hooks, relevant tests, target-specific builds, documentation updates, and a rebase on the latest main are complete.
Use commit messages in the form type: short description, with a valid type and a first line under 72 characters.

Files:

  • crates/python/tests/coverage/py_api_coverage_tests.rs
  • crates/python/src/py_api/mod.rs
**/*.{rs,py,go,js,ts}

📄 CodeRabbit inference engine (.agents/skills/validate-change/SKILL.md)

If a language surface changed, always run that language's test target even when Rust core did not change.

**/*.{rs,py,go,js,ts}: When observability configuration or lifecycle is exposed, keep FFI and Python, Go, and Node.js binding-native config objects and subscriber/exporter methods aligned in logical knobs and semantics.
Require every OpenTelemetry endpoint to have a type and nonblank destination; resolve header_env values at activation and reject missing, blank, or duplicate headers.
Concatenate layered ATOF sink, ATIF storage, and OpenTelemetry endpoint lists with higher-precedence entries first.
Preserve correct handling of mark events, start/end events, orphan cases, and span or trajectory fields derived from intended event data.
Run affected Rust tests and just test-rust when event fields change; run just test-python, just test-go, and just test-node when binding-native configuration or lifecycle changes.

Files:

  • crates/python/tests/coverage/py_api_coverage_tests.rs
  • crates/python/src/py_api/mod.rs
**/*.{rs,py,js,ts,tsx,go,java,kt,swift}

📄 CodeRabbit inference engine (.agents/skills/add-middleware/SKILL.md)

Add tests covering registration and duplicate names, deregistration and missing names, priority ordering, callback failure policy, scope-local inheritance and cleanup, event payload semantics, immutable mark and scope fields, and parity across affected bindings.

Files:

  • crates/python/tests/coverage/py_api_coverage_tests.rs
  • crates/python/src/py_api/mod.rs
**/*.{rs,py,js,jsx,ts,tsx,go,c,h,cc,cpp,md,toml,yml,yaml,sh}

📄 CodeRabbit inference engine (AGENTS.md)

Keep SPDX headers on source, documentation, scripts, and configuration files; the project is Apache-2.0.

Files:

  • crates/python/tests/coverage/py_api_coverage_tests.rs
  • crates/python/src/py_api/mod.rs
**/*.{rs,py}

📄 CodeRabbit inference engine (AGENTS.md)

Use snake_case naming in Rust and Python.

Files:

  • crates/python/tests/coverage/py_api_coverage_tests.rs
  • crates/python/src/py_api/mod.rs
crates/**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

crates/**/*.rs: Use Json = serde_json::Value in Rust-facing runtime APIs where existing code expects JSON payloads.
Treat Rust as the source of truth for runtime behavior; binding APIs should mirror Rust semantics unless a language-specific wrapper intentionally improves ergonomics.

Files:

  • crates/python/tests/coverage/py_api_coverage_tests.rs
  • crates/python/src/py_api/mod.rs
**/*.{rs,py,js,mjs,ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Preserve the existing Tokio-based asynchronous model and callback/future lifetimes; do not unexpectedly block or hide async work in bindings.

Files:

  • crates/python/tests/coverage/py_api_coverage_tests.rs
  • crates/python/src/py_api/mod.rs
**/*.{rs,py,go,js,jsx,ts,tsx,c,h}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

**/*.{rs,py,go,js,jsx,ts,tsx,c,h}: Run tests for every language affected by a change; changes to the core Rust crate require tests across all bindings.
Use SONAR_IGNORE_START / SONAR_IGNORE_END only for documented false positives, keep ignored blocks minimal, explain them with a comment, and obtain reviewer sign-off.
Preserve the layered architecture in which Rust provides the core runtime and C FFI, PyO3, and NAPI provide bindings that mirror the full API surface.

Files:

  • crates/python/tests/coverage/py_api_coverage_tests.rs
  • crates/python/src/py_api/mod.rs
**/{test,tests}/**/*

📄 CodeRabbit inference engine (CONTRIBUTING.md)

When adding functionality, include tests in the appropriate test files for each affected language binding.

Files:

  • crates/python/tests/coverage/py_api_coverage_tests.rs
**/*.{rs,py,go,js,jsx,ts,tsx,c,h,html,md,mdx,toml}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Include the appropriate SPDX copyright and Apache-2.0 license header in every source file.

Files:

  • crates/python/tests/coverage/py_api_coverage_tests.rs
  • crates/python/src/py_api/mod.rs
crates/{python,ffi,node}/**/*

⚙️ CodeRabbit configuration file

crates/{python,ffi,node}/**/*: Treat binding changes as public API changes. Check for parity with the other language bindings, FFI ownership/lifetime safety,
callback error propagation, stable type conversion, and consistent async/stream semantics.
Flag changes that update one binding without corresponding tests or documentation for the same surface elsewhere.

Files:

  • crates/python/tests/coverage/py_api_coverage_tests.rs
  • crates/python/src/py_api/mod.rs
{crates/**/tests/**,python/tests/**,go/nemo_relay/**/*_test.go}

⚙️ CodeRabbit configuration file

{crates/**/tests/**,python/tests/**,go/nemo_relay/**/*_test.go}: Tests should cover the behavior promised by the changed API surface, including error paths and cross-request isolation where relevant.
Prefer assertions on lifecycle events, scope stacks, middleware ordering, and binding parity over shallow smoke tests.

Files:

  • crates/python/tests/coverage/py_api_coverage_tests.rs
{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)

Update the language-native bindings for every exposed surface in Python, Go, and Node.js.

Files:

  • crates/python/src/py_api/mod.rs
{crates/**/src/**/*.rs,python/**/*.py}

📄 CodeRabbit inference engine (.agents/skills/maintain-dynamic-plugins/SKILL.md)

Do not add tests under src; Rust tests belong in crate tests/ trees, and Python SDK tests belong under python/tests.

Files:

  • crates/python/src/py_api/mod.rs
🧠 Learnings (1)
📚 Learning: 2026-08-03T19:55:03.931Z
Learnt from: afourniernv
Repo: NVIDIA/NeMo-Relay PR: 558
File: crates/pii-redaction/src/rampart/mod.rs:265-274
Timestamp: 2026-08-03T19:55:03.931Z
Learning: In NeMo Relay first-party plugin registration helpers, treat the documented duplicate-registration `PluginError::RegistrationFailed` result from `register_plugin` as success when registration is intended to be idempotent. Do not locally reclassify this as `PluginError::Conflict`; changing the classification requires a core-wide review of the public API and FFI behavior.

Applied to files:

  • crates/python/tests/coverage/py_api_coverage_tests.rs
  • crates/python/src/py_api/mod.rs
🔇 Additional comments (1)
crates/python/src/py_api/mod.rs (1)

44-44: 📐 Maintainability & Code Quality

Run the required Rust validation.

Provide successful output for cargo fmt --all, cargo clippy --workspace --all-targets -- -D warnings, and just test-rust before merge.

As per coding guidelines, “Any Rust change must run just test-rust”, “cargo fmt --all”, and “cargo clippy --workspace --all-targets -- -D warnings”.

Also applies to: 73-171, 819-819

Source: Coding guidelines

Comment thread crates/python/src/py_api/mod.rs
Comment thread crates/python/tests/coverage/py_api_coverage_tests.rs
@willkill07 willkill07 added this to the 0.7 milestone Aug 4, 2026
@willkill07 willkill07 self-assigned this Aug 4, 2026

@mnajafian-nv mnajafian-nv 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.

LGTM!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
crates/python/src/py_api/mod.rs (1)

137-150: ⚠️ Potential issue | 🟠 Major

Abort the inner Tokio task when the Python future is cancelled.

Line 139 creates the JoinHandle inside tokio::select!. If the cancellation branch wins at Line 148, dropping the handle detaches the task. The tool future can continue after Python reports cancellation and can still perform side effects.

Create the handle before select!. Select on &mut task. Call task.abort() in the cancellation branch. Add a regression test that verifies the Rust-side work stops after cancellation.

Proposed fix
-        let result = tokio::select! {
-            result = tokio::spawn(pyo3_async_runtimes::tokio::scope(locals, future)) => Some(
+        let mut task = tokio::spawn(pyo3_async_runtimes::tokio::scope(locals, future));
+        let result = tokio::select! {
+            result = &mut task => Some(
                 match result {
                     Ok(result) => result,
                     Err(error) if error.is_panic() => Err(pyo3_async_runtimes::err::RustPanic::new_err(
                         format!("rust future panicked: {}", panic_message(error.into_panic().as_ref())),
                     )),
                     Err(error) => Err(pyo3::exceptions::PyRuntimeError::new_err(error.to_string())),
                 },
             ),
-            _ = &mut cancel_receiver => None,
+            _ = &mut cancel_receiver => {
+                task.abort();
+                None
+            },
         };
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/python/src/py_api/mod.rs` around lines 137 - 150, Update the async
task flow around the `tokio::select!` block to store the spawned inner task in a
`JoinHandle` before entering `select!`, then select on `&mut task` and call
`task.abort()` when `cancel_receiver` wins. Preserve the existing result and
panic handling for completed tasks, and add a regression test verifying
Rust-side work stops after Python cancellation.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@crates/python/src/py_api/mod.rs`:
- Around line 137-150: Update the async task flow around the `tokio::select!`
block to store the spawned inner task in a `JoinHandle` before entering
`select!`, then select on `&mut task` and call `task.abort()` when
`cancel_receiver` wins. Preserve the existing result and panic handling for
completed tasks, and add a regression test verifying Rust-side work stops after
Python cancellation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Enterprise

Run ID: b4c87469-b196-4913-9de5-b1f0871cf9eb

📥 Commits

Reviewing files that changed from the base of the PR and between 47d1bbf and a8dcb8c.

📒 Files selected for processing (2)
  • crates/python/src/py_api/mod.rs
  • crates/python/tests/coverage/py_api_coverage_tests.rs
📜 Review details
⏰ Context from checks skipped due to timeout. (2)
  • GitHub Check: Check / Run
  • GitHub Check: Preview docs
🧰 Additional context used
📓 Path-based instructions (15)
**/*.rs

📄 CodeRabbit inference engine (.agents/skills/prepare-pr/SKILL.md)

**/*.rs: Any Rust change must run just test-rust
Any Rust change must run cargo fmt --all
Any Rust change must run cargo clippy --workspace --all-targets -- -D warnings

**/*.rs: Run cargo fmt --all for all FFI work since it is Rust work
Run just test-rust to validate FFI changes
Run cargo clippy --workspace --all-targets -- -D warnings to enforce strict linting on FFI work

When Rust files changed as part of Go work, also run cargo fmt --all, just test-rust, and cargo clippy --workspace --all-targets -- -D warnings

**/*.rs: Run cargo fmt --all when Rust files are changed as part of Node work
Run cargo clippy --workspace --all-targets -- -D warnings when Rust files are changed as part of Node work
Run just test-rust when Rust files are changed as part of Node work

**/*.rs: If any Rust code changed, always run just test-rust.
If any Rust code changed, also run cargo fmt --all.
If any Rust code changed, also run cargo clippy --workspace --all-targets -- -D warnings.
For Rust changes headed for review, run cargo fmt --all and cargo clippy --workspace --all-targets -- -D warnings even if relying on pre-commit.

**/*.rs: Format Rust code with rustfmt defaults using cargo fmt.
Run cargo clippy -- -D warnings; all Rust warnings must be treated as errors.
Use Rust snake_case naming conventions.

Files:

  • crates/python/tests/coverage/py_api_coverage_tests.rs
  • crates/python/src/py_api/mod.rs
**/*

📄 CodeRabbit inference engine (.agents/skills/validate-change/SKILL.md)

**/*: Format changed files with the language-native formatter before the final lint/test pass.
If dynamic plugin behavior changed, use maintain-dynamic-plugins and include the native SDK, worker protocol, Python SDK, docs, packaging, and Codecov surfaces in the validation plan.
If code changes alter APIs, bindings, commands, paths, packaging behavior, observability/adaptive semantics, or documented best practices, update any dependent maintainer or consumer skills in the same branch.
During iteration, prefer uv run pre-commit run --files <changed files...>.
Before review or handoff, run uv run pre-commit run --all-files.

**/*: Use release tags in raw Rust-compatible SemVer without a leading v; tags such as v0.1.0 are prohibited.
Use branch prefixes feat/, fix/, docs/, test/, or refactor/ according to the change purpose.
Every commit in a pull request must include a DCO Signed-off-by: sign-off.
Before submitting a pull request, ensure pre-commit hooks, relevant tests, target-specific builds, documentation updates, and a rebase on the latest main are complete.
Use commit messages in the form type: short description, with a valid type and a first line under 72 characters.

Files:

  • crates/python/tests/coverage/py_api_coverage_tests.rs
  • crates/python/src/py_api/mod.rs
**/*.{rs,py,go,js,ts}

📄 CodeRabbit inference engine (.agents/skills/validate-change/SKILL.md)

If a language surface changed, always run that language's test target even when Rust core did not change.

**/*.{rs,py,go,js,ts}: When observability configuration or lifecycle is exposed, keep FFI and Python, Go, and Node.js binding-native config objects and subscriber/exporter methods aligned in logical knobs and semantics.
Require every OpenTelemetry endpoint to have a type and nonblank destination; resolve header_env values at activation and reject missing, blank, or duplicate headers.
Concatenate layered ATOF sink, ATIF storage, and OpenTelemetry endpoint lists with higher-precedence entries first.
Preserve correct handling of mark events, start/end events, orphan cases, and span or trajectory fields derived from intended event data.
Run affected Rust tests and just test-rust when event fields change; run just test-python, just test-go, and just test-node when binding-native configuration or lifecycle changes.

Files:

  • crates/python/tests/coverage/py_api_coverage_tests.rs
  • crates/python/src/py_api/mod.rs
**/*.{rs,py,js,ts,tsx,go,java,kt,swift}

📄 CodeRabbit inference engine (.agents/skills/add-middleware/SKILL.md)

Add tests covering registration and duplicate names, deregistration and missing names, priority ordering, callback failure policy, scope-local inheritance and cleanup, event payload semantics, immutable mark and scope fields, and parity across affected bindings.

Files:

  • crates/python/tests/coverage/py_api_coverage_tests.rs
  • crates/python/src/py_api/mod.rs
**/*.{rs,py,js,jsx,ts,tsx,go,c,h,cc,cpp,md,toml,yml,yaml,sh}

📄 CodeRabbit inference engine (AGENTS.md)

Keep SPDX headers on source, documentation, scripts, and configuration files; the project is Apache-2.0.

Files:

  • crates/python/tests/coverage/py_api_coverage_tests.rs
  • crates/python/src/py_api/mod.rs
**/*.{rs,py}

📄 CodeRabbit inference engine (AGENTS.md)

Use snake_case naming in Rust and Python.

Files:

  • crates/python/tests/coverage/py_api_coverage_tests.rs
  • crates/python/src/py_api/mod.rs
crates/**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

crates/**/*.rs: Use Json = serde_json::Value in Rust-facing runtime APIs where existing code expects JSON payloads.
Treat Rust as the source of truth for runtime behavior; binding APIs should mirror Rust semantics unless a language-specific wrapper intentionally improves ergonomics.

Files:

  • crates/python/tests/coverage/py_api_coverage_tests.rs
  • crates/python/src/py_api/mod.rs
**/*.{rs,py,js,mjs,ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Preserve the existing Tokio-based asynchronous model and callback/future lifetimes; do not unexpectedly block or hide async work in bindings.

Files:

  • crates/python/tests/coverage/py_api_coverage_tests.rs
  • crates/python/src/py_api/mod.rs
**/*.{rs,py,go,js,jsx,ts,tsx,c,h}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

**/*.{rs,py,go,js,jsx,ts,tsx,c,h}: Run tests for every language affected by a change; changes to the core Rust crate require tests across all bindings.
Use SONAR_IGNORE_START / SONAR_IGNORE_END only for documented false positives, keep ignored blocks minimal, explain them with a comment, and obtain reviewer sign-off.
Preserve the layered architecture in which Rust provides the core runtime and C FFI, PyO3, and NAPI provide bindings that mirror the full API surface.

Files:

  • crates/python/tests/coverage/py_api_coverage_tests.rs
  • crates/python/src/py_api/mod.rs
**/{test,tests}/**/*

📄 CodeRabbit inference engine (CONTRIBUTING.md)

When adding functionality, include tests in the appropriate test files for each affected language binding.

Files:

  • crates/python/tests/coverage/py_api_coverage_tests.rs
**/*.{rs,py,go,js,jsx,ts,tsx,c,h,html,md,mdx,toml}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Include the appropriate SPDX copyright and Apache-2.0 license header in every source file.

Files:

  • crates/python/tests/coverage/py_api_coverage_tests.rs
  • crates/python/src/py_api/mod.rs
crates/{python,ffi,node}/**/*

⚙️ CodeRabbit configuration file

crates/{python,ffi,node}/**/*: Treat binding changes as public API changes. Check for parity with the other language bindings, FFI ownership/lifetime safety,
callback error propagation, stable type conversion, and consistent async/stream semantics.
Flag changes that update one binding without corresponding tests or documentation for the same surface elsewhere.

Files:

  • crates/python/tests/coverage/py_api_coverage_tests.rs
  • crates/python/src/py_api/mod.rs
{crates/**/tests/**,python/tests/**,go/nemo_relay/**/*_test.go}

⚙️ CodeRabbit configuration file

{crates/**/tests/**,python/tests/**,go/nemo_relay/**/*_test.go}: Tests should cover the behavior promised by the changed API surface, including error paths and cross-request isolation where relevant.
Prefer assertions on lifecycle events, scope stacks, middleware ordering, and binding parity over shallow smoke tests.

Files:

  • crates/python/tests/coverage/py_api_coverage_tests.rs
{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)

Update the language-native bindings for every exposed surface in Python, Go, and Node.js.

Files:

  • crates/python/src/py_api/mod.rs
{crates/**/src/**/*.rs,python/**/*.py}

📄 CodeRabbit inference engine (.agents/skills/maintain-dynamic-plugins/SKILL.md)

Do not add tests under src; Rust tests belong in crate tests/ trees, and Python SDK tests belong under python/tests.

Files:

  • crates/python/src/py_api/mod.rs
🧠 Learnings (1)
📚 Learning: 2026-08-03T19:55:03.931Z
Learnt from: afourniernv
Repo: NVIDIA/NeMo-Relay PR: 558
File: crates/pii-redaction/src/rampart/mod.rs:265-274
Timestamp: 2026-08-03T19:55:03.931Z
Learning: In NeMo Relay first-party plugin registration helpers, treat the documented duplicate-registration `PluginError::RegistrationFailed` result from `register_plugin` as success when registration is intended to be idempotent. Do not locally reclassify this as `PluginError::Conflict`; changing the classification requires a core-wide review of the public API and FFI behavior.

Applied to files:

  • crates/python/tests/coverage/py_api_coverage_tests.rs
  • crates/python/src/py_api/mod.rs
🔇 Additional comments (3)
crates/python/tests/coverage/py_api_coverage_tests.rs (1)

41-63: Add closed-event-loop regression coverage.

This test runs run_until_complete while the event loop is open. The helper closes the loop only after the future settles, so this test does not exercise the closed-loop branch in safe_future_into_py. Add a case that keeps the Rust future pending, closes the event loop before it settles, and verifies that no completion callback or unraisable callback error occurs.

As per path instructions, tests should cover the behavior promised by the changed API surface, including error paths.

Source: Path instructions

crates/python/src/py_api/mod.rs (2)

44-44: LGTM!

Also applies to: 73-136, 151-170


819-843: Run the required validation before handoff.

Run cargo fmt --all, cargo clippy --workspace --all-targets -- -D warnings, just test-rust, just test-python, and uv run pre-commit run --all-files. Verify the SPDX headers in both changed files.

As per coding guidelines, Rust and binding-surface changes require formatter, strict Clippy, affected-language tests, and all-files pre-commit validation.

Source: Coding guidelines

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

Signed-off-by: Will Killian <wkillian@nvidia.com>
@github-actions github-actions Bot added size:M PR is medium and removed size:S PR is small labels Aug 4, 2026
@willkill07

Copy link
Copy Markdown
Member Author

/merge

@rapids-bot
rapids-bot Bot merged commit 0ef068f into NVIDIA:release/0.7 Aug 4, 2026
43 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Aug 4, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug issue describes bug; PR fixes bug lang:rust PR changes/introduces Rust code size:M PR is medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants