Skip to content

fix: EnvGroup nested routing silently misroutes to envs[0]#1058

Open
dieutx wants to merge 4 commits intoPrimeIntellect-ai:mainfrom
dieutx:fix/env-group-nested-routing
Open

fix: EnvGroup nested routing silently misroutes to envs[0]#1058
dieutx wants to merge 4 commits intoPrimeIntellect-ai:mainfrom
dieutx:fix/env-group-nested-routing

Conversation

@dieutx
Copy link
Copy Markdown

@dieutx dieutx commented Mar 24, 2026

Summary

Fixes #1008 — when an EnvGroup is wrapped inside another EnvGroup (as prime-rl does), the outer group overwrites inner task names, causing:

  • All rollouts silently routed to envs[0] via get_env_for_task fallback
  • Scoring returns reward=0.0 for all unrecognized task names

Changes

  • get_env_for_task: Raises ValueError with available task names instead of silently falling back to envs[0]
  • __init__ dataset loop: When a sub-env is an EnvGroup, preserves its inner task names in the dataset and registers them in env_map for correct routing
  • Tests: Updated existing fallback test, added 2 new tests for nested EnvGroup task preservation and mixed nested/flat routing

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Test plan

  • All 797 existing tests pass
  • test_get_env_for_task updated: unknown task now raises ValueError
  • test_nested_env_group_preserves_inner_tasks: inner task names preserved in outer dataset and env_map
  • test_nested_env_group_with_flat_env: mixed nested EnvGroup + flat env routing works correctly
  • ruff check and ruff format pass

Note

Medium Risk
Changes EnvGroup routing semantics by removing the silent fallback to envs[0] and raising a ValueError for unknown tasks, which could break callers relying on the previous behavior. Nested task registration touches dataset construction and env_map wiring, so mis-registration could affect rollout routing/scoring across tasks.

Overview
Fixes nested EnvGroup task routing so inner task labels are preserved through dataset concatenation and registered in the outer env_map, preventing misrouting when groups are wrapped inside other groups.

get_env_for_task now raises a ValueError listing available tasks instead of silently falling back to envs[0]; tests and docs are updated and expanded to cover unknown-task errors, nested groups (including eval-only and deep nesting), and mixed nested/flat configurations.

Written by Cursor Bugbot for commit 851174a. This will update automatically on new commits. Configure here.

… fallback

When an EnvGroup is nested inside another EnvGroup, the outer group
previously overwrote inner task names, causing all rollouts to be
silently misrouted to envs[0] and scoring to return reward=0.0.

Changes:
- get_env_for_task now raises ValueError for unknown tasks instead of
  silently falling back to envs[0]
- Nested EnvGroup task names are preserved in the outer group's dataset
  and env_map, enabling correct routing through the nesting chain

Closes PrimeIntellect-ai#1008
Comment thread verifiers/envs/env_group.py Outdated
Comment thread verifiers/envs/env_group.py
Comment thread verifiers/envs/env_group.py Outdated
- Use dataset["task"] unique values instead of env.env_names to handle
  arbitrary nesting depth (3+ levels)
- Register inner task names from eval datasets too, fixing eval-only
  nested EnvGroups where build_dataset() returns None
- Update docs/environments.md and docs/reference.md to document nested
  EnvGroup support and ValueError behavior
- Add tests for eval-only nested EnvGroup and 3-level deep nesting
Comment thread verifiers/envs/env_group.py
When a nested EnvGroup is detected, the initial outer name entry
(e.g., "my_envs") was left in env_map as a phantom key. This could
cause get_env_for_task to succeed at the outer level but fail inside
the inner group, and would list misleading task names in error messages.
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Comment thread verifiers/envs/env_group.py Outdated
…task

When the outer env_name matches an inner task name (e.g., outer name
"math" with an inner group containing a "math" task), the unconditional
pop would remove the just-registered valid task. Now only removes the
stale entry when it doesn't collide with an inner task name.
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.

EnvGroup nested in outer EnvGroup silently misroutes all tasks to envs[0]

1 participant