Skip to content

refactor: resolve core and FFI Sonar findings#430

Merged
rapids-bot[bot] merged 3 commits into
NVIDIA:mainfrom
willkill07:refactor/sonar-core-ffi
Jul 15, 2026
Merged

refactor: resolve core and FFI Sonar findings#430
rapids-bot[bot] merged 3 commits into
NVIDIA:mainfrom
willkill07:refactor/sonar-core-ffi

Conversation

@willkill07

@willkill07 willkill07 commented Jul 15, 2026

Copy link
Copy Markdown
Member

Overview

  • This is a new feature, refactoring, or tests
  • This is a bug fix

Details

Resolves all seven core-runtime and FFI findings in the main-branch Sonar backlog. Optimization recording is separated into reservation, schema validation, bounded serialization, and commit phases while retaining lock release and sequence retry behavior. Optimization summary construction is decomposed into contribution, usage, pricing, limitation, and summary phases. OpenTelemetry and OpenInference now use one private common optimization-attribute builder. LLM end handling, ATOF validation, and FFI JSON parsing are similarly split into private helpers.

Validation:

  • cargo fmt --all
  • cargo clippy -p nemo-relay -p nemo-relay-ffi --all-targets -- -D warnings
  • focused optimization tests
  • cargo test -p nemo-relay-ffi
  • just test-rust
  • just test-python
  • just test-go
  • just test-node
  • uv run pre-commit run --all-files
  • verified no generated FFI header diff

No public API, ABI, serialized configuration, telemetry key/value, or error-message changes are intended.

Where should the reviewer start?

Start with crates/core/src/api/optimization.rs, then the common attribute helpers in crates/core/src/observability/mod.rs, and finally the smaller LLM, ATOF, and FFI extractions.

Related Issues:

  • Relates to: none

Summary by CodeRabbit

  • Enhancements
    • Improved LLM optimization accounting and summary finalization, including effective/baseline model selection, token-savings analysis, and cost/pricing estimates.
    • Centralized OpenTelemetry/OpenInference emission of common optimization attributes for consistent status and pricing metadata.
    • Streamlined request interception handling for optional JSON inputs with consistent null-to-default behavior.
  • Bug Fixes
    • Preserved end lifecycle behavior when response annotation decoding fails with fatal-on-error settings.
    • Strengthened ATOF validation for stream sink name (non-empty, no leading/trailing whitespace, unique).
  • Tests
    • Added unit coverage for invalid stream sink name diagnostics and for recorder finalization waiting on reserved attempts.

Signed-off-by: Will Killian <wkillian@nvidia.com>
@willkill07
willkill07 requested a review from a team as a code owner July 15, 2026 14:18
@github-actions github-actions Bot added size:XL PR is extra large Improvement improvement to existing functionality lang:rust PR changes/introduces Rust code labels Jul 15, 2026
@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

Refactors LLM annotation resolution, optimization contribution recording and summary finalization, shared OTLP/OpenInference attribute emission, ATOF sink validation, and nullable JSON parsing in the FFI intercept-outcome API.

Changes

LLM optimization lifecycle

Layer / File(s) Summary
LLM end annotation resolution
crates/core/src/api/llm.rs
Extracts annotation selection and response decoding into resolve_llm_end_annotation, preserving decode-error handling and optional estimated cost attachment.
Contribution recording pipeline
crates/core/src/api/optimization.rs, crates/core/tests/unit/optimization_tests.rs
Tracks reserved attempts, separates contribution validation, identity assignment, sequencing, bounded serialization, and commit outcomes, and waits for active attempts during finalization.
Optimization summary analysis and pricing
crates/core/src/api/optimization.rs
Derives contribution limitations, usage, model selection, baseline usage, pricing, and final summary data through dedicated helpers.
Shared optimization observability attributes
crates/core/src/observability/mod.rs, crates/core/src/observability/openinference.rs, crates/core/src/observability/otel.rs
Centralizes model, token, cost, savings, status, and pricing provenance attributes for both integrations.

ATOF sink validation

Layer / File(s) Summary
ATOF sink validation dispatch
crates/core/src/observability/plugin_component.rs, crates/core/tests/unit/observability/plugin_component_tests.rs
Extracts per-sink validation, enforces stream-name formatting and uniqueness, and tests the resulting diagnostics.

FFI intercept JSON parsing

Layer / File(s) Summary
Optional intercept JSON parsing
crates/ffi/src/api/mod.rs
Uses shared nullable JSON parsing for annotated requests, pending marks, and optimization contributions, with empty defaults and consolidated invalid-JSON errors.

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

Sequence Diagram(s)

sequenceDiagram
  participant finalize_optimization_summary
  participant analyze_contributions
  participant derive_optimization_usage
  participant price_optimization_usage
  participant LlmOptimizationSummary
  finalize_optimization_summary->>analyze_contributions: derive limitations, tokens, and model inputs
  finalize_optimization_summary->>derive_optimization_usage: derive effective and baseline usage
  finalize_optimization_summary->>price_optimization_usage: compute gated cost estimates
  finalize_optimization_summary->>LlmOptimizationSummary: assemble finalized summary
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title uses Conventional Commits and accurately summarizes the refactor across core and FFI Sonar findings.
Description check ✅ Passed The PR description follows the required template and covers overview, details, reviewer start, and related issues.
Docstring Coverage ✅ Passed Docstring coverage is 94.59% 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 unit tests (beta)
  • Create PR with unit tests

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

@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/optimization.rs (1)

64-139: 🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

Keep reserved-attempt diagnostics atomic with finalization.

A record can reserve while open, then close_for_finalization/finish can run before note_invalid_payload_schema or the size-limit diagnostic reacquires the lock. Because those helpers ignore closed state, the limitation is lost and the optimization summary may be omitted. Track in-flight reservations or otherwise prevent finalization from draining state before their diagnostic/commit outcome is recorded.

As per path instructions, “Pay close attention to … event lifecycle regressions.”

Also applies to: 174-178

🤖 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/optimization.rs` around lines 64 - 139, Make the
reserved-attempt lifecycle atomic with finalization: update
reserve_record_attempt and the corresponding diagnostic/commit paths so an
in-flight reservation cannot be drained by close_for_finalization or finish
before its outcome is recorded. Track in-flight reservations or hold equivalent
state through serialized_contribution_size, note_invalid_payload_schema, and
commit_contribution, and ensure finalization waits for or accounts for those
reservations before producing the summary.

Source: 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.

Inline comments:
In `@crates/core/src/observability/plugin_component.rs`:
- Around line 1978-2008: Add focused regression tests for
validate_atof_stream_sink_name covering missing, empty,
leading/trailing-whitespace, duplicate, and valid stream names. Assert both
validation outcomes and that emitted diagnostics use the expected
sinks[index].name field, while confirming valid names produce no diagnostic.

---

Outside diff comments:
In `@crates/core/src/api/optimization.rs`:
- Around line 64-139: Make the reserved-attempt lifecycle atomic with
finalization: update reserve_record_attempt and the corresponding
diagnostic/commit paths so an in-flight reservation cannot be drained by
close_for_finalization or finish before its outcome is recorded. Track in-flight
reservations or hold equivalent state through serialized_contribution_size,
note_invalid_payload_schema, and commit_contribution, and ensure finalization
waits for or accounts for those reservations before producing the summary.
🪄 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: 4c7e800c-18bb-4a50-9bc4-ebaeb62166ce

📥 Commits

Reviewing files that changed from the base of the PR and between 45831fc and 29fe3af.

📒 Files selected for processing (7)
  • crates/core/src/api/llm.rs
  • crates/core/src/api/optimization.rs
  • crates/core/src/observability/mod.rs
  • crates/core/src/observability/openinference.rs
  • crates/core/src/observability/otel.rs
  • crates/core/src/observability/plugin_component.rs
  • crates/ffi/src/api/mod.rs
📜 Review details
🧰 Additional context used
📓 Path-based instructions (19)
crates/core/src/api/{tool,llm}.rs

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

Wire the new middleware chain into the execute path in crates/core/src/api/tool.rs or crates/core/src/api/llm.rs at the appropriate pipeline stage

Files:

  • crates/core/src/api/llm.rs
**/*.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/llm.rs
  • crates/core/src/observability/openinference.rs
  • crates/core/src/observability/otel.rs
  • crates/core/src/observability/mod.rs
  • crates/core/src/observability/plugin_component.rs
  • crates/ffi/src/api/mod.rs
  • crates/core/src/api/optimization.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/llm.rs
  • crates/core/src/observability/openinference.rs
  • crates/core/src/observability/otel.rs
  • crates/core/src/observability/mod.rs
  • crates/core/src/observability/plugin_component.rs
  • crates/core/src/api/optimization.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/llm.rs
  • crates/core/src/observability/openinference.rs
  • crates/core/src/observability/otel.rs
  • crates/core/src/observability/mod.rs
  • crates/core/src/observability/plugin_component.rs
  • crates/core/src/api/optimization.rs
**/*.{rs,py}

📄 CodeRabbit inference engine (AGENTS.md)

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

Files:

  • crates/core/src/api/llm.rs
  • crates/core/src/observability/openinference.rs
  • crates/core/src/observability/otel.rs
  • crates/core/src/observability/mod.rs
  • crates/core/src/observability/plugin_component.rs
  • crates/ffi/src/api/mod.rs
  • crates/core/src/api/optimization.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/llm.rs
  • crates/core/src/observability/openinference.rs
  • crates/core/src/observability/otel.rs
  • crates/core/src/observability/mod.rs
  • crates/core/src/observability/plugin_component.rs
  • crates/ffi/src/api/mod.rs
  • crates/core/src/api/optimization.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/llm.rs
  • crates/core/src/observability/openinference.rs
  • crates/core/src/observability/otel.rs
  • crates/core/src/observability/mod.rs
  • crates/core/src/observability/plugin_component.rs
  • crates/ffi/src/api/mod.rs
  • crates/core/src/api/optimization.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/llm.rs
  • crates/core/src/observability/openinference.rs
  • crates/core/src/observability/otel.rs
  • crates/core/src/observability/mod.rs
  • crates/core/src/observability/plugin_component.rs
  • crates/ffi/src/api/mod.rs
  • crates/core/src/api/optimization.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/llm.rs
  • crates/core/src/api/optimization.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/llm.rs
  • crates/core/src/observability/openinference.rs
  • crates/core/src/observability/otel.rs
  • crates/core/src/observability/mod.rs
  • crates/core/src/observability/plugin_component.rs
  • crates/ffi/src/api/mod.rs
  • crates/core/src/api/optimization.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/llm.rs
  • crates/core/src/observability/openinference.rs
  • crates/core/src/observability/otel.rs
  • crates/core/src/observability/mod.rs
  • crates/core/src/observability/plugin_component.rs
  • crates/ffi/src/api/mod.rs
  • crates/core/src/api/optimization.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/llm.rs
  • crates/core/src/observability/openinference.rs
  • crates/core/src/observability/otel.rs
  • crates/core/src/observability/mod.rs
  • crates/core/src/observability/plugin_component.rs
  • crates/core/src/api/optimization.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/llm.rs
  • crates/core/src/observability/openinference.rs
  • crates/core/src/observability/otel.rs
  • crates/core/src/observability/mod.rs
  • crates/core/src/observability/plugin_component.rs
  • crates/ffi/src/api/mod.rs
  • crates/core/src/api/optimization.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/llm.rs
  • crates/core/src/observability/openinference.rs
  • crates/core/src/observability/otel.rs
  • crates/core/src/observability/mod.rs
  • crates/core/src/observability/plugin_component.rs
  • crates/core/src/api/optimization.rs
crates/core/src/observability/{atif,otel,openinference}.rs

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

When changing the core event model, emitted fields, exporter behavior, subscriber config, or lifecycle, keep the ATIF, OpenTelemetry, and OpenInference implementations in sync.

Files:

  • crates/core/src/observability/openinference.rs
  • crates/core/src/observability/otel.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/src/api/mod.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/src/api/mod.rs
{crates/ffi/src/api/*.rs,crates/ffi/nemo_relay.h}

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

Add or update the shared C/FFI surface in the relevant crates/ffi/src/api/*.rs module, re-export it through crates/ffi/src/api/mod.rs, and keep the generated crates/ffi/nemo_relay.h header correct.

Files:

  • crates/ffi/src/api/mod.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/ffi/src/api/mod.rs
🔇 Additional comments (11)
crates/core/src/observability/plugin_component.rs (2)

1947-1949: LGTM!

Also applies to: 1951-1976, 1978-2008


1947-2008: 📐 Maintainability & Code Quality

Confirm the required Rust/core validation passed.

As per coding guidelines, Rust changes must run just test-rust, cargo fmt --all, and cargo clippy --workspace --all-targets -- -D warnings; crates/core changes also require validate-change, the full language matrix, and uv run pre-commit run --all-files.

Source: Coding guidelines

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

691-697: LGTM!

Also applies to: 744-766

crates/core/src/api/optimization.rs (2)

704-763: 📐 Maintainability & Code Quality

Confirm the remaining core-runtime validation gates.

The supplied validation list does not mention cargo deny check or the repository’s validate-change workflow.

As per coding guidelines, core-runtime changes must satisfy cargo deny check and use validate-change.

Source: Coding guidelines


17-19: LGTM!

Also applies to: 312-316, 409-468, 470-702

crates/core/src/observability/mod.rs (1)

75-221: LGTM!

crates/core/src/observability/openinference.rs (1)

1044-1049: LGTM!

crates/core/src/observability/otel.rs (1)

841-846: LGTM!

crates/ffi/src/api/mod.rs (3)

44-44: LGTM!

Also applies to: 57-57


299-351: Refactor preserves behavior correctly.

Sequential parse-with-early-return, unwrap_or_default() for the two collection fields, and passthrough Option for annotated_request are consistent with the prior semantics and the AI summary.


353-365: 🎯 Functional Correctness

Re-check diagnostic parity in parse_optional_intercept_json. The c_str_to_json failure path should set a field-specific last_error if it does not already, and the call needs an explicit unsafe {} if c_str_to_json is unsafe under edition 2024.

Comment thread crates/core/src/observability/plugin_component.rs
Signed-off-by: Will Killian <wkillian@nvidia.com>
@willkill07 willkill07 added this to the 0.6 milestone Jul 15, 2026
@willkill07 willkill07 self-assigned this Jul 15, 2026
rapids-bot Bot pushed a commit that referenced this pull request Jul 15, 2026
#### Overview

This isolates an unrelated macOS CI flake observed while validating #430. A test listener is nonblocking, but its accepted socket was read as though it were blocking; macOS returned WouldBlock and the test helper panicked.

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

#### Details

Reset the accepted mock HTTP socket to blocking mode before applying its bounded read timeout. This matches the shared accept_bounded test helper and changes test infrastructure only.

Validation:
- Repeated foreign_and_incompatible_listeners_are_never_adopted 30 times.
- cargo clippy -p nemo-relay-cli --lib -- -D warnings
- just test-rust
- uv run pre-commit run --all-files

#### Where should the reviewer start?

Review the accepted-socket setup in crates/cli/tests/coverage/shared/bootstrap_tests.rs.

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

- Relates to #430



## Summary by CodeRabbit

* **Tests**
  * Improved test server connection handling to ensure reliable blocking I/O during request processing.

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

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

URL: #435

@zhongxuanwang-nv zhongxuanwang-nv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A nitty thing, and everything is great!

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

@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/optimization.rs`:
- Around line 48-61: Rename LlmOptimizationRecorder.state to accumulator and
Accumulator.state to inner, then update every affected access and initialization
throughout the file, including the listed call sites, so references use
self.accumulator.inner.lock() while preserving existing behavior.
🪄 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: 3cda3413-5b38-42ca-ab9e-322dc7b99832

📥 Commits

Reviewing files that changed from the base of the PR and between c12b486 and bd32f8f.

📒 Files selected for processing (2)
  • crates/core/src/api/optimization.rs
  • crates/core/tests/unit/optimization_tests.rs
📜 Review details
⏰ Context from checks skipped due to timeout. (2)
  • GitHub Check: Check / Run
  • GitHub Check: Preview docs
🧰 Additional context used
📓 Path-based instructions (14)
**/*.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/unit/optimization_tests.rs
  • crates/core/src/api/optimization.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/unit/optimization_tests.rs
  • crates/core/src/api/optimization.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/unit/optimization_tests.rs
  • crates/core/src/api/optimization.rs
**/*.{rs,py}

📄 CodeRabbit inference engine (AGENTS.md)

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

Files:

  • crates/core/tests/unit/optimization_tests.rs
  • crates/core/src/api/optimization.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/unit/optimization_tests.rs
  • crates/core/src/api/optimization.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/unit/optimization_tests.rs
  • crates/core/src/api/optimization.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/unit/optimization_tests.rs
  • crates/core/src/api/optimization.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/unit/optimization_tests.rs
  • crates/core/src/api/optimization.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/unit/optimization_tests.rs
  • crates/core/src/api/optimization.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/unit/optimization_tests.rs
  • crates/core/src/api/optimization.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/unit/optimization_tests.rs
  • crates/core/src/api/optimization.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/unit/optimization_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/optimization.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/optimization.rs
🔇 Additional comments (4)
crates/core/src/api/optimization.rs (3)

136-136: Past clone-avoidance concern is resolved.

commit_contribution now takes &mut Option<LlmOptimizationContribution> and only .take()s on Committed; on Retry/Rejected the caller keeps its Some(...) without cloning, addressing the earlier feedback to avoid contribution.clone() on retry.

Also applies to: 167-216


7-7: LGTM!

Also applies to: 34-46, 48-61, 70-125, 230-240, 262-262, 275-275, 287-287, 301-301, 315-361, 370-383


475-895: 🎯 Functional Correctness

Analysis/pricing pipeline could not be reviewed line-by-line.

Raw diff text for analyze_contributions, derive_optimization_usage, derive_baseline_usage, price_optimization_usage, and finalize_optimization_summary wasn't provided (only summaries and two bare context lines). Downstream tests in optimization_tests.rs (combined pricing/cost snapshot, partial-status missing-cost test) appear consistent with the described behavior, but please confirm cargo clippy --workspace --all-targets -- -D warnings and the full optimization_tests.rs suite pass for this hunk specifically, given its complexity (flagged code_block_complexity_high for 536-677, 705-747, and 768-829).

crates/core/tests/unit/optimization_tests.rs (1)

8-9: LGTM!

Also applies to: 735-759

Comment thread crates/core/src/api/optimization.rs
@willkill07

Copy link
Copy Markdown
Member Author

/merge

@rapids-bot
rapids-bot Bot merged commit b47edca into NVIDIA:main Jul 15, 2026
68 of 69 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Improvement improvement to existing functionality lang:rust PR changes/introduces Rust code size:XL PR is extra large

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants