Make ResourceSessionFactory generic over its session type#1007
Open
sergiopaniego wants to merge 1 commit into
Open
Make ResourceSessionFactory generic over its session type#1007sergiopaniego wants to merge 1 commit into
sergiopaniego wants to merge 1 commit into
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
Pure static typing change with no runtime or API behavior differences; existing non-parameterized subclasses stay compatible.
Overview
ResourceSessionFactoryis now generic socreate()can be typed to return the concrete session class instead of alwaysResourceSession.The harness adds
SessionT(bound toResourceSession),ResourceSessionFactory(ABC, Generic[SessionT]), and changescreate()’s return type fromResourceSessiontoSessionT.OpenCodeSessionFactoryis updated toResourceSessionFactory[OpenCodeSession], aligning the factory type with its existingcreate() -> OpenCodeSessionimplementation.Subclasses that omit the type parameter (e.g. browsergym, openspiel) remain valid; this is typing-only with no runtime behavior change.
Reviewed by Cursor Bugbot for commit ed861aa. Bugbot is set up for automated code reviews on this repo. Configure here.