Rust Worker
The examples/rust-grpc-worker-plugin project is the Rust version of the
Python worker. It uses nemo-relay-worker 1.0.0
and implements Plugin. It supports all 17
callback types. Its
configuration selects which callbacks to register. The SDK starts the authenticated
nvidia.nemo.relay.worker.v1 server from Relay’s activation environment.
Internal Diagnostic Observations
Use runtime.diagnostics().await to obtain diagnostics for the activation.
The SDK sets up delivery once and reuses the host’s selected context. It does
not create a worker-local store or enable diagnostic collection.
This example matches the Rust native and Python worker example. Register its
component once from asynchronous code, then retain it for later lookups.
Plugin::register returns a future and can initialize helpers during registration.
This example captures shared state in an asynchronous callback and initializes the
helper once with a Tokio OnceCell.
Cache initialization failure as well to avoid repeated registration attempts.
It declares separate failure and success codes, records positive occurrence counts,
and attaches a request ID. Call the failure helper only after observing an
unavailable backend. Call the success helper only after a completed lookup.
Handle registration and recording failures separately from execution failures.
Rust returns DiagnosticDeliveryError variants.
The helpers expose those errors so the caller can apply its delivery policy.
Do not propagate an optional diagnostic failure as the lookup’s result.
try_record_lazy returns Ok(()) after local queue admission. It does not return a
host acceptance receipt. An inactive component returns without recording. Disabled
or unsupported collection skips the observation factory. A full queue also skips
the factory. diagnostics.availability() reports negotiated availability.
Check diagnostics.delivery_stats() for dropped, rejected, and uncertain work.
Use diagnostics.flush(Duration).await to wait for earlier queue work.
The timeout is a std::time::Duration. Flush does not return per-record receipts
or acknowledge disk storage. Never replay uncertain observations into a new session.
Use component.close().await when the component’s work ends. SDK shutdown
limits diagnostic drain time and closes delivery tasks. Explicit delivery shutdown
uses diagnostics.close(Duration).await. Canonical snapshot and memory reads are
not available to workers, even when a native plugin has a read grant.
Refer to Plugin Diagnostics for the shared pattern, built-in code declarations, and native/worker API differences. The delivery protocol defines host limits, retries, and session authority.
Configure the Snapshot Location
Before starting a worker, Relay copies its package and runtime files into an
activation snapshot. This is a separate directory for that activation. Set
NEMO_RELAY_PLUGIN_SNAPSHOT_DIR in the environment that starts Relay to choose
where snapshots are stored. Relay creates the directory if needed. Keep it
outside plugin packages and all copied entrypoint and library directories:
Build and Calculate Integrity
Building a Rust worker requires Buf 1.75.0 or later on PATH, or selected
through BUF. Cargo supplies protoc automatically. The first build needs
access to the Buf Schema Registry to download the locked validation schema.
Build the executable and create a manifest for your platform:
-
Build and test the example from its own directory.
-
Copy
relay-plugin.tomltorelay-plugin.local.tomland replace<platform-worker-file>withnemo-relay-rust-grpc-worker-plugin-exampleon macOS or Linux, or the same name with.exeon Windows. -
Calculate the SHA-256 digest before registration. On macOS run:
On Linux run
sha256sum target/debug/<platform-worker-file>. In PowerShell runGet-FileHash -Algorithm SHA256 target/debug/<platform-worker-file>. Put the lowercase hexadecimal value aftersha256:in[integrity].sha256.
Success at this stage means tests pass, the manifest entrypoint resolves to the built executable, and integrity describes the exact executable that starts.
The local manifest retains the checked package identity and replaces only the executable name and digest placeholders:
The manifest requires Relay 1.0 and the typed nvidia.nemo.relay.worker.v1
protocol. ToolNext::call returns ToolExecutionResult. It keeps the application
payload and optional annotation separate from Relay-owned pending marks. Rebuild
the worker when adopting this SDK release.
The artifact and entrypoint paths must identify the same executable. Relay verifies the
artifact digest before it starts the command, and the worker
handshake must return the
same plugin identity and nvidia.nemo.relay.worker.v1 protocol.
Register and Start the Worker
Use the following procedure to register the manifest and inspect worker activation:
-
From the repository root, validate, add, and enable the local manifest.
-
Start Relay from the repository root. Inspect the activation report and confirm the handshake reports plugin identity, SDK and runtime metadata,
nvidia.nemo.relay.worker.v1, multiple-component behavior, and all 17 surfaces.
Build the Worker Implementation
The example uses the current public worker crate and creates both a library for focused tests and the executable named in the manifest.
Plugin::register is an asynchronous registration step. It parses the validated JSON
and registers callbacks through PluginContext. Those callbacks return futures.
The binary contains no transport configuration. serve_plugin reads the activation
environment, starts the authenticated SDK service, and stays alive until Relay sends the
shutdown stage.
Exercise and Remove the Worker
Use the following procedure to verify the registered callbacks and stop the worker cleanly:
-
Exercise allowed and blocked calls, unary and streaming continuations, codec decode and encode proxies, pending marks, optimization contributions, nested and isolated scopes, and cancellation.
-
Disable and remove the component only after in-flight invocations have settled.
Success means shutdown rejects new invocations, cancels or drains active work, closes the authenticated endpoint, stops the process, and leaves no owned runtime registrations.