> This page is for version 0.6.0.
> 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.core.episode_context

The episode that the current request or task belongs to.

## Module Contents

### Functions

| Name                                                                                              | Description                                                                                         |
| ------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- |
| [`check_rollout_id_length`](#nemo_gym-core-episode_context-check_rollout_id_length)               | Refuse a rollout id whose capture files would pass the 255-byte file name limit at some attempt.    |
| [`current_episode_id`](#nemo_gym-core-episode_context-current_episode_id)                         | Return the logical rollout and attempt carried by the current capture key.                          |
| [`current_rollout_id`](#nemo_gym-core-episode_context-current_rollout_id)                         | -                                                                                                   |
| [`current_verifier_invocation_id`](#nemo_gym-core-episode_context-current_verifier_invocation_id) | Return the enclosing verify execution, if any.                                                      |
| [`maybe_rollout_id_from_run_body`](#nemo_gym-core-episode_context-maybe_rollout_id_from_run_body) | Build the capture key for a run request.                                                            |
| [`note_verifier_model_request`](#nemo_gym-core-episode_context-note_verifier_model_request)       | Note that the enclosing verify execution sent a request to a model server; outside one, do nothing. |
| [`rollout_context`](#nemo_gym-core-episode_context-rollout_context)                               | -                                                                                                   |
| [`verifier_invocation_context`](#nemo_gym-core-episode_context-verifier_invocation_context)       | Carry one verify execution's identity across its concurrent judge calls.                            |
| [`verifier_model_requests`](#nemo_gym-core-episode_context-verifier_model_requests)               | The model servers the enclosing verify execution has sent requests to so far.                       |

### Data

[`MAX_ROLLOUT_ID_LENGTH`](#nemo_gym-core-episode_context-MAX_ROLLOUT_ID_LENGTH)

[`ROLLOUT_ID_PATTERN`](#nemo_gym-core-episode_context-ROLLOUT_ID_PATTERN)

[`VERIFIER_INVOCATION_HEADER`](#nemo_gym-core-episode_context-VERIFIER_INVOCATION_HEADER)

[`_ROLLOUT_ID`](#nemo_gym-core-episode_context-_ROLLOUT_ID)

[`_VERIFIER_INVOCATION_ID`](#nemo_gym-core-episode_context-_VERIFIER_INVOCATION_ID)

[`_VERIFIER_MODEL_REQUESTS`](#nemo_gym-core-episode_context-_VERIFIER_MODEL_REQUESTS)

### API

```python
nemo_gym.core.episode_context.check_rollout_id_length(
    rollout_id: str
) -> None
```

Refuse a rollout id whose capture files would pass the 255-byte file name limit at some attempt.

```python
nemo_gym.core.episode_context.current_episode_id() -> typing.Optional[nemo_gym.core.episode_types.EpisodeId]
```

Return the logical rollout and attempt carried by the current capture key.

```python
nemo_gym.core.episode_context.current_rollout_id() -> typing.Optional[str]
```

```python
nemo_gym.core.episode_context.current_verifier_invocation_id() -> typing.Optional[str]
```

Return the enclosing verify execution, if any.

```python
nemo_gym.core.episode_context.maybe_rollout_id_from_run_body(
    body: pydantic.BaseModel | collections.abc.Mapping[str, typing.Any] | None
) -> typing.Optional[str]
```

Build the capture key for a run request.

An explicit `_ng_rollout_id` takes precedence.
Otherwise derive `"{task}-{rollout}"` from the task and rollout indices.
Re-dispatch attempts append `-a{n}`.
The suffix is reserved: an explicit id ending in `-a<N>` names attempt N of the rollout before it,
as a training controller names a restored attempt,
and rollout collection refuses dataset rows that use it as a plain id.
Writers and consumers must use this same identity.
Reused task and rollout indices produce a repeated capture key.
Use an explicit id when numbering restarts across dispatches.

```python
nemo_gym.core.episode_context.note_verifier_model_request(
    server_name: str
) -> None
```

Note that the enclosing verify execution sent a request to a model server; outside one, do nothing.

```python
nemo_gym.core.episode_context.rollout_context(
    rollout_id: typing.Optional[str]
) -> collections.abc.Iterator[None]
```

```python
nemo_gym.core.episode_context.verifier_invocation_context(
    invocation_id: str
) -> collections.abc.Iterator[None]
```

Carry one verify execution's identity across its concurrent judge calls.

```python
nemo_gym.core.episode_context.verifier_model_requests() -> list[str]
```

The model servers the enclosing verify execution has sent requests to so far.

```python
nemo_gym.core.episode_context.MAX_ROLLOUT_ID_LENGTH = 255 - len('.capture.incomplete') - len('-a9999')
```

```python
nemo_gym.core.episode_context.ROLLOUT_ID_PATTERN = re.compile('^[A-Za-z0-9][A-Za-z0-9._-]*$')
```

```python
nemo_gym.core.episode_context.VERIFIER_INVOCATION_HEADER = 'x-ng-verifier-invocation-id'
```

```python
nemo_gym.core.episode_context._ROLLOUT_ID: ContextVar[Optional[str]] = ContextVar('nemo_gym_rollout_id', default=None)
```

```python
nemo_gym.core.episode_context._VERIFIER_INVOCATION_ID: ContextVar[Optional[str]] = ContextVar('nemo_gym_verifier_invocation_id', default=None)
```

```python
nemo_gym.core.episode_context._VERIFIER_MODEL_REQUESTS: ContextVar[Optional[list[str]]] = ContextVar('nemo_gym_verifier_model_requests', default=None)
```