Skip to content

fix: preserve structured ATIF tool results#223

Merged
rapids-bot[bot] merged 1 commit into
NVIDIA:mainfrom
dnandakumar-nv:fix-atif-bug
Jun 4, 2026
Merged

fix: preserve structured ATIF tool results#223
rapids-bot[bot] merged 1 commit into
NVIDIA:mainfrom
dnandakumar-nv:fix-atif-bug

Conversation

@dnandakumar-nv
Copy link
Copy Markdown
Contributor

@dnandakumar-nv dnandakumar-nv commented Jun 4, 2026

Overview

Fix ATIF v1.7 export so tool observation result content is never serialized as an arbitrary JSON object. Structured tool outputs are now preserved
under extra.tool_result, while valid string and content-part array outputs remain in content.

Details

  • Restrict AtifObservationResult.content to ATIF-compatible values:
    • strings
    • valid content-part arrays
    • omitted for null or structured non-content JSON
  • Preserve structured tool result payloads, including {"status":"closed_by_turn_end"}, in AtifObservationResult.extra.tool_result.
  • Merge observation extra metadata when tool observations and subagent references are combined.
  • Add regression coverage for structured tool-close payloads and content-part array preservation.
  • Tighten ATIF v1.7 test assertions so object-valued observation.results[].content is rejected.

Validation run:

  • cargo fmt --all
  • cargo test -p nemo-relay observability::atif::tests
  • just test-rust
  • cargo clippy --workspace --all-targets -- -D warnings
  • just test-python
  • just test-go
  • just test-node
  • just test-wasm
  • uv run pre-commit run --all-files
  • git diff --check

Where should the reviewer start?

Start with crates/core/src/observability/atif.rs, especially the observation content/extra helpers and observation merge path. The focused
regression coverage is in crates/core/tests/unit/atif_tests.rs.

Summary by CodeRabbit

  • Tests
    • Updated and expanded test coverage for ATIF observation handling, including new tests for structured tool result exports and content-part array preservation.

Signed-off-by: dnandakumar-nv <dnandakumar@nvidia.com>
@dnandakumar-nv dnandakumar-nv requested a review from a team as a code owner June 4, 2026 18:33
@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot Bot commented Jun 4, 2026

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions github-actions Bot added size:M PR is medium Bug issue describes bug; PR fixes bug lang:rust PR changes/introduces Rust code labels Jun 4, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 4, 2026

Review Change Stack

Walkthrough

Updated ATIF exporter refactors observation handling to extract structured tool results into observation extras via new observation_content_value and observation_extra functions. Tool end events now populate extras with computed payloads; merged observations combine extras via merge_observation_extra. Test helpers and coverage updated to validate the new representation.

Changes

ATIF Observation Result Structure

Layer / File(s) Summary
Observation content filtering and tool result extra extraction
crates/core/src/observability/atif.rs
New observation_content_value function restricts content to string or ATIF content-part arrays. New observation_extra and observation_tool_result_extra helpers compute and filter tool result payloads for observation extras, omitting null/string/content-part arrays while preserving other non-null data.
Tool event integration and result merging
crates/core/src/observability/atif.rs
Tool end event handling switched from generic event_extra() to observation_extra() to include computed tool_result in observation result extras. merge_observation_result now merges incoming and existing extras via merge_observation_extra helper, which unions object keys without overwriting existing values.
Test helpers and new observation tests
crates/core/tests/unit/atif_tests.rs
assert_atif_observation_content_value now validates only string or content-part arrays (rejects null). New assert_structured_observation_result_extra helper asserts structured tool results via extra["tool_result"] with unset content. Added test_exporter_moves_structured_tool_close_result_to_observation_extra and test_exporter_preserves_tool_content_part_array_observation_content tests.
Existing test assertion updates
crates/core/tests/unit/atif_tests.rs
Updated assertions across tool lifecycle, Anthropic/OpenAI/Hermes integrations, and subagent tests to use assert_structured_observation_result_extra instead of direct content validation, confirming structured tool outputs are now in observation result extras.

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 45.83% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title follows Conventional Commits format with type 'fix', concise imperative summary, 42 characters, and no trailing period.
Description check ✅ Passed The description provides a comprehensive overview, detailed changes, reviewer guidance, related issues reference, and validation steps.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

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

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

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

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/observability/atif.rs (1)

2330-2335: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Structured tool results can be dropped by later pruning.

handle_tool_end now correctly emits structured outputs in result.extra.tool_result with content = None, but prune_subagent_refs currently retains results only when content or subagent_trajectory_ref exists (Line 2731). That drops valid extra-only tool observations and loses data.

Suggested fix
-            result.content.is_some() || result.subagent_trajectory_ref.is_some()
+            result.content.is_some()
+                || result.subagent_trajectory_ref.is_some()
+                || result.extra.is_some()
🤖 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/observability/atif.rs` around lines 2330 - 2335,
prune_subagent_refs is dropping valid observations that only have structured
tool results in result.extra.tool_result (emitted by handle_tool_end) because it
currently retains results only when content or subagent_trajectory_ref exist;
update the retention condition in prune_subagent_refs to also keep
AtifObservationResult entries when extra is Some and extra.tool_result is Some
(i.e., check result.extra.as_ref().and_then(|e|
e.tool_result.as_ref()).is_some()), so observations with content = None but a
structured tool_result are preserved.
🤖 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/observability/atif.rs`:
- Around line 2330-2335: prune_subagent_refs is dropping valid observations that
only have structured tool results in result.extra.tool_result (emitted by
handle_tool_end) because it currently retains results only when content or
subagent_trajectory_ref exist; update the retention condition in
prune_subagent_refs to also keep AtifObservationResult entries when extra is
Some and extra.tool_result is Some (i.e., check
result.extra.as_ref().and_then(|e| e.tool_result.as_ref()).is_some()), so
observations with content = None but a structured tool_result are preserved.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Enterprise

Run ID: dba4bb98-b9d1-4d4d-b779-0148d8a2345e

📥 Commits

Reviewing files that changed from the base of the PR and between 7155406 and c727dbe.

📒 Files selected for processing (2)
  • crates/core/src/observability/atif.rs
  • crates/core/tests/unit/atif_tests.rs
📜 Review details
🧰 Additional context used
📓 Path-based instructions (14)
**/*.rs

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

Use snake_case naming convention for Rust identifiers (e.g., nemo_relay_tool_call)

**/*.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

**/*.rs: Run cargo fmt --all to format all Rust code
Run cargo clippy --workspace --all-targets -- -D warnings to enforce all clippy lints as errors

**/*.rs: Run cargo fmt --all when Rust files changed as part of WebAssembly work
Run cargo clippy --workspace --all-targets -- -D warnings when Rust files changed as part of WebAssembly work

**/*.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
Run Rust formatting with cargo fmt --all
Run Rust linting with cargo clippy --workspace --all-targets -- -D warnings

**/*.rs: Use cargo fmt for Rust code formatting
Run cargo clippy -- -D warnings to lint Rust code and treat all warnings as errors
Use Rust snake_case naming convention for Rust identifiers
Include SPDX license header in all Rust source files using double-slash comment syntax
Validate Rust code with uv run pre-commit run --all-files to enforce cargo fmt formatting check, cargo clippy lints, and cargo deny aud...

Files:

  • crates/core/src/observability/atif.rs
  • crates/core/tests/unit/atif_tests.rs
crates/core/src/observability/{atif,otel,openinference}.rs

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

When changing event fields in ATIF, OpenTelemetry, or OpenInference observability surfaces, keep the core event model in crates/core/src/observability/atif.rs, crates/core/src/observability/otel.rs, and crates/core/src/observability/openinference.rs in sync

Files:

  • crates/core/src/observability/atif.rs
**/{Cargo.toml,**/*.rs}

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

Maintain consistency between Rust package names in Cargo.toml and their actual usage across the codebase

Files:

  • crates/core/src/observability/atif.rs
  • crates/core/tests/unit/atif_tests.rs
**/*.{h,hpp,c,cpp,rs}

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

Ensure FFI header and library naming follows consistent conventions across platform-specific builds

Files:

  • crates/core/src/observability/atif.rs
  • crates/core/tests/unit/atif_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/observability/atif.rs
  • crates/core/tests/unit/atif_tests.rs
**/*.{rs,toml}

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

Update Rust crate names and module prefixes during coordinated rename operations

Files:

  • crates/core/src/observability/atif.rs
  • crates/core/tests/unit/atif_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

crates/core/**/*.rs: 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. Keep errors explicit and binding-appropriate at the wrapper layer.

Files:

  • crates/core/src/observability/atif.rs
  • crates/core/tests/unit/atif_tests.rs
crates/{core,adaptive}/**

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

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

Files:

  • crates/core/src/observability/atif.rs
  • crates/core/tests/unit/atif_tests.rs
**/*.{rs,py,js,ts,tsx,jsx,go,sh,toml,yaml,yml,md}

📄 CodeRabbit inference engine (AGENTS.md)

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

Files:

  • crates/core/src/observability/atif.rs
  • crates/core/tests/unit/atif_tests.rs
**/*.{rs,py,go,js,ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Follow binding naming conventions: Rust and Python use snake_case, C FFI exports prefixed nemo_relay_, Go uses PascalCase for public APIs, Node.js uses camelCase.

Files:

  • crates/core/src/observability/atif.rs
  • crates/core/tests/unit/atif_tests.rs
crates/**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

crates/**/*.rs: Keep async behavior on the existing tokio-based model. Bindings should preserve callback and future lifetimes rather than blocking or hiding async work unexpectedly.
Use Json = serde_json::Value in Rust-facing runtime APIs for JSON payload handling.

Files:

  • crates/core/src/observability/atif.rs
  • crates/core/tests/unit/atif_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/observability/atif.rs
  • crates/core/tests/unit/atif_tests.rs
{crates/adaptive/**/*.rs,**/*test*.{rs,py,go,ts,js},**/*adaptive*test*.{rs,py,go,ts,js},docs/plugins/adaptive/**}

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

Maintain documented and tested validation and report behavior for adaptive surfaces

Files:

  • crates/core/tests/unit/atif_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/unit/atif_tests.rs
🔇 Additional comments (2)
crates/core/src/observability/atif.rs (1)

522-546: LGTM!

Also applies to: 2677-2698

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

388-397: LGTM!

Also applies to: 399-405, 491-491, 528-556, 558-585, 966-969, 1212-1212, 1373-1376, 1751-1751, 1864-1864, 3054-3054

@willkill07
Copy link
Copy Markdown
Member

/ok to test c727dbe

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 4, 2026

@dnandakumar-nv
Copy link
Copy Markdown
Contributor Author

/merge

@rapids-bot rapids-bot Bot merged commit bbb0657 into NVIDIA:main Jun 4, 2026
71 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug issue describes bug; PR fixes bug lang:rust PR changes/introduces Rust code size:M PR is medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants