Skip to content

fix(python): keep a pending exception through native stream wakes - #1421

Merged
greysonlalonde merged 1 commit into
NVIDIA:mainfrom
greysonlalonde:fix/python-stream-wake-pending-exception
Oct 20, 2026
Merged

greysonlalonde merged 1 commit into
NVIDIA:mainfrom
greysonlalonde:fix/python-stream-wake-pending-exception

Conversation

@greysonlalonde

@greysonlalonde greysonlalonde commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Overview

  • 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

Where should the reviewer start?

Related Issues: (use one of the action keywords Closes / Fixes / Resolves / Relates to)

  • Closes #

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability when asynchronous callbacks run while a Python exception is pending.
    • Preserved pending exceptions during event-loop wake handling.
    • Improved streaming LLM error handling so connection failures are forwarded correctly or can be recovered with replacement output, including failures occurring before or after initial streamed content.

@greysonlalonde greysonlalonde added this to the 0.11 milestone Oct 20, 2026
@greysonlalonde greysonlalonde self-assigned this Oct 20, 2026
@greysonlalonde greysonlalonde added the Bug issue describes bug; PR fixes bug label Oct 20, 2026
@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: NVIDIA/NeMo-Relay/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Enterprise
  • Run ID: ec8e9609-f147-43b9-9994-9b5ccf8822e8
📥 Commits

Reviewing files that changed from the base of the PR and between 9ce4466 and 3524506.

📒 Files selected for processing: 2
  • crates/python/src/py_async.rs
  • python/tests/test_llm.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 8 remain after this review.

📜 Recent review details
🧰 Additional context used
📚 Code guidelines: 1
CONTRIBUTING.md — configured
📓 Path-based instructions: 4
Tests should cover the behavior promised by the changed API surface, including error paths and cross-request isolation where relevant.

⚙️ CodeRabbit configuration file

Files:

  • python/tests/test_llm.py
Treat binding changes as public API changes.

⚙️ CodeRabbit configuration file

Files:

  • crates/python/src/py_async.rs
Applicability reference: AGENTS.md: # NeMo Relay Repository Guidance See `CONTRIBUTING.md` and `docs/contribute/testing-and-docs.mdx` for contributor details, and `.agents/skills/README.md` for the maintainer skill boundar...

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Files:

  • crates/python/src/py_async.rs
  • python/tests/test_llm.py
Applicability reference: AGENTS.md: # NeMo Relay Repository Guidance See `CONTRIBUTING.md` and `docs/contribute/testing-and-docs.mdx` for contributor details, and `.agents/skills/README.md` for the maintainer skill boundary.

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Files:

  • crates/python/src/py_async.rs
  • python/tests/test_llm.py
🔇 Additional comments: 1
python/tests/test_llm.py: 1

12-13: LGTM!

Also applies to: 24-24, 1955-2012, 2192-2200

Walkthrough

The event-loop wake path now preserves Python’s pending exception. Streaming-intercept tests cover provider connection errors after zero or one chunks, including error propagation and recovery with a replacement token.

Changes

Pending exception preservation

Layer / File(s) Summary
Capture and restore pending exceptions
crates/python/src/py_async.rs
PendingException fetches the pending Python exception and restores it on drop. wake_by_ref captures the exception before interacting with the event loop and callback.

Streaming-intercept error tests

Layer / File(s) Summary
Test streaming error propagation and recovery
python/tests/test_llm.py
Parameterized tests cover provider ConnectionErrors after zero or one emitted chunks. They verify propagation or recovery by yielding a replacement token.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~15 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 35245

No actionable issue remains that would prevent merging after normal checks.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Description check Warning The description includes the required headings and completed overview checkboxes, but the Details and reviewer-start sections are empty, and the related issue remains an incomplete placeholder. Describe the implementation and validation in Details, identify the file or test where review should start, and replace "Closes #" with a valid issue reference.
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title follows Conventional Commits format, uses the allowed lowercase type and scope, clearly describes the fix, stays under 72 characters, and has no trailing period.
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 a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@github-actions github-actions Bot added size:S PR is small lang:python PR changes/introduces Python code lang:rust PR changes/introduces Rust code labels Oct 20, 2026
@willkill07
willkill07 marked this pull request as ready for review October 20, 2026 19:33
@willkill07
willkill07 requested a review from a team as a code owner October 20, 2026 19:33
@greysonlalonde
greysonlalonde merged commit 5061ff7 into NVIDIA:main Oct 20, 2026
56 of 57 checks passed

This branch was previously deployed

1 inactive deployment
fern — 3524506d Deployed Oct 20, 2026 by greysonlalonde via Clean up docs preview #6062
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:python PR changes/introduces Python code lang:rust PR changes/introduces Rust code size:S PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants