Skip to content

feat: queue scope and mark event publication - #570

Merged
rapids-bot[bot] merged 9 commits into
mainfrom
wkk_relay-509-event-publication
Jul 29, 2026
Merged

feat: queue scope and mark event publication#570
rapids-bot[bot] merged 9 commits into
mainfrom
wkk_relay-509-event-publication

Conversation

@willkill07

@willkill07 willkill07 commented Jul 28, 2026

Copy link
Copy Markdown
Member

Overview

Keep scope and mark emission synchronous while moving event sanitization and subscriber publication onto a serial background dispatcher.

  • 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

  • Snapshot events, visible sanitizer chains, and subscribers at emission time.
  • Process snapshots through a FIFO background queue so start, end, and mark ordering is preserved.
  • Fail open on sanitizer errors and make dispatcher send failures observable.
  • Document delayed publication semantics.

This is PR 1 of 2 in the RELAY-509 GitHub stack, which is rooted on upstream main:

  1. feat: queue scope and mark event publication #570 — queued event publication
  2. #571 — async middleware across primary bindings, based on feat: queue scope and mark event publication #570

Where should the reviewer start?

Start with crates/core/src/api/runtime/subscriber_dispatcher.rs and the FIFO/snapshot coverage in crates/core/tests/integration/subscriber_dispatcher_tests.rs.

Validation:

  • cargo test -p nemo-relay --test subscriber_dispatcher_integration -- --nocapture
  • Commit hooks, including Cargo fmt, clippy, check, and docs link validation

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

  • Relates to RELAY-509

Summary by CodeRabbit

  • New Features
    • Subscriber delivery can now apply an optional sanitizer chain before invoking callbacks, snapshotted at emission time to preserve scope/mark ordering.
    • Native dispatch supports delivering events with an explicit sanitizer list and scope context.
    • Node.js flushSubscribers() is now Promise-based (should be awaited).
  • Bug Fixes
    • Sanitizer panics are caught and logged; delivery continues with the last valid sanitized snapshot.
    • If there are no subscribers, sanitizer callbacks are not invoked.
  • Documentation
    • Added “Publication Semantics” describing sanitizer timing and FIFO behavior.
  • Tests
    • Updated integration and Node.js tests to await flushSubscribers() and validate sanitizer edge cases.

@willkill07
willkill07 requested review from a team as code owners July 28, 2026 18:07
@github-actions github-actions Bot added size:M PR is medium Feature a new feature lang:rust PR changes/introduces Rust code labels Jul 28, 2026
@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Event emission snapshots sanitizer chains and queues events for serial dispatcher processing. Scope lifecycle APIs use the new path, sanitizer execution handles panics, and Node subscriber flushing is now asynchronous.

Changes

Sanitized event delivery

Layer / File(s) Summary
Snapshot sanitizer chains
crates/core/src/api/shared.rs
Separates sanitizer guardrail snapshotting from event snapshot-chain construction.
Dispatcher-side sanitization
crates/core/src/api/runtime/subscriber_dispatcher.rs, crates/core/src/api/runtime/state.rs
Carries sanitizer chains in queued messages, applies them before subscriber delivery, and catches sanitizer panics.
Scope emission integration and validation
crates/core/src/api/scope.rs, crates/core/tests/integration/subscriber_dispatcher_tests.rs, crates/ffi/tests/unit/api/registry_tests.rs, docs/reference/event-sanitizers.mdx
Routes scope and mark publication through sanitized dispatch and adds deferred-publication, concurrency, filtering, panic, flush, and documentation coverage.
Asynchronous subscriber flushing
crates/node/src/api/mod.rs, crates/node/README.md, crates/node/tests/*.mjs, integrations/openclaw/src/hooks-backend.ts
Changes Node flushSubscribers to an awaited operation and updates integrations, examples, and tests accordingly.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ScopeAPI
  participant SanitizerSnapshot
  participant SubscriberDispatcher
  participant Subscribers
  ScopeAPI->>SanitizerSnapshot: snapshot_event_sanitizers(event, scope_stack)
  ScopeAPI->>SubscriberDispatcher: dispatch_sanitized_event(event, sanitizers, subscribers, scope_stack)
  SubscriberDispatcher->>SubscriberDispatcher: event_sanitize_snapshot_chain(event, sanitizers)
  SubscriberDispatcher->>Subscribers: deliver sanitized event
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title follows Conventional Commits and accurately summarizes the queued publication change.
Description check ✅ Passed The description includes all required template sections and is sufficiently detailed for review.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch wkk_relay-509-event-publication

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

@willkill07

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@willkill07 willkill07 added this to the 0.7 milestone Jul 28, 2026
@willkill07 willkill07 self-assigned this Jul 28, 2026
@github-actions

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
crates/core/src/api/scope.rs (1)

282-327: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

pop_scope doc comment wasn't updated to match push_scope/event.

Both push_scope and event got a new doc comment explaining the snapshot-then-defer publication contract, but pop_scope — which has the trickiest ordering requirement (snapshot sanitizers before task_scope_remove) — didn't. Worth adding the same clarification for API consumers.

📝 Proposed doc addition
+/// The event and its visible middleware/subscriber chains are snapshotted
+/// before this function returns. Sanitization and subscriber delivery happen
+/// later on the serial publication dispatcher.
 pub fn pop_scope(params: PopScopeParams<'_>) -> Result<()> {
🤖 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/core/src/api/scope.rs` around lines 282 - 327, Update the
documentation for pop_scope to describe its snapshot-then-defer publication
contract, explicitly noting that scope-local sanitizers are snapshotted before
task_scope_remove and publication occurs afterward using that snapshot. Keep the
documentation aligned with the corresponding push_scope and event comments.
🤖 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/core/src/api/runtime/subscriber_dispatcher.rs`:
- Around line 84-118: Update dispatch_sanitized_event to return true immediately
when subscribers.is_empty(), before constructing DispatcherMessage::Deliver or
calling dispatcher_sender(). Match the existing short-circuit behavior in
dispatch_event and leave the non-empty subscriber dispatch path unchanged.

---

Outside diff comments:
In `@crates/core/src/api/scope.rs`:
- Around line 282-327: Update the documentation for pop_scope to describe its
snapshot-then-defer publication contract, explicitly noting that scope-local
sanitizers are snapshotted before task_scope_remove and publication occurs
afterward using that snapshot. Keep the documentation aligned with the
corresponding push_scope and event comments.
🪄 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: 9d58b120-1e17-4411-bfbe-0aa5a8d6b4da

📥 Commits

Reviewing files that changed from the base of the PR and between 2a72b45 and 475271a.

📒 Files selected for processing (5)
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/src/api/scope.rs
  • crates/core/src/api/shared.rs
  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
  • docs/reference/event-sanitizers.mdx
📜 Review details
🧰 Additional context used
📓 Path-based instructions (23)
**/*.mdx

📄 CodeRabbit inference engine (.agents/skills/review-doc-style/SKILL.md)

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

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

Files:

  • docs/reference/event-sanitizers.mdx
**/*.{md,mdx}

📄 CodeRabbit inference engine (AGENTS.md)

Update README.md, fern/, package READMEs, and binding-support notes when public behavior, package names, examples, or supported bindings change.

**/*.{md,mdx}: Prefer the documented public API, not internal shortcuts
Keep package names, repo references, and build commands current
Keep release-process and release-notes guidance in repo-maintainer docs such as RELEASING.md, not as user-facing docs pages or CHANGELOG.md
Keep stable user-facing wrappers at scripts/ root in docs and examples; only point at namespaced helper paths when documenting internal maintenance work
When detailed dynamic plugin guides exist, keep Rust native plugin examples, Python worker plugin examples, and grpc-v1 protocol details on separate pages

If links in documentation change, run just docs-linkcheck.

Files:

  • docs/reference/event-sanitizers.mdx
**/*.{md,markdown,mdx}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Add the SPDX license header to all Markdown/MDX documentation files using the HTML comment block form.

Files:

  • docs/reference/event-sanitizers.mdx
{docs,examples}/**/*

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

Update docs and examples.

Files:

  • docs/reference/event-sanitizers.mdx
**/*

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

**/*: Format changed files with the language-native formatter before the final lint/test pass.
If dynamic plugin behavior changed, use maintain-dynamic-plugins and include the native SDK, worker protocol, Python SDK, docs, packaging, and Codecov surfaces in the validation plan.
If code changes alter APIs, bindings, commands, paths, packaging behavior, observability/adaptive semantics, or documented best practices, update any dependent maintainer or consumer skills in the same branch.
During iteration, prefer uv run pre-commit run --files <changed files...>.
Before review or handoff, run uv run pre-commit run --all-files.

Files:

  • docs/reference/event-sanitizers.mdx
  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/src/api/scope.rs
  • crates/core/src/api/shared.rs
docs/**/*

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

If documentation examples or commands under docs/ change, run the targeted docs checks appropriate to the change.

Files:

  • docs/reference/event-sanitizers.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/reference/event-sanitizers.mdx
**/*.rs

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

**/*.rs: Any Rust change must run just test-rust
Any Rust change must run cargo fmt --all
Any Rust change must run cargo clippy --workspace --all-targets -- -D warnings

**/*.rs: Run cargo fmt --all for all FFI work since it is Rust work
Run just test-rust to validate FFI changes
Run cargo clippy --workspace --all-targets -- -D warnings to enforce strict linting on FFI work

When Rust files changed as part of Go work, also run cargo fmt --all, just test-rust, and cargo clippy --workspace --all-targets -- -D warnings

**/*.rs: Run cargo fmt --all when Rust files are changed as part of Node work
Run cargo clippy --workspace --all-targets -- -D warnings when Rust files are changed as part of Node work
Run just test-rust when Rust files are changed as part of Node work

When changing the core Rust runtime or Rust-facing API surface, format Rust code with cargo fmt (rustfmt defaults), keep cargo clippy -- -D warnings clean, and satisfy cargo deny check per deny.toml.

**/*.rs: If any Rust code changed, always run just test-rust.
If any Rust code changed, also run cargo fmt --all.
If any Rust code changed, also run cargo clippy --workspace --all-targets -- -D warnings.
For Rust changes headed for review, run cargo fmt --all and cargo clippy --workspace --all-targets -- -D warnings even if relying on pre-commit.

Files:

  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/src/api/scope.rs
  • crates/core/src/api/shared.rs
{crates/core,crates/adaptive}/**/*

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

Changes to crates/core or crates/adaptive must run the full language matrix

Files:

  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/src/api/scope.rs
  • crates/core/src/api/shared.rs
crates/core/**/*.rs

📄 CodeRabbit inference engine (.agents/skills/test-go-binding/SKILL.md)

If the change touched crates/core or shared runtime semantics, also use validate-change for broader validation

Files:

  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/src/api/scope.rs
  • crates/core/src/api/shared.rs
**/*.{rs,py}

📄 CodeRabbit inference engine (AGENTS.md)

Follow binding naming conventions in Rust and Python: use snake_case.

Files:

  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/src/api/scope.rs
  • crates/core/src/api/shared.rs
**/*.{rs,py,js,mjs,cjs,ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{rs,py,js,mjs,cjs,ts,tsx}: Use Json = serde_json::Value in Rust-facing runtime APIs where the existing code expects JSON payloads.
Use Result<T> with FlowError in core runtime paths, and keep errors explicit and binding-appropriate at the wrapper layer.
Keep async behavior on the existing tokio-based model; bindings should preserve callback and future lifetimes rather than blocking or hiding async work unexpectedly.

Files:

  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/src/api/scope.rs
  • crates/core/src/api/shared.rs
**/*.{rs,py,go,js,ts,c,h}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Use language-appropriate naming conventions: Rust snake_case, C FFI exports prefixed nemo_relay_, Go PascalCase, Node.js camelCase, and Python snake_case.

Files:

  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/src/api/scope.rs
  • crates/core/src/api/shared.rs
**/*.{rs,go,js,ts}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Add the SPDX license header to all Rust, Go, JavaScript, and TypeScript source files using the corresponding // comment form.

Files:

  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/src/api/scope.rs
  • crates/core/src/api/shared.rs
crates/{core,adaptive}/**/*

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

If crates/core or crates/adaptive changed, run the full validation matrix across Rust, Python, Go, and Node.js.

Files:

  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/src/api/scope.rs
  • crates/core/src/api/shared.rs
**/*.{rs,py,go,js,ts}

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

If a language surface changed, always run that language's test target even when Rust core did not change.

Files:

  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/src/api/scope.rs
  • crates/core/src/api/shared.rs
**/*.{rs,py,js,ts,tsx,go,java,kt,swift}

📄 CodeRabbit inference engine (.agents/skills/add-middleware/SKILL.md)

Add tests covering registration and duplicate names, deregistration and missing names, priority ordering, callback failure policy, scope-local inheritance and cleanup, event payload semantics, immutable mark and scope fields, and parity across affected bindings.

Files:

  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/src/api/scope.rs
  • crates/core/src/api/shared.rs
crates/{core,adaptive}/**/*.rs

⚙️ CodeRabbit configuration file

crates/{core,adaptive}/**/*.rs: Review the Rust runtime for async correctness, scope isolation, middleware ordering, and event lifecycle regressions.
Pay close attention to task-local/thread-local scope propagation, callback lifetimes, stream finalization, and root_uuid isolation.
Public API changes should preserve existing behavior unless tests and docs show the intended migration path.

Files:

  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/src/api/scope.rs
  • crates/core/src/api/shared.rs
{crates/**/tests/**,python/tests/**,go/nemo_relay/**/*_test.go}

⚙️ CodeRabbit configuration file

{crates/**/tests/**,python/tests/**,go/nemo_relay/**/*_test.go}: Tests should cover the behavior promised by the changed API surface, including error paths and cross-request isolation where relevant.
Prefer assertions on lifecycle events, scope stacks, middleware ordering, and binding parity over shallow smoke tests.

Files:

  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
crates/core/src/{api/**/*.rs,api/runtime/**/*.rs,codec/**/*.rs,json.rs}

📄 CodeRabbit inference engine (.agents/skills/add-binding-feature/SKILL.md)

Implement the new or changed public runtime behavior first in the Rust core, especially under crates/core/src/api/ and related core modules such as crates/core/src/api/runtime/, crates/core/src/codec/, and crates/core/src/json.rs.

Files:

  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/src/api/scope.rs
  • crates/core/src/api/shared.rs
{crates/**/src/**/*.rs,python/**/*.py}

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

Do not add tests under src; Rust tests belong in crate tests/ trees, and Python SDK tests belong under python/tests.

Files:

  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/src/api/scope.rs
  • crates/core/src/api/shared.rs
crates/core/src/api/**/*.rs

📄 CodeRabbit inference engine (.agents/skills/add-middleware/SKILL.md)

Preserve the documented pipeline order: conditional guardrails, request intercepts, request sanitization, execution intercepts, and response sanitization for tool and LLM execution; specialized sanitization, event creation, and dispatch for mark and scope events.

Files:

  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/src/api/scope.rs
  • crates/core/src/api/shared.rs
crates/core/src/api/{tool,llm,shared,scope}.rs

📄 CodeRabbit inference engine (.agents/skills/add-middleware/SKILL.md)

Wire the new middleware chain into the appropriate lifecycle owner and pipeline stage: tool and LLM execution paths use tool.rs or llm.rs; shared mark and scope event sanitization uses shared.rs and is called from scope.rs.

Files:

  • crates/core/src/api/scope.rs
  • crates/core/src/api/shared.rs
🧠 Learnings (1)
📚 Learning: 2026-07-28T03:31:05.964Z
Learnt from: willkill07
Repo: NVIDIA/NeMo-Relay PR: 564
File: crates/core/src/api/runtime/subscriber_dispatcher.rs:297-314
Timestamp: 2026-07-28T03:31:05.964Z
Learning: In this codebase’s runtime API, do not implement incremental native LLM stream forwarding via the native ABI v3 asynchronous middleware protocol (it can only settle a single JSON value via a one-shot completion handle and cannot forward stream chunks incrementally). If a latency-sensitive plugin needs streaming behavior, review for use of synchronous native stream intercepts or worker plugins instead of trying to chunk-deliver or incrementally forward over the ABI v3 async path.

Applied to files:

  • crates/core/src/api/runtime/subscriber_dispatcher.rs
🔇 Additional comments (5)
crates/core/src/api/shared.rs (1)

10-14: LGTM!

Also applies to: 53-72, 108-108

crates/core/src/api/runtime/subscriber_dispatcher.rs (1)

7-10: LGTM!

Also applies to: 30-30, 53-53, 192-195, 204-222, 242-252

crates/core/src/api/scope.rs (1)

6-12: LGTM!

Also applies to: 220-226, 246-255, 285-285

crates/core/tests/integration/subscriber_dispatcher_tests.rs (1)

9-18: LGTM! Solid coverage of the deferred snapshot/publication contract, matching the behavior-over-smoke-test guidance for this path.

Also applies to: 104-163

docs/reference/event-sanitizers.mdx (1)

56-68: 📐 Maintainability & Code Quality

The subscriber flush API wording is consistent with the Python, Go, and Node bindings (nemo_relay.subscribers.flush(), nemo_relay.FlushSubscribers(), and flushSubscribers()).

			> Likely an incorrect or invalid review comment.

Comment thread crates/core/src/api/runtime/subscriber_dispatcher.rs

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
crates/core/src/api/runtime/subscriber_dispatcher.rs (1)

207-225: 🚀 Performance & Scalability | 🟠 Major | ⚡ Quick win

Avoid cloning unsanitized events on every delivery.

dispatch_event always queues sanitizers: Vec::new() (Lines [51-54]), but deliver_event clones the full Event at Line [214] before sanitization. This adds unnecessary copying to every ordinary subscriber event; only the non-empty sanitizer path needs an original snapshot for panic fallback.

Proposed fix
-        let original = (*event).clone();
-        let event = catch_unwind(AssertUnwindSafe(|| {
-            NemoRelayContextState::event_sanitize_snapshot_chain(*event, &sanitizers)
-        }))
-        .unwrap_or_else(|_| {
-            log::error!(
-                target: "nemo_relay.runtime",
-                event = "event_sanitizer_panicked";
-                "Event sanitizer panicked; publishing the original event snapshot"
-            );
-            original
-        });
+        let event = if sanitizers.is_empty() {
+            *event
+        } else {
+            let original = (*event).clone();
+            catch_unwind(AssertUnwindSafe(|| {
+                NemoRelayContextState::event_sanitize_snapshot_chain(*event, &sanitizers)
+            }))
+            .unwrap_or_else(|_| {
+                log::error!(
+                    target: "nemo_relay.runtime",
+                    event = "event_sanitizer_panicked";
+                    "Event sanitizer panicked; publishing the original event snapshot"
+                );
+                original
+            })
+        };
🤖 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/core/src/api/runtime/subscriber_dispatcher.rs` around lines 207 - 225,
Update deliver_event so the original Event snapshot is created only when
sanitizers is non-empty, preserving the unsanitized event without cloning for
the ordinary path. Keep the sanitizer panic fallback in the
event_sanitize_snapshot_chain handling, using the conditional snapshot only
where required.
crates/core/tests/integration/subscriber_dispatcher_tests.rs (1)

105-163: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Add coverage for sanitizer panic fallback.

The dispatcher now promises fail-open publication when a sanitizer panics, but these tests cover only blocking delivery and the no-subscriber short-circuit. Add an integration case with a panicking sanitizer and assert that the subscriber receives the original event fields.

Also applies to: 165-189

🤖 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/core/tests/integration/subscriber_dispatcher_tests.rs` around lines
105 - 163, Add an integration test alongside
mark_emission_snapshots_sanitizers_and_returns_before_they_finish that registers
a sanitizer which panics, emits a mark with known original fields, and verifies
the subscriber receives those unchanged fields. Include the same setup and
cleanup for global state, sanitizer registration, and subscriber registration,
and assert the panic is contained while publication falls back to the original
event.

Sources: Coding guidelines, Path instructions

🤖 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.

Outside diff comments:
In `@crates/core/src/api/runtime/subscriber_dispatcher.rs`:
- Around line 207-225: Update deliver_event so the original Event snapshot is
created only when sanitizers is non-empty, preserving the unsanitized event
without cloning for the ordinary path. Keep the sanitizer panic fallback in the
event_sanitize_snapshot_chain handling, using the conditional snapshot only
where required.

In `@crates/core/tests/integration/subscriber_dispatcher_tests.rs`:
- Around line 105-163: Add an integration test alongside
mark_emission_snapshots_sanitizers_and_returns_before_they_finish that registers
a sanitizer which panics, emits a mark with known original fields, and verifies
the subscriber receives those unchanged fields. Include the same setup and
cleanup for global state, sanitizer registration, and subscriber registration,
and assert the panic is contained while publication falls back to the original
event.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Enterprise

Run ID: 783ec91e-94c4-4898-b215-360ede46b8c5

📥 Commits

Reviewing files that changed from the base of the PR and between d5a95dc and 9c0cf99.

📒 Files selected for processing (2)
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
📜 Review details
🧰 Additional context used
📓 Path-based instructions (16)
**/*.rs

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

**/*.rs: Any Rust change must run just test-rust
Any Rust change must run cargo fmt --all
Any Rust change must run cargo clippy --workspace --all-targets -- -D warnings

**/*.rs: Run cargo fmt --all for all FFI work since it is Rust work
Run just test-rust to validate FFI changes
Run cargo clippy --workspace --all-targets -- -D warnings to enforce strict linting on FFI work

When Rust files changed as part of Go work, also run cargo fmt --all, just test-rust, and cargo clippy --workspace --all-targets -- -D warnings

**/*.rs: Run cargo fmt --all when Rust files are changed as part of Node work
Run cargo clippy --workspace --all-targets -- -D warnings when Rust files are changed as part of Node work
Run just test-rust when Rust files are changed as part of Node work

When changing the core Rust runtime or Rust-facing API surface, format Rust code with cargo fmt (rustfmt defaults), keep cargo clippy -- -D warnings clean, and satisfy cargo deny check per deny.toml.

**/*.rs: If any Rust code changed, always run just test-rust.
If any Rust code changed, also run cargo fmt --all.
If any Rust code changed, also run cargo clippy --workspace --all-targets -- -D warnings.
For Rust changes headed for review, run cargo fmt --all and cargo clippy --workspace --all-targets -- -D warnings even if relying on pre-commit.

Files:

  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
{crates/core,crates/adaptive}/**/*

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

Changes to crates/core or crates/adaptive must run the full language matrix

Files:

  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
crates/core/**/*.rs

📄 CodeRabbit inference engine (.agents/skills/test-go-binding/SKILL.md)

If the change touched crates/core or shared runtime semantics, also use validate-change for broader validation

Files:

  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
**/*.{rs,py}

📄 CodeRabbit inference engine (AGENTS.md)

Follow binding naming conventions in Rust and Python: use snake_case.

Files:

  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
**/*.{rs,py,js,mjs,cjs,ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{rs,py,js,mjs,cjs,ts,tsx}: Use Json = serde_json::Value in Rust-facing runtime APIs where the existing code expects JSON payloads.
Use Result<T> with FlowError in core runtime paths, and keep errors explicit and binding-appropriate at the wrapper layer.
Keep async behavior on the existing tokio-based model; bindings should preserve callback and future lifetimes rather than blocking or hiding async work unexpectedly.

Files:

  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
**/*.{rs,py,go,js,ts,c,h}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Use language-appropriate naming conventions: Rust snake_case, C FFI exports prefixed nemo_relay_, Go PascalCase, Node.js camelCase, and Python snake_case.

Files:

  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
**/*.{rs,go,js,ts}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Add the SPDX license header to all Rust, Go, JavaScript, and TypeScript source files using the corresponding // comment form.

Files:

  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
**/*

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

**/*: Format changed files with the language-native formatter before the final lint/test pass.
If dynamic plugin behavior changed, use maintain-dynamic-plugins and include the native SDK, worker protocol, Python SDK, docs, packaging, and Codecov surfaces in the validation plan.
If code changes alter APIs, bindings, commands, paths, packaging behavior, observability/adaptive semantics, or documented best practices, update any dependent maintainer or consumer skills in the same branch.
During iteration, prefer uv run pre-commit run --files <changed files...>.
Before review or handoff, run uv run pre-commit run --all-files.

Files:

  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
crates/{core,adaptive}/**/*

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

If crates/core or crates/adaptive changed, run the full validation matrix across Rust, Python, Go, and Node.js.

Files:

  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
**/*.{rs,py,go,js,ts}

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

If a language surface changed, always run that language's test target even when Rust core did not change.

Files:

  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
**/*.{rs,py,js,ts,tsx,go,java,kt,swift}

📄 CodeRabbit inference engine (.agents/skills/add-middleware/SKILL.md)

Add tests covering registration and duplicate names, deregistration and missing names, priority ordering, callback failure policy, scope-local inheritance and cleanup, event payload semantics, immutable mark and scope fields, and parity across affected bindings.

Files:

  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
crates/{core,adaptive}/**/*.rs

⚙️ CodeRabbit configuration file

crates/{core,adaptive}/**/*.rs: Review the Rust runtime for async correctness, scope isolation, middleware ordering, and event lifecycle regressions.
Pay close attention to task-local/thread-local scope propagation, callback lifetimes, stream finalization, and root_uuid isolation.
Public API changes should preserve existing behavior unless tests and docs show the intended migration path.

Files:

  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
{crates/**/tests/**,python/tests/**,go/nemo_relay/**/*_test.go}

⚙️ CodeRabbit configuration file

{crates/**/tests/**,python/tests/**,go/nemo_relay/**/*_test.go}: Tests should cover the behavior promised by the changed API surface, including error paths and cross-request isolation where relevant.
Prefer assertions on lifecycle events, scope stacks, middleware ordering, and binding parity over shallow smoke tests.

Files:

  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
crates/core/src/{api/**/*.rs,api/runtime/**/*.rs,codec/**/*.rs,json.rs}

📄 CodeRabbit inference engine (.agents/skills/add-binding-feature/SKILL.md)

Implement the new or changed public runtime behavior first in the Rust core, especially under crates/core/src/api/ and related core modules such as crates/core/src/api/runtime/, crates/core/src/codec/, and crates/core/src/json.rs.

Files:

  • crates/core/src/api/runtime/subscriber_dispatcher.rs
{crates/**/src/**/*.rs,python/**/*.py}

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

Do not add tests under src; Rust tests belong in crate tests/ trees, and Python SDK tests belong under python/tests.

Files:

  • crates/core/src/api/runtime/subscriber_dispatcher.rs
crates/core/src/api/**/*.rs

📄 CodeRabbit inference engine (.agents/skills/add-middleware/SKILL.md)

Preserve the documented pipeline order: conditional guardrails, request intercepts, request sanitization, execution intercepts, and response sanitization for tool and LLM execution; specialized sanitization, event creation, and dispatch for mark and scope events.

Files:

  • crates/core/src/api/runtime/subscriber_dispatcher.rs
🧠 Learnings (1)
📚 Learning: 2026-07-28T03:31:05.964Z
Learnt from: willkill07
Repo: NVIDIA/NeMo-Relay PR: 564
File: crates/core/src/api/runtime/subscriber_dispatcher.rs:297-314
Timestamp: 2026-07-28T03:31:05.964Z
Learning: In this codebase’s runtime API, do not implement incremental native LLM stream forwarding via the native ABI v3 asynchronous middleware protocol (it can only settle a single JSON value via a one-shot completion handle and cannot forward stream chunks incrementally). If a latency-sensitive plugin needs streaming behavior, review for use of synchronous native stream intercepts or worker plugins instead of trying to chunk-deliver or incrementally forward over the ABI v3 async path.

Applied to files:

  • crates/core/src/api/runtime/subscriber_dispatcher.rs
🔇 Additional comments (2)
crates/core/src/api/runtime/subscriber_dispatcher.rs (1)

7-10: LGTM!

Also applies to: 30-30, 53-53, 84-121, 195-198, 245-255

crates/core/tests/integration/subscriber_dispatcher_tests.rs (1)

6-19: LGTM!

@willkill07

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@willkill07

Copy link
Copy Markdown
Member Author

Addressed both outside-diff CodeRabbit findings in 7e5e0bc: unsanitized delivery now avoids cloning the event, and an integration test verifies sanitizer panics publish the original snapshot.

@willkill07

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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/core/src/api/runtime/subscriber_dispatcher.rs`:
- Around line 214-229: The event sanitization flow in subscriber_dispatcher.rs
must catch failures per sanitizer rather than around the entire
event_sanitize_snapshot_chain, preserving and publishing the latest valid
snapshot while logging the failing guardrail context; update the sanitizer loop
near NemoRelayContextState::event_sanitize_snapshot_chain. In
crates/core/tests/integration/subscriber_dispatcher_tests.rs lines 198-231, add
a successful sanitizer before the panicking sanitizer and assert the delivered
event contains the successful sanitizer’s redaction.
🪄 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: 9e4c70f1-ab09-491c-9826-80d530a7e69b

📥 Commits

Reviewing files that changed from the base of the PR and between 9c0cf99 and 7e5e0bc.

📒 Files selected for processing (2)
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
📜 Review details
🧰 Additional context used
📓 Path-based instructions (16)
**/*.rs

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

**/*.rs: Any Rust change must run just test-rust
Any Rust change must run cargo fmt --all
Any Rust change must run cargo clippy --workspace --all-targets -- -D warnings

**/*.rs: Run cargo fmt --all for all FFI work since it is Rust work
Run just test-rust to validate FFI changes
Run cargo clippy --workspace --all-targets -- -D warnings to enforce strict linting on FFI work

When Rust files changed as part of Go work, also run cargo fmt --all, just test-rust, and cargo clippy --workspace --all-targets -- -D warnings

**/*.rs: Run cargo fmt --all when Rust files are changed as part of Node work
Run cargo clippy --workspace --all-targets -- -D warnings when Rust files are changed as part of Node work
Run just test-rust when Rust files are changed as part of Node work

When changing the core Rust runtime or Rust-facing API surface, format Rust code with cargo fmt (rustfmt defaults), keep cargo clippy -- -D warnings clean, and satisfy cargo deny check per deny.toml.

**/*.rs: If any Rust code changed, always run just test-rust.
If any Rust code changed, also run cargo fmt --all.
If any Rust code changed, also run cargo clippy --workspace --all-targets -- -D warnings.
For Rust changes headed for review, run cargo fmt --all and cargo clippy --workspace --all-targets -- -D warnings even if relying on pre-commit.

Files:

  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
{crates/core,crates/adaptive}/**/*

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

Changes to crates/core or crates/adaptive must run the full language matrix

Files:

  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
crates/core/**/*.rs

📄 CodeRabbit inference engine (.agents/skills/test-go-binding/SKILL.md)

If the change touched crates/core or shared runtime semantics, also use validate-change for broader validation

Files:

  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
**/*.{rs,py}

📄 CodeRabbit inference engine (AGENTS.md)

Follow binding naming conventions in Rust and Python: use snake_case.

Files:

  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
**/*.{rs,py,js,mjs,cjs,ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{rs,py,js,mjs,cjs,ts,tsx}: Use Json = serde_json::Value in Rust-facing runtime APIs where the existing code expects JSON payloads.
Use Result<T> with FlowError in core runtime paths, and keep errors explicit and binding-appropriate at the wrapper layer.
Keep async behavior on the existing tokio-based model; bindings should preserve callback and future lifetimes rather than blocking or hiding async work unexpectedly.

Files:

  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
**/*.{rs,py,go,js,ts,c,h}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Use language-appropriate naming conventions: Rust snake_case, C FFI exports prefixed nemo_relay_, Go PascalCase, Node.js camelCase, and Python snake_case.

Files:

  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
**/*.{rs,go,js,ts}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Add the SPDX license header to all Rust, Go, JavaScript, and TypeScript source files using the corresponding // comment form.

Files:

  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
crates/core/src/{api/**/*.rs,api/runtime/**/*.rs,codec/**/*.rs,json.rs}

📄 CodeRabbit inference engine (.agents/skills/add-binding-feature/SKILL.md)

Implement the new or changed public runtime behavior first in the Rust core, especially under crates/core/src/api/ and related core modules such as crates/core/src/api/runtime/, crates/core/src/codec/, and crates/core/src/json.rs.

Files:

  • crates/core/src/api/runtime/subscriber_dispatcher.rs
{crates/**/src/**/*.rs,python/**/*.py}

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

Do not add tests under src; Rust tests belong in crate tests/ trees, and Python SDK tests belong under python/tests.

Files:

  • crates/core/src/api/runtime/subscriber_dispatcher.rs
**/*

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

**/*: Format changed files with the language-native formatter before the final lint/test pass.
If dynamic plugin behavior changed, use maintain-dynamic-plugins and include the native SDK, worker protocol, Python SDK, docs, packaging, and Codecov surfaces in the validation plan.
If code changes alter APIs, bindings, commands, paths, packaging behavior, observability/adaptive semantics, or documented best practices, update any dependent maintainer or consumer skills in the same branch.
During iteration, prefer uv run pre-commit run --files <changed files...>.
Before review or handoff, run uv run pre-commit run --all-files.

Files:

  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
crates/{core,adaptive}/**/*

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

If crates/core or crates/adaptive changed, run the full validation matrix across Rust, Python, Go, and Node.js.

Files:

  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
**/*.{rs,py,go,js,ts}

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

If a language surface changed, always run that language's test target even when Rust core did not change.

Files:

  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
crates/core/src/api/**/*.rs

📄 CodeRabbit inference engine (.agents/skills/add-middleware/SKILL.md)

Preserve the documented pipeline order: conditional guardrails, request intercepts, request sanitization, execution intercepts, and response sanitization for tool and LLM execution; specialized sanitization, event creation, and dispatch for mark and scope events.

Files:

  • crates/core/src/api/runtime/subscriber_dispatcher.rs
**/*.{rs,py,js,ts,tsx,go,java,kt,swift}

📄 CodeRabbit inference engine (.agents/skills/add-middleware/SKILL.md)

Add tests covering registration and duplicate names, deregistration and missing names, priority ordering, callback failure policy, scope-local inheritance and cleanup, event payload semantics, immutable mark and scope fields, and parity across affected bindings.

Files:

  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
crates/{core,adaptive}/**/*.rs

⚙️ CodeRabbit configuration file

crates/{core,adaptive}/**/*.rs: Review the Rust runtime for async correctness, scope isolation, middleware ordering, and event lifecycle regressions.
Pay close attention to task-local/thread-local scope propagation, callback lifetimes, stream finalization, and root_uuid isolation.
Public API changes should preserve existing behavior unless tests and docs show the intended migration path.

Files:

  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
{crates/**/tests/**,python/tests/**,go/nemo_relay/**/*_test.go}

⚙️ CodeRabbit configuration file

{crates/**/tests/**,python/tests/**,go/nemo_relay/**/*_test.go}: Tests should cover the behavior promised by the changed API surface, including error paths and cross-request isolation where relevant.
Prefer assertions on lifecycle events, scope stacks, middleware ordering, and binding parity over shallow smoke tests.

Files:

  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
🧠 Learnings (2)
📚 Learning: 2026-07-28T03:31:05.964Z
Learnt from: willkill07
Repo: NVIDIA/NeMo-Relay PR: 564
File: crates/core/src/api/runtime/subscriber_dispatcher.rs:297-314
Timestamp: 2026-07-28T03:31:05.964Z
Learning: In this codebase’s runtime API, do not implement incremental native LLM stream forwarding via the native ABI v3 asynchronous middleware protocol (it can only settle a single JSON value via a one-shot completion handle and cannot forward stream chunks incrementally). If a latency-sensitive plugin needs streaming behavior, review for use of synchronous native stream intercepts or worker plugins instead of trying to chunk-deliver or incrementally forward over the ABI v3 async path.

Applied to files:

  • crates/core/src/api/runtime/subscriber_dispatcher.rs
📚 Learning: 2026-07-28T20:07:29.880Z
Learnt from: willkill07
Repo: NVIDIA/NeMo-Relay PR: 571
File: crates/core/src/api/runtime/state.rs:996-1020
Timestamp: 2026-07-28T20:07:29.880Z
Learning: In NeMo Relay (RELAY-509), sanitizer callback failures must be treated as intentional fail-open behavior. When an event/tool (request/response) or LLM (request/response) sanitizer callback fails, the sanitizer chain should retain and publish the last valid event/payload snapshot (rather than dropping/invalidating the data) and log the failure including callback context (e.g., which sanitizer/callback failed and relevant identifiers). Apply this consistently across all sanitizer chains mentioned in the RELAY-509 documentation/migration guide.

Applied to files:

  • crates/core/src/api/runtime/subscriber_dispatcher.rs
🔇 Additional comments (2)
crates/core/src/api/runtime/subscriber_dispatcher.rs (2)

27-120: LGTM!

Also applies to: 191-198


84-120: 📐 Maintainability & Code Quality

Provide the required core validation results.

This crates/core Rust change requires cargo fmt --all, cargo clippy --workspace --all-targets -- -D warnings, just test-rust, cargo deny check, validate-change, and the full Rust/Python/Go/Node validation matrix before handoff. As per coding guidelines, “Changes to crates/core … must run the full language matrix.”

Source: Coding guidelines

Comment thread crates/core/src/api/runtime/subscriber_dispatcher.rs Outdated
@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@willkill07

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.58824% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.97%. Comparing base (e3de5c9) to head (f5b9449).

Files with missing lines Patch % Lines
...ates/core/src/api/runtime/subscriber_dispatcher.rs 79.49% 8 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #570   +/-   ##
=======================================
  Coverage   92.96%   92.97%           
=======================================
  Files         319      319           
  Lines       88929    88992   +63     
  Branches      104      104           
=======================================
+ Hits        82670    82732   +62     
- Misses       6258     6259    +1     
  Partials        1        1           
Components Coverage Δ
Rust Runtime 94.57% <90.59%> (-0.03%) ⬇️
Shared DTO Types 99.05% <ø> (ø)
CLI 90.02% <ø> (ø)
Go Binding 95.40% <ø> (+0.14%) ⬆️
Python Binding 94.78% <ø> (ø)
Node Binding 98.00% <ø> (ø)
Dynamic Plugin SDKs 97.37% <ø> (ø)
Files with missing lines Coverage Δ
crates/core/src/api/runtime/state.rs 99.13% <100.00%> (+0.01%) ⬆️
crates/core/src/api/scope.rs 100.00% <100.00%> (ø)
crates/core/src/api/shared.rs 99.48% <100.00%> (+0.01%) ⬆️
...ates/core/src/api/runtime/subscriber_dispatcher.rs 82.99% <79.49%> (-1.41%) ⬇️

... and 2 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e3de5c9...f5b9449. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@willkill07
willkill07 force-pushed the wkk_relay-509-event-publication branch from 79a3979 to 64ab12a Compare July 29, 2026 03:44
Signed-off-by: Will Killian <wkillian@nvidia.com>
Signed-off-by: Will Killian <wkillian@nvidia.com>
Signed-off-by: Will Killian <wkillian@nvidia.com>
Signed-off-by: Will Killian <wkillian@nvidia.com>
Signed-off-by: Will Killian <wkillian@nvidia.com>
Signed-off-by: Will Killian <wkillian@nvidia.com>
Signed-off-by: Will Killian <wkillian@nvidia.com>
Signed-off-by: Will Killian <wkillian@nvidia.com>
@willkill07
willkill07 force-pushed the wkk_relay-509-event-publication branch from 64ab12a to 44f8ef0 Compare July 29, 2026 16:52
@willkill07

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
crates/core/src/api/scope.rs (1)

226-256: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Align push_scope's sanitizer-snapshot timing with subscribers and with pop_scope.

subscribers is snapshotted at Line 229-230 using the scope stack before task_scope_push, but sanitizers is snapshotted at Line 249 after task_scope_push, against the same live emission_scope_stack handle. pop_scope instead snapshots both subscribers and sanitizers before its scope-stack mutation (task_scope_remove). Today this is harmless — a brand-new scope can't yet have scope-local sanitizer guardrails registered on it before this function returns the handle — but the asymmetry is fragile: it silently relies on that invariant instead of being structurally consistent with the "snapshot represents pre-mutation state" pattern used elsewhere in this file.

♻️ Align snapshot ordering with pop_scope
-    task_scope_push(handle.clone());
-    if let Some(sanitizers) = snapshot_event_sanitizers(&event, &emission_scope_stack) {
+    let sanitizers = snapshot_event_sanitizers(&event, &emission_scope_stack);
+    task_scope_push(handle.clone());
+    if let Some(sanitizers) = sanitizers {
         let _ = subscriber_dispatcher::dispatch_sanitized_event(
             event,
             sanitizers,
             &subscribers,
             emission_scope_stack,
         );
     }
     Ok(handle)

Based on path instructions, "Pay close attention to task-local/thread-local scope propagation, callback lifetimes, stream finalization, and root_uuid isolation" and "Review the Rust runtime for async correctness, scope isolation, middleware ordering, and event lifecycle regressions."

🤖 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/core/src/api/scope.rs` around lines 226 - 256, Update push_scope so
snapshot_event_sanitizers is called alongside snapshot_event_subscribers before
task_scope_push mutates the scope stack, using the pre-mutation
emission_scope_stack. Carry the sanitizer snapshot out of the setup block and
dispatch it afterward, preserving the existing event and subscriber behavior
while matching pop_scope’s pre-mutation snapshot ordering.

Source: Path instructions

integrations/openclaw/src/hooks-backend.ts (1)

425-432: 🩺 Stability & Availability | 🔵 Trivial

Good fix: cleanup now waits for subscriber delivery before dropping session state.

Awaiting flushSubscriberDelivery before forgetPendingSubagentLineage/deleteSession closes a real ordering gap — previously the flush was fire-and-forget, so session bookkeeping could be torn down while a subscriber callback for the close event was still in flight. All call sites (onSessionEnd, cleanupSession, closeAllSessions) already await closeSession, so this is safe.

One scaling note: closeAllSessions (Line 462-466) now performs one full dispatcher flush per session sequentially during stop/drainForGatewayStop. Each flush is likely cheap, but it scales linearly with session count during gateway shutdown — worth keeping an eye on if shutdown latency becomes noticeable with many concurrent sessions.

Also applies to: 469-478

🤖 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 `@integrations/openclaw/src/hooks-backend.ts` around lines 425 - 432, Keep
closeSession’s awaited flushSubscriberDelivery ordering intact, but update
closeAllSessions to avoid performing a full subscriber flush sequentially for
every session during shutdown. Coordinate shutdown cleanup so delivery is
flushed efficiently while session bookkeeping is not removed before its close
callbacks complete.
🤖 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/core/src/api/runtime/subscriber_dispatcher.rs`:
- Around line 84-120: Update dispatch_sanitized_event and the dispatcher channel
setup behind dispatcher_sender to use a bounded queue, preserving FIFO delivery.
Define explicit overload handling when the queue is full—such as rejecting the
event—and return false while emitting saturation telemetry that distinguishes
queue-full drops from dispatcher disconnection or startup failure.

---

Outside diff comments:
In `@crates/core/src/api/scope.rs`:
- Around line 226-256: Update push_scope so snapshot_event_sanitizers is called
alongside snapshot_event_subscribers before task_scope_push mutates the scope
stack, using the pre-mutation emission_scope_stack. Carry the sanitizer snapshot
out of the setup block and dispatch it afterward, preserving the existing event
and subscriber behavior while matching pop_scope’s pre-mutation snapshot
ordering.

In `@integrations/openclaw/src/hooks-backend.ts`:
- Around line 425-432: Keep closeSession’s awaited flushSubscriberDelivery
ordering intact, but update closeAllSessions to avoid performing a full
subscriber flush sequentially for every session during shutdown. Coordinate
shutdown cleanup so delivery is flushed efficiently while session bookkeeping is
not removed before its close callbacks complete.
🪄 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: bda568a3-fae6-46ef-9174-2219ebb5f9cf

📥 Commits

Reviewing files that changed from the base of the PR and between 79a3979 and 44f8ef0.

📒 Files selected for processing (14)
  • crates/core/src/api/runtime/state.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/src/api/scope.rs
  • crates/core/src/api/shared.rs
  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
  • crates/ffi/tests/unit/api/registry_tests.rs
  • crates/node/README.md
  • crates/node/src/api/mod.rs
  • crates/node/tests/event_sanitizers_tests.mjs
  • crates/node/tests/llm_tests.mjs
  • crates/node/tests/scope_tests.mjs
  • crates/node/tests/tools_tests.mjs
  • docs/reference/event-sanitizers.mdx
  • integrations/openclaw/src/hooks-backend.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (2)
  • GitHub Check: Check / Run
  • GitHub Check: Preview docs
🧰 Additional context used
📓 Path-based instructions (35)
crates/node/**/*.{js,mjs,cjs,ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Use camelCase for Node.js public APIs.

Files:

  • crates/node/tests/tools_tests.mjs
  • crates/node/tests/llm_tests.mjs
  • crates/node/tests/scope_tests.mjs
  • crates/node/tests/event_sanitizers_tests.mjs
**/*.{rs,py,js,mjs,cjs,ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{rs,py,js,mjs,cjs,ts,tsx}: Use Json = serde_json::Value in Rust-facing runtime APIs where the existing code expects JSON payloads.
Use Result<T> with FlowError in core runtime paths, and keep errors explicit and binding-appropriate at the wrapper layer.
Keep async behavior on the existing tokio-based model; bindings should preserve callback and future lifetimes rather than blocking or hiding async work unexpectedly.

Files:

  • crates/node/tests/tools_tests.mjs
  • crates/node/tests/llm_tests.mjs
  • crates/core/src/api/runtime/state.rs
  • integrations/openclaw/src/hooks-backend.ts
  • crates/node/src/api/mod.rs
  • crates/ffi/tests/unit/api/registry_tests.rs
  • crates/core/src/api/shared.rs
  • crates/node/tests/scope_tests.mjs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
  • crates/node/tests/event_sanitizers_tests.mjs
  • crates/core/src/api/scope.rs
**/*

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

**/*: Format changed files with the language-native formatter before the final lint/test pass.
If dynamic plugin behavior changed, use maintain-dynamic-plugins and include the native SDK, worker protocol, Python SDK, docs, packaging, and Codecov surfaces in the validation plan.
If code changes alter APIs, bindings, commands, paths, packaging behavior, observability/adaptive semantics, or documented best practices, update any dependent maintainer or consumer skills in the same branch.
During iteration, prefer uv run pre-commit run --files <changed files...>.
Before review or handoff, run uv run pre-commit run --all-files.

Files:

  • crates/node/tests/tools_tests.mjs
  • crates/node/README.md
  • crates/node/tests/llm_tests.mjs
  • crates/core/src/api/runtime/state.rs
  • integrations/openclaw/src/hooks-backend.ts
  • crates/node/src/api/mod.rs
  • crates/ffi/tests/unit/api/registry_tests.rs
  • crates/core/src/api/shared.rs
  • crates/node/tests/scope_tests.mjs
  • docs/reference/event-sanitizers.mdx
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
  • crates/node/tests/event_sanitizers_tests.mjs
  • crates/core/src/api/scope.rs
crates/{python,ffi,node}/**/*

⚙️ CodeRabbit configuration file

crates/{python,ffi,node}/**/*: 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/tests/tools_tests.mjs
  • crates/node/README.md
  • crates/node/tests/llm_tests.mjs
  • crates/node/src/api/mod.rs
  • crates/ffi/tests/unit/api/registry_tests.rs
  • crates/node/tests/scope_tests.mjs
  • crates/node/tests/event_sanitizers_tests.mjs
{crates/**/tests/**,python/tests/**,go/nemo_relay/**/*_test.go}

⚙️ CodeRabbit configuration file

{crates/**/tests/**,python/tests/**,go/nemo_relay/**/*_test.go}: Tests should cover the behavior promised by the changed API surface, including error paths and cross-request isolation where relevant.
Prefer assertions on lifecycle events, scope stacks, middleware ordering, and binding parity over shallow smoke tests.

Files:

  • crates/node/tests/tools_tests.mjs
  • crates/node/tests/llm_tests.mjs
  • crates/ffi/tests/unit/api/registry_tests.rs
  • crates/node/tests/scope_tests.mjs
  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
  • crates/node/tests/event_sanitizers_tests.mjs
**/*.{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,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
**/*.md

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

**/*.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 that pull readers away from a procedure unless the link is a p...

Files:

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

📄 CodeRabbit inference engine (AGENTS.md)

Update README.md, fern/, package READMEs, and binding-support notes when public behavior, package names, examples, or supported bindings change.

**/*.{md,mdx}: Prefer the documented public API, not internal shortcuts
Keep package names, repo references, and build commands current
Keep release-process and release-notes guidance in repo-maintainer docs such as RELEASING.md, not as user-facing docs pages or CHANGELOG.md
Keep stable user-facing wrappers at scripts/ root in docs and examples; only point at namespaced helper paths when documenting internal maintenance work
When detailed dynamic plugin guides exist, keep Rust native plugin examples, Python worker plugin examples, and grpc-v1 protocol details on separate pages

If links in documentation change, run just docs-linkcheck.

Files:

  • crates/node/README.md
  • docs/reference/event-sanitizers.mdx
**/*.{md,markdown,mdx}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Add the SPDX license header to all Markdown/MDX documentation files using the HTML comment block form.

Files:

  • crates/node/README.md
  • docs/reference/event-sanitizers.mdx
**/*.rs

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

**/*.rs: Any Rust change must run just test-rust
Any Rust change must run cargo fmt --all
Any Rust change must run cargo clippy --workspace --all-targets -- -D warnings

**/*.rs: Run cargo fmt --all for all FFI work since it is Rust work
Run just test-rust to validate FFI changes
Run cargo clippy --workspace --all-targets -- -D warnings to enforce strict linting on FFI work

When Rust files changed as part of Go work, also run cargo fmt --all, just test-rust, and cargo clippy --workspace --all-targets -- -D warnings

**/*.rs: Run cargo fmt --all when Rust files are changed as part of Node work
Run cargo clippy --workspace --all-targets -- -D warnings when Rust files are changed as part of Node work
Run just test-rust when Rust files are changed as part of Node work

When changing the core Rust runtime or Rust-facing API surface, format Rust code with cargo fmt (rustfmt defaults), keep cargo clippy -- -D warnings clean, and satisfy cargo deny check per deny.toml.

**/*.rs: If any Rust code changed, always run just test-rust.
If any Rust code changed, also run cargo fmt --all.
If any Rust code changed, also run cargo clippy --workspace --all-targets -- -D warnings.
For Rust changes headed for review, run cargo fmt --all and cargo clippy --workspace --all-targets -- -D warnings even if relying on pre-commit.

Files:

  • crates/core/src/api/runtime/state.rs
  • crates/node/src/api/mod.rs
  • crates/ffi/tests/unit/api/registry_tests.rs
  • crates/core/src/api/shared.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
  • crates/core/src/api/scope.rs
{crates/core,crates/adaptive}/**/*

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

Changes to crates/core or crates/adaptive must run the full language matrix

Files:

  • crates/core/src/api/runtime/state.rs
  • crates/core/src/api/shared.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
  • crates/core/src/api/scope.rs
crates/core/**/*.rs

📄 CodeRabbit inference engine (.agents/skills/test-go-binding/SKILL.md)

If the change touched crates/core or shared runtime semantics, also use validate-change for broader validation

Files:

  • crates/core/src/api/runtime/state.rs
  • crates/core/src/api/shared.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
  • crates/core/src/api/scope.rs
**/*.{rs,py}

📄 CodeRabbit inference engine (AGENTS.md)

Follow binding naming conventions in Rust and Python: use snake_case.

Files:

  • crates/core/src/api/runtime/state.rs
  • crates/node/src/api/mod.rs
  • crates/ffi/tests/unit/api/registry_tests.rs
  • crates/core/src/api/shared.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
  • crates/core/src/api/scope.rs
**/*.{rs,py,go,js,ts,c,h}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Use language-appropriate naming conventions: Rust snake_case, C FFI exports prefixed nemo_relay_, Go PascalCase, Node.js camelCase, and Python snake_case.

Files:

  • crates/core/src/api/runtime/state.rs
  • integrations/openclaw/src/hooks-backend.ts
  • crates/node/src/api/mod.rs
  • crates/ffi/tests/unit/api/registry_tests.rs
  • crates/core/src/api/shared.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
  • crates/core/src/api/scope.rs
**/*.{rs,go,js,ts}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Add the SPDX license header to all Rust, Go, JavaScript, and TypeScript source files using the corresponding // comment form.

Files:

  • crates/core/src/api/runtime/state.rs
  • integrations/openclaw/src/hooks-backend.ts
  • crates/node/src/api/mod.rs
  • crates/ffi/tests/unit/api/registry_tests.rs
  • crates/core/src/api/shared.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
  • crates/core/src/api/scope.rs
crates/core/src/{api/**/*.rs,api/runtime/**/*.rs,codec/**/*.rs,json.rs}

📄 CodeRabbit inference engine (.agents/skills/add-binding-feature/SKILL.md)

Implement the new or changed public runtime behavior first in the Rust core, especially under crates/core/src/api/ and related core modules such as crates/core/src/api/runtime/, crates/core/src/codec/, and crates/core/src/json.rs.

Files:

  • crates/core/src/api/runtime/state.rs
  • crates/core/src/api/shared.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/src/api/scope.rs
{crates/**/src/**/*.rs,python/**/*.py}

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

Do not add tests under src; Rust tests belong in crate tests/ trees, and Python SDK tests belong under python/tests.

Files:

  • crates/core/src/api/runtime/state.rs
  • crates/node/src/api/mod.rs
  • crates/core/src/api/shared.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/src/api/scope.rs
crates/{core,adaptive}/**/*

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

If crates/core or crates/adaptive changed, run the full validation matrix across Rust, Python, Go, and Node.js.

Files:

  • crates/core/src/api/runtime/state.rs
  • crates/core/src/api/shared.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
  • crates/core/src/api/scope.rs
**/*.{rs,py,go,js,ts}

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

If a language surface changed, always run that language's test target even when Rust core did not change.

Files:

  • crates/core/src/api/runtime/state.rs
  • integrations/openclaw/src/hooks-backend.ts
  • crates/node/src/api/mod.rs
  • crates/ffi/tests/unit/api/registry_tests.rs
  • crates/core/src/api/shared.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
  • crates/core/src/api/scope.rs
crates/core/src/api/runtime/state.rs

📄 CodeRabbit inference engine (.agents/skills/add-middleware/SKILL.md)

crates/core/src/api/runtime/state.rs: Add a SortedRegistry<GuardrailEntry<...>> or SortedRegistry<Intercept<...>> field to NemoRelayContextState for the new middleware type.
Add chain-execution helpers to NemoRelayContextState, following existing helpers such as tool_sanitize_request_chain or tool_request_intercepts_chain.

Files:

  • crates/core/src/api/runtime/state.rs
crates/core/src/api/**/*.rs

📄 CodeRabbit inference engine (.agents/skills/add-middleware/SKILL.md)

Preserve the documented pipeline order: conditional guardrails, request intercepts, request sanitization, execution intercepts, and response sanitization for tool and LLM execution; specialized sanitization, event creation, and dispatch for mark and scope events.

Files:

  • crates/core/src/api/runtime/state.rs
  • crates/core/src/api/shared.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/src/api/scope.rs
**/*.{rs,py,js,ts,tsx,go,java,kt,swift}

📄 CodeRabbit inference engine (.agents/skills/add-middleware/SKILL.md)

Add tests covering registration and duplicate names, deregistration and missing names, priority ordering, callback failure policy, scope-local inheritance and cleanup, event payload semantics, immutable mark and scope fields, and parity across affected bindings.

Files:

  • crates/core/src/api/runtime/state.rs
  • integrations/openclaw/src/hooks-backend.ts
  • crates/node/src/api/mod.rs
  • crates/ffi/tests/unit/api/registry_tests.rs
  • crates/core/src/api/shared.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
  • crates/core/src/api/scope.rs
crates/{core,adaptive}/**/*.rs

⚙️ CodeRabbit configuration file

crates/{core,adaptive}/**/*.rs: Review the Rust runtime for async correctness, scope isolation, middleware ordering, and event lifecycle regressions.
Pay close attention to task-local/thread-local scope propagation, callback lifetimes, stream finalization, and root_uuid isolation.
Public API changes should preserve existing behavior unless tests and docs show the intended migration path.

Files:

  • crates/core/src/api/runtime/state.rs
  • crates/core/src/api/shared.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/tests/integration/subscriber_dispatcher_tests.rs
  • crates/core/src/api/scope.rs
**/*.{py,go,js,ts}

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

Keep Python, Go, and Node.js config objects and subscriber/exporter methods aligned so all bindings expose the same logical knobs and semantics.

Files:

  • integrations/openclaw/src/hooks-backend.ts
{crates/python/src/py_api/mod.rs,python/nemo_relay/**/*.py,python/nemo_relay/**/*.pyi,go/nemo_relay/**/*.go,crates/node/src/api/**/*.rs}

📄 CodeRabbit inference engine (.agents/skills/add-binding-feature/SKILL.md)

Update the language-native bindings for every exposed surface in Python, Go, and Node.js.

Files:

  • crates/node/src/api/mod.rs
crates/ffi/**

📄 CodeRabbit inference engine (.agents/skills/test-ffi-surface/SKILL.md)

Rebuild the FFI crate in release mode so the shared library and header stay in sync when making changes to crates/ffi

Files:

  • crates/ffi/tests/unit/api/registry_tests.rs
crates/ffi/**/*.rs

📄 CodeRabbit inference engine (.agents/skills/test-go-binding/SKILL.md)

If the change touched crates/ffi, also use test-ffi-surface for validation

Use C FFI export names prefixed with nemo_relay_ in the raw C FFI layer.

Files:

  • crates/ffi/tests/unit/api/registry_tests.rs
crates/core/src/api/{tool,llm,shared,scope}.rs

📄 CodeRabbit inference engine (.agents/skills/add-middleware/SKILL.md)

Wire the new middleware chain into the appropriate lifecycle owner and pipeline stage: tool and LLM execution paths use tool.rs or llm.rs; shared mark and scope event sanitization uses shared.rs and is called from scope.rs.

Files:

  • crates/core/src/api/shared.rs
  • crates/core/src/api/scope.rs
**/*.mdx

📄 CodeRabbit inference engine (.agents/skills/review-doc-style/SKILL.md)

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

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

Files:

  • docs/reference/event-sanitizers.mdx
{docs,examples}/**/*

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

Update docs and examples.

Files:

  • docs/reference/event-sanitizers.mdx
docs/**/*

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

If documentation examples or commands under docs/ change, run the targeted docs checks appropriate to the change.

Files:

  • docs/reference/event-sanitizers.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/reference/event-sanitizers.mdx
🧠 Learnings (4)
📚 Learning: 2026-07-28T03:31:05.964Z
Learnt from: willkill07
Repo: NVIDIA/NeMo-Relay PR: 564
File: crates/core/src/api/runtime/subscriber_dispatcher.rs:297-314
Timestamp: 2026-07-28T03:31:05.964Z
Learning: In this codebase’s runtime API, do not implement incremental native LLM stream forwarding via the native ABI v3 asynchronous middleware protocol (it can only settle a single JSON value via a one-shot completion handle and cannot forward stream chunks incrementally). If a latency-sensitive plugin needs streaming behavior, review for use of synchronous native stream intercepts or worker plugins instead of trying to chunk-deliver or incrementally forward over the ABI v3 async path.

Applied to files:

  • crates/core/src/api/runtime/state.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
📚 Learning: 2026-07-28T20:07:29.880Z
Learnt from: willkill07
Repo: NVIDIA/NeMo-Relay PR: 571
File: crates/core/src/api/runtime/state.rs:996-1020
Timestamp: 2026-07-28T20:07:29.880Z
Learning: In NeMo Relay (RELAY-509), sanitizer callback failures must be treated as intentional fail-open behavior. When an event/tool (request/response) or LLM (request/response) sanitizer callback fails, the sanitizer chain should retain and publish the last valid event/payload snapshot (rather than dropping/invalidating the data) and log the failure including callback context (e.g., which sanitizer/callback failed and relevant identifiers). Apply this consistently across all sanitizer chains mentioned in the RELAY-509 documentation/migration guide.

Applied to files:

  • crates/core/src/api/runtime/state.rs
  • crates/core/src/api/shared.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/src/api/scope.rs
📚 Learning: 2026-05-07T18:04:44.387Z
Learnt from: mnajafian-nv
Repo: NVIDIA/NeMo-Flow PR: 67
File: integrations/openclaw/src/modules.ts:1-2
Timestamp: 2026-05-07T18:04:44.387Z
Learning: In NVIDIA/NeMo-Flow, TypeScript source files should use `//` line comments for SPDX headers (e.g., `// SPDX-FileCopyrightText: ...` and `// SPDX-License-Identifier: ...`) rather than C-style block comments (`/* ... */`). The repo’s copyright checker enforces this mapping, so `//` SPDX headers in `.ts` files should not be flagged as a style violation.

Applied to files:

  • integrations/openclaw/src/hooks-backend.ts
📚 Learning: 2026-07-28T23:57:11.641Z
Learnt from: willkill07
Repo: NVIDIA/NeMo-Relay PR: 570
File: crates/node/src/api/mod.rs:3265-3282
Timestamp: 2026-07-28T23:57:11.641Z
Learning: In the Node.js binding, `flushSubscribers()` is Promise-based/async and must be awaited. Any session-close or teardown path (e.g., the OpenClaw live smoke session-close flow) must await `flushSubscribers()` before continuing to live ATIF export assertions and before teardown, so queued subscriber delivery fully completes and tests/assertions observe the final state.

Applied to files:

  • crates/node/src/api/mod.rs
🔇 Additional comments (12)
crates/core/src/api/shared.rs (1)

10-14: LGTM!

Also applies to: 57-108

crates/core/src/api/runtime/subscriber_dispatcher.rs (1)

7-10: LGTM!

Also applies to: 30-30, 53-53, 195-214, 234-243

crates/core/src/api/runtime/state.rs (1)

642-654: 📐 Maintainability & Code Quality

Provide the required validation results before merge.

  • crates/core/src/api/runtime/state.rs#L642-L654: run cargo fmt --all, cargo clippy --workspace --all-targets -- -D warnings, just test-rust, cargo deny check, and the required core full-language validation.
  • crates/ffi/tests/unit/api/registry_tests.rs#L246-L247: run test-ffi-surface and rebuild the FFI crate in release mode.
  • crates/node/src/api/mod.rs#L3240-L3257: run the Node binding test target and the repository pre-commit validation.

As per coding guidelines, Rust, FFI, core-runtime, and language-binding changes require these validation steps.

Source: Coding guidelines

crates/node/tests/scope_tests.mjs (1)

32-36: LGTM!

Also applies to: 365-370

crates/node/tests/tools_tests.mjs (1)

50-62: LGTM!

crates/core/src/api/scope.rs (1)

6-12: LGTM!

Also applies to: 282-332, 356-401

crates/core/tests/integration/subscriber_dispatcher_tests.rs (1)

6-19: LGTM!

Also applies to: 105-163, 165-189, 191-243

docs/reference/event-sanitizers.mdx (1)

56-68: LGTM!

crates/node/README.md (1)

91-105: LGTM!

crates/node/tests/event_sanitizers_tests.mjs (2)

60-60: LGTM!

Also applies to: 96-96, 154-154, 187-187, 218-218, 246-246, 274-278, 315-315


132-139: 🎯 Functional Correctness

No change needed getLastCallbackError() records nemo_relay: JS event sanitizer callback failed: invalid JS event sanitizer result, so /invalid JS event sanitizer result/ matches.

			> Likely an incorrect or invalid review comment.
crates/node/tests/llm_tests.mjs (1)

53-58: LGTM!

Comment thread crates/core/src/api/runtime/subscriber_dispatcher.rs
Signed-off-by: Will Killian <wkillian@nvidia.com>
@willkill07

Copy link
Copy Markdown
Member Author

/merge

@rapids-bot

rapids-bot Bot commented Jul 29, 2026

Copy link
Copy Markdown

Failed to merge PR using squash strategy.

@willkill07

Copy link
Copy Markdown
Member Author

/merge

@rapids-bot
rapids-bot Bot merged commit bc4f2e8 into main Jul 29, 2026
73 checks passed
rapids-bot Bot pushed a commit that referenced this pull request Jul 30, 2026
#### Overview

Convert middleware callbacks to an async Rust contract and add awaitable/Promise support across the primary Python and Node.js bindings.

> [!WARNING]
> **BREAKING CHANGE:** Rust middleware callbacks now return futures. Update guardrails, request/execution intercepts, tool/LLM sanitizers, and event sanitizers to return `Box::pin(async move { ... })` (or an equivalent future). Native plugins must be rebuilt against context ABI v3. Raw C FFI and Go middleware callbacks remain synchronous and occupy a native thread while running. Python and Node.js support awaitables/Promises additively; scope, mark, and manual lifecycle event-emission APIs remain synchronous.

- [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

- Await middleware sequentially in merged global/scope priority order.
- Preserve execution and stream-intercept continuation semantics.
- Await event sanitizers on the queued publication path without making emission APIs awaitable.
- Add Python awaitable and Node Promise adapters for every middleware family.
- Upgrade native plugin and worker callback adapters to the common async contract.
- Update middleware, event-sanitizer, native-plugin, and migration documentation.

This is PR 2 of 2 in the RELAY-509 GitHub stack. The stack is rooted on upstream `main`, and this PR is based on #570:

1. [#570 — queued event publication](#570)
2. **#571 — async middleware across primary bindings**

#### Where should the reviewer start?

Start with `crates/core/src/api/runtime/callbacks.rs`, then review the Python adapter in `crates/python/src/py_callable.rs` and Node bridge in `crates/node/src/promise_call.rs`.

Validation:

- `just test-rust` — passed
- `just test-python` — 595 passed
- `just test-node` — 325 passed
- `just test-go` — passed; raw C FFI middleware remains synchronous
- `just docs` and `uv run pre-commit run --all-files` — passed

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

- Relates to RELAY-509



## Summary by CodeRabbit

* **New Features**
  * Middleware and guardrails now support asynchronous callbacks across Rust, Python, Node.js, worker plugins, and native plugins.
  * Native plugin support now includes ABI v3 and completion-based asynchronous middleware.
  * Raw C FFI and Go middleware callbacks remain synchronous and occupy a native thread while running; no completion-based registration API is exposed.
  * Python and Node.js APIs support Promise/awaitable callbacks and async standalone execution.
  * Subscriber delivery preserves FIFO ordering while awaiting asynchronous sanitizers.

* **Bug Fixes**
  * Sanitizer failures now preserve the last valid observability payload instead of clearing it.
  * Improved error propagation for callback failures and panics.

* **Documentation**
  * Added migration guidance and updated middleware, sanitizer, and native plugin documentation.

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

Approvers:
  - Maryam Najafian (https://github.com/mnajafian-nv)
  - https://github.com/Salonijain27
  - Bryan Bednarski (https://github.com/bbednarski9)

URL: #571
@willkill07
willkill07 deleted the wkk_relay-509-event-publication branch August 1, 2026 01:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature a new feature 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.

3 participants