Skip to content

MILAB-6145: propagate wasm deps through cached template upload path#1689

Open
blackcat wants to merge 1 commit into
mainfrom
MILAB-6145_pl-middle-layer-cached-wasm-propagation
Open

MILAB-6145: propagate wasm deps through cached template upload path#1689
blackcat wants to merge 1 commit into
mainfrom
MILAB-6145_pl-middle-layer-cached-wasm-propagation

Conversation

@blackcat

@blackcat blackcat commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Summary

  • flattenV3Tree in template_cache.ts previously had no handling for tpl.wasm — the loadTemplateCached path (used by dev-v2 blocks and others) silently stripped wasm field declarations during upload, leaving the backend's PlTemplateV1 resource with no wasm/<alias> fields. RuntimeV1.deps.Wasm was empty at render time, so plapi.loadWasm aborted with alias "<id>" is not a wasm dependency of this template even though the bytes were bundled in the block-pack.
  • Adds hashWasmV3, a processWasm helper, and the wasm field wiring in processTemplate, mirroring the handling already present in direct_template_loader_v3.ts.

Test plan

  • End-to-end smoke against a dev-v2 rarefaction block calling :pframes.build-query-wasm against a local source-built backend with wasm:v1 capability — block now reaches Done with outputErrors: false (previously failed with "alias is not a wasm dependency"). Both upload paths (loadTemplateCached here, direct_template_loader_v3.ts already wired) now create matching wasm/<alias> fields on the backend PlTemplateV1 resource.
  • CI runs against the rest of the suite.

Greptile Summary

This PR fixes a bug where flattenV3Tree in template_cache.ts silently discarded tpl.wasm entries, leaving PlTemplateV1 backend resources with no wasm/<alias> fields on the cached upload path. Blocks using plapi.loadWasm over the loadTemplateCached path therefore always aborted at render time with "alias is not a wasm dependency of this template".

  • Adds hashWasmV3 and a processWasm closure in flattenV3Tree, following the same seen-set deduplication and CacheableNode structure used for libs and software.
  • Wires wasm entries in processTemplate's child loop, appending wasm/<alias> fields to the template resource (matching PlTemplateV1.wasmPrefix) and including their hashes in the parent's hash composition.

Confidence Score: 5/5

Safe to merge — the change is a targeted additive fix that brings the cached upload path into parity with the direct loader path without touching any existing logic.

The new processWasm closure and hashWasmV3 function mirror the established patterns for processLib and processSoftware exactly: same seen-set deduplication, same CacheableNode with childHashes: [], same tx.createValue call, and same use of wasm.sourceHash as a proxy for source content. The field name wasm/ is derived from PlTemplateV1.wasmPrefix, matching both direct_template_loader_v3.ts and the backend Go constant. The wasm children are included in the parent template's hash composition, so the cache will correctly invalidate existing entries that are missing wasm fields.

No files require special attention.

Important Files Changed

Filename Overview
lib/node/pl-middle-layer/src/mutator/template/template_cache.ts Adds hashWasmV3, processWasm, and wasm-child wiring in flattenV3Tree — structurally correct, consistent with all sibling node types, and properly integrated into the hash and child-field plumbing.
.changeset/cached-wasm-template-propagation.md Changeset entry for @milaboratories/pl-middle-layer at patch level; description accurately captures the root cause and fix.

Sequence Diagram

sequenceDiagram
    participant Caller
    participant loadTemplateCached
    participant flattenV3Tree
    participant processTemplate
    participant processWasm
    participant materialize
    participant Backend

    Caller->>loadTemplateCached: spec (CompiledTemplateV3)
    loadTemplateCached->>flattenV3Tree: data
    flattenV3Tree->>processTemplate: data.template
    loop for each tpl.wasm entry
        processTemplate->>processWasm: wasm (TemplateWasmDataV3)
        processWasm-->>processTemplate: hash (CacheableNode added)
    end
    processTemplate-->>flattenV3Tree: rootHash
    flattenV3Tree-->>loadTemplateCached: nodes[]
    loadTemplateCached->>materialize: nodes, rootHash
    materialize->>Backend: createValue(PlWasmV1, base64Source)
    materialize->>Backend: createStruct(PlTemplateV1) + createField(wasm/alias)
    Backend-->>materialize: SignedResourceId
    materialize-->>loadTemplateCached: rootId
    loadTemplateCached-->>Caller: SignedResourceId
Loading

Reviews (1): Last reviewed commit: "MILAB-6145: propagate wasm deps through ..." | Re-trigger Greptile

flattenV3Tree in template_cache.ts previously had no handling for
tpl.wasm — the loadTemplateCached path (used by dev-v2 blocks) silently
stripped wasm field declarations during upload, leaving the backend's
PlTemplateV1 resource with no wasm/<alias> fields. RuntimeV1.deps.Wasm
was empty at render time, so plapi.loadWasm aborted with 'alias is not
a wasm dependency of this template' even though the bytes were bundled
in the block-pack.

Adds hashWasmV3, a processWasm helper, and wasm field wiring in
processTemplate, mirroring the handling already present in
direct_template_loader_v3.ts.
@changeset-bot

changeset-bot Bot commented Jun 8, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f54a040

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@milaboratories/pl-middle-layer Patch
@platforma-sdk/pl-cli Patch
@platforma-sdk/test Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@notion-workspace

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request ensures that WASM dependencies are correctly propagated through the cached template upload path. It introduces hashWasmV3, a processWasm helper, and wires WASM fields within processTemplate inside template_cache.ts to mirror the direct template loader's behavior. There are no review comments, so no feedback is provided.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@codecov

codecov Bot commented Jun 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 52.31%. Comparing base (21f3e16) to head (f54a040).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...iddle-layer/src/mutator/template/template_cache.ts 0.00% 11 Missing ⚠️

❌ Your patch check has failed because the patch coverage (0.00%) is below the target coverage (50.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1689      +/-   ##
==========================================
+ Coverage   52.26%   52.31%   +0.05%     
==========================================
  Files         273      273              
  Lines       16207    16218      +11     
  Branches     3522     3524       +2     
==========================================
+ Hits         8470     8484      +14     
+ Misses       6599     6594       -5     
- Partials     1138     1140       +2     

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

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

4 participants