Skip to content

docs: fix Node.js quickstart scope handle and LLM request usage#196

Open
zhongxuanwang-nv wants to merge 1 commit into
NVIDIA:mainfrom
zhongxuanwang-nv:docs/fix-nodejs-quickstart
Open

docs: fix Node.js quickstart scope handle and LLM request usage#196
zhongxuanwang-nv wants to merge 1 commit into
NVIDIA:mainfrom
zhongxuanwang-nv:docs/fix-nodejs-quickstart

Conversation

@zhongxuanwang-nv
Copy link
Copy Markdown
Member

@zhongxuanwang-nv zhongxuanwang-nv commented May 31, 2026

Overview

The Node.js quick start and the nemo-relay-node package README shipped an example that crashed and then hung. This corrects both examples so the documented workflow runs to completion and exits cleanly. No runtime/binding behavior changes; this is a docs-only correction aligned with the contract the Node binding tests already exercise.

  • 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

The examples passed the informational handle returned by withScope directly into event, toolCallExecute, and llmCallExecute. Those APIs accept either null (target the current scope) or a real ScopeHandle; the plain handle object cannot be recovered, so the first call threw internal error: Failed to recover ScopeHandle type from napi value. Because that rejection skipped deregisterSubscriber, the subscriber's ThreadsafeFunction stayed referenced and the process hung instead of exiting.

The LLM example also built the request with new LlmRequest({}, { ... }), but llmCallExecute expects a plain { headers, content } JSON object, so the request content was dropped.

Changes:

  • docs/getting-started/quick-start/nodejs.mdx: pass null for the active scope in event / toolCallExecute / llmCallExecute, send the LLM request as a plain { headers, content } object, and drop the now-unused LlmRequest import.
  • crates/node/README.md: pass null instead of the handle in the event snippet.

Validation:

  • Ran the corrected quick start end to end: it prints the scope/mark/tool/LLM event lines, { echo: 'hello' }, and the LLM result, then exits 0 with no hang.
  • uv run pre-commit run --files crates/node/README.md docs/getting-started/quick-start/nodejs.mdx passed (copyright header, markdown linkcheck, formatting).

Where should the reviewer start?

Start with docs/getting-started/quick-start/nodejs.mdx — the withScope callback body shows the corrected handle argument (null) and the plain { headers, content } request. Cross-check against crates/node/tests/scope_tests.mjs (the withScope handle is informational) and crates/node/tests/llm_tests.mjs (makeNative() returns a plain { headers, content } object), which is the behavior the docs now match.

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

  • Relates to: none

Summary by CodeRabbit

  • Documentation
    • Updated Node.js quick-start and README examples with simplified API usage patterns.
    • Clarified scope-handling behavior in event emission and function call examples.

The Node.js quick start and the nemo-relay-node package README passed the
informational handle from `withScope` straight into `event`, `toolCallExecute`,
and `llmCallExecute`. Those APIs expect either `null` (the current scope) or a
real `ScopeHandle`, so the plain handle object failed with "Failed to recover
`ScopeHandle` type from napi value" on the first call. The rejected promise then
skipped `deregisterSubscriber`, leaving the subscriber's ThreadsafeFunction
ref'd and hanging the process.

The LLM example also built the request with `new LlmRequest(...)`, but
`llmCallExecute` takes a plain `{ headers, content }` JSON object.

Update both examples to pass `null` for the active scope and a plain request
object, matching the behavior covered by the Node binding tests.

Signed-off-by: Zhongxuan Wang <daniewang@nvidia.com>
@zhongxuanwang-nv zhongxuanwang-nv requested a review from a team as a code owner May 31, 2026 23:50
@github-actions github-actions Bot added size:S PR is small Documentation documentation-related labels May 31, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 31, 2026

Review Change Stack

Walkthrough

This PR updates Node.js documentation and examples to demonstrate correct scope-targeting semantics. The quick-start guide removes LlmRequest from destructuring and updates multiple API calls to pass null instead of handle for scope targeting. The README example reinforces this pattern with a clarifying comment.

Changes

Documentation: Scope-targeting semantics and LlmRequest simplification

Layer / File(s) Summary
Scope-targeting and LlmRequest simplification in examples
docs/getting-started/quick-start/nodejs.mdx, crates/node/README.md
The quick-start example drops LlmRequest from destructuring, updates event("initialized"), toolCallExecute, and llmCallExecute to pass null instead of handle for scope targeting, and simplifies LLM requests to plain objects. The README example adds a clarifying comment distinguishing handle from the current scope and updates the initialized event call to use null.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed Title follows Conventional Commits format (docs type), is concise and imperative, stays under 72 characters (63 total), and accurately describes the documentation fix.
Description check ✅ Passed Description includes all required sections: Overview with confirmations, detailed explanation of the bug and fix, clear direction for reviewers, and validation steps.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

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/node/README.md`:
- Line 80: Update the explanatory comment that mentions handle to wrap the
literal null in inline code formatting; specifically change the comment "//
`handle` describes the active scope; pass null to target the current scope." so
that the word null is surrounded by backticks (i.e., `null`) to match
documentation formatting and coding guidelines for code elements.

In `@docs/getting-started/quick-start/nodejs.mdx`:
- Line 60: The sentence "For lifecycle calls inside the scope, pass null to
target the current scope." should format the literal null as inline code; update
the docs text in docs/getting-started/quick-start/nodejs.mdx so that `null` is
wrapped in backticks (i.e., change the plain word null to a monospace code
element) to follow the project's docs formatting guidelines for code elements.
🪄 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: 747dbda6-9d62-47e3-bb0b-0a004321b7d9

📥 Commits

Reviewing files that changed from the base of the PR and between b0557a9 and 9022420.

📒 Files selected for processing (2)
  • crates/node/README.md
  • docs/getting-started/quick-start/nodejs.mdx
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Check / Run
  • GitHub Check: Preview docs
🧰 Additional context used
📓 Path-based instructions (22)
**/*.{md,rst,html,txt}

📄 CodeRabbit inference engine (.agents/skills/review-doc-style/assets/nvidia-style-brand-terminology.md)

**/*.{md,rst,html,txt}: Always spell NVIDIA in all caps. Do not use Nvidia, nvidia, nVidia, nVIDIA, or NV.
Use an NVIDIA before a noun because the name starts with an 'en' sound.
Do not add a registered trademark symbol after NVIDIA when referring to the company.
Use trademark symbols with product names only when the document type or legal guidance requires them.
Verify official capitalization, spacing, and hyphenation for product names.
Precede NVIDIA product names with NVIDIA on first mention when it is natural and accurate.
Do not rewrite product names for grammar or title-case rules.
Preserve third-party product names according to the owner's spelling.
Include the company name and full model qualifier on first use when it helps identify the model.
Preserve the official capitalization and punctuation of model names.
Use shorter family names only after the full name is established.
Spell out a term on first use and put the acronym in parentheses unless the acronym is widely understood by the intended audience.
Use the acronym on later mentions after it has been defined.
For long documents, reintroduce the full term if readers might lose context.
Form plurals of acronyms with s, not an apostrophe, such as GPUs.
In headings, common acronyms can remain abbreviated. Spell out the term in the first or second sentence of the body.
Common terms such as CPU, GPU, PC, API, and UI usually do not need to be spelled out for developer audiences.

Files:

  • crates/node/README.md
**/*.{md,rst,html}

📄 CodeRabbit inference engine (.agents/skills/review-doc-style/assets/nvidia-style-brand-terminology.md)

Link the first mention of a product name when the destination helps the reader.

Files:

  • crates/node/README.md
**/*.md

📄 CodeRabbit inference engine (.agents/skills/contribute-integration/SKILL.md)

Documentation must be updated if activation or usage changed

**/*.md: Use title case consistently in technical documentation headings
Avoid quotation marks, ampersands, and exclamation marks in headings
Keep product, event, research, and whitepaper names in their official title case
Use title case for table headers
Do not force social-media sentence case into technical docs
Format code elements, commands, parameters, package names, and expressions in monospace
Format directories, file names, and paths in monospace using backticks
Use angle brackets inside monospace for variables inside paths, such as /home/<username>/.login
Format error messages and strings in quotation marks, keeping literal code strings in code formatting when clearer
Format UI buttons, menus, fields, and labels in bold
Use angle brackets between UI labels for menu paths, such as File > Save As
Use italics for new terms on first use, sparingly and only when introducing the term
Use italics for publication titles
Format keyboard shortcuts in plain text, such as Press Ctrl+Alt+Delete
Use owner/repo link text for GitHub repositories, preferring [NVIDIA/NeMo](link) over prose references like 'the GitHub repo'
Introduce every code block with a complete sentence
Do not make a code block complete the grammar of the previous sentence
Do not continue a sentence after a code block
Use syntax highlighting when the format supports it for code blocks
Avoid the word 'snippet' unless the surrounding docs already use it as a term of art
Keep inline method, function, and class references consistent with nearby docs, omitting empty parentheses for prose readability when no call is shown
Use descriptive anchor text that matches the destination title when possible for links
Avoid raw URLs in running text
Avoid generic anchor text such as 'here,' 'this page,' and 'read more'
Include acronyms in link text when a linked term includes an acronym
Do not link long sentences or multiple sentences
Avoid links ...

Files:

  • crates/node/README.md
{crates/adaptive/**,python/nemo_relay/adaptive.py,python/nemo_relay/plugin.py,go/nemo_relay/adaptive/**,go/nemo_relay/!(adaptive)/**,**/node/**,**/wasm/**}

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

Keep adaptive surface in sync across crates/adaptive, shared plugin behavior in core and bindings, Python adaptive/plugin wrappers in python/nemo_relay/adaptive.py and python/nemo_relay/plugin.py, Go adaptive helpers under go/nemo_relay/adaptive plus shared plugin helpers in go/nemo_relay, and Node/WebAssembly adaptive helpers and plugin wrappers

Files:

  • crates/node/README.md
{crates/adaptive/**,python/nemo_relay/plugin.py,go/nemo_relay/**,**/node/**,**/wasm/**}

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

{crates/adaptive/**,python/nemo_relay/plugin.py,go/nemo_relay/**,**/node/**,**/wasm/**}: Maintain consistent plugin lifecycle across all language bindings (Python, Go, Node/WebAssembly, and Rust)
Keep plugin context surfaces aligned across all language implementations

Files:

  • crates/node/README.md
**/{docs,examples,**/*.md,*.patch,*.diff,.github,*.sh,*.yaml,*.yml}

📄 CodeRabbit inference engine (.agents/skills/rename-surfaces/SKILL.md)

Update documentation, examples, CI configuration, and patch artifacts when performing rename operations

Files:

  • crates/node/README.md
**/*.{md,rst,txt}

📄 CodeRabbit inference engine (.agents/skills/review-doc-style/assets/nvidia-style-guide.md)

Spell NVIDIA in all caps. Do not use Nvidia, nvidia, or NV.

Files:

  • crates/node/README.md
**/*.{md,rst}

📄 CodeRabbit inference engine (.agents/skills/review-doc-style/assets/nvidia-style-guide.md)

**/*.{md,rst}: Format commands, code elements, expressions, package names, file names, and paths as inline code.
Use descriptive link text. Avoid raw URLs and weak anchors such as "here" or "read more."
Use title case consistently for technical documentation headings.
Introduce code blocks, lists, tables, and images with complete sentences.
Write procedures as imperative steps. Keep steps parallel and split long procedures into smaller tasks.
Prefer active voice, present tense, short sentences, contractions, and plain English.
Use can for possibility and reserve may for permission.
Use after for temporal relationships instead of once.
Prefer refer to over see when the wording points readers to another resource.
Avoid culture-specific idioms, unnecessary Latinisms, jokes, and marketing exaggeration in technical docs.
Spell out months in body text, avoid ordinal dates, and use clear time zones.
Spell out whole numbers from zero through nine unless they are technical values, parameters, versions, or UI values.
Use numerals for 10 or greater and include commas in thousands.
Do not add trademark symbols to learning-oriented docs unless the source, platform, or legal guidance explicitly requires them.

Files:

  • crates/node/README.md
{docs/**,README.md,CONTRIBUTING.md,**/*.md}

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

Run docs link validation with just docs-linkcheck when links change

Files:

  • crates/node/README.md
  • docs/getting-started/quick-start/nodejs.mdx
{docs/**,README.md,**/Cargo.toml,**/package.json,**/*.md}

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

Ensure renamed public surfaces are reflected consistently in manifests and docs for large or public-facing changes

Files:

  • crates/node/README.md
  • docs/getting-started/quick-start/nodejs.mdx
**/*.{md,mdx,py,sh,yaml,yml,toml,json}

📄 CodeRabbit inference engine (.agents/skills/contribute-docs/SKILL.md)

Keep package names, repo references, and build commands current

Files:

  • crates/node/README.md
  • docs/getting-started/quick-start/nodejs.mdx
**/*.{html,md,mdx}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Include SPDX license header in HTML and Markdown files using HTML comment syntax

Files:

  • crates/node/README.md
  • docs/getting-started/quick-start/nodejs.mdx
**/README.md

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Update relevant crate or package README when that surface changed

Files:

  • crates/node/README.md
**/*.{rs,py,js,ts,tsx,jsx,go,sh,toml,yaml,yml,md}

📄 CodeRabbit inference engine (AGENTS.md)

Keep SPDX headers on source, docs, scripts, and configuration files. The project is Apache-2.0.

Files:

  • crates/node/README.md
crates/{python,ffi,node,wasm}/**/*

⚙️ CodeRabbit configuration file

crates/{python,ffi,node,wasm}/**/*: 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/node/README.md
{docs/**,README.md,CONTRIBUTING.md}

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

{docs/**,README.md,CONTRIBUTING.md}: For docs-only changes, run targeted checks only if commands, package names, or examples changed. Use just docs for docs-site builds and just docs-linkcheck when links changed
Run docs site build with just docs

Files:

  • docs/getting-started/quick-start/nodejs.mdx
{docs/**,README.md}

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

Verify README and docs entry points still match current package names and paths for large or public-facing changes

Files:

  • docs/getting-started/quick-start/nodejs.mdx
{docs/**,examples/**,README.md}

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

Verify examples still run with documented commands for large or public-facing changes

Files:

  • docs/getting-started/quick-start/nodejs.mdx
**/*.mdx

📄 CodeRabbit inference engine (.agents/skills/contribute-docs/SKILL.md)

In MDX files, top-of-file comments must use JSX comment delimiters: {/* to open and */} to close. Do not use HTML comments for MDX SPDX headers.

MDX top-of-file SPDX comments must use {/* ... */} delimiters instead of HTML comment delimiters (Must-Fix)

Files:

  • docs/getting-started/quick-start/nodejs.mdx
docs/**/*.{md,mdx}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Update embedded documentation snippets, patch docs, and binding-support notes if examples or supported bindings changed

Files:

  • docs/getting-started/quick-start/nodejs.mdx
docs/**

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Run just docs or ./scripts/build-docs.sh html to regenerate ignored Fern API reference pages before validation for documentation site changes

Files:

  • docs/getting-started/quick-start/nodejs.mdx
{docs/**,README.md,CONTRIBUTING.md,RELEASING.md,SECURITY.md}

⚙️ CodeRabbit configuration file

{docs/**,README.md,CONTRIBUTING.md,RELEASING.md,SECURITY.md}: Review documentation for technical accuracy against the current API, command correctness, and consistency across language bindings.
Flag stale examples, missing SPDX headers where required, and instructions that no longer match CI or pre-commit behavior.

Files:

  • docs/getting-started/quick-start/nodejs.mdx

Comment thread crates/node/README.md

await withScope("demo-agent", ScopeType.Agent, async (handle) => {
event("initialized", handle, { binding: "node" }, null);
// `handle` describes the active scope; pass null to target the current scope.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Use inline code formatting for null in the explanatory comment.

Wrap null in backticks for consistency with documentation code-element formatting rules.

As per coding guidelines, "Format commands, code elements, expressions, package names, file names, and paths as inline code."

🤖 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/node/README.md` at line 80, Update the explanatory comment that
mentions handle to wrap the literal null in inline code formatting; specifically
change the comment "// `handle` describes the active scope; pass null to target
the current scope." so that the word null is surrounded by backticks (i.e.,
`null`) to match documentation formatting and coding guidelines for code
elements.

await withScope("demo-agent", ScopeType.Agent, async (handle) => {
event("initialized", handle, { binding: "node" }, null);
// `handle` describes the active scope (handle.uuid, handle.name, handle.scopeType).
// For lifecycle calls inside the scope, pass null to target the current scope.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Format null as inline code in prose comments.

Use backticks around null in this sentence to keep code elements consistently formatted in docs.

As per coding guidelines, "Format code elements, commands, parameters, package names, and expressions in monospace."

🤖 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 `@docs/getting-started/quick-start/nodejs.mdx` at line 60, The sentence "For
lifecycle calls inside the scope, pass null to target the current scope." should
format the literal null as inline code; update the docs text in
docs/getting-started/quick-start/nodejs.mdx so that `null` is wrapped in
backticks (i.e., change the plain word null to a monospace code element) to
follow the project's docs formatting guidelines for code elements.

@github-actions
Copy link
Copy Markdown

@willkill07 willkill07 added this to the 0.4 milestone Jun 1, 2026
Copy link
Copy Markdown
Member

@willkill07 willkill07 left a comment

Choose a reason for hiding this comment

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

Manually specifying a handle should work though. What was the raised panic?

@zhongxuanwang-nv
Copy link
Copy Markdown
Member Author

zhongxuanwang-nv commented Jun 1, 2026

Manually specifying a handle should work though. What was the raised panic?

@willkill07 Hey Will, yes I think manually specifying a handle does work; here it's mainly a rejected Promise / thrown napi error; I should've included the error output:

(nemo-relay) daniewang@DKF2M99Y76 1 % node 1.js
event=scope name=demo-agent
event=scope name=demo-agent
[Error: internal error: Failed to recover `ScopeHandle` type from napi value] {
  code: 'GenericFailure'
}

And then it's stuck there forever.

It's because withScope gives its callback a plain JSON object ({ uuid, name, scopeType, ... }) across the ThreadsafeFunction thread boundary, not a napi_wrap's ScopeHandle. So when that object hits event/toolCallExecute/llmCallExecute (Option<&ScopeHandle>), napi_unwrap returns invalid_arg → the error above. It throws on the first such call (event("initialized", handle, ...)), which skips the following deregisterSubscriber and leaves the subscriber hang.

Therefore, I made withScope pass a real ScopeHandle. I'm wondering what do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation documentation-related size:S PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants