Skip to content

feat(expression): evaluation budget (max steps, max interval length) - #563

Open
WePlus-Particle wants to merge 3 commits into
gorules:masterfrom
WePlus-Particle:feat/expression-budget
Open

WePlus-Particle wants to merge 3 commits into
gorules:masterfrom
WePlus-Particle:feat/expression-budget

Conversation

@WePlus-Particle

Copy link
Copy Markdown

Part 2 of #561 (expressions); part 1 is #562.

New EXPRESSION_CONFIG in zen-expression, re-exported by zen-engine, with two global limits that default to 0 = no limit, so nothing changes for existing users:

Limit Bounds
max_steps VM instructions executed by one evaluation. Loops (map, filter, some, …) run a few instructions per element, so this bounds both the time and the memory a loop can take
max_interval_length elements an interval [a..b] may be expanded to when it is iterated. Membership tests (x in [a..b]) do not expand the interval and are not affected
  • When a limit is exceeded the evaluation fails with VMError::BudgetExceeded { budget, limit } ("Evaluation budget exceeded: steps over 5000").
  • The step counter is one u64 increment per instruction and is skipped entirely when max_steps is 0.
  • VmInterval::len() computes the size of the expansion without allocating, so an oversized interval is rejected before any memory is used.
  • Exposed in the Node and uniffi bindings as expressionMaxSteps and expressionMaxIntervalLength (override_config).
  • README of zen-expression: "Evaluation budget" section; zen-engine README points to it.

Test: evaluation_budget_limits_steps_and_intervals in core/expression/tests/isolate.rs covers no limit, the step limit, the interval limit, and in on an interval staying unaffected. Full zen-expression and zen-engine suites green; zen-nodejs and zen-uniffi compile.

New EXPRESSION_CONFIG in zen-expression, re-exported by zen-engine, with two global limits that default to 0
(no limit, the historical behaviour):

- max_steps: VM instructions executed by one evaluation; loops run a few instructions per element, so this
  bounds the time and the memory a map/filter/... can take;
- max_interval_length: elements an interval [a..b] may be expanded to when it is iterated. Membership tests
  (x in [a..b]) do not expand the interval and are not affected.

When a limit is exceeded the evaluation fails with VMError::BudgetExceeded. Exposed in the Node and uniffi
bindings as expressionMaxSteps and expressionMaxIntervalLength.

Refs gorules#561
"Failed to evaluate expression: ..." dropped the underlying VM error, so a caller could not tell a budget
error (or any other evaluation error) from a malformed expression. The reason is now appended, as the other
nodes already do with node_context_message.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants