[bindings] Expose Engine.clone() to JS and add explicit Engine.prepare() warm-up API across bindings#722
[bindings] Expose Engine.clone() to JS and add explicit Engine.prepare() warm-up API across bindings#722Copilot wants to merge 7 commits into
Engine.clone() to JS and add explicit Engine.prepare() warm-up API across bindings#722Conversation
Agent-Logs-Url: https://github.com/microsoft/regorus/sessions/58419b20-1586-4a23-85fb-5aed5f5d5961 Co-authored-by: anakrish <35780660+anakrish@users.noreply.github.com>
Engine.clone() to JS and add explicit Engine.prepare() warm-up API
|
|
||
| /// Clone this engine. | ||
| /// | ||
| /// Useful for creating per-request engines after loading policy/data once. |
There was a problem hiding this comment.
Remarks on the performance of this. Tahe a deep look. It is intended to avoid deep colies.
There was a problem hiding this comment.
Updated the clone docs to clarify performance intent: clone avoids reparsing/reloading immutable policy structures, while mutable evaluation state is copied for isolation. Commit: 730e6de.
| /// Prepare the engine for evaluation. | ||
| /// | ||
| /// This initializes internal evaluation structures so a cloned engine can | ||
| /// evaluate without requiring an initial "dummy" evaluation. |
There was a problem hiding this comment.
Do we need to remark that if we don't call this, the first eval on the engine will pay this cost. Also about adding policies after preparation.
There was a problem hiding this comment.
Added explicit prepare semantics in wasm docs: first eval pays this one-time setup if prepare() is not called, and modifying policy/data after prepare invalidates prepared state. Commit: 730e6de.
| /// Prepare the engine for evaluation without executing a query or rule. | ||
| /// | ||
| /// This parses and initializes internal evaluation data structures so that | ||
| /// subsequent evaluations (or cloned engines) can run without paying the |
There was a problem hiding this comment.
Can we make the documentation more clear about why this is needed, what ahappens if not called, what happens if policies added after this etc.
There was a problem hiding this comment.
Expanded core Engine::prepare() docs with why it exists, behavior when omitted (first eval prepares implicitly), and invalidation rules after policy/data changes. Commit: 730e6de.
Agent-Logs-Url: https://github.com/microsoft/regorus/sessions/49ba4462-95d3-42c0-a302-db1b81df4f65 Co-authored-by: anakrish <35780660+anakrish@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/regorus/sessions/49ba4462-95d3-42c0-a302-db1b81df4f65 Co-authored-by: anakrish <35780660+anakrish@users.noreply.github.com>
Not just wasm. I added |
Engine.clone() to JS and add explicit Engine.prepare() warm-up APIEngine.clone() to JS and add explicit Engine.prepare() warm-up API across bindings
There was a problem hiding this comment.
Pull request overview
Adds an explicit Engine.prepare() warm-up API to the core engine and propagates it to every binding (WASM, Ruby, Python, Java, Go, FFI/C, C++, C#). Also exposes Engine.clone() to JS (WASM) since the underlying Rust Clone impl was not previously bridged. The intended workflow is: load policies/data → prepare() once → clone() per request.
Changes:
- Adds
Engine::prepare()insrc/engine.rs(a public wrapper around the existing internalprepare_for_eval(false, false)). - Bridges
prepare()(and JSclone()) across all bindings, updates docs/examples/tests accordingly. - Adds a
prepare_then_clone_without_initial_evalintegration test.
Reviewed changes
Copilot reviewed 17 out of 18 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/engine.rs | New public prepare() method delegating to prepare_for_eval. |
| tests/engine/mod.rs | Test validating prepare → clone → independent evals. |
| bindings/wasm/src/lib.rs | Exposes clone and prepare to JS; test uses prepare(). |
| bindings/wasm/test.js | Demonstrates prepare + clone workflow. |
| bindings/wasm/README.md | Documents recommended prepare/clone usage. |
| bindings/ffi/src/engine.rs | New regorus_engine_prepare C FFI export. |
| bindings/cpp/regorus.hpp | C++ prepare() wrapper. |
| bindings/csharp/Regorus/{Engine.cs,NativeMethods.cs} | C# Prepare() and P/Invoke binding. |
| bindings/go/pkg/regorus/mod.go | Go Prepare() wrapper. |
| bindings/java/src/main/java/.../Engine.java | Java prepare() method + native declaration. |
| bindings/java/src/lib.rs | JNI nativePrepare implementation. |
| bindings/java/com_microsoft_regorus_Engine.h | JNI header for nativePrepare. |
| bindings/java/src/test/java/.../EngineTest.java | Test exercising prepare() + clone(). |
| bindings/python/src/lib.rs | Python prepare() binding. |
| bindings/python/test.py | Adds prepare() before clone in example. |
| bindings/ruby/ext/regorusrb/src/lib.rs | Ruby prepare method + class registration. |
| bindings/ruby/test/test_regorus.rb | Test calls prepare before clone. |
Files not reviewed (1)
- bindings/java/com_microsoft_regorus_Engine.h: Language not supported
| pub fn prepare(&mut self) -> Result<()> { | ||
| self.prepare_for_eval(false, false) | ||
| } |
|
@copilot Review this PR from different perspectives using different agents. Also launch an agent to review the PR using the deep-review skill |
Ran a deep multi-agent review (3 discovery agents, 2 micro-passes, 1 adversarial verifier). Consolidated outcome: 1 confirmed High issue and 1 confirmed Low test gap.
No additional findings from adversarial pass. If you want, I can submit a follow-up patch to make target-aware preparation idempotent/safe and add the missing azure-policy regression test. |
|
@copilot Address all review comments. Respond to the comments in thread as well. |
Agent-Logs-Url: https://github.com/microsoft/regorus/sessions/f964122b-5af3-41a7-bc51-d87b7271a455 Co-authored-by: anakrish <35780660+anakrish@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/regorus/sessions/f964122b-5af3-41a7-bc51-d87b7271a455 Co-authored-by: anakrish <35780660+anakrish@users.noreply.github.com>
Addressed all actionable review comments in code. Implemented fix for target-aware preparation so Commits: Validation run completed: targeted tests pass ( |
|
@copilot Run a the deep-review skill to review this PR |
Ran deep-review on current PR tip Findings:
Dropped: Ruby cfg-gating candidate was not introduced by this diff. |
|
@copilot Address the review findings |
Agent-Logs-Url: https://github.com/microsoft/regorus/sessions/c2c0f3ef-f641-4d83-94f8-a3cd3ede6db8 Co-authored-by: anakrish <35780660+anakrish@users.noreply.github.com>
Addressed in
Validation run passed for targeted Rust + Java tests; parallel validation code review succeeded and CodeQL timed out in the validation service. |
WASM
EngineimplementedClonein Rust but did not expose cloning to JavaScript. Also, cloning before first evaluation incurred heavy one-time preparation cost, requiring users to run a dummy eval; this change formalizes that warm-up path with an explicitprepareAPI and extends that capability across bindings.Core engine API
Engine::prepare()insrc/engine.rs.prepare()initializes internal evaluation structures without executing a query/rule, enabling explicit warm-up before cloning.Engine::prepare()docs to clarify:prepare()is not called,azure_policy: callingprepare()beforecompile_for_target()now still performs target resolution/resource-type inference (no longer skipped due toself.preparedshort-circuit).WASM binding surface
engine.clone()inbindings/wasm/src/lib.rs(js_name = "clone").engine.prepare()inbindings/wasm/src/lib.rs, mapped to coreEngine::prepare().Other bindings
regorus_engine_prepareEngine.Prepare()Engine::prepare()Engine.Prepare()Engine.prepare()/nativePrepareEngine.prepare()Engine#prepareBehavioral coverage
prepare_then_clone_without_initial_evalintests/engine/mod.rsto validate prepare-then-clone flow without a dummy initial eval.azure_policyregression testprepare_then_compile_for_targetintests/engine/mod.rsto validateprepare() -> compile_for_target()behavior.WASM docs/examples
bindings/wasm/README.mdandbindings/wasm/test.jsto show recommended usage: load policy/data →prepare()→clone()per request.