Conversation
…ver role_play.common.environment with canonical enum mapping\n- Switch config_loader, dependencies, storage_factory to unified resolver\n- Guard PCM logs via Environment.PROD only\n- BaseServer health/env reporting via resolver\n- Delegate server.config.get_config to config_loader\n- Align logging_config to use environment_name/resolve_environment\n\nThis removes duplicate Environment enums and inconsistent ENV/ENVIRONMENT parsing.
|
Claude finished @xCatG's task —— View job PR Review: Unify Environment HandlingReview Tasks:
SummaryThis PR successfully consolidates environment detection logic by introducing a unified resolver with clear precedence rules. The changes eliminate duplicate Environment enums and inconsistent parsing logic across the codebase. Code Quality & Best Practices ✅Strengths:
Minor Improvements Suggested:
Potential Bugs & Issues
|
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request does a great job of unifying environment detection and handling across the Python backend. By centralizing the logic in the new role_play.common.environment module, you've eliminated duplicate code and made the configuration more predictable and less error-prone. The updates to logging, storage, and server components to use this new resolver are well-executed.
I've found a couple of issues in the new implementation that could lead to bugs in environment detection. My review includes suggestions to fix these to make the new module more robust. Overall, this is a solid and valuable refactoring.
| if config_file: | ||
| # Try to extract the environment from the filename | ||
| # e.g., /app/config/beta.yaml -> beta | ||
| m = re.search(r"/(\\w+)\\.yaml$", config_file) |
There was a problem hiding this comment.
The regular expression used to extract the environment from the config filename is incorrect and not robust. The double backslashes \\ in the raw string will be treated as literal backslashes, which will cause the pattern to fail to match. Additionally, using a regex that matches on the full path is brittle as it assumes a specific directory structure.
A more robust approach is to operate on the base name of the file. An even better, more Pythonic solution would be to use pathlib.Path(config_file).stem to avoid regex altogether.
| m = re.search(r"/(\\w+)\\.yaml$", config_file) | |
| m = re.search(r"(\w+)\.yaml$", os.path.basename(config_file)) |
| try: | ||
| env_enum = resolve_environment() | ||
| else: | ||
| env_enum = Environment(environment) |
There was a problem hiding this comment.
When an environment string is passed to get_config, it's used directly to initialize the Environment enum. This will raise a ValueError if a synonym like "development" or "production" is passed, as the enum constructor only accepts the canonical values ("dev", "beta", "prod").
You should use the parse_environment_str function from the new environment module to correctly handle synonyms and invalid values. You'll also need to update the import on line 19 to bring in this function:
from ..common.environment import resolve_environment, parse_environment_str
| env_enum = Environment(environment) | |
| env_enum = parse_environment_str(environment) |
This PR consolidates environment detection and usage across the Python backend.\n\nKey changes:\n- Add role_play.common.environment with a single resolver (CONFIG_FILE > ENV > ENVIRONMENT > dev) and synonym mapping (development->dev, production->prod).\n- Use common.models.Environment everywhere; remove duplicate enum in server/config_loader.py.\n- Delegate server.config.get_config() to server.config_loader.get_config().\n- Update server/dependencies.py, common/storage_factory.py to use the unified resolver.\n- Align logging and health endpoint to report consistent environment names.\n- Guard PCM audio logging strictly by Environment.PROD.\n\nWhy:\n- Avoids mismatches between storage selection and app config.\n- Eliminates duplicate enums/naming drift.\n- Provides predictable precedence for env sources.\n\nTesting plan:\n- make run-local-docker DATA_DIR=...; curl localhost:8080/health shows environment dev|beta|prod per ENV/ENVIRONMENT/CONFIG_FILE.\n- Verify logging format switches to structured JSON in non-dev environments.\n- Ensure file storage is rejected in beta/prod but allowed in dev per storage_factory restrictions.\n\nDocs follow-up suggested to reference the resolver for Python code.