Skip to content

feat: capture OpenShell request receipts for CLI model calls - #1780

Merged
afourniernv merged 3 commits into
NVIDIA:mainfrom
afourniernv:codex/openshell-cli-receipts
Nov 20, 2026
Merged

afourniernv merged 3 commits into
NVIDIA:mainfrom
afourniernv:codex/openshell-cli-receipts

Conversation

@afourniernv

@afourniernv afourniernv commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Overview

Connect a CLI model call in Relay to the OpenShell security records for the same HTTP request, without a harness-specific adapter.

In a Codex/Claude-style CLI deployment, Relay records the model call while OpenShell separately records its enforcement decisions. If a request fails, the Relay trace alone does not identify the corresponding OpenShell records. This PR captures the request ID OpenShell returns and records it under the correct Relay model call, so operators can match the two.

  • 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

  1. A model request forwarded by Relay's standalone CLI gateway or daemon receives an HTTP response containing x-openshell-request-id.
  2. Relay records an openshell.request.receipt mark under the owning model call. Its payload contains only request_id and http_status.
  3. An operator or subscriber can match that ID to metadata.correlation_uid in OpenShell's OCSF records. For example, this lets someone investigating a failed model call find what OpenShell allowed, changed or blocked.

The header is captured before reading the body, including on HTTP errors. The receipt remains available if the body subsequently fails or is cancelled. Missing, malformed or duplicate headers produce no mark and leave response handling unchanged.

The OCSF records stay in OpenShell. This adds a request-ID join, not automatic trace stitching or OCSF ingestion into Relay. The header is an unverified correlation hint, not proof of authorization, upstream execution or completed delivery.

Scope:

  • CLI gateway and daemon model requests only. Native-agent HTTP clients, arbitrary tool/MCP requests, passthrough routes and WebSocket frames are not instrumented.
  • Consumes the response header when present; it does not make OpenShell emit it on additional paths or change outgoing W3C trace headers, routing or policy.
  • Uses the existing mark/subscriber machinery. ATOF and the full/openinference trace projections retain marks; gen_ai omits them.
  • No public Rust/SDK API, binding, ABI, dependency or configuration changes. The new mark is an additive telemetry event.

A separate prerequisite commit corrects an existing one-line test import on main (nemo_relay::logging to nemo_relay_logging), with no production change.

Validation: pre-commit checks passed, including Clippy and workspace checks. just test-rust passed: 6,922 tests, four existing skips, retries disabled. No new live OpenShell run was performed on this refreshed source.

Where should the reviewer start?

Start with crates/cli/src/openshell_receipts.rs for header validation and mark creation. Then check the response hooks in gateway/mod.rs and daemon/worker/managed.rs. The daemon context binding keeps each receipt attached to its own model call, including under concurrency.

Tests cover receipt ownership and payload, HTTP errors, real stream truncation, absent headers, and unchanged daemon trace-header handling. Header-validation edge cases are kept in the compact parser test.

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

Summary by CodeRabbit

  • New Features
    • Managed model requests can now record a receipt containing the upstream request ID and HTTP status when the response includes a valid request ID. Receipts are captured before the response body is read, including for error responses.
    • Added documentation for gateway live and realtime WebSocket routes and request receipt behavior.
  • Tests
    • Added coverage for receipt handling across successful, denied, incomplete, and missing-header responses.

@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Managed gateway and worker response paths now observe eligible OpenShell request receipts. The change adds request-ID validation and event recording, integration tests for receipt behavior, and gateway reference updates.

Changes

OpenShell request receipts

