Skip to content

[FIX] fix the template imports and types#430

Merged
burtenshaw merged 3 commits intomainfrom
fix/small-fixes-in-template
Mar 16, 2026
Merged

[FIX] fix the template imports and types#430
burtenshaw merged 3 commits intomainfrom
fix/small-fixes-in-template

Conversation

@burtenshaw
Copy link
Collaborator

Summary

This PR fixes the template. There were two errors:

  1. a misaligned type setting
  2. some users were starting servers with relative import. This adds a try accept to allow that.

Type of Change

  • Bug fix

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 Mar 8, 2026
@burtenshaw burtenshaw requested a review from Darktex March 8, 2026 16:05
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 8, 2026

Greptile Summary

This PR fixes two bugs in the OpenEnv environment template: it adds the missing third State type parameter to EnvClient's generic instantiation in client.py (satisfying the INVARIANTS.md requirement that all clients use EnvClient[ActT, ObsT, StateT]), and it wraps the server-side model imports in a try/except ImportError fallback so the template works correctly both when used as a Python package (relative imports) and when run directly with PYTHONPATH-based imports in Docker or script mode.

Key changes:

  • client.py: EnvClient[Action, Observation]EnvClient[Action, Observation, State] — correct three-parameter generic, no invariant violations.
  • server/__ENV_NAME___environment.py & server/app.py: Replaced hard-coded PYTHONPATH-relative imports with a try/except that attempts the relative import first, falling back to the flat import — accommodates both package and script execution contexts.
  • Alignment: No invariant violations detected. Client-server separation is maintained; the client does not import from server/, and shared types remain in models.py. Reward logic stays inside the environment boundary.

Style note: Both except ImportError blocks should ideally be narrowed to except ModuleNotFoundError to avoid silently masking genuine import errors originating inside the imported modules (see inline comment on app.py).

Confidence Score: 4/5

  • Safe to merge — both fixes are correct and no invariants are violated. A minor style improvement to exception narrowing is recommended but not blocking.
  • The missing State type parameter fix in client.py is correct and aligns with INVARIANTS.md. The try/except import fallback pattern is a sound approach for supporting both package-mode and script-mode execution. The only concern is using broad ImportError instead of the narrower ModuleNotFoundError in two places, which is a best-practice issue rather than a functional bug. This can be addressed in a quick follow-up and does not block the merge.
  • Minor style improvement in server/app.py and server/__ENV_NAME___environment.py for exception narrowing (use ModuleNotFoundError instead of ImportError).

Important Files Changed

Filename Overview
src/openenv/cli/templates/openenv_env/client.py Correctly adds the missing State third type parameter to EnvClient generic instantiation at line 19. This satisfies the INVARIANTS.md requirement that all clients use EnvClient[ActT, ObsT, StateT] with three type parameters. No concerns.
src/openenv/cli/templates/openenv_env/server/__ENV_NAME___environment.py Adds a try/except import fallback at lines 19–22 to support both package-mode (relative imports) and script/Docker-mode (PYTHONPATH-based imports) execution. The fallback pattern is correct. Note: uses broad ImportError instead of the more specific ModuleNotFoundError, which could mask errors inside models.py; narrowing to ModuleNotFoundError is recommended.
src/openenv/cli/templates/openenv_env/server/app.py Adds the same try/except import fallback pattern at lines 38–43 for both models and the environment module, accommodating both package-mode and script/Docker-mode execution. Same broad ImportError concern as in __ENV_NAME___environment.py; ModuleNotFoundError would be safer (see inline comment).

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[app.py / __ENV_NAME___environment.py starts] --> B{Relative import<br/>from ..models}
    B -->|Success - package mode| C[Use ..models & .__ENV_NAME___environment]
    B -->|ImportError - script/Docker mode| D[Fallback: from models &<br/>from server.__ENV_NAME___environment]
    C --> E[create_app with<br/>Action, Observation, Environment]
    D --> E

    F[client.py] --> G["EnvClient[Action, Observation, State]<br/>(3 type params — fixed)"]
    G --> H[Type-safe generic client]
Loading

Last reviewed commit: 98b5869

burtenshaw and others added 2 commits March 12, 2026 09:07
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@burtenshaw burtenshaw merged commit 7a8bb93 into main Mar 16, 2026
11 checks passed
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