Skip to content

fix(node): preserve stream errors when close races a poll - #1451

Merged
willkill07 merged 1 commit into
NVIDIA:mainfrom
willkill07:fix/node-stream-close-cancellation-race
Oct 21, 2026
Merged

willkill07 merged 1 commit into
NVIDIA:mainfrom
willkill07:fix/node-stream-close-cancellation-race

Conversation

@willkill07

@willkill07 willkill07 commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Overview

When close() cancels a forwarded Node.js LLM stream during a poll, resolve the pending next() with null and report the collector error from close(), ahead of a producer cleanup failure. This fixes the intermittent Node test failure observed in PR #1449's CI job.

  • 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

  • Recheck cancellation after polling the stream: a biased Tokio select cannot interrupt a stream branch already being polled.
  • Preserve an error consumed during cancellation for close(), and log a secondary cleanup failure using the existing runtime warning.
  • Add a deterministic native regression test that cancels inside the stream poll. Cover chunks and errors with and without cancellation, without sleeps or production test hooks.
  • Add the Node crate's direct log dependency; the resolved version is already present in the lockfile.

Validation:

  • The new regression test failed against the original implementation and passed with the fix.
  • just test-node: 6 native tests, 503 JavaScript tests, and 26 language-binding plugin example tests passed.
  • uv run pre-commit run passed, including workspace Clippy/checks, link checks, dependency audits, and generated Rust attribution verification.
  • Other language suites were not run because the change is confined to the Node binding and restores its documented behavior.

Where should the reviewer start?

Start with forward_stream_to_channel in crates/node/src/stream.rs, then crates/node/tests/rust/stream_tests.rs. The regression forces cancellation after the select checks it but before the stream poll returns, and verifies error ownership and cleanup precedence.

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

Summary by CodeRabbit

  • Bug Fixes

    • Improved stream cancellation handling so errors encountered during cancellation are no longer silently discarded.
    • Stream cleanup now reports the most relevant failure while retaining additional cleanup failure details for diagnostics.
    • Pending reads now close correctly when cancellation occurs, without delivering unintended data.
  • Tests

    • Added coverage for cancellation, cleanup failures, collector errors, and their combinations to improve stream reliability.

@willkill07
willkill07 requested a review from a team as a code owner October 21, 2026 23:08
@github-actions github-actions Bot added size:S PR is small Bug issue describes bug; PR fixes bug lang:rust PR changes/introduces Rust code labels Oct 21, 2026
@coderabbitai

coderabbitai Bot commented Oct 21, 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: b457197e-0ad7-4d09-b7f2-aa4f4ef6ba4d
📥 Commits

Reviewing files that changed from the base of the PR and between f555c2d and f02a4fe.

⛔ Files ignored due to path filters: 1
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing: 3
  • crates/node/Cargo.toml
  • crates/node/src/stream.rs
  • crates/node/tests/rust/stream_tests.rs

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

📜 Recent review details
⏰ Context from checks skipped due to timeout: 28
  • GitHub Check: Node.js / Package (windows-arm64)
  • GitHub Check: Node.js / Test (macos-arm64)
  • GitHub Check: Node.js / Package (macos-arm64)
  • GitHub Check: Node.js / Package (linux-musl-arm64)
  • GitHub Check: Node.js / Package (windows-amd64)
  • GitHub Check: Node.js / Test (linux-arm64)
  • GitHub Check: Rust / Package (windows-amd64)
  • GitHub Check: Node.js / Test (windows-amd64)
  • GitHub Check: Node.js / Package (linux-amd64)
  • GitHub Check: Node.js / Test (windows-arm64)
  • GitHub Check: Rust / Package (linux-musl-amd64)
  • GitHub Check: Rust / Test (macos-arm64)
  • GitHub Check: Node.js / Test (linux-amd64)
  • GitHub Check: Rust / Package (linux-arm64)
  • GitHub Check: Rust / Package (windows-arm64)
  • GitHub Check: Node.js / Package (linux-musl-amd64)
  • GitHub Check: Rust / Package (linux-amd64)
  • GitHub Check: Check / Run
  • GitHub Check: Rust / Test (windows-arm64)
  • GitHub Check: Rust / Test (linux-amd64)
  • GitHub Check: Node.js / Package (linux-arm64)
  • GitHub Check: Rust / Package (macos-arm64)
  • GitHub Check: Rust / Test (linux-arm64)
  • GitHub Check: Rust / Package (linux-musl-arm64)
  • GitHub Check: Rust / Test (windows-amd64)
  • GitHub Check: License Diff / Run
  • GitHub Check: Node.js / Package OpenClaw plugin
  • GitHub Check: Preview docs
🧰 Additional context used
📚 Code guidelines: 4
CONTRIBUTING.md — configured
.agents/skills/prepare-code-freeze/SKILL.md — configured
.agents/skills/update-project-version/SKILL.md — configured
.agents/skills/maintain-packaging/SKILL.md — configured
📓 Path-based instructions: 7
Tests should cover the behavior promised by the changed API surface, including error paths and cross-request isolation where relevant.

⚙️ CodeRabbit configuration file

Files:

  • crates/node/tests/rust/stream_tests.rs
Treat binding changes as public API changes.

⚙️ CodeRabbit configuration file

Files:

  • crates/node/Cargo.toml
  • crates/node/src/stream.rs
  • crates/node/tests/rust/stream_tests.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/node/src/stream.rs
  • crates/node/tests/rust/stream_tests.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 boundary.

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Files:

  • crates/node/src/stream.rs
  • crates/node/tests/rust/stream_tests.rs
Source excerpt: Run `just set-version ` to update all project-owned unified-release version surfaces on `main`, including Cargo, Python, Node, plugins, lockfiles, and coding-agent manifests.

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

Files:

  • crates/node/Cargo.toml
Source excerpt: Python surfaces use PEP 440 translations where required; Cargo, npm, and plugin manifests use the repository SemVer form.

📄 CodeRabbit inference engine (.agents/skills/update-project-version/SKILL.md)

Files:

  • crates/node/Cargo.toml
Source excerpt: Rust `Cargo.toml` package names and workspace metadata

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

Files:

  • crates/node/Cargo.toml
🔇 Additional comments: 2
crates/node/src/stream.rs: 1

203-203: LGTM!

Also applies to: 231-237, 240-260, 836-839

crates/node/tests/rust/stream_tests.rs: 1

1-82: LGTM!

Walkthrough

Stream forwarding now preserves an error consumed but not delivered during cancellation. Cleanup failures are logged when that error exists. Tests cover cancellation and collector outcomes.

Changes

Stream Forwarding

Layer / File(s) Summary
Cancellation-safe stream cleanup
crates/node/Cargo.toml, crates/node/src/stream.rs, crates/node/tests/rust/stream_tests.rs
Forwarding retains errors consumed during cancellation. If one exists, cleanup returns that error and logs cleanup failures; otherwise, cleanup returns its result. Tests cover cancellation, delivery suppression, and collector success or failure. The node crate adds the log dependency.

Priority: ⬇️ Low

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

Change: Bug fix

Merge Risk: ⚪ Minimal · up to f02a4

The cancellation behavior and its regression test align with the intended cleanup behavior. No identified issue remains to block merging after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 2 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title follows Conventional Commits format with the allowed type fix, lowercase scope node, a concise imperative summary, valid length, and no trailing period.
Description check Passed The description includes all required sections, completed contribution and duplicate-work confirmations, implementation details, validation results, reviewer guidance, and related issues using the req…
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.
Full details: Description check

Explanation

The description includes all required sections, completed contribution and duplicate-work confirmations, implementation details, validation results, reviewer guidance, and related issues using the required Relates to keyword.

Full details: Docstring Coverage

Explanation

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

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

✨ 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

Copy link
Copy Markdown

License Diff

Compared against origin/main.

Lockfile license changes

Lockfile License Changes

Rust

Added

  • None

Removed

  • None

Updated/Changed

  • None

Node

Added

  • None

Removed

  • None

Updated/Changed

  • None

Python

Added

  • None

Removed

  • None

Updated/Changed

  • None
Status output
[license-diff] selected languages: rust, node, python
[license-diff] generating current inventory
[license-diff] current: generating Rust inventory
[license-diff] current: Rust inventory complete (479 packages)
[license-diff] current: generating Node inventory
[license-diff] current: Node inventory complete (424 packages)
[license-diff] current: generating Python inventory
[license-diff] current: Python inventory complete (115 packages)
[license-diff] current inventory complete
[license-diff] checking out base ref origin/main into a temporary worktree
[license-diff] base: generating Rust inventory
[license-diff] base: Rust inventory complete (479 packages)
[license-diff] base: generating Node inventory
[license-diff] base: Node inventory complete (424 packages)
[license-diff] base: generating Python inventory
[license-diff] base: Python inventory complete (115 packages)
[license-diff] base inventory complete
[license-diff] removing temporary base worktree
[license-diff] comparing inventories
[license-diff] rendering Markdown output
[license-diff] done

@github-actions

Copy link
Copy Markdown

@greysonlalonde greysonlalonde 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.

🥇

@willkill07
willkill07 merged commit a75a4a7 into NVIDIA:main Oct 21, 2026
65 checks passed
@willkill07 willkill07 self-assigned this Oct 23, 2026
@willkill07 willkill07 added this to the 0.11 milestone Oct 23, 2026
@willkill07
willkill07 deleted the fix/node-stream-close-cancellation-race branch October 30, 2026 14:46
@coderabbitai coderabbitai Bot mentioned this pull request Nov 2, 2026
2 tasks done

This branch was previously deployed

1 inactive deployment
fern — f02a4fe1 Deployed Oct 21, 2026 by willkill07 via Clean up docs preview #6202
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:S PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants