fix(adapters): address review feedback from #1593 — error suppression, session IDs, test bug#1607
Closed
miyannishar wants to merge 1 commit into
Closed
fix(adapters): address review feedback from #1593 — error suppression, session IDs, test bug#1607miyannishar wants to merge 1 commit into
miyannishar wants to merge 1 commit into
Conversation
Fixes 5 issues raised by @imran-siddique: BLOCKING: - SK wrap_kernel(), PydanticAI wrap(): remove contextlib.suppress(Exception) which was silently swallowing ALL exceptions (not just DeprecationWarning). Now uses warnings.catch_warnings() alone to suppress only the nested DeprecationWarning, so real errors (invalid kernel, policy validation failures) propagate correctly. BUG: - test_smolagents_hooks: test_blocks_pattern_in_observation incorrectly assumed a step with no tool calls but a blocked observation would pass. GovernanceStepCallback scans observations unconditionally; the test now correctly asserts PolicyViolationError is raised in both cases (no-tool- call step and allowed-tool-call step with blocked observation). WARNINGS: - Anthropic wrap_client(): suppress nested DeprecationWarning from kernel.wrap() so callers see only one warning instead of two. - Anthropic wrap()/as_message_hook(), SK GovernanceFunctionFilter: replace int(time.time()) session IDs with uuid.uuid4().hex[:12] to prevent same-second session ID collisions in audit trails. - SK GovernanceFunctionFilter: use the uuid-based ID as the _contexts dict key so calling as_filter() multiple times no longer overwrites the first filter's context entry. Part of: microsoft#1593
🤖 AI Agent: security-scanner — View detailsNo security issues found. |
🤖 AI Agent: docs-sync-checker — Docs SyncDocs Sync
|
🤖 AI Agent: code-reviewer — Action Items:TL;DR: 0 blockers, 3 warnings. Solid fixes; minor improvements can follow later.
Action Items:
Warnings (fine as follow-up PRs):
|
🤖 AI Agent: breaking-change-detector — API CompatibilityAPI Compatibility
|
🤖 AI Agent: test-generator — `semantic_kernel_adapter.py`
|
PR Review Summary
Verdict: ❌ Changes needed |
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
Addresses all 5 issues raised by @imran-siddique in #1593 before it was closed and rebased as #1605. The original native-hook adapter code has already been merged via #1605; this PR contains only the correctness fixes from the review.
Fixes Applied
🔴 Blocking — Error suppression
Files:
semantic_kernel_adapter.py(wrap_kernel()),pydantic_ai_adapter.py(module-levelwrap())contextlib.suppress(Exception)was silently swallowing all exceptions, not justDeprecationWarning. This meant a real failure (invalid kernel, failed policy validation) insidewrap()would returnNonewith no indication of the problem.Fix: Removed
contextlib.suppress(Exception). Both functions now use onlywarnings.catch_warnings()to suppress the nestedDeprecationWarning.🔴 Bug — Test
test_blocks_pattern_in_observationFile:
tests/test_smolagents_hooks.pyThe test incorrectly assumed
callback(step_with_blocked_obs, agent)would pass when the step had no tool-call action.GovernanceStepCallbackscans observations unconditionally, so it always raises for a blocked observation regardless of whether tool calls are present.Fix: Rewrote the test to correctly assert that
PolicyViolationErroris raised in both the no-tool-call and the allowed-tool-call-with-blocked-observation cases.🟡 Warning — Double deprecation in
wrap_client()File:
anthropic_adapter.pywrap_client()calledkernel.wrap()without suppressing the inner deprecation, so users saw twoDeprecationWarningmessages per invocation.Fix: Wrapped the inner call with
warnings.catch_warnings()to suppress the nested warning, matching the pattern already used in SK/PydanticAI.🟡 Warning — Session ID collisions
Files:
anthropic_adapter.py,semantic_kernel_adapter.pySession IDs used
int(time.time()), causing two hooks created within the same second to share a session ID and corrupt audit trails.Fix: Replaced with
uuid.uuid4().hex[:12]for guaranteed uniqueness.🟡 Warning —
as_filter()overwrites context on repeated callsFile:
semantic_kernel_adapter.py—GovernanceFunctionFilter.__init__The context was stored under the hardcoded key
"sk-filter", so callingas_filter()twice on the same wrapper silently discarded the first filter's execution context.Fix: The context key is now the same uuid-based
_filter_idgenerated per-instance, so each filter has its own isolated entry inwrapper._contexts.Testing
ast.parse)grepconfirms zero remainingcontextlib.suppress(Exception)orint(time.time())session IDs across the three adapter filestest_smolagents_hooks.pynow correctly specifies the unconditional observation-scan behaviourCloses the feedback loop on #1593.