Skip to content

fix: pass a real ScopeHandle to Node withScope callbacks#196

Merged
zhongxuanwang-nv merged 3 commits into
NVIDIA:mainfrom
zhongxuanwang-nv:docs/fix-nodejs-quickstart
Jun 2, 2026
Merged

fix: pass a real ScopeHandle to Node withScope callbacks#196
zhongxuanwang-nv merged 3 commits 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

withScope in the Node.js binding handed its callback a plain JSON object ({ uuid, name, scopeType, ... }) instead of a real ScopeHandle. Passing that object back into event, toolCallExecute, or llmCallExecute (which accept null or a ScopeHandle) threw internal error: Failed to recover ScopeHandle type from napi value on the first call, and because the rejection skipped deregisterSubscriber, the process hung. This fixes the binding so the callback receives a real, reusable ScopeHandle, matching the Rust, Python, and WebAssembly bindings where the scope helper hands back a usable handle. The existing Node quick start and nemo-relay-node README examples already pass the handle, so they now run as written with no doc changes.

  • 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

Root cause: Node's with_scope invokes the callback across a ThreadsafeFunction boundary, and a napi_wrap'd ScopeHandle cannot cross that boundary, so the previous code serialized the handle to a plain JSON object. That object carries no wrapped native handle, so napi_unwrap fails when it is later passed to an API typed Option<&ScopeHandle>.

Changes:

  • crates/node/src/promise_call.rs: add an Arg0Builder (Box<dyn FnOnce(&Env) -> napi::Result<JsUnknown> + Send>) and a call_with_arg0 method so the first callback argument can be materialized on the JS thread inside the threadsafe call. The existing call / call_with_json_next / call_with_stream_next JSON paths are unchanged.
  • crates/node/src/api/mod.rs: with_scope now builds a real ScopeHandle instance through that builder (ToNapiValue::to_napi_value) instead of serde_json::json!({...}), so the callback receives a handle it can pass straight into event, toolCallExecute, and llmCallExecute. The auto-pop and error paths are unchanged.
  • crates/node/tests/scope_tests.mjs: add callback receives a reusable ScopeHandle, which passes the callback handle into event, pushScope (as an explicit parent), toolCallExecute, and llmCallExecute and asserts the results.

This aligns Node with the existing cross-binding behavior and does not change the shared runtime contract or the other bindings. No documentation changes are required: the quick start and README already pass the handle, and LlmRequest is delivered to llmCallExecute correctly, so those examples run unchanged once the binding is fixed.

Validation:

  • just build-node and just test-node: 226/226 pass, including the new test.
  • Ran the existing Node quick start end to end against the fixed build: it prints the scope/mark/tool/LLM event lines, { echo: 'hello' }, and the LLM result, then exits 0 with no hang (previously it threw on the first event(...) call and hung).
  • cargo fmt --all, cargo clippy -p nemo-relay-node --all-targets -- -D warnings, and uv run pre-commit pass.

Where should the reviewer start?

Start with with_scope in crates/node/src/api/mod.rs: the callback argument is now a real ScopeHandle built on the JS thread through the new Arg0Builder path in crates/node/src/promise_call.rs. Cross-check crates/node/tests/scope_tests.mjs (callback receives a reusable ScopeHandle), which reuses the handle across event, pushScope, toolCallExecute, and llmCallExecute — the calls that previously threw.

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

  • Relates to: none

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 refactors promise-aware callback invocation to support non-JSON argument builders, enabling with_scope to pass real ScopeHandle instances instead of JSON snapshots to JavaScript callbacks. The infrastructure change is tested with scope reusability verification and documentation is simplified to use plain request objects.

Changes

ScopeHandle Callback Materialization

Layer / File(s) Summary
Promise call Arg0Builder infrastructure
crates/node/src/promise_call.rs
PromiseAwareFn introduces Arg0Builder type and call_with_arg0 method; threadsafe-function payload refactored from plain Json to PrimaryArg enum supporting builder-based materialization on the JS thread; existing call, call_with_json_next, call_with_stream_next route through new PrimaryArg-aware infrastructure.
with_scope callback receives ScopeHandle
crates/node/src/api/mod.rs
with_scope clones the ScopeHandle and creates an Arg0Builder closure that materializes it to an N-API value on the JS thread; promise-aware call updated to use call_with_arg0 instead of passing JSON metadata snapshot.
Test coverage for ScopeHandle reusability
crates/node/tests/scope_tests.mjs
New withScope test verifies the callback receives a reusable ScopeHandle that can emit events, serve as parent for child scopes, and act as execution target for tool and LLM calls; asserts child scope's parentUuid matches the handle.
Documentation update to plain request objects
docs/getting-started/quick-start/nodejs.mdx
Quick-start example removes unused LlmRequest import and updates llmCallExecute to pass a plain request object { headers: {}, content: { messages: [...] } } instead of new LlmRequest(...).

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed Title follows Conventional Commits format with 'fix' type, clear scope '(Node withScope callbacks)', and concise imperative summary under 72 characters.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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 PR description is comprehensive and well-structured with all required template sections completed: Overview with confirmations, Details explaining root cause and changes, Where to start guidance, and Related Issues.