Layer / File(s) Summary
Receipt validation and event recording
crates/cli/src/openshell_receipts.rs, crates/cli/src/lib.rs, crates/cli/tests/coverage/shared/openshell_receipts_tests.rs
The new module accepts one valid hyphenated UUID request ID and records a receipt when an active event UUID exists and the status is below 600. Tests cover valid and invalid header values.
Managed worker response observation
crates/cli/src/daemon/worker/managed.rs, crates/cli/tests/coverage/daemon/worker_managed_tests.rs, crates/cli/tests/coverage/daemon/server_tests.rs
Worker dispatch runs with the LLM handle UUID as the active event UUID. Both response paths observe headers and status before preparing the forwarded response. Tests cover ownership, trace-context rules, denial, delivery, and body cancellation.
Gateway response observation and reference updates
crates/cli/src/gateway/mod.rs, crates/cli/tests/coverage/shared/gateway_receipts_tests.rs, docs/nemo-relay-cli/gateway-reference.mdx
The gateway observes responses only when an effective managed request is present. Integration tests cover complete, denied, truncated-stream, and missing-header responses. The reference documents receipt behavior and lists two WebSocket upgrade routes.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Gateway as forward_upstream_request
  participant Upstream
  participant Observer as openshell_receipts::observe
  participant Continuation as Middleware continuation context
  Gateway->>Upstream: Forward managed request
  Upstream-->>Gateway: Response headers and status
  Gateway->>Observer: Observe response headers and status
  Observer->>Continuation: Emit receipt event when eligible
Loading
Merge Risk: Minimal · up to d9704

This change adds a correlation mark for model requests that carry a valid OpenShell request ID. Forwarding behavior is unchanged when the header is missing or invalid, or when recording fails. No actionable merge-blocking risk remains.

Security architecture risk: Minimal · up to d9704

The change adds a bounded, explicitly untrusted correlation record without granting access or changing authorization. Inspection found no introduced material risk to security, request isolation, or failure containment.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — An upstream capable of choosing response headers can supply an arbitrary syntactically valid correlation UUID. In the inspected new path, that influence reaches the owning call's telemetry payload, not an authorization decision or credential-selection operation.

Trust Boundaries and Controls

  • observed — The upstream header is parsed into a UUID rather than copied as arbitrary text. The payload excludes unrelated headers and response bodies. Gateway observation additionally requires an effective managed request, while the shared observer requires an active event.

Resilience and Maintainability Implications

  • inferred — Per-future event binding and synchronous receipt submission preserve attribution without leaving a thread lease across an asynchronous suspension. Once queued, later body failure does not undo the receipt. Inspected tests assert exact parents and bounded payloads across concurrent successful, denied, truncated, and header-absent responses; these tests were not run.
Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title uses the conventional type 'feat', is 60 characters (under 72), has no trailing period, and states the main change: capturing OpenShell request receipts for CLI model calls. The scope is not…
Description check Passed The description follows the repository template. It includes the Overview with both confirmation checkboxes checked, the Details section, the 'Where should the reviewer start?' section, and a Related …
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.
Full details: Title check

Explanation

The title uses the conventional type 'feat', is 60 characters (under 72), has no trailing period, and states the main change: capturing OpenShell request receipts for CLI model calls. The scope is not stated, which the format makes optional. The title follows the required format and matches the changeset.

Full details: Description check

Explanation

The description follows the repository template. It includes the Overview with both confirmation checkboxes checked, the Details section, the 'Where should the reviewer start?' section, and a Related Issues section that uses the 'Relates to' keyword. It explains the change, its scope, its limits, and the validation performed. The Related Issues line links OpenShell #5210 instead of an issue this PR closes, which matches the author's stated intent.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 23f0520 and d9704f4.

Files selected for processing: 9

  • crates/cli/src/daemon/worker/managed.rs
  • crates/cli/src/gateway/mod.rs
  • crates/cli/src/lib.rs
  • crates/cli/src/openshell_receipts.rs
  • crates/cli/tests/coverage/daemon/server_tests.rs
  • crates/cli/tests/coverage/daemon/worker_managed_tests.rs
  • crates/cli/tests/coverage/shared/gateway_receipts_tests.rs
  • crates/cli/tests/coverage/shared/openshell_receipts_tests.rs
  • docs/nemo-relay-cli/gateway-reference.mdx

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

Recent review details

Context from checks skipped due to timeout: 4

  • GitHub Check: CodeRabbit
  • GitHub Check: Rust / Package smoke (windows-arm64)
  • GitHub Check: Rust / Test (macos-arm64)
  • GitHub Check: Rust / Test (windows-arm64)
Additional context used

Code guidelines: 2

.agents/skills/contribute-docs/SKILL.md — configured
.agents/skills/review-doc-style/SKILL.md — configured
Path-based instructions: 4

Review documentation for technical accuracy against the current API, command correctness, and consistency across language bindings.

CodeRabbit configuration file

Files:

  • docs/nemo-relay-cli/gateway-reference.mdx
Tests should cover the behavior promised by the changed API surface, including error paths and cross-request isolation where relevant.

CodeRabbit configuration file

Files:

  • crates/cli/tests/coverage/daemon/server_tests.rs
  • crates/cli/tests/coverage/daemon/worker_managed_tests.rs
  • crates/cli/tests/coverage/shared/gateway_receipts_tests.rs
  • crates/cli/tests/coverage/shared/openshell_receipts_tests.rs
Source excerpt: In MDX files, top-of-file comments must use JSX comment delimiters: `{/*` to open and `*/}` to close.

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

Files:

  • docs/nemo-relay-cli/gateway-reference.mdx
Source excerpt: Verify MDX files use JSX delimiters for top-of-file SPDX comments.

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

Files:

  • docs/nemo-relay-cli/gateway-reference.mdx
Learnings: 1

Learning: 2026-07-28T21:11:43.864Z

Learnt from: willkill07
Repo: NVIDIA/NeMo-Relay PR: 0
File: :0-0
Timestamp: 2026-07-28T21:11:43.864Z
Learning: Queued event-publication assertions in NeMo Relay tests must call `flush_subscribers()` after the triggering lifecycle operation, including after scope-pop cleanup checks, because sanitizer and subscriber delivery occurs asynchronously on the dispatcher.

Applied to files:

  • crates/cli/tests/coverage/daemon/worker_managed_tests.rs
  • crates/cli/tests/coverage/shared/gateway_receipts_tests.rs

@github-actions github-actions Bot added size:L PR is large Feature a new feature lang:rust PR changes/introduces Rust code labels Nov 20, 2026
@github-actions

Copy link
Copy Markdown

@codecov

codecov Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.94595% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.13%. Comparing base (23f0520) to head (d9704f4).

Files with missing lines Patch % Lines
crates/cli/src/openshell_receipts.rs 90.62% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1780      +/-   ##
==========================================
+ Coverage   94.11%   94.13%   +0.02%     
==========================================
  Files         538      539       +1     
  Lines      170359   171528    +1169     
  Branches      173      173              
==========================================
+ Hits       160320   161460    +1140     
- Misses      10038    10067      +29     
  Partials        1        1              
Components Coverage Δ
Rust Runtime 96.19% <ø> (-0.02%) ⬇️
Shared DTO Types 98.01% <ø> (ø)
CLI 91.60% <95.95%> (+0.14%) ⬆️
Go Binding 94.37% <ø> (ø)
Python Binding 95.44% <ø> (ø)
Node Binding 99.59% <ø> (ø)
Dynamic Plugin SDKs 94.44% <ø> (+<0.01%) ⬆️
Files with missing lines Coverage Δ
crates/cli/src/daemon/worker/managed.rs 94.10% <100.00%> (+0.19%) ⬆️
crates/cli/src/gateway/mod.rs 95.26% <100.00%> (+0.07%) ⬆️
crates/cli/src/lib.rs 85.71% <ø> (ø)
crates/cli/src/openshell_receipts.rs 90.62% <90.62%> (ø)

... and 15 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 23f0520...d9704f4. 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.

@afourniernv
afourniernv marked this pull request as ready for review November 20, 2026 18:28
@afourniernv
afourniernv requested review from a team as code owners November 20, 2026 18:28

@mnajafian-nv mnajafian-nv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm

@afourniernv
afourniernv merged commit 711cdc2 into NVIDIA:main Nov 20, 2026
60 checks passed
@willkill07 willkill07 added this to the 1.0 milestone Nov 20, 2026

This branch was previously deployed

1 inactive deployment
fern — d9704f47 Deployed Nov 20, 2026 by afourniernv via Clean up docs preview #7468
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature a new feature lang:rust PR changes/introduces Rust code size:L PR is large

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants