Skip to content

fix(node): stop aborting on codec callbacks queued at process exit - #1635

Merged
willkill07 merged 1 commit into
NVIDIA:release/0.11from
greysonlalonde:fix/node-codec-publication-at-exit
Nov 4, 2026
Merged

willkill07 merged 1 commit into
NVIDIA:release/0.11from
greysonlalonde:fix/node-codec-publication-at-exit

Conversation

@greysonlalonde

@greysonlalonde greysonlalonde commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Overview

This PR prevents the Node.js process from aborting when a codec callback is queued during process shutdown.

  • 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

  • detect when the node.js environment begins shutting down.
  • refuse new queued callbacks with a normal error during shutdown.
  • apply the same shutdown behavior to codec, tool, llm, guardrail, and plugin callbacks.
  • replace duplicate callback queue handling with one shared path.
  • add a regression test that queues a response codec callback during process exit.

Where should the reviewer start?

start with crates/node/src/callable.rs to review the shared callback queue and shutdown handling.

then review:

  • crates/node/src/promise_call.rs for process-exit detection.
  • crates/node/src/callback_factory.rs for callback reply handling.
  • crates/node/tests/llm_tests.mjs for the process-exit regression test.
  • crates/node/tests/callback_error_tests.mjs for closed-callback behavior.

Summary by CodeRabbit

  • Bug Fixes
    • Improved callback handling during Node.js shutdown. Calls that cannot be queued are now reported as errors instead of being accepted, and shutdown-related callback failures are handled without abruptly terminating the process.
    • Improved error reporting when a callback queue refuses a request.
  • Tests
    • Added coverage for callbacks invoked after shutdown and for callbacks whose queues have closed.

- carry threadsafe callback replies in call payloads via `reply_tsfn` and
  `call_with_reply` in `callable.rs`
- route scoped execution, conditional gate, and plugin validate and
  register callbacks through `call_with_reply` in `api/mod.rs`
- keep codec threadsafe function unreferenced and refuse queued calls
  after process exit via `mark_env_exiting_on_process_exit` in
  `promise_call.rs`
- remove unused middleware wrappers, threadsafe function builders, macro
  wrapper parameters, and closed-callback test hooks
- add reply callback factory and `__testClosedReplyCallback` hook
- add child-process exit test in `llm_tests.mjs`

Signed-off-by: Greyson Lalonde <[email protected]>
@greysonlalonde greysonlalonde added this to the 0.11 milestone Nov 3, 2026
@greysonlalonde greysonlalonde self-assigned this Nov 3, 2026
@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Walkthrough

Node callback paths now use reply-capable threadsafe functions for scoped execution, conditional gates, plugin callbacks, and codecs. The Node process exit event marks the environment as exiting. Callback queue refusals use the reply-call result path, and tests cover closed callbacks and queued codec work during shutdown.

Changes

Node callback and shutdown flow

Layer / File(s) Summary
Reply callback and shutdown foundation
crates/node/src/callback_factory.rs, crates/node/src/promise_call.rs, crates/node/src/callable.rs, crates/node/src/api/mod.rs, crates/node/tests/llm_tests.mjs
Adds the reply callback factory and teardown-aware reply calls. The process exit event marks the environment as exiting. Codec callbacks use the reply path, and a subprocess test checks queued callback behavior during shutdown.
Scoped callback migration
crates/node/src/api/mod.rs, crates/node/src/callable.rs, crates/node/tests/callback_error_tests.mjs
Scoped JSON, tool, and LLM callbacks use reply calls. Removes synchronous middleware wrappers and callback-wrapper macro parameters. Replaces the closed tool and LLM callback test helpers with a closed reply callback helper.
Conditional gates and plugin callbacks
crates/node/src/api/mod.rs
Conditional gate, plugin validation, and plugin registration callbacks use reply TSFNs. Queue refusals are reported through the updated error paths.

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

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant NodeProcess
  participant mark_env_exiting_on_process_exit
  participant env_teardown_flag
  participant JsCodecCallback
  participant ReplyTsfn
  NodeProcess->>mark_env_exiting_on_process_exit: process exit event
  mark_env_exiting_on_process_exit->>env_teardown_flag: set exiting
  JsCodecCallback->>ReplyTsfn: call_with_reply(payload)
  ReplyTsfn-->>JsCodecCallback: return queue refusal
Loading
Merge Risk: Minimal · up to 8ae33

The change moves Node callbacks onto reply-capable threadsafe functions and stops queued codec callbacks from aborting at process exit. No actionable merge-blocking issue was found in the reviewed changes.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 15.79% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… 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 with the allowed type "fix" and scope "node". It is 66 characters, under the 72-character limit, has no trailing period, and uses an imperative summary. The chan…
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.
Description check Passed The description includes the overview, contribution checklist, implementation details, reviewer starting points, and regression test information. The required Related Issues section is missing, so add…
Full details: Title check

Explanation

The title follows Conventional Commits with the allowed type "fix" and scope "node". It is 66 characters, under the 72-character limit, has no trailing period, and uses an imperative summary. The changeset adds queue-refusal handling for codec callbacks at process exit (ENV_SHUTTING_DOWN, mark_env_exiting_on_process_exit, ReplyTsfn), which matches the title. The change also removes many TSFN wrappers, but the title covers the main fix.

Full details: Description check

Explanation

The description includes the overview, contribution checklist, implementation details, reviewer starting points, and regression test information. The required Related Issues section is missing, so add an applicable action-keyword reference such as Closes #123 or state that no related issue applies.

Full details: Docstring Coverage

Explanation

Docstring coverage is 15.79% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 19 functions across 6 files.

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
Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between d5c024d and 8ae33e9.

Files selected for processing: 6
  • crates/node/src/api/mod.rs
  • crates/node/src/callable.rs
  • crates/node/src/callback_factory.rs
  • crates/node/src/promise_call.rs
  • crates/node/tests/callback_error_tests.mjs
  • crates/node/tests/llm_tests.mjs

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: 4
  • GitHub Check: Prepare
  • GitHub Check: Detect docs changes
  • GitHub Check: request / require-nvskills-ci / require-nvskills-ci
  • GitHub Check: Apply PR labels
Additional context used
Code guidelines: 1
CLAUDE.md — configured
Path-based instructions: 3
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/callback_error_tests.mjs
  • crates/node/tests/llm_tests.mjs
Treat binding changes as public API changes.

CodeRabbit configuration file

Files:

  • crates/node/tests/callback_error_tests.mjs
  • crates/node/src/promise_call.rs
  • crates/node/tests/llm_tests.mjs
  • crates/node/src/callback_factory.rs
  • crates/node/src/callable.rs
  • crates/node/src/api/mod.rs
Source excerpt: A public or observable runtime change requires identifying which bindings expose the affected contract.

CodeRabbit inference engine (CLAUDE.md)

Files:

  • crates/node/tests/callback_error_tests.mjs
  • crates/node/src/promise_call.rs
  • crates/node/tests/llm_tests.mjs
  • crates/node/src/callback_factory.rs
  • crates/node/src/callable.rs
  • crates/node/src/api/mod.rs
Additional comments: 13
crates/node/src/callback_factory.rs: 1

13-13: LGTM!

Also applies to: 559-573, 715-718

crates/node/src/promise_call.rs: 1

22-22: LGTM!

Also applies to: 656-657, 675-692, 807-816

crates/node/src/api/mod.rs: 7

23-23: LGTM!

Also applies to: 658-658

1126-1155: LGTM!

Also applies to: 1161-1161, 1165-1165, 1172-1187, 1199-1199, 1207-1222

2170-2170: LGTM!

Also applies to: 2200-2212, 2224-2236

2311-2311: LGTM!

Also applies to: 2322-2337, 2346-2346, 2399-2415

2752-2764: LGTM!

4081-4081: LGTM!

Also applies to: 4123-4123, 4139-4139, 4185-4185, 4232-4232, 4665-4665, 4714-4714, 4731-4731, 4786-4786, 4839-4839

6322-6324: LGTM!

Also applies to: 6334-6343

crates/node/src/callable.rs: 2

48-51: LGTM!

Also applies to: 839-945, 1228-1228

1450-1450: LGTM!

Also applies to: 1463-1465, 1505-1518

crates/node/tests/llm_tests.mjs: 1

6-6: LGTM!

Also applies to: 4245-4266, 4285-4294

crates/node/tests/callback_error_tests.mjs: 1

15-15: LGTM!

Also applies to: 69-71

@greysonlalonde
greysonlalonde marked this pull request as ready for review November 3, 2026 22:59
@greysonlalonde
greysonlalonde requested a review from a team as a code owner November 3, 2026 22:59
@greysonlalonde greysonlalonde added the Bug issue describes bug; PR fixes bug label Nov 3, 2026
@github-actions github-actions Bot added size:XL PR is extra large lang:js PR changes/introduces Javascript/Typescript code lang:rust PR changes/introduces Rust code labels Nov 3, 2026
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

@willkill07
willkill07 merged commit 222e27c into NVIDIA:release/0.11 Nov 4, 2026
53 of 57 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Nov 4, 2026
2 tasks done

This branch was previously deployed

1 inactive deployment
fern — 8ae33e90 Deployed Nov 4, 2026 by willkill07 via Clean up docs preview #6979
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:js PR changes/introduces Javascript/Typescript code lang:rust PR changes/introduces Rust code size:XL PR is extra large

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants