Skip to content

refactor(config): migrate from .env to YAML with OmegaConf#350

Open
looksaw2 wants to merge 3 commits into
apache:mainfrom
looksaw2:yaml-config-migration
Open

refactor(config): migrate from .env to YAML with OmegaConf#350
looksaw2 wants to merge 3 commits into
apache:mainfrom
looksaw2:yaml-config-migration

Conversation

@looksaw2
Copy link
Copy Markdown

Migrated config storage from .env to config.yaml using OmegaConf.

  • YAML replaces .env — all settings live in one config.yaml under llm / hugegraph
    / admin / index sections with nested structure.
  • Hot reload — background file watcher picks up changes to config.yaml without
    restarting. Polling interval is configurable.
  • Auto migration — existing .env is automatically converted to config.yaml on
    first run, no manual setup needed.
  • Env vars take priority — OPENAI_API_KEY and similar secrets still come from
    environment variables, overriding YAML values (12-factor friendly).
  • No breaking changes — llm_settings.language and all other attribute access works
    exactly the same, 46 consumer files untouched.

looksaw2 and others added 3 commits May 30, 2026 22:57
Replace pydantic-settings + python-dotenv with OmegaConf-based
config.yaml. Supports nested YAML structure, environment variable
override (os.environ > config.yaml > defaults), auto-migration
from existing .env, and hot-reload via file watcher.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Update design.md to reflect the nested YAML structure (via flat↔nested
mapping), update tasks.md to mark all 10 task groups completed, and
document implementation differences from the original plan.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Translate requirements.md, design.md, and tasks.md from Chinese
to English to meet project contribution guidelines.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@dosubot dosubot Bot added size:XXL This PR changes 1000+ lines, ignoring generated files. enhancement New feature or request labels May 30, 2026
@github-actions github-actions Bot added the llm label May 30, 2026
Copy link
Copy Markdown
Member

@imbajin imbajin left a comment

Choose a reason for hiding this comment

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

Auto reviewed the config migration and found one blocking regression in environment-variable precedence.

# Load .env into os.environ for backward compatibility and priority override
if os.path.exists(self._env_path):
for k, v in dotenv_values(self._env_path).items():
os.environ[k] = v
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

‼️ Preserve real environment-variable precedence

This loop copies every key from .env into os.environ before YAML/env override resolution. That reverses the intended deployment precedence when the process already has real environment variables: I reproduced this with .env containing OPENAI_API_KEY=from_dotenv while launching with OPENAI_API_KEY=from_real_env, and llm_settings.openai_chat_api_key became from_dotenv. Existing pydantic settings gave the real environment precedence over the dotenv file, so a stale local .env can override Docker/Kubernetes secrets after this migration. Please only fill missing keys from .env (for example os.environ.setdefault(...), skipping empty values) and add a regression test for env > .env/config.yaml precedence.

Suggested change
os.environ[k] = v
for k, v in dotenv_values(self._env_path).items():
if v:
os.environ.setdefault(k, v)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request llm size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants