Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion envs/opencode_env/harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def fetch_proxy_trace(self) -> list[dict[str, Any]]:
return records


class OpenCodeSessionFactory(ResourceSessionFactory):
class OpenCodeSessionFactory(ResourceSessionFactory[OpenCodeSession]):
"""Produce isolated per-rollout :class:`OpenCodeSession` instances.

The factory owns sandbox provisioning, opencode install, config injection,
Expand Down
17 changes: 13 additions & 4 deletions src/openenv/core/harness/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import math
from abc import ABC, abstractmethod
from dataclasses import dataclass, field
from typing import Any, Callable, Protocol
from typing import Any, Callable, Generic, Protocol, TypeVar

from ..client_types import StepResult
from ..env_server.mcp_types import JsonRpcErrorCode, JsonRpcResponse, Tool
Expand Down Expand Up @@ -141,16 +141,25 @@ def close(self) -> None:
"""Release session resources."""


class ResourceSessionFactory(ABC):
"""Factory for producing isolated per-rollout sessions."""
SessionT = TypeVar("SessionT", bound=ResourceSession)


class ResourceSessionFactory(ABC, Generic[SessionT]):
"""Factory for producing isolated per-rollout sessions.

Generic over the concrete session type it creates, so a subclass such as
``OpenCodeSessionFactory(ResourceSessionFactory[OpenCodeSession])`` types
``create`` as returning ``OpenCodeSession``. Subclassing without a type
argument stays valid and behaves as before.
"""

@abstractmethod
def create(
self,
task: Any,
seed: int | None = None,
episode_id: str | None = None,
) -> ResourceSession:
) -> SessionT:
"""Create one isolated resource session for a rollout."""


Expand Down
Loading