Skip to content

Fix(cel): bound an expression's evaluation by cost and by its caller's context - #156

Open
briankane wants to merge 1 commit into
kubevela:mainfrom
briankane:release-1.12/fixes
Open

briankane wants to merge 1 commit into
kubevela:mainfrom
briankane:release-1.12/fixes

Conversation

@briankane

@briankane briankane commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Description of your changes

Bounds a CEL expression's evaluation. Found in the v1.12 release testing.

  • Fix(cel): bound an expression's evaluation by cost and by its caller's context

An expression now stops at a cost limit of 1,000,000 and when its caller's context is cancelled, instead of
running for as long as it takes. kubevela/kubevela picks this up for the 1.12 release.

How has this code been tested

Unit tests for the cost limit and for cancellation, red before the fix and green after; the package suites pass
(envtest 1.37.0).


Summary by cubic

Bounds CEL expression evaluation so expensive expressions stop at a cost limit and respect their caller's context instead of running to completion. Evaluation now fails with "expression exceeds the evaluation cost limit" when it passes 1,000,000 (the per-expression limit Kubernetes sets for CRD validation rules), and Plan.Eval aborts early when its context is cancelled. Adds tests covering the cost limit and cancellation for previously unbounded evaluations.

Written for commit c361028. Summary will update on new commits.

View guided diff

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 4 files

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Comment thread cel/engine.go Resolved
@codecov

codecov Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.57143% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.54%. Comparing base (ed78b6e) to head (c361028).

Files with missing lines Patch % Lines
cel/eval.go 75.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #156      +/-   ##
==========================================
- Coverage   92.58%   92.54%   -0.04%     
==========================================
  Files         115      115              
  Lines        6929     6937       +8     
==========================================
+ Hits         6415     6420       +5     
- Misses        514      517       +3     
Flag Coverage Δ
unit-test 92.54% <78.57%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 1 file (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="cel/engine.go">

<violation number="1" location="cel/engine.go:82">
P3: This says every compiled program is cached, but typed-environment programs are recompiled instead. Qualify the statement so readers do not infer that a `CostLimit` change has the same cached-program behavior for every environment.</violation>
</file>

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Comment thread cel/engine.go Outdated
Comment on lines +82 to +83
// program, which is cached, so a host that changes it does so at startup, before
// any expression is compiled.

@cubic-dev-ai cubic-dev-ai Bot Nov 16, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: This says every compiled program is cached, but typed-environment programs are recompiled instead. Qualify the statement so readers do not infer that a CostLimit change has the same cached-program behavior for every environment.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At cel/engine.go, line 82:

<comment>This says every compiled program is cached, but typed-environment programs are recompiled instead. Qualify the statement so readers do not infer that a `CostLimit` change has the same cached-program behavior for every environment.</comment>

<file context>
@@ -78,8 +78,9 @@ const (
-// sets for CRD validation rules. It is process-wide and read when an expression
-// is compiled, so a host that changes it does so before the first evaluation.
+// sets for CRD validation rules. It is process-wide and fixed into each compiled
+// program, which is cached, so a host that changes it does so at startup, before
+// any expression is compiled.
 var CostLimit uint64 = 1_000_000
</file context>
Suggested change
// program, which is cached, so a host that changes it does so at startup, before
// any expression is compiled.
// program. Programs for the dynamic environment are cached; typed-environment
// programs are not, so hosts should set it at startup, before any expression
// is compiled.
Fix with cubic

…s context

An expression ran to completion however long it took, ignoring every
deadline, so a costly one held a CPU in the webhook or a controller
until it finished.

Programs are compiled with a runtime cost limit, CostLimit (1,000,000,
the per-expression limit Kubernetes sets for CRD validation rules), and
an interrupt check, and Plan.Eval runs under its caller's context. An
evaluation past the limit fails with "expression exceeds the
evaluation cost limit"; one whose context is done fails wrapping the
context's error. Cost tracking adds about a microsecond or a few to an
evaluation in the package's benchmarks.

Signed-off-by: Brian Kane <briankane1@gmail.com>
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.

1 participant