Skip to content

refactor(core): split the episode modules into types, context and failure records - #5564

Merged
ananthsub merged 1 commit into
mainfrom
ananthsub/core-episode-split
Nov 4, 2026
Merged

ananthsub merged 1 commit into
mainfrom
ananthsub/core-episode-split

Conversation

@ananthsub

Copy link
Copy Markdown
Contributor

What changed and why

After #5536 moved episode_types.py into nemo_gym/core/, the package has two modules with overlapping names:

  • episode.py held episode identity (EpisodeId, TaskId) and the context variables for the current episode.
  • episode_types.py held the episode wire envelopes and the failure records.

A reader looking for an episode type had to guess which of the two holds it. This PR gives every episode type one home and gives each concern its own module:

Name Was in Now in
EpisodeId, TaskId core/episode.py core/episode_types.py
MaterializedTask, BaseEpisodeRequest, BaseEpisodeResponse, is_materialized_task_row core/episode_types.py core/episode_types.py (unchanged)
VERIFIER_INVOCATION_HEADER, ROLLOUT_ID_PATTERN, maybe_rollout_id_from_run_body, current_rollout_id, current_episode_id, rollout_context, current_verifier_invocation_id, verifier_invocation_context, and the two context variables core/episode.py core/episode_context.py (new)
FailureBoundary, SdkErrorDetails, SandboxFailureDetails, ModelFailureDetails, FailureEvent, validate_failure_event_map, FailureReport, EpisodeFailure core/episode_types.py core/failure_records.py (new)

core/episode.py is removed. failure_records.py sits beside failure_kinds.py and failure_transport.py, so the three failure modules read as one group.

flowchart BT
  kinds["core/failure_kinds"]
  records["core/failure_records"]
  types["core/episode_types"]
  context["core/episode_context"]
  exceptions["core/typed_exceptions"]
  transport["core/failure_transport"]
  records --> kinds
  types --> records
  context --> types
  exceptions --> records
  transport --> records
Loading

Arrows mean "imports". The definitions move unchanged. One test patched validate_failure_event_map through episode_types; it now patches it in failure_records, where the failure report looks it up.

Imports follow the layout rule. Library code and its tests import each name from the module that defines it; python scripts/migrate_imports.py rewrote them. Code outside nemo_gym/ already imported these names from nemo_gym.core, which serves the same public names from the new modules, so no server changes apart from one docstring.

Compatibility

  • nemo_gym.core.episode never shipped in a release, so it gets no old-path entry. The old-path entries that pointed into it (for nemo_gym.server_utils, nemo_gym.rollout_correlation and nemo_gym.models.base_responses_api_model) now point at episode_context or episode_types.
  • nemo_gym.episode_types shipped in 0.7.0 with EpisodeId, TaskId and EpisodeFailure. EpisodeId and TaskId are defined in its new location again. The failure names that moved out of it, and FailureStage and validate_failure_kind, which it imported, resolve through MOVED_NAMES with a DeprecationWarning until 0.10.0. The import snapshot test checks every recorded name.
  • Docs: the redirect for the nemo_gym/episode_types page pointed at server_runtime/episode_types, which refactor(core): move the failure modules from #5072 into their packages #5536 removed. It now points at core/episode_types, and the core/episode page redirects there too.

Validation

  • lint-imports: the layer contract is kept, with no new ignored imports.
  • A fresh interpreter imports the old paths (nemo_gym.episode_types, nemo_gym.rollout_correlation, nemo_gym.server_utils) and gets the identical objects from the new modules, each with a DeprecationWarning; nemo_gym.core.episode no longer imports.
  • The moved-path, public API, migrate_imports and import-linter coverage tests pass.
  • pytest -n 16 -o addopts="" tests/unit_tests: everything passes except tests that fail the same way on main on this host: four Harbor run summary tests and one benchmark listing test (the hostname resolves to 127.0.1.1, which Gym refuses to advertise to a sandbox) and two Docker PTY tests.
  • pre-commit run on every changed file passes.

Rollout evidence

N/A: the types move unchanged and only import lines change, so no rollout behavior changes. The unit suite covers the moved code.

Overlap with open PRs

None of #5526, #5528, #5531, #5533 or #5553 has merged; this branch is based on the current main. A trial merge against each head:

The conflicts are adjacent import lines. Whichever PR lands second needs a small rebase. Because nemo_gym.core.episode never shipped, it has no old-path entry: a branch that adds an import from it must switch that import to episode_types or episode_context.

Follow-up to #5166.

…lure records

After #5536 moved episode_types.py into core/, the package held two modules
with overlapping names. episode.py held episode identity and the current
episode's context variables; episode_types.py held the episode wire
envelopes and the failure records. Episode types now have one home, and
each concern has its own module:

- core/episode_types.py: every episode data type, including EpisodeId and
  TaskId, which come back to the module that shipped them in 0.7.0.
- core/episode_context.py (new): the current episode, that is, the context
  variables, the rollout id rules and the verifier invocation id.
- core/failure_records.py (new): failure boundaries, failure events, the
  failure report and the episode failure envelope, beside failure_kinds.py
  and failure_transport.py.

core/episode.py is removed. It never shipped in a release, so it gets no
old-path entry. The old-path entries that pointed into it now point at the
new modules. nemo_gym.episode_types (0.7.0) keeps serving the failure names
that moved out of it until 0.10.0. nemo_gym.core serves the same public
names. The docs redirect for nemo_gym.episode_types now points at the
core/episode_types page instead of the server_runtime page that #5536
removed, and the core/episode page redirects to core/episode_types.

Follow-up to #5166.

Signed-off-by: Ananth Subramaniam <[email protected]>
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

@svcnvidia-nemo-ci svcnvidia-nemo-ci left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

SHIP

LGTM — no concerns found. I reviewed the changed hunks and traced the relocated definitions through public and legacy imports, request context, failure transport, and checkpoint and rollout consumers. I found no introduced correctness or compatibility defects.

I couldn't execute tests or build the generated documentation in this read-only review.

Note: formal approval is not available for this request, so this review is posted as a comment only.

Review generated by codex. This was a full review. Request a full review with /review reset=true.

@ananthsub
ananthsub merged commit 11b9a11 into main Nov 4, 2026
55 of 58 checks passed
@ananthsub
ananthsub deleted the ananthsub/core-episode-split branch November 4, 2026 00:55

This branch was previously deployed

1 inactive deployment
public — 4c452fec Deployed Nov 4, 2026 by copy-pr-bot[bot] via release / finalize / notify #9836
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants