Skip to navigation

nemo_gym.core.typed_exceptions

View as MarkdownOpen in Claude

The exception a failure boundary raises, and the conversion of its explicit cause chain to report data.

Flow: a boundary raises NgFailureEvent(...) from cause. failure_report_for turns that chain into a FailureReport (one FailureEvent per exception, linked by cause_id). nemo_gym.core.failure_transport sends the report with the HTTP reply; the receiver rebuilds the chain with rebuild_failure and Collection saves it. Nothing here chooses retries, terminality or scores.

Module Contents

Classes

NameDescription
NgFailureEventOne Gym failure: the exception a boundary raises and the data it serializes, in one object.

Functions

NameDescription
agent_route_failureThe agent boundary’s failure for route operation; raise it from cause.
failure_report_forerror’s Gym failures and their explicit causes as a FailureReport.
find_boundary_failureThe outermost failure in error’s explicit cause chain that names a boundary, or None.
rebuild_failureThe failure report.failure_id names, rebuilt with its causes as __cause__; else None.
route_reply_errorThe error whose HTTP reply a route sends: an agent route failure answers with its cause’s reply.
sdk_error_detailsThe type, message and HTTP status of a third-party SDK error, without its request or body.

Data

_EVENT_FIELDS

API

class nemo_gym.core.typed_exceptions.NgFailureEvent(
failure_kind: str,
failure_reason: str,
http_status: int | None = None,
foreign_error: nemo_gym.core.failure_records.SdkErrorDetails | None = None,
event_id: str | None = None,
operation: str | None = None,
operation_id: str | None = None,
attempt_id: str | None = None,
exception_type: str | None = None,
message_args: tuple[object, ...] = ()
)
Exception

Bases: Exception

One Gym failure: the exception a boundary raises and the data it serializes, in one object.

The raiser names its own boundary and a registered failure_kind; both are validated here, and event_id is fixed here and travels unchanged. Raise it from the error it reports. to_record derives each cause_id from __cause__; from_record rebuilds the chain with the same ids and boundaries and never imports a type from the payload (the original type name stays data).

Pass message_args only when str() must differ from failure_reason.

event
FailureEvent

This failure’s fields as its saved event, without cause_id (to_record adds it).

http_error
ClientResponseError | None = None

The HTTP response that carried a remote failure, separate from its original causal chain.

nemo_gym.core.typed_exceptions.NgFailureEvent.__init_subclass__(
kwargs: object = {}
) -> None
nemo_gym.core.typed_exceptions.NgFailureEvent.__reduce__() -> tuple
nemo_gym.core.typed_exceptions.NgFailureEvent._set_fields(
message_args: tuple[object, ...] = (),
fields: object = {}
) -> None
nemo_gym.core.typed_exceptions.NgFailureEvent.from_record(
record: collections.abc.Mapping[str, object]
) -> 'NgFailureEvent'
classmethod

The failure record["failure_id"] names, with its causes as __cause__ and the same ids.

nemo_gym.core.typed_exceptions.NgFailureEvent.to_record(
unravel_inner: bool = True
) -> dict[str, object]

failure_id and failure_events for this failure.

By default the map holds this failure and every explicit cause once, linked by cause_id. With unravel_inner=False it holds only this failure and its cause_id; combine it with the cause’s records before transport or storage.

nemo_gym.core.typed_exceptions.agent_route_failure(
cause: Exception,
operation: str,

The agent boundary’s failure for route operation; raise it from cause.

It names the cause’s type, not its text, and takes no kind from it. route_reply_error selects the cause as the HTTP reply.

nemo_gym.core.typed_exceptions.failure_report_for(
error: BaseException | None

error’s Gym failures and their explicit causes as a FailureReport.

Only NgFailureEvents become events, each under its own id. An SDK or builtin exception in the chain is not an event: its type, bounded SDK-selected message and HTTP status become the foreign_error of the Gym failure directly above it, unless that failure already selected one. A Gym failure below a foreign intermediate stays linked by cause_id. failure_id is the outermost Gym failure.

nemo_gym.core.typed_exceptions.find_boundary_failure(
error: BaseException | None

The outermost failure in error’s explicit cause chain that names a boundary, or None.

nemo_gym.core.typed_exceptions.rebuild_failure(

The failure report.failure_id names, rebuilt with its causes as __cause__; else None.

Every event becomes a NgFailureEvent with the same event, so serializing it again gives the same ids.

nemo_gym.core.typed_exceptions.route_reply_error(
error: BaseException
) -> BaseException

The error whose HTTP reply a route sends: an agent route failure answers with its cause’s reply.

nemo_gym.core.typed_exceptions.sdk_error_details(
error: BaseException,
message: str | None = None

The type, message and HTTP status of a third-party SDK error, without its request or body.

message is the text the adapter selected for this SDK; by default the SDK’s own message field. A missing or non-string message gives an empty one, so it never hides the original failure. Long text keeps a visible truncation marker.

nemo_gym.core.typed_exceptions._EVENT_FIELDS = ('event_id', 'boundary', 'exception_type', 'failure_reason', 'failure_kind', 'op...