Skip to content

[FIX] lazy loading in core #393

Open
burtenshaw wants to merge 5 commits intomainfrom
lazy-loading-fix
Open

[FIX] lazy loading in core #393
burtenshaw wants to merge 5 commits intomainfrom
lazy-loading-fix

Conversation

@burtenshaw
Copy link
Collaborator

@burtenshaw burtenshaw commented Feb 17, 2026

Summary

This lets env builders lazy load core when the import code relatively.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • New environment
  • Refactoring

Alignment Checklist

Before submitting, verify:

  • I have read .claude/docs/PRINCIPLES.md and this PR aligns with our principles
  • I have checked .claude/docs/INVARIANTS.md and no invariants are violated
  • I have run /pre-submit-pr (or bash .claude/hooks/lint.sh and tests) and addressed all issues

RFC Status

  • Not required (bug fix, docs, minor refactoring)
  • RFC exists: #___
  • RFC needed (will create before merge)

Test Plan

Claude Code Review

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Feb 17, 2026
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 17, 2026

Greptile Summary

This PR implements lazy loading for the core module to enable environment builders to import openenv without loading heavy dependencies like gradio, fastmcp, or smolagents.

Key Changes

  • Lazy module loading: src/openenv/__init__.py now uses __getattr__ to defer imports of core and cli modules until first access
  • Lazy attribute loading: Client classes (EnvClient, SyncEnvClient, etc.) are imported on-demand rather than eagerly
  • Optional dependency handling: Gracefully handles missing optional dependencies (gradio, fastmcp, smolagents) by setting them to None with try/except blocks
  • Import optimization: Enables minimal imports for environment builders who only need server-side components

Issues Found

  • Critical: typing_extensions is imported in src/openenv/core/env_server/interfaces.py:11 but not listed in pyproject.toml dependencies, which will cause ModuleNotFoundError at runtime

Confidence Score: 3/5

  • PR has a critical import error that will cause runtime failures
  • The lazy loading implementation is well-structured and aligns with the goal of reducing import overhead. However, the missing typing_extensions dependency in pyproject.toml is a blocking issue that will cause ModuleNotFoundError when interfaces.py is imported. This must be fixed before merge.
  • Pay close attention to src/openenv/core/env_server/interfaces.py - the typing_extensions import will fail without the dependency being added to pyproject.toml

Important Files Changed

Filename Overview
src/openenv/init.py Implements lazy loading for core modules and attributes using __getattr__ and __dir__, allowing env builders to import from openenv without loading heavy dependencies
src/openenv/core/init.py Implements lazy loading for client classes, preventing eager import of client dependencies when only server components are needed
src/openenv/core/env_server/init.py Adds graceful fallback for optional dependencies (gradio for web_interface, fastmcp for mcp_environment) by catching ModuleNotFoundError and setting to None
src/openenv/core/tools/init.py Adds graceful fallback for PyExecutor when smolagents is not installed, allowing environments to use Git tooling without Python execution support
src/openenv/core/env_server/interfaces.py Changes TypedDict import from typing to typing_extensions, but typing_extensions is not in dependencies

Flowchart

flowchart TD
    A[import openenv] --> B{Access attribute}
    B --> C{In _LAZY_MODULES?}
    C -->|Yes| D[import_module]
    C -->|No| E{In _LAZY_ATTRS?}
    E -->|Yes| F[import_module + getattr]
    E -->|No| G[AttributeError]
    D --> H[Cache in globals]
    F --> H
    H --> I[Return value]
    
    J[import openenv.core] --> K{Optional deps?}
    K -->|gradio missing| L[WebInterfaceManager = None]
    K -->|fastmcp missing| M[MCPEnvironment = None]
    K -->|smolagents missing| N[PyExecutor = None]
    K -->|All available| O[Normal imports]
Loading

Last reviewed commit: bccd977

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

5 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@burtenshaw burtenshaw changed the title fix lazy loading in core [2/n] Decouple Envs from version: fix lazy loading in core Feb 17, 2026
@burtenshaw burtenshaw changed the title [2/n] Decouple Envs from version: fix lazy loading in core [FIX] lazy loading in core Feb 17, 2026
burtenshaw and others added 4 commits February 17, 2026 12:39
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
# Conflicts:
#	src/openenv/__init__.py
#	src/openenv/core/__init__.py
#	src/openenv/core/env_server/__init__.py
#	src/openenv/core/env_server/interfaces.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant