Code quality: silent exception swallowing + unbounded LRU cache (shared Stainless pattern)
Summary
We ran HefestoAI (deterministic static analysis, no AI/LLM) against openai-python and found patterns that may warrant review.
Notable: These findings are structurally identical to patterns we reported in anthropics/anthropic-sdk-python (#1372) — both SDKs appear to be generated by Stainless, so the root cause likely lives in the generator.
Findings
1. Silent exception swallowing (4 instances)
src/openai/_models.py:542 — union type validation:
try:
return validate_type(type_=cast("type[object]", original_type or type_), value=value)
except Exception:
pass
Silently swallows validation errors during union type construction. A malformed API response could produce an incorrect model object instead of raising.
src/openai/_base_client.py:844,1453 — __del__ finalizers catching Exception. Defensible (finalizers should not raise), but noted for completeness.
src/openai/cli/_cli.py:228 — CLI error handling.
2. Unbounded LRU cache (1 instance)
src/openai/_base_client.py:2119:
@lru_cache(maxsize=None)
def platform_headers(version: str, *, platform: Platform | None) -> Dict[str, str]:
Low risk in practice (bounded input space), but maxsize=None on a public SDK means downstream long-running processes inherit unbounded caches.
3. Stainless generator observation
The _base_client.py, _models.py, and platform_headers patterns are byte-for-byte identical to the Anthropic SDK. If these originate in the Stainless code generator, fixing the generator would fix both SDKs (and any other Stainless-generated SDK).
Reproduction
pip install hefesto-ai
git clone --depth 1 https://github.com/openai/openai-python.git
hefesto analyze openai-python/ --severity LOW
About
HefestoAI is an open-source (MIT) deterministic code quality and security analyzer. All findings are from static, offline, reproducible rules — no AI/LLM was used.
Closing this issue. After further review, some findings need additional verification before being reported externally. We will re-evaluate and re-open with verified findings only if warranted. Apologies for the noise.