✏️ 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 Outdated
Comment thread docs/getting-started/quick-start/nodejs.mdx Outdated
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 31, 2026

@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?

@willkill07
Copy link
Copy Markdown
Member

@zhongxuanwang-nv i think this PR should also fix that bug -- in other languages, we do get a scope handle back.

@zhongxuanwang-nv zhongxuanwang-nv changed the title docs: fix Node.js quickstart scope handle and LLM request usage fix: pass a real ScopeHandle to Node withScope callbacks Jun 2, 2026
@github-actions github-actions Bot added Bug issue describes bug; PR fixes bug and removed Documentation documentation-related labels Jun 2, 2026
Node's withScope handed its callback a plain JSON object instead of a
real ScopeHandle, so passing it back into event, toolCallExecute, or
llmCallExecute threw "Failed to recover ScopeHandle type from napi
value" on the first call, and the skipped deregisterSubscriber left the
process hung. Materialize a real ScopeHandle on the JS thread inside the
threadsafe-function call (via a new Arg0Builder path in PromiseAwareFn)
so the callback receives a usable handle, matching the Rust, Python, and
WebAssembly bindings.

Keep the Node quick start passing the handle and send the LLM request as
a plain { headers, content } object, and add a Node test that reuses the
callback handle across event, pushScope, toolCallExecute, and
llmCallExecute.

Signed-off-by: Zhongxuan Wang <daniewang@nvidia.com>
@github-actions github-actions Bot added size:M PR is medium lang:js PR changes/introduces Javascript/Typescript code lang:rust PR changes/introduces Rust code and removed size:S PR is small labels Jun 2, 2026
@zhongxuanwang-nv
Copy link
Copy Markdown
Member Author

@zhongxuanwang-nv i think this PR should also fix that bug -- in other languages, we do get a scope handle back.

Thanks Will! I think the new proposed changes fixed that to make it consistent with other languages :)

willkill07
willkill07 previously approved these changes Jun 2, 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.

Approving with one open question

Comment thread docs/getting-started/quick-start/nodejs.mdx
LlmRequest delivers headers and content to llmCallExecute correctly, so
the quick start needs no plain-object request. Restore the quick start to
its original LlmRequest usage; the scope-handle fix alone makes the
example run end to end.

Signed-off-by: Zhongxuan Wang <daniewang@nvidia.com>
@zhongxuanwang-nv
Copy link
Copy Markdown
Member Author

/merge

@zhongxuanwang-nv zhongxuanwang-nv merged commit fa734cf into NVIDIA:main Jun 2, 2026
41 checks passed
rapids-bot Bot pushed a commit that referenced this pull request Jun 2, 2026
…201)

#### Overview

The package READMEs' "Getting Started" examples register a subscriber, emit events, then deregister without calling flush. Native subscriber delivery is non-blocking, so an example that exits right after deregistering can lose queued events. This updates all four package READMEs to flush before deregister, matching the quickstarts (which already flush).

- [x] I confirm this contribution is my own work, or I have the right to submit it under this project's license.
- [x] I searched existing issues and open pull requests, and this does not duplicate existing work.

#### Details

**Functional fixes** (verified by running — the example dropped events without flush):
- `python/nemo_relay/README.md`: printed nothing, or intermittently a single partial line; the `to_dict()` / `to_json()` callback never ran. Adds `nemo_relay.subscribers.flush()` before each `deregister(...)`.
- `go/nemo_relay/README.md`: flaky — dropped the trailing tool-end and scope-end events on exit (2 of 3 runs partial). Adds `defer nemo.FlushSubscribers()`, ordered to run after the deferred `scope.Pop` emits the scope-end event and before the deferred deregister.

**Parity** (not currently broken; updated so every README models the same pattern):
- `crates/node/README.md`: Node keeps the event loop alive via the ref'd ThreadsafeFunction, so it already delivers; adds `flushSubscribers()` for consistency.
- `crates/wasm/README.md`: WASM's `flushSubscribers()` is a single-threaded no-op (tested as such); adds it for consistency.

#### Where should the reviewer start?

The four README diffs — each adds a flush before `deregister(...)` (Node/WASM also import `flushSubscribers`). Verified by running each example with the flush added: events deliver deterministically (Go 5/5, Python and Node 3/3 across repeated runs). WASM's `flushSubscribers` is an exported no-op (`crates/wasm/src/api/mod.rs`; covered by `crates/wasm/tests-js/scope_tests.mjs`).

Note: the `crates/node/README.md` example also depends on the Node binding change in #196 (pass a real `ScopeHandle` to `withScope` callbacks). That is orthogonal to this flush change — #196 is code-only and does not touch the README.

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

- Relates to: #196 (Node `withScope` ScopeHandle; orthogonal, touches the same Node README example)




## Summary by CodeRabbit

* **Documentation**
  * Updated Getting Started examples across Python, Node.js, WebAssembly, and Go language bindings to reflect the proper sequence for flushing subscribers before deregistration.

Authors:
  - Zhongxuan (Daniel) Wang (https://github.com/zhongxuanwang-nv)

Approvers:
  - Will Killian (https://github.com/willkill07)

URL: #201
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:M PR is medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants