feat: Add PolicyEngine.EvaluateAsync so external backends aren't forced into sync-over-async - #3778
Open
Garrett Beatty (GarrettBeatty) wants to merge 1 commit into
Conversation
…c-over-async PolicyEngine only exposed a synchronous Evaluate that calls IExternalPolicyBackend.Evaluate, so backends whose work is async (a network call) had to block a thread with GetAwaiter().GetResult(). - Extract the shared prologue (Prepare) and result combination (Combine) from Evaluate. - Add PolicyEngine.EvaluateAsync(agentDid, context, ct) that awaits backends' EvaluateAsync; external backends are evaluated sequentially to preserve ordering. Internal (in-memory) policy evaluation and the fail-closed resolution are unchanged. - Sync Evaluate keeps its exact previous behavior. Adds tests that EvaluateAsync uses the backend async path (and Evaluate the sync path), plus async fail-closed on backend error. Refs microsoft#3775
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
PR Review Summary
Verdict: AI review comments are untrusted advisory output. The summary reports workflow-generated completion status only, not model-authored pass/fail claims. |
Author
|
@microsoft-github-policy-service agree company="Amazon" |
Garrett Beatty (GarrettBeatty)
marked this pull request as ready for review
August 18, 2026 23:32
Garrett Beatty (GarrettBeatty)
requested review from
MohammadHaroonAbuomar and
liamcrumm
as code owners
August 18, 2026 23:32
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
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.
Draft implementation for #3775.
Problem
PolicyEngineonly exposes a synchronousEvaluatethat callsIExternalPolicyBackend.Evaluate. A backend whose decision requires a network call (an async-only SDK) has to block a thread with.GetAwaiter().GetResult(), which pressures the thread pool under load.Change
Prepare: validate, snapshot, build context, run in-memory policies) and result combination (Combine: fail-closed resolution) out ofEvaluate.PolicyEngine.EvaluateAsync(agentDid, context, ct)that awaits each backend'sEvaluateAsync. External backends run sequentially to preserve ordering and avoid assuming they're concurrency-safe.Evaluatekeeps its exact previous behavior; internal policy evaluation and fail-closed semantics are unchanged.Tests
Adds coverage that
EvaluateAsyncuses the backend async path,Evaluateuses the sync path, andEvaluateAsyncstill fails closed on a backend error. All existing policy tests pass (146 total).Open questions for maintainers
GovernanceKernel.EvaluateToolCall(and the MCP decorator, which is alreadyasync)? Kept this PR to the engine to stay focused; happy to follow up.Draft: opening to align on shape before finalizing.