fix(py-gov-compliance): log optional-dep ImportError fallbacks at DEBUG#2186
Merged
imran-siddique merged 1 commit intoMay 12, 2026
Conversation
agent_compliance/__init__.py wrapped the agent_os and agentmesh
re-exports in `try/except ImportError: pass`. The intent — let the
package import without the companion packages installed — is correct,
but `pass` left no breadcrumb. Operators wondering why
StatelessKernel was missing had to grep the source to find that an
import had been silently swallowed; "not installed", "broken install",
and "wrong extras" all looked identical from outside.
Replaces the bare `pass` with a `logger.debug(...)` line that records
the missing symbol and the original ImportError message. Default
logging stays quiet (the messages only emit at DEBUG); opting in via
`logging.getLogger("agent_compliance").setLevel(logging.DEBUG)`
surfaces the cause without touching default-config callers.
Verified: PYTHONPATH=src python -m pytest tests/test_init_imports.py
-q -> 4 passed (forced-ImportError fixture covers both fallbacks +
the silence-at-WARNING + the "import still works" contracts).
Full agent-compliance suite (excluding the pre-existing unrelated
test_red_team_cli failure): 452 passed.
🤖 AI Agent: breaking-change-detector — API CompatibilityAPI CompatibilityNo breaking changes detected. |
🤖 AI Agent: test-generator — `agent_compliance/__init__.py`
|
🤖 AI Agent: security-scanner — View detailsNo security issues found. |
🤖 AI Agent: code-reviewer — View detailsTL;DR: 0 blockers, 0 warnings. No issues found. Clean change. |
🤖 AI Agent: docs-sync-checker — Docs SyncDocs Sync
|
|
🟡 Contributor Check: MEDIUM
Automated check by AGT Contributor Check. |
PR Review Summary
Verdict: ✅ Ready for human review |
MohammadHaroonAbuomar
pushed a commit
to MohammadHaroonAbuomar/agt-acs
that referenced
this pull request
Jun 1, 2026
…UG (microsoft#2186) agent_compliance/__init__.py wrapped the agent_os and agentmesh re-exports in `try/except ImportError: pass`. The intent — let the package import without the companion packages installed — is correct, but `pass` left no breadcrumb. Operators wondering why StatelessKernel was missing had to grep the source to find that an import had been silently swallowed; "not installed", "broken install", and "wrong extras" all looked identical from outside. Replaces the bare `pass` with a `logger.debug(...)` line that records the missing symbol and the original ImportError message. Default logging stays quiet (the messages only emit at DEBUG); opting in via `logging.getLogger("agent_compliance").setLevel(logging.DEBUG)` surfaces the cause without touching default-config callers. Verified: PYTHONPATH=src python -m pytest tests/test_init_imports.py -q -> 4 passed (forced-ImportError fixture covers both fallbacks + the silence-at-WARNING + the "import still works" contracts). Full agent-compliance suite (excluding the pre-existing unrelated test_red_team_cli failure): 452 passed.
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
agent_compliance/__init__.pywrapped theagent_osandagentmeshre-exports in:The intent — letting the package import without companion packages installed — is correct. But the bare
passleft no breadcrumb: operators wondering whyStatelessKernelwas missing at runtime had to grep the source to find that an import had been silently swallowed. "Not installed," "broken install," and "wrong extras" all looked identical from outside.Change
Replaces each
passwith a_logger.debug(...)line that records the missing symbol and the originalImportErrormessage:Default logging stays quiet (
WARNINGand above are silent). Opting in vialogging.getLogger("agent_compliance").setLevel(logging.DEBUG)surfaces the cause without touching default-config callers — exactly the failure mode the bullet flagged.Tests
New
tests/test_init_imports.pyuses a__builtins__.__import__monkeypatch to force ImportError on either or both optional deps and reimportsagent_compliancefrom scratch:test_missing_agent_os_logs_at_debugtest_missing_agentmesh_logs_at_debugtest_default_log_level_stays_quiettest_import_still_succeeds_without_optional_depsPromptDefenseEvaluator,SupplyChainGuardstill importableFull agent-compliance suite (excluding a pre-existing unrelated
test_red_team_clifailure): 452 passed, 2 skipped.Test plan
test_init_imports.pycases passagent_complianceimport works when bothagent_osandagentmeshare absent (the original behaviour)logging.getLogger("agent_compliance").setLevel(logging.DEBUG)surfaces the new breadcrumbsSurfaced during independent audit conducted by @finnoybu (Ken Tannenbaum, AEGIS Initiative); [LOW, Python Governance].