> This page is for version 0.2.1.
> For other versions, use one of these documentation indexes:
> - Main (default): https://docs.nvidia.com/nemo/gym/main/llms.txt
> - 0.7.0: https://docs.nvidia.com/nemo/gym/v0.7.0/llms.txt
> - 0.6.0: https://docs.nvidia.com/nemo/gym/v0.6.0/llms.txt
> - 0.5.1: https://docs.nvidia.com/nemo/gym/v0.5.1/llms.txt
> - 0.5.0: https://docs.nvidia.com/nemo/gym/v0.5.0/llms.txt
> - 0.4.0: https://docs.nvidia.com/nemo/gym/v0.4.0/llms.txt
> - 0.3.0: https://docs.nvidia.com/nemo/gym/v0.3.0/llms.txt
> - 0.2.1: https://docs.nvidia.com/nemo/gym/v0.2.1/llms.txt

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/nemo/gym/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/nemo/gym/_mcp/server.

# nemo_gym.agent_utils.ordered_operations

In-process exactly-once ordered operations for agent activations.

## Module Contents

### Classes

| Name                                                                                          | Description                                                                   |
| --------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- |
| [`ActivationConflictError`](#nemo_gym-agent_utils-ordered_operations-ActivationConflictError) | An activation conflicts with its session's ordering or immutable input.       |
| [`OrderedOperationLedger`](#nemo_gym-agent_utils-ordered_operations-OrderedOperationLedger)   | Join/replay identical calls, reject conflicts, and fence work before closing. |
| [`_Operation`](#nemo_gym-agent_utils-ordered_operations-_Operation)                           | -                                                                             |

### API

```python
class nemo_gym.agent_utils.ordered_operations.ActivationConflictError()
```

**Bases:** `ValueError`

An activation conflicts with its session's ordering or immutable input.

```python
class nemo_gym.agent_utils.ordered_operations.OrderedOperationLedger()
```

Join/replay identical calls, reject conflicts, and fence work before closing.

Owners must serialize seed/close binding separately and retain this ledger for
the session lifetime. Disconnecting a waiter leaves execution alive. Failed
operations are retained and replay their failure; a new physical episode is
needed to retry with different inputs. This is process-local, not crash recovery.

**`_lock`** `= asyncio.Lock()`

---

**`_operations`** `list[_Operation[Result]] = []`

---

```python
nemo_gym.agent_utils.ordered_operations.OrderedOperationLedger.close(
    timeout: float
) -> None
```

async

Fence new work, cancel/await the active operation, then allow owner cleanup.

A timeout retains the active task and the fence, so cleanup cannot be
declared successful while an activation might still launch remotely.

```python
nemo_gym.agent_utils.ordered_operations.OrderedOperationLedger.execute(
    index: int,
    request: pydantic.BaseModel,
    operation: collections.abc.Callable[[], collections.abc.Awaitable[nemo_gym.agent_utils.ordered_operations.OrderedOperationLedger[Result]]]
) -> nemo_gym.agent_utils.ordered_operations.OrderedOperationLedger[Result]
```

async

Run the next operation once or join an exact retry, without holding the lock while running.

```python
class nemo_gym.agent_utils.ordered_operations._Operation(
    request: pydantic.BaseModel,
    task: asyncio.Task[nemo_gym.agent_utils.ordered_operations._Operation[Result]]
)
```

Dataclass

**`request`** `BaseModel`

---

**`task`** `Task[Result]`

---