← Back to Pull requests

feat: add a cache of compiled Wasm modules #4869

Closed
unknown closed this pull request without merging on Nov 28, 2026 19:32 UTC
View on GitHub
unknown unknown commented on Nov 25, 2026 01:01 UTC
Author

What type of PR is this?

/kind feature

What this PR does / Why we need it:

Adds pkg/util/wasm, a fixed size, least recently used cache of compiled Wasm (Extism) modules, for Wasm allocation actions (#4151).

An allocation can name a Wasm module by URL. Downloading and compiling it on every allocation would be far too slow, so the allocator will keep compiled modules in this cache:

  • A module is downloaded and compiled the first time it is called. Later calls reuse it.

  • Modules are keyed by URL, hash and CA bundle, so changing any of them loads a new module.

  • Every call gets its own instance, as Extism instances are not thread safe, and is limited to 5 seconds.

  • Each Call sets the policy's config on its instance, so policies that share a module can use different config.

  • Concurrent first calls for the same module share one download and compile (singleflight), and different modules load in parallel, so a slow or unreachable URL only holds up calls that use that module.

  • A call stops waiting for a load when its context is done, while the load carries on for the other calls waiting on it, so one cancelled allocation does not fail the others.

  • When a module is evicted it is closed in the background, once any calls that are using it finish. A call that finds its module was closed between loading and calling it loads the module again, until its context is done. Call checks its context before each attempt, so it does not run a plugin for a caller that has given up, or keep reloading a module that is evicted each time (possible when the cache is much smaller than the number of modules in use).
  • Nothing uses the cache yet. The allocator will in a later PR, with a flag and Helm setting for the cache size. github.com/tetratelabs/wazero and golang.org/x/sync move to direct dependencies. Both were already vendored, so vendor/ only gains golang.org/x/sync/singleflight.

    Which issue(s) this PR fixes:

    Work on #4151

    Did you use AI tools in preparing this PR?:

    Y

    Special notes for your reviewer:

    Have a look at the timeouts for fetch and call. I think they are fine, but would like a second opinion.
    I don't think we'll use this for FleetAutoscaling, as there is a natural 1:1 relationship between a FleetAutoscaler and it's wasm modules, which makes that much simpler.

    Diff: 302 lines (+226 / -76) across 3 files Reviewer: markmandel Review duration: 5431m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.40) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 302 lines diff across 3 files
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.342
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #4869"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 40.1% (MEDIUM) · Higher = larger blast radius
    40.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17.3% · Safe to merge
    17.3%