Make ResourceSessionFactory generic over its session type - #1007
Merged
burtenshaw merged 2 commits intoJul 28, 2026
Merged
Conversation
ResourceSessionFactory.create() was typed as returning the base ResourceSession, so callers lost the concrete session type and had to cast. Parameterize the factory over a SessionT bound to ResourceSession, so a subclass like OpenCodeSessionFactory(ResourceSessionFactory[OpenCodeSession]) types create() as returning OpenCodeSession. Subclassing without a type argument stays valid and behaves as before, so existing envs are unaffected.
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Makes
ResourceSessionFactorygeneric over the session type it produces.Why
ResourceSessionFactory.create()is typed as returning the baseResourceSession, so callers lose the concrete session type and have to cast. This is one of theTODO(@openenv)gaps flagged in TRL's loop-owning harness rollout work (huggingface/trl#6420), where the worker doescast(LoopOwningSession, session)because the factory type cannot express which session subtype it returns.Change
ResourceSessionFactory(ABC, Generic[SessionT])withSessionTbound toResourceSession, andcreate()returnsSessionT.OpenCodeSessionFactoryis nowResourceSessionFactory[OpenCodeSession], so itscreate()types as returningOpenCodeSession.Compatibility
Backward compatible: subclassing without a type argument (
class MyFactory(ResourceSessionFactory)) stays valid and behaves exactly as before. The other envs that subclass it (browsergym, openspiel, reasoning_gym) are unaffected and import cleanly. Pure typing change, no runtime behavior difference.AI-assisted.
Note
Low Risk
Typing-only change with no runtime or behavioral impact; existing factory subclasses without type arguments stay compatible.
Overview
ResourceSessionFactoryis now generic socreate()can be typed to return a concrete session subtype instead of alwaysResourceSession.In
openenv.core.harness, the factory addsSessionT(bound toResourceSession) andcreate()is annotated as-> SessionT.OpenCodeSessionFactoryis updated toResourceSessionFactory[OpenCodeSession], so callers getOpenCodeSessionfromcreate()without casts—relevant for TRL loop-owning harness work that previously neededcast(LoopOwningSession, session).No runtime behavior change. Subclasses that omit the type parameter (e.g. browsergym, openspiel, reasoning_gym) remain valid and unchanged.
Reviewed by Cursor Bugbot for commit 37100cc. Bugbot is set up for automated code reviews on this repo. Configure here.