Skip to content

fix: await trajectory subscriber delivery - #727

Open
AjayThorve wants to merge 1 commit into
NVIDIA:mainfrom
AjayThorve:fix/subscriber-delivery-barrier
Open

fix: await trajectory subscriber delivery#727
AjayThorve wants to merge 1 commit into
NVIDIA:mainfrom
AjayThorve:fix/subscriber-delivery-barrier

Conversation

@AjayThorve

@AjayThorve AjayThorve commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Overview

Ensure coding-agent terminal hooks do not acknowledge completion until subscriber callbacks queued through that trajectory boundary have run. This fixes the race where a downstream evaluator snapshots Relay output immediately after the agent exits and can observe ATOF while the ATIF subscriber is still writing the trajectory.

  • 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

  • Classify AgentEnded and TurnEnded as trajectory-finalizing events and route Codex, Claude Code, and Hermes hook outcomes through one lifecycle-aware handler.
  • After applying a finalizing hook, run Relay's queued-subscriber barrier on a blocking worker before returning the hook response. The narrower barrier does not make normal hook delivery synchronous and does not wait for unrelated pending managed publications in another session.
  • Keep the core barrier documentation-hidden and binding-neutral; this adds no supported Python, Go, Node.js, or native binding API.
  • Return an unsuccessful hook response if the barrier itself cannot complete rather than claiming the trajectory boundary completed.
  • Add a deterministic regression that blocks terminal scope-end delivery and proves the HTTP response cannot overtake the ATIF snapshot. The test fails on the base revision before the production change and passes with this change.
  • Document the targeted coding-agent lifecycle guarantee. There are no schema changes, breaking changes, or changes to ordinary streaming delivery.

Validation:

  • cargo nextest run --workspace --profile ci --no-fail-fast: 3,852 passed, 0 skipped.
  • just test-python: 639 passed.
  • just test-go: passed.
  • just test-node: 353 passed on the supported Node 24 toolchain.
  • just docs: passed; Fern reported only the expected unauthenticated redirect-check warning.
  • uv run pre-commit run --all-files: passed.
  • Real NeMo Fabric Codex E2E with no Fabric ATIF wait workaround: one-shot and two-turn persistent streaming both produced ATOF plus complete ATIF-v1.7 trajectories.
  • NeMo Platform evaluator E2E at the reported failing revision: 40/40 real Codex trials passed at parallelism 1, 3, 5, and 10. Every trial produced promoted ATOF and ATIF artifacts with non-empty steps, and all 40 used isolated Relay output directories. Workspace-failure isolation and skill A/B adjacent paths also passed.

For downstream compatibility validation only, the production diff was built as Relay 0.7.0 and exercised with Fabric's schema-v3/Relay-0.7 compatibility work, which contains no ATIF polling or sleep. This PR itself targets main; it does not request a release-branch hotfix.

Where should the reviewer start?

Start with apply_hook_outcome in crates/cli/src/server/mod.rs, then review codex_stop_response_waits_for_atif_finalization in crates/cli/tests/coverage/shared/server_tests.rs. The key design choice is the queued-only barrier: terminal hook responses gain a delivery guarantee without turning normal hooks or unrelated in-flight sessions into a global synchronous path.

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

Summary by CodeRabbit

  • New Features

    • Hook responses now wait for completion at trajectory-ending boundaries before returning, so final state is available immediately.
    • Subscriber callbacks queued through these boundaries are now flushed as part of normal completion flow.
  • Bug Fixes

    • Improved handling of terminal events to ensure end-of-trajectory actions are recognized consistently.
    • Added safeguards so failures during queued callback processing are surfaced cleanly.
  • Documentation

    • Updated guides to explain when boundary callbacks complete and when results become visible.

Signed-off-by: Ajay Thorve <athorve@nvidia.com>
@AjayThorve
AjayThorve requested review from a team as code owners August 6, 2026 15:18
@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 Aug 6, 2026
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

The CLI now detects trajectory-finalizing events and flushes queued subscribers before closing hook responses. The runtime exposes the flush barrier. Tests cover event classification and Codex Stop behavior. Documentation describes the new delivery semantics.

Changes

Trajectory boundary delivery

Layer / File(s) Summary
Trajectory boundary and subscriber barrier contract
crates/cli/src/events/mod.rs, crates/core/src/api/runtime.rs, crates/core/src/api/runtime/subscriber_dispatcher.rs, crates/cli/tests/coverage/shared/events_tests.rs
AgentEnded and TurnEnded now identify trajectory boundaries. flush_queued_subscribers is publicly re-exported with lifecycle-boundary documentation. Unit tests cover the event classification.
Hook outcome barrier integration
crates/cli/src/server/mod.rs, crates/cli/tests/coverage/shared/server_tests.rs
Codex, Claude Code, and Hermes hooks use shared outcome processing. Finalizing events flush queued subscribers before the response returns. The integration test verifies sanitizer blocking, health availability, shutdown, and ATIF output.
Delivery behavior documentation
docs/about-nemo-relay/concepts/subscribers.mdx, docs/nemo-relay-cli/codex.mdx, integrations/coding-agents/codex/README.md
Documentation describes synchronous subscriber completion at trajectory boundaries and immediate local ATIF availability after a successful write.

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

Sequence Diagram(s)

sequenceDiagram
  participant CodexHook
  participant apply_hook_outcome
  participant flush_queued_subscribers
  participant ATIFSubscribers
  CodexHook->>apply_hook_outcome: apply normalized hook events
  apply_hook_outcome->>flush_queued_subscribers: flush after trajectory-finalizing event
  flush_queued_subscribers->>ATIFSubscribers: deliver queued callbacks
  ATIFSubscribers-->>flush_queued_subscribers: complete or return failure
  flush_queued_subscribers-->>apply_hook_outcome: barrier result
  apply_hook_outcome-->>CodexHook: return hook response or launch error
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description check ✅ Passed The description includes all required sections, explains the implementation and validation, identifies review entry points, and references a related issue.
Title check ✅ Passed The title uses the valid fix type, states the change clearly, is imperative, has no trailing period, and is under 72 characters.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

@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: 8

🤖 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/cli/src/server/mod.rs`:
- Around line 1231-1235: Change the error mapping around the subscriber delivery
barrier spawned by spawn_blocking to use the request-specific CliError variant
instead of CliError::Launch, while preserving the existing message text and
inner FlowError propagation.
- Around line 1227-1236: Bound the await around flush_queued_subscribers in the
await_delivery branch using a timeout such as TRAJECTORY_BARRIER_TIMEOUT,
defined with the other server tunables. Preserve existing task and subscriber
errors, but when the timeout expires log the condition and return the hook
response without propagating a barrier failure, restoring asynchronous degraded
behavior and preventing blocking-pool starvation.

In `@crates/cli/tests/coverage/shared/events_tests.rs`:
- Around line 17-30: Extend trajectory_boundaries_require_subscriber_delivery
with negative assertions that NormalizedEvent::SubagentEnded, LlmEnded, and
ToolEnded return false from finalizes_trajectory. Construct each variant using
the existing test-module constructors and required payload types, while
preserving the current positive and HookMark assertions.

In `@crates/cli/tests/coverage/shared/server_tests.rs`:
- Line 1175: Replace the unwrap on release_tx.send in the surrounding test flow
with an ignored send result, allowing execution to reach the descriptive
response-ordering assertion when the receiver has already been dropped.
- Line 1201: Remove the exact "ATIF-v1.7" assertion from the
response-to-snapshot ordering test, keeping the test focused on ordering
behavior and aligned with the sibling test’s content-based assertions.
- Around line 1164-1167: Increase the timeout used by the readiness wait around
started_rx in the sanitizer test from one second to a few seconds, while leaving
the later 100 ms release window unchanged because it still detects a genuine
defect.

In `@crates/core/src/api/runtime/subscriber_dispatcher.rs`:
- Around line 1265-1269: Update the doc comment for flush_queued_subscribers to
explicitly state that it must not be called from subscriber, event-sanitizer,
guardrail, or intercept callbacks, because it does not establish a barrier there
and may create a wait cycle.

In `@docs/about-nemo-relay/concepts/subscribers.mdx`:
- Around line 150-155: Move the gateway barrier paragraph from before the
milestones table to after the table’s final row and before the “Use the
subscriber flush API” paragraph. Keep the paragraph text unchanged so the table
lead-in directly introduces the table.
🪄 Autofix

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: 98627723-4061-47cb-b8ce-d7bf3ecc3b0a

📥 Commits

Reviewing files that changed from the base of the PR and between c4bbb8a and 183698d.

📒 Files selected for processing (9)
  • crates/cli/src/events/mod.rs
  • crates/cli/src/server/mod.rs
  • crates/cli/tests/coverage/shared/events_tests.rs
  • crates/cli/tests/coverage/shared/server_tests.rs
  • crates/core/src/api/runtime.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • docs/about-nemo-relay/concepts/subscribers.mdx
  • docs/nemo-relay-cli/codex.mdx
  • integrations/coding-agents/codex/README.md
📜 Review details
⏰ Context from checks skipped due to timeout. (2)
  • GitHub Check: Changes / Detect
  • GitHub Check: Preview docs
🧰 Additional context used
📓 Path-based instructions (34)
**/*.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

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

**/*.rs: Format Rust code with rustfmt defaults using cargo fmt.
Run cargo clippy -- -D warnings; all Rust warnings must be treated as errors.
Use Rust snake_case naming conventions.

Files:

  • crates/cli/src/events/mod.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/src/api/runtime.rs
  • crates/cli/tests/coverage/shared/events_tests.rs
  • crates/cli/tests/coverage/shared/server_tests.rs
  • crates/cli/src/server/mod.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/cli/src/events/mod.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/src/api/runtime.rs
  • crates/cli/src/server/mod.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.

**/*: Use release tags in raw Rust-compatible SemVer without a leading v; tags such as v0.1.0 are prohibited.
Use branch prefixes feat/, fix/, docs/, test/, or refactor/ according to the change purpose.
Every commit in a pull request must include a DCO Signed-off-by: sign-off.
Before submitting a pull request, ensure pre-commit hooks, relevant tests, target-specific builds, documentation updates, and a rebase on the latest main are complete.
Use commit messages in the form type: short description, with a valid type and a first line under 72 characters.

Files:

  • crates/cli/src/events/mod.rs
  • docs/about-nemo-relay/concepts/subscribers.mdx
  • docs/nemo-relay-cli/codex.mdx
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • integrations/coding-agents/codex/README.md
  • crates/core/src/api/runtime.rs
  • crates/cli/tests/coverage/shared/events_tests.rs
  • crates/cli/tests/coverage/shared/server_tests.rs
  • crates/cli/src/server/mod.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.

**/*.{rs,py,go,js,ts}: When observability configuration or lifecycle is exposed, keep FFI and Python, Go, and Node.js binding-native config objects and subscriber/exporter methods aligned in logical knobs and semantics.
Require every OpenTelemetry endpoint to have a type and nonblank destination; resolve header_env values at activation and reject missing, blank, or duplicate headers.
Concatenate layered ATOF sink, ATIF storage, and OpenTelemetry endpoint lists with higher-precedence entries first.
Preserve correct handling of mark events, start/end events, orphan cases, and span or trajectory fields derived from intended event data.
Run affected Rust tests and just test-rust when event fields change; run just test-python, just test-go, and just test-node when binding-native configuration or lifecycle changes.

Files:

  • crates/cli/src/events/mod.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/src/api/runtime.rs
  • crates/cli/tests/coverage/shared/events_tests.rs
  • crates/cli/tests/coverage/shared/server_tests.rs
  • crates/cli/src/server/mod.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/cli/src/events/mod.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/src/api/runtime.rs
  • crates/cli/tests/coverage/shared/events_tests.rs
  • crates/cli/tests/coverage/shared/server_tests.rs
  • crates/cli/src/server/mod.rs
**/*.{rs,py,js,jsx,ts,tsx,go,c,h,cc,cpp,md,toml,yml,yaml,sh}

📄 CodeRabbit inference engine (AGENTS.md)

Keep SPDX headers on source, documentation, scripts, and configuration files; the project is Apache-2.0.

Files:

  • crates/cli/src/events/mod.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • integrations/coding-agents/codex/README.md
  • crates/core/src/api/runtime.rs
  • crates/cli/tests/coverage/shared/events_tests.rs
  • crates/cli/tests/coverage/shared/server_tests.rs
  • crates/cli/src/server/mod.rs
**/*.{rs,py}

📄 CodeRabbit inference engine (AGENTS.md)

Use snake_case naming in Rust and Python.

Files:

  • crates/cli/src/events/mod.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/src/api/runtime.rs
  • crates/cli/tests/coverage/shared/events_tests.rs
  • crates/cli/tests/coverage/shared/server_tests.rs
  • crates/cli/src/server/mod.rs
crates/**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

crates/**/*.rs: Use Json = serde_json::Value in Rust-facing runtime APIs where existing code expects JSON payloads.
Treat Rust as the source of truth for runtime behavior; binding APIs should mirror Rust semantics unless a language-specific wrapper intentionally improves ergonomics.

Files:

  • crates/cli/src/events/mod.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/src/api/runtime.rs
  • crates/cli/tests/coverage/shared/events_tests.rs
  • crates/cli/tests/coverage/shared/server_tests.rs
  • crates/cli/src/server/mod.rs
**/*.{rs,py,js,mjs,ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Preserve the existing Tokio-based asynchronous model and callback/future lifetimes; do not unexpectedly block or hide async work in bindings.

Files:

  • crates/cli/src/events/mod.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/src/api/runtime.rs
  • crates/cli/tests/coverage/shared/events_tests.rs
  • crates/cli/tests/coverage/shared/server_tests.rs
  • crates/cli/src/server/mod.rs
**/*.{rs,py,go,js,jsx,ts,tsx,c,h}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

**/*.{rs,py,go,js,jsx,ts,tsx,c,h}: Run tests for every language affected by a change; changes to the core Rust crate require tests across all bindings.
Use SONAR_IGNORE_START / SONAR_IGNORE_END only for documented false positives, keep ignored blocks minimal, explain them with a comment, and obtain reviewer sign-off.
Preserve the layered architecture in which Rust provides the core runtime and C FFI, PyO3, and NAPI provide bindings that mirror the full API surface.

Files:

  • crates/cli/src/events/mod.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/src/api/runtime.rs
  • crates/cli/tests/coverage/shared/events_tests.rs
  • crates/cli/tests/coverage/shared/server_tests.rs
  • crates/cli/src/server/mod.rs
**/*.{rs,py,go,js,jsx,ts,tsx,c,h,html,md,mdx,toml}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Include the appropriate SPDX copyright and Apache-2.0 license header in every source file.

Files:

  • crates/cli/src/events/mod.rs
  • docs/about-nemo-relay/concepts/subscribers.mdx
  • docs/nemo-relay-cli/codex.mdx
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • integrations/coding-agents/codex/README.md
  • crates/core/src/api/runtime.rs
  • crates/cli/tests/coverage/shared/events_tests.rs
  • crates/cli/tests/coverage/shared/server_tests.rs
  • crates/cli/src/server/mod.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)

**/*.mdx: In MDX files, top-of-file comments must use JSX comment delimiters ({/* and */}); do not use HTML comments for MDX SPDX headers.
New or regenerated MDX files must use {/* ... */} for top-of-file SPDX comments.

Files:

  • docs/about-nemo-relay/concepts/subscribers.mdx
  • docs/nemo-relay-cli/codex.mdx
{docs,examples}/**/*

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

Update docs and examples.

Files:

  • docs/about-nemo-relay/concepts/subscribers.mdx
  • docs/nemo-relay-cli/codex.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/about-nemo-relay/concepts/subscribers.mdx
  • docs/nemo-relay-cli/codex.mdx
**/*.{md,mdx}

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

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

Use documented public APIs and stable wrapper commands in examples and user-facing documentation; do not rely on internal helpers.

**/*.{md,mdx}: Prefer the documented public API over internal shortcuts in documentation and examples.
Keep package names, repository references, and build commands current.
Contribution workflow documentation must require an issue before external contribution pull requests and note that NVIDIA contributors may use a GitHub or Linear issue.
Update entry-point documentation when examples or reading paths change.
Keep release-process and release-notes guidance in maintainer documentation such as RELEASING.md, rather than user-facing documentation pages or CHANGELOG.md.
Use stable user-facing wrappers at the scripts/ root in documentation and examples; reference namespaced helper paths only for internal maintenance documentation.
When detailed dynamic plugin guides exist, keep Rust native plugin examples, Python worker plugin examples, and grpc-v1 protocol details on separate pages.
Dynamic plugin manifests in documentation and examples should use compat.relay = ">=0.5,<1.0" unless deliberately narrower.
Render images, diagrams, tables, and other visual content at representative page widths, ensuring legibility and complete access without clipping; use responsive scaling, reflow, or overflow as appropriate and scope visual styling narrowly.
Dynamic plugin entry pages should link to native, worker, Rust example, Python example, and protocol pages when those pages exist.
Images, diagrams, tables, and custom visual content must remain legible and fully accessible at representative desktop and narrow page widths.
Release-policy documentation must point to GitHub Releases as the only release-history source of truth.
Run just docs when the documentation site changes; retain ./scripts/build-docs.sh html as the compatibility wrapper.

Files:

  • docs/about-nemo-relay/concepts/subscribers.mdx
  • docs/nemo-relay-cli/codex.mdx
  • integrations/coding-agents/codex/README.md
**/*.{md,mdx,py,go,js,ts}

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

Examples and documentation must use each exporter's documented flush/deregister order before shutdown.

Files:

  • docs/about-nemo-relay/concepts/subscribers.mdx
  • docs/nemo-relay-cli/codex.mdx
  • integrations/coding-agents/codex/README.md
docs/{about-nemo-relay/concepts/subscribers.mdx,configure-plugins/observability/**/*.mdx}

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

Update observability documentation and examples alongside implementation changes, including configuration version 3 with one opentelemetry section containing typed endpoints and no standalone public OpenInference surface.

Files:

  • docs/about-nemo-relay/concepts/subscribers.mdx
docs/**/*.{md,mdx}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Update relevant reference documentation when public behavior or APIs change.

Files:

  • docs/about-nemo-relay/concepts/subscribers.mdx
  • docs/nemo-relay-cli/codex.mdx
**/*.{md,mdx,rst}

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

**/*.{md,mdx,rst}: Use title case consistently for technical documentation headings and table headers; avoid quotation marks, ampersands, and exclamation marks in headings, while preserving official product, event, research, and whitepaper title case.
Format code elements, commands, parameters, package names, expressions, directories, file names, and paths in monospace; represent path placeholders with angle brackets inside monospace.
Format UI buttons, menus, fields, and labels in bold, and separate consecutive UI navigation labels with >.
Use quotation marks for error messages and strings when appropriate, italics for newly introduced terms and publication titles, and plain text for keyboard shortcuts.
Represent GitHub repositories with owner/repository link text, such as [NVIDIA/NeMo](link), rather than generic repository wording.
Introduce every code block with a complete sentence; do not let a code block complete or interrupt the grammar of surrounding prose; use syntax highlighting when supported.
Keep inline method, function, and class references consistent with nearby documentation; omit empty parentheses in prose when no call is shown.
Use descriptive link text matching the destination title when possible; avoid raw URLs, generic anchors, long-sentence links, and unnecessary links that distract from procedures.
Ensure lists have a complete lead-in sentence, more than one item, no more than two levels, parallel construction, one idea or action per item, and appropriate punctuation; use bullets for unordered items and numbers for ordered tasks.
Format definition lists with a bold term followed by a complete, parallel, punctuated definition.
Use tables for reference information, decision support, compatibility matrices, and comparable choices; flag one-row tables, missing captions or lead-ins, sentence-case headers where title case is expected, unexplained empty cells, and code or links that would be clearer as prose.
Write procedure steps as imperative ...

Files:

  • docs/about-nemo-relay/concepts/subscribers.mdx
  • docs/nemo-relay-cli/codex.mdx
  • integrations/coding-agents/codex/README.md
{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/about-nemo-relay/concepts/subscribers.mdx
  • docs/nemo-relay-cli/codex.mdx
{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/src/api/runtime.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

Use Result<T> with FlowError in core runtime paths, keeping wrapper-layer errors explicit and binding-appropriate.

Files:

  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/src/api/runtime.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/runtime.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/src/api/runtime.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/runtime.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/src/api/runtime.rs
**/*.{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:

  • integrations/coding-agents/codex/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:

  • integrations/coding-agents/codex/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:

  • integrations/coding-agents/codex/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:

  • integrations/coding-agents/codex/README.md
**/README.md

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Update the relevant crate or package README when that package surface changes.

Update relevant package or crate README.md files when examples or binding guidance changes.

Files:

  • integrations/coding-agents/codex/README.md
**/{README.md,docs/index.md}

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

Update README.md or docs/index.md when documentation entry points change.

Files:

  • integrations/coding-agents/codex/README.md
**/{test,tests}/**/*

📄 CodeRabbit inference engine (CONTRIBUTING.md)

When adding functionality, include tests in the appropriate test files for each affected language binding.

Files:

  • crates/cli/tests/coverage/shared/events_tests.rs
  • crates/cli/tests/coverage/shared/server_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/cli/tests/coverage/shared/events_tests.rs
  • crates/cli/tests/coverage/shared/server_tests.rs
🧠 Learnings (3)
📚 Learning: 2026-08-03T19:55:03.931Z
Learnt from: afourniernv
Repo: NVIDIA/NeMo-Relay PR: 558
File: crates/pii-redaction/src/rampart/mod.rs:265-274
Timestamp: 2026-08-03T19:55:03.931Z
Learning: In NeMo Relay first-party plugin registration helpers, treat the documented duplicate-registration `PluginError::RegistrationFailed` result from `register_plugin` as success when registration is intended to be idempotent. Do not locally reclassify this as `PluginError::Conflict`; changing the classification requires a core-wide review of the public API and FFI behavior.

Applied to files:

  • crates/cli/src/events/mod.rs
  • crates/core/src/api/runtime/subscriber_dispatcher.rs
  • crates/core/src/api/runtime.rs
  • crates/cli/tests/coverage/shared/events_tests.rs
  • crates/cli/tests/coverage/shared/server_tests.rs
  • crates/cli/src/server/mod.rs
📚 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
  • crates/core/src/api/runtime.rs
🔇 Additional comments (6)
crates/cli/src/events/mod.rs (1)

84-89: LGTM!

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

35-36: LGTM!

crates/cli/src/server/mod.rs (1)

44-49: LGTM!

Also applies to: 1188-1188, 1201-1201, 1214-1226

crates/cli/tests/coverage/shared/server_tests.rs (1)

21-24: LGTM!

Also applies to: 130-136

docs/nemo-relay-cli/codex.mdx (1)

412-415: LGTM!

integrations/coding-agents/codex/README.md (1)

47-51: LGTM!

Comment on lines +1227 to +1236
if await_delivery {
// Agent and turn scope-end subscribers write the final trajectory snapshot. Use the
// queued-only barrier so an active managed publication in another session cannot hold the
// hook response open.
tokio::task::spawn_blocking(nemo_relay::api::runtime::flush_queued_subscribers)
.await
.map_err(|error| {
CliError::Launch(format!("subscriber delivery barrier task failed: {error}"))
})??;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Bound the barrier wait; an unbounded flush blocks the hook response and the blocking pool.

flush_queued_subscribers waits for every queued subscriber callback. Those callbacks include user-registered subscribers, event sanitizers, and scope-end guardrails. A slow or hung callback holds this await open with no upper bound, and the hook response never returns. The invoking agent process waits on that response, so the coding agent stalls instead of finishing its turn. Your own test proves the mechanism: the codex-atif-boundary-sanitizer in crates/cli/tests/coverage/shared/server_tests.rs keeps the Stop response pending until a channel is released, and only the test's tokio::time::timeout bounds it.

The second effect is pool pressure. Each finalizing hook occupies one Tokio blocking thread for the whole barrier. Concurrent Codex, Claude Code, and Hermes sessions share this gateway, so slow callbacks can saturate the blocking pool and stall unrelated spawn_blocking work.

Wrap the barrier in a timeout. On expiry, log and return the hook response instead of hanging, since the pre-change behavior was fully asynchronous delivery and is the correct degraded mode.

🛡️ Proposed fix to bound the wait
     if await_delivery {
         // Agent and turn scope-end subscribers write the final trajectory snapshot. Use the
         // queued-only barrier so an active managed publication in another session cannot hold the
         // hook response open.
-        tokio::task::spawn_blocking(nemo_relay::api::runtime::flush_queued_subscribers)
-            .await
-            .map_err(|error| {
-                CliError::Launch(format!("subscriber delivery barrier task failed: {error}"))
-            })??;
+        let barrier =
+            tokio::task::spawn_blocking(nemo_relay::api::runtime::flush_queued_subscribers);
+        match tokio::time::timeout(TRAJECTORY_BARRIER_TIMEOUT, barrier).await {
+            Ok(joined) => joined.map_err(|error| {
+                CliError::Launch(format!("subscriber delivery barrier task failed: {error}"))
+            })??,
+            Err(_) => tracing::warn!(
+                timeout_secs = TRAJECTORY_BARRIER_TIMEOUT.as_secs(),
+                "subscriber delivery barrier timed out; returning hook response with delivery still queued"
+            ),
+        }
     }

Define the constant near the other server tunables:

/// Upper bound on the trajectory-boundary subscriber barrier. A slow subscriber
/// callback must not hold a hook response open indefinitely.
const TRAJECTORY_BARRIER_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(10);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if await_delivery {
// Agent and turn scope-end subscribers write the final trajectory snapshot. Use the
// queued-only barrier so an active managed publication in another session cannot hold the
// hook response open.
tokio::task::spawn_blocking(nemo_relay::api::runtime::flush_queued_subscribers)
.await
.map_err(|error| {
CliError::Launch(format!("subscriber delivery barrier task failed: {error}"))
})??;
}
if await_delivery {
// Agent and turn scope-end subscribers write the final trajectory snapshot. Use the
// queued-only barrier so an active managed publication in another session cannot hold the
// hook response open.
let barrier =
tokio::task::spawn_blocking(nemo_relay::api::runtime::flush_queued_subscribers);
match tokio::time::timeout(TRAJECTORY_BARRIER_TIMEOUT, barrier).await {
Ok(joined) => joined.map_err(|error| {
CliError::Launch(format!("subscriber delivery barrier task failed: {error}"))
})??,
Err(_) => tracing::warn!(
timeout_secs = TRAJECTORY_BARRIER_TIMEOUT.as_secs(),
"subscriber delivery barrier timed out; returning hook response with delivery still queued"
),
}
}
🤖 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/cli/src/server/mod.rs` around lines 1227 - 1236, Bound the await
around flush_queued_subscribers in the await_delivery branch using a timeout
such as TRAJECTORY_BARRIER_TIMEOUT, defined with the other server tunables.
Preserve existing task and subscriber errors, but when the timeout expires log
the condition and return the hook response without propagating a barrier
failure, restoring asynchronous degraded behavior and preventing blocking-pool
starvation.

Comment on lines +1231 to +1235
tokio::task::spawn_blocking(nemo_relay::api::runtime::flush_queued_subscribers)
.await
.map_err(|error| {
CliError::Launch(format!("subscriber delivery barrier task failed: {error}"))
})??;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Inspect CliError variants, its From impls, and its IntoResponse mapping.
set -euo pipefail

fd -t f 'error.rs' crates/cli/src | while IFS= read -r file; do
  echo "===== $file ====="
  cat -n "$file"
done

echo "===== From impls / IntoResponse for CliError ====="
rg -nP -C 6 'impl\s+(From<[^>]+>\s+for\s+CliError|IntoResponse\s+for\s+CliError)' crates/cli/src

echo "===== return type of flush_queued_subscribers and its Result alias ====="
ast-grep run --pattern 'pub fn flush_queued_subscribers() -> $RET { $$$ }' --lang rust crates/core/src
rg -nP -C 3 'pub (type|use).*\bResult\b' crates/core/src/api/runtime/subscriber_dispatcher.rs crates/core/src/error.rs 2>/dev/null || true

Repository: NVIDIA/NeMo-Relay

Length of output: 9292


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "===== server call site ====="
sed -n '1195,1250p' crates/cli/src/server/mod.rs

echo "===== CliError construction and hook handlers ====="
rg -n -P -C 4 'CliError::(Launch|Flow|HookDelivery)|flush_queued_subscribers|IntoResponse' crates/cli/src crates/core/src

echo "===== direct status probe from source semantics ====="
python3 - <<'PY'
from pathlib import Path

error = Path("crates/cli/src/error.rs").read_text()
assert "Flow(#[from] nemo_relay::error::FlowError)" in error
assert "Self::Flow(_)" in error
assert "StatusCode::INTERNAL_SERVER_ERROR" in error

server = Path("crates/cli/src/server/mod.rs").read_text()
needle = "tokio::task::spawn_blocking(nemo_relay::api::runtime::flush_queued_subscribers)"
assert needle in server
assert "CliError::Launch(format!(\"subscriber delivery barrier task failed: {error}\"))" in server
print("flush_queued_subscribers errors convert through CliError::Flow or the explicit JoinError mapping; both map to HTTP 500.")
print("The explicit JoinError mapping uses CliError::Launch, whose log kind is launch and whose HTTP status is also 500.")
PY

Repository: NVIDIA/NeMo-Relay

Length of output: 50373


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "===== log_kind consumers ====="
rg -n -P -C 5 'log_kind\(\)|hook.*error|error_kind' crates/cli/src/server crates/cli/src/hooks crates/cli/src/tests 2>/dev/null | head -n 240

echo "===== hook route registration ====="
rg -n -P -C 6 'claude_hook|hermes_hook|apply_hook_outcome|Router::|route\(' crates/cli/src/server/mod.rs | head -n 260

echo "===== focused error tests ====="
sed -n '1,260p' crates/cli/tests/coverage/shared/error_tests.rs 2>/dev/null || true

Repository: NVIDIA/NeMo-Relay

Length of output: 16204


Use a request-specific error variant for the subscriber delivery barrier.

The inner ? converts FlowError through CliError::Flow, and both error paths return HTTP 500. CliError::Launch still mislabels this request failure as a launcher error in the response and logs. Preserve the message text with a request-specific variant.

🤖 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/cli/src/server/mod.rs` around lines 1231 - 1235, Change the error
mapping around the subscriber delivery barrier spawned by spawn_blocking to use
the request-specific CliError variant instead of CliError::Launch, while
preserving the existing message text and inner FlowError propagation.

Comment on lines +17 to +30
#[test]
fn trajectory_boundaries_require_subscriber_delivery() {
let event = || SessionEvent {
session_id: "session-1".into(),
agent_kind: AgentKind::Codex,
event_name: "test".into(),
payload: json!({}),
metadata: json!({}),
};

assert!(NormalizedEvent::TurnEnded(event()).finalizes_trajectory());
assert!(NormalizedEvent::AgentEnded(event()).finalizes_trajectory());
assert!(!NormalizedEvent::HookMark(event()).finalizes_trajectory());
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert the terminal-but-not-finalizing variants.

is_terminal returns true for SubagentEnded, LlmEnded, and ToolEnded, but finalizes_trajectory must return false for them. That distinction is the intentional part of the contract, and no assertion protects it. A future change that routes the hook barrier through is_terminal would pass this test.

Add negative cases for those variants. SubagentEnded needs a SubagentEvent and LlmEnded/ToolEnded need their own payload types, so use the existing constructors in this test module.

Based on learnings from the path instructions: "Tests should cover the behavior promised by the changed API surface".

♻️ Suggested additional assertions
     assert!(NormalizedEvent::TurnEnded(event()).finalizes_trajectory());
     assert!(NormalizedEvent::AgentEnded(event()).finalizes_trajectory());
     assert!(!NormalizedEvent::HookMark(event()).finalizes_trajectory());
+    // Terminal scopes that must not trigger the hook-response barrier.
+    assert!(!NormalizedEvent::Compaction(event()).finalizes_trajectory());
+    assert!(!NormalizedEvent::AgentStarted(event()).finalizes_trajectory());
 }
🤖 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/cli/tests/coverage/shared/events_tests.rs` around lines 17 - 30,
Extend trajectory_boundaries_require_subscriber_delivery with negative
assertions that NormalizedEvent::SubagentEnded, LlmEnded, and ToolEnded return
false from finalizes_trajectory. Construct each variant using the existing
test-module constructors and required payload types, while preserving the
current positive and HookMark assertions.

Source: Path instructions

Comment on lines +1164 to +1167
tokio::time::timeout(std::time::Duration::from_secs(1), started_rx)
.await
.expect("terminal sanitizer should observe the turn end")
.unwrap();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Raise the sanitizer-readiness timeout.

This 1-second bound must cover an HTTP round trip to the gateway, hook classification, apply_events, and the first scope-end dispatch after plugin activation. On a loaded CI runner that is tight, and expiry fails the test even when the code is correct.

The later 100 ms window at Line 1169 is sound, because release_tx fires only at Line 1175, so an early return there is a genuine defect. This readiness wait has no such property. Raise it to a few seconds.

🔧 Proposed change
-    tokio::time::timeout(std::time::Duration::from_secs(1), started_rx)
+    tokio::time::timeout(std::time::Duration::from_secs(10), started_rx)
         .await
         .expect("terminal sanitizer should observe the turn end")
         .unwrap();
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
tokio::time::timeout(std::time::Duration::from_secs(1), started_rx)
.await
.expect("terminal sanitizer should observe the turn end")
.unwrap();
tokio::time::timeout(std::time::Duration::from_secs(10), started_rx)
.await
.expect("terminal sanitizer should observe the turn end")
.unwrap();
🤖 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/cli/tests/coverage/shared/server_tests.rs` around lines 1164 - 1167,
Increase the timeout used by the readiness wait around started_rx in the
sanitizer test from one second to a few seconds, while leaving the later 100 ms
release window unchanged because it still detects a genuine defect.

let returned_early = early_response.is_some();
let health = client.get(format!("{url}/healthz")).send().await.unwrap();
assert_eq!(health.status(), StatusCode::OK);
release_tx.send(()).unwrap();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Do not unwrap the release send; it masks the failure this test exists to report.

If the Stop response returned early, the sanitizer future may already be dropped, and release_tx.send returns Err. This unwrap then panics here, before the run reaches the descriptive assertion at Line 1193 that names the actual defect. The failure output would point at a channel send instead of the response-ordering violation.

Ignore the send result.

🔧 Proposed change
-    release_tx.send(()).unwrap();
+    // The receiver is gone if the response already returned; the ordering assertion below reports that.
+    let _ = release_tx.send(());
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
release_tx.send(()).unwrap();
// The receiver is gone if the response already returned; the ordering assertion below reports that.
let _ = release_tx.send(());
🤖 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/cli/tests/coverage/shared/server_tests.rs` at line 1175, Replace the
unwrap on release_tx.send in the surrounding test flow with an ignored send
result, allowing execution to reach the descriptive response-ordering assertion
when the receiver has already been dropped.

.iter()
.find(|trajectory| atif_matches_session(trajectory, "codex-atif-boundary"))
.expect("the Stop response must not precede its ATIF snapshot");
assert_eq!(trajectory["schema_version"], "ATIF-v1.7");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Drop the exact ATIF schema-version assertion.

This test verifies response-to-snapshot ordering. Pinning "ATIF-v1.7" couples it to ATIF schema evolution, so a schema bump fails a test that has nothing to do with the schema. The sibling test at Lines 1058-1062 asserts trajectory content without pinning a version.

Assert the property you care about, or remove the line.

♻️ Suggested change
-    assert_eq!(trajectory["schema_version"], "ATIF-v1.7");
+    assert!(
+        trajectory["schema_version"].is_string(),
+        "expected an ATIF schema version, got {trajectory:?}"
+    );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
assert_eq!(trajectory["schema_version"], "ATIF-v1.7");
assert!(
trajectory["schema_version"].is_string(),
"expected an ATIF schema version, got {trajectory:?}"
);
🤖 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/cli/tests/coverage/shared/server_tests.rs` at line 1201, Remove the
exact "ATIF-v1.7" assertion from the response-to-snapshot ordering test, keeping
the test focused on ordering behavior and aligned with the sibling test’s
content-based assertions.

Comment on lines +1265 to +1269
/// Lifecycle boundaries use this narrower barrier when they need queued
/// observer work to be visible without waiting for unrelated managed
/// publications that are still in flight.
#[doc(hidden)]
pub fn flush_queued_subscribers() -> Result<()> {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Document the callback prohibition on the newly public barrier.

docs/about-nemo-relay/concepts/subscribers.mdx states that a subscriber flush must not run inside a subscriber, event-sanitizer, guardrail, or intercept callback, because it does not establish a barrier there and can create a wait cycle. This function is now pub, so callers outside the crate can reach it, and #[doc(hidden)] keeps it out of rendered docs. The source comment is the only place a caller will read the constraint.

Add the constraint to the doc comment.

♻️ Suggested doc addition
 /// Lifecycle boundaries use this narrower barrier when they need queued
 /// observer work to be visible without waiting for unrelated managed
 /// publications that are still in flight.
+///
+/// Do not call this from a subscriber, event-sanitizer, guardrail, or
+/// intercept callback. It does not establish a barrier there and can create a
+/// wait cycle.
 #[doc(hidden)]
 pub fn flush_queued_subscribers() -> Result<()> {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/// Lifecycle boundaries use this narrower barrier when they need queued
/// observer work to be visible without waiting for unrelated managed
/// publications that are still in flight.
#[doc(hidden)]
pub fn flush_queued_subscribers() -> Result<()> {
/// Lifecycle boundaries use this narrower barrier when they need queued
/// observer work to be visible without waiting for unrelated managed
/// publications that are still in flight.
///
/// Do not call this from a subscriber, event-sanitizer, guardrail, or
/// intercept callback. It does not establish a barrier there and can create a
/// wait cycle.
#[doc(hidden)]
pub fn flush_queued_subscribers() -> 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/runtime/subscriber_dispatcher.rs` around lines 1265 -
1269, Update the doc comment for flush_queued_subscribers to explicitly state
that it must not be called from subscriber, event-sanitizer, guardrail, or
intercept callbacks, because it does not establish a barrier there and may
create a wait cycle.

Comment on lines +150 to +155
The coding-agent gateway adds a targeted barrier at trajectory boundaries.
Before the gateway acknowledges a hook that closes an agent or turn scope, it
waits for subscriber callbacks queued through that boundary. When a local ATIF
write succeeds, the trajectory file is therefore visible when the hook response
returns. Other hook events and native runtime calls remain asynchronous.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Move this paragraph; it separates the table lead-in from the table.

Lines 145-148 end with a colon: "Use the following milestones to choose the barrier that matches the output you need to observe:". The table at Line 156 is what that sentence introduces. This new paragraph now sits between them, so the lead-in no longer reads into the table.

Place the gateway paragraph after the table instead, where it qualifies the milestones it depends on. The content itself is accurate and matches apply_hook_outcome in crates/cli/src/server/mod.rs.

As per coding guidelines: "Introduce code blocks, lists, tables, and images with complete sentences" and "do not let a code block complete or interrupt the grammar of surrounding prose".

📝 Proposed reordering
 following milestones to choose the barrier that matches the output you need to
 observe:
 
-The coding-agent gateway adds a targeted barrier at trajectory boundaries.
-Before the gateway acknowledges a hook that closes an agent or turn scope, it
-waits for subscriber callbacks queued through that boundary. When a local ATIF
-write succeeds, the trajectory file is therefore visible when the hook response
-returns. Other hook events and native runtime calls remain asynchronous.
-
 | Milestone | What It Establishes | What It Does Not Establish |
 |---|---|---|

Then insert the paragraph after the table's final row, before the "Use the subscriber flush API" paragraph:

The coding-agent gateway adds a targeted barrier at trajectory boundaries.
Before the gateway acknowledges a hook that closes an agent or turn scope, it
waits for subscriber callbacks queued through that boundary. When a local ATIF
write succeeds, the trajectory file is therefore visible when the hook response
returns. Other hook events and native runtime calls remain asynchronous.
🤖 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 `@docs/about-nemo-relay/concepts/subscribers.mdx` around lines 150 - 155, Move
the gateway barrier paragraph from before the milestones table to after the
table’s final row and before the “Use the subscriber flush API” paragraph. Keep
the paragraph text unchanged so the table lead-in directly introduces the table.

Source: Coding guidelines

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

// Agent and turn scope-end subscribers write the final trajectory snapshot. Use the
// queued-only barrier so an active managed publication in another session cannot hold the
// hook response open.
tokio::task::spawn_blocking(nemo_relay::api::runtime::flush_queued_subscribers)

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.

I don't like this. we should only be flushing subscribers for the session being closed.

There may be one instance of Relay running per user, which means that while multiple sessions with Codex and/or Claude could be running, you'd be potentially deadlocking.

@willkill07 willkill07 added this to the 0.8 milestone Aug 6, 2026
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