Skip to content

[codex] fix: clarify best-effort environment probe failures#38

Merged
mldangelo-oai merged 1 commit intomainfrom
mdangelo/codex/handle-best-effort-probe-reads
Apr 4, 2026
Merged

[codex] fix: clarify best-effort environment probe failures#38
mldangelo-oai merged 1 commit intomainfrom
mdangelo/codex/handle-best-effort-probe-reads

Conversation

@mldangelo-oai
Copy link
Copy Markdown
Contributor

Summary

GitHub code scanning flagged several empty except OSError: pass blocks in src/promptfoo/environment.py.

Those handlers were intentional best-effort fallbacks around optional /proc and /sys probe files, so the findings are effectively false positives from a runtime behavior perspective. The downside was that the code made this intent implicit, which left the scanner and human readers with no explanation for why those exceptions were ignored.

Fix

This change centralizes optional probe-file reads in _read_probe_file(), which returns None when a probe file is missing or unreadable and documents why that fallback is safe for environment detection.

The Linux distro, cloud provider, container, and WSL detectors now call that helper instead of repeating inline try/except OSError blocks.

Validation

Ran:

  • uv run ruff check src/ tests/test_environment.py
  • uv run ruff format --check src/ tests/test_environment.py
  • uv run mypy src/promptfoo/
  • uv run pyright src/promptfoo/
  • uv run pytest tests/test_environment.py

@mldangelo-oai mldangelo-oai marked this pull request as ready for review April 3, 2026 02:35
@mldangelo-oai mldangelo-oai merged commit 158007c into main Apr 4, 2026
15 checks passed
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.

1 participant