rl icon indicating copy to clipboard operation
rl copied to clipboard

[BUG] AsyncEnvPool / ParallelEnv silently drops kwargs during reset()

Open coder-jayp opened this issue 2 months ago • 1 comments

Describe the bug

Currently, asynchronous environments like AsyncEnvPool and ParallelEnv accept **kwargs in their reset() method but silently drop them, never forwarding them to the underlying sub-environments.

To Reproduce

import torch
from torchrl.envs import AsyncEnvPool, GymEnv

def make_env():
    return GymEnv("Pendulum-v1")

if __name__ == "__main__":
    pool = AsyncEnvPool([make_env, make_env])
    
    # We attempt to pass an arbitrary kwarg to the sub-environments.
    # It executes without crashing, but the kwarg is completely dropped 
    # across the worker boundary and never reaches the underlying GymEnvs.
    pool.reset(some_arbitrary_kwarg=True)
    print("Reset finished, but 'some_arbitrary_kwarg' was silently dropped by the pool!")

Expected behavior

The kwargs passed to reset() (such as set_state=True) should be properly forwarded across the worker boundary and executed by the underlying sub-environments.

Screenshots

N/A

Additional context

As discussed in PR #4501, we temporarily added a NotImplementedError to specifically catch set_state=True to prevent it from failing silently, but the underlying architectural bug remains for all kwargs.

Reason and Possible fixes

When the reset() method is called on the pool, it sends a reset command to the workers, but the _run_worker function and the internal multiprocessing communication channels do not currently pack or unpack the kwargs along with the command.

I would like to take up the follow-up PR to implement proper kwarg forwarding across the _run_worker and multiprocessing boundaries so that kwargs are respected by the sub-environments.

Checklist

  • [x] I have checked that there is no similar issue in the repo (required)
  • [x] I have read the documentation (required)
  • [x] I have provided a minimal working example to reproduce the bug (required)

coder-jayp avatar Oct 03 '26 15:10 coder-jayp

/assign

coder-jayp avatar Oct 03 '26 15:10 coder-jayp