Skip to content

fix(providers): log resolved .env source#124

Merged
warren618 merged 2 commits into
HKUDS:mainfrom
Teerapat-Vatpitak:pr/providers-dotenv-log
May 17, 2026
Merged

fix(providers): log resolved .env source#124
warren618 merged 2 commits into
HKUDS:mainfrom
Teerapat-Vatpitak:pr/providers-dotenv-log

Conversation

@Teerapat-Vatpitak
Copy link
Copy Markdown
Contributor

Summary

  • Emit one behavior-preserving INFO line at .env resolution naming
    which candidate slot won, plus the resolved provider/model/base.
  • The slot is a fixed symbolic label (~/.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.
  • Observability-only: resolution order, first-match latch,
    override=False, and packaging anchor are unchanged.

Why

.env resolution was silent. With a first-match latch and
override=False, a stale or shadowed .env won the whole-process
config 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 to none (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

  • Existing tests pass (pytest --ignore=agent/tests/e2e_backtest --tb=short -q) — 1162 passed, 1 skipped (pre-existing TUSHARE_TOKEN)
  • New tests added — 4 in test_dotenv_observability.py
  • Tested manually — runtime check confirms the emitted line is dotenv resolved from <AGENT_DIR>/.env | provider=… … with no absolute path / OS username / sk- present
  • ruff check clean on changed files (lint is best-effort; CI does not enforce ruff)

Checklist

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
@warren618 warren618 merged commit 54820e5 into HKUDS:main May 17, 2026
1 check passed
@Teerapat-Vatpitak Teerapat-Vatpitak deleted the pr/providers-dotenv-log branch May 17, 2026 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Discuss: .env resolution observability in providers/llm.py (protected module)

2 participants