fix(providers): log resolved .env source#124
Merged
Merged
Conversation
A stale or shadowed .env silently won the whole-process config with zero diagnostic signal, turning a misconfig into hours of triage (P08, R1). Emit one behavior-preserving INFO line at .env resolution naming which candidate slot won, plus the resolved provider/model/base. The slot is reported via a fixed symbolic label (~/.vibe-trading/.env, <AGENT_DIR>/.env, <CWD>/.env) instead of the absolute path, so the OS username / home / CWD never leak (CWE-209); the API key is never logged. agent/src/providers/ is a protected module: this change is observability-only -- the first-match latch, override=False, and packaging anchor semantics are unchanged. Semantic fixes (R3-R7: precedence, anchor, override) are deferred to issue-first discussion per the protected-module rule. Closes HKUDS#123
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
INFOline at.envresolution namingwhich candidate slot won, plus the resolved provider/model/base.
~/.vibe-trading/.env,<AGENT_DIR>/.env,<CWD>/.env) — the absolute path, OS username,home and CWD are never logged (CWE-209); the API key is never logged.
override=False, and packaging anchor are unchanged.Why
.envresolution was silent. With a first-match latch andoverride=False, a stale or shadowed.envwon the whole-processconfig with no signal as to which file/precedence won — turning a
misconfig into hours of triage (P08, R1).
This is the protected-module change discussed and approved in #123
(@warren618, 2026-05-16: "no API key, redacted path — sounds right").
Deeper precedence/anchor/override changes (R3–R7) remain deferred to
separate issue-first discussion per the protected-module rule.
Closes #123
Changes
agent/src/providers/llm.py: add_ENV_LABELS+_redact_env_source()(maps a resolved candidate to a leak-free symbolic label; unknown
paths collapse to
<.env>, missing tonone (no .env file found)),and one
logger.info(...)in_ensure_dotenv().agent/tests/test_dotenv_observability.py(new): 4 regression tests —redacted-label-not-path (CWE-209), helper mapping, none-case, and
latch-preserved (no re-log on second call).
Test Plan
pytest --ignore=agent/tests/e2e_backtest --tb=short -q) — 1162 passed, 1 skipped (pre-existingTUSHARE_TOKEN)test_dotenv_observability.pydotenv resolved from <AGENT_DIR>/.env | provider=… …with no absolute path / OS username /sk-presentruff checkclean on changed files (lint is best-effort; CI does not enforce ruff)Checklist
src/providers/were discussed and approved first (Discuss: .env resolution observability in providers/llm.py (protected module) #123)