feat!: Ability to limit policy evaluation time#539
Merged
anakrish merged 1 commit intomicrosoft:mainfrom Jan 28, 2026
Merged
Conversation
4657e46 to
28ad239
Compare
6233f35 to
9f21f1d
Compare
…inding - Introduce ExecutionTimer/ExecutionTimerConfig to allow limiting evaluating time. - To amortize time checking costs, checking interval can be configured via the notion of work units - A global fallback time limit can be set to universally limit all evaluation in addition to engine level limit setting. - Implement limnits in interpreter and RVM. In RVM, also handle suspend/resume so that time during pause is not counted. - Add engine-level APIs to set/clear per-engine timer configuration and apply global fallback defaults. - Surface execution-time limits through FFI and C# bindings - Add C# tests and example usage to validate engine overrides, global fallback behavior, and compiled policy enforcement. - Expand docs for execution-time limit - Add interpreter YAML cases and VM unit tests for time-limit behavior and deterministic time sources. Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
9f21f1d to
5c8e662
Compare
dpokluda
reviewed
Jan 27, 2026
| action(handlePtr); | ||
| return null; | ||
| }); | ||
| } |
There was a problem hiding this comment.
nit: I don't know how hot is this code path but we are boxing null as object?. We could instead copy/paste the UseHandle method without the return:
private void UseHandle(Action<IntPtr> action)
{
var handle = GetHandleForUse();
bool addedRef = false;
try
{
handle.DangerousAddRef(ref addedRef);
var pointer = handle.DangerousGetHandle();
if (pointer == IntPtr.Zero)
{
throw new ObjectDisposedException(nameof(CompiledPolicy));
}
action(pointer);
}
finally
{
if (addedRef)
{
handle.DangerousRelease();
}
}
}There was a problem hiding this comment.
An alternative option would be to refactor the handle handling :-) logic to a separate method and call it from both:
private T UseHandle<T>(Func<IntPtr, T> func)
{
T? result = default!;
WithHandle(ptr => result = func(ptr));
return result!;
}
private void UseHandle(Action<IntPtr> action)
{
WithHandle(action);
}
private void WithHandle(Action<IntPtr> body)
{
var handle = GetHandleForUse();
bool addedRef = false;
try
{
handle.DangerousAddRef(ref addedRef);
var pointer = handle.DangerousGetHandle();
if (pointer == IntPtr.Zero)
{
throw new ObjectDisposedException(nameof(CompiledPolicy));
}
body(pointer);
}
finally
{
if (addedRef)
{
handle.DangerousRelease();
}
}
}
Collaborator
Author
There was a problem hiding this comment.
Created #554 to track this. There is one C# specific PR remaining (expose VM to C#) that will wrap up the recent stream of work to improve robustness at Azure scale (super strict clippy lints, memory limits, executions limits). I will address this along with that.
Closed
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.
Uh oh!
There was an error while loading. Please reload this page.