Skip to content

MILAB-6145: !!!EXPERIMENTAL DON'T MERGE!!! add :pframes.build-query-wasm (opt-in wasm-backed buildQuery)#1685

Draft
blackcat wants to merge 4 commits into
mainfrom
MILAB-6145-buildQuery-wasm
Draft

MILAB-6145: !!!EXPERIMENTAL DON'T MERGE!!! add :pframes.build-query-wasm (opt-in wasm-backed buildQuery)#1685
blackcat wants to merge 4 commits into
mainfrom
MILAB-6145-buildQuery-wasm

Conversation

@blackcat

@blackcat blackcat commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Introduces @platforma-sdk/workflow-tengo:pframes.build-query-wasm — a sibling library to :pframes.build-query that routes through the @milaboratories/pframes-rs-wasip2 wasm component, so the SpecQueryJoinEntry tree is built by the rust source-of-truth (pframes-rs/packages/spec/src/requests/build_query/{logic,request}.rs).
  • Public API mirrors :pframes.build-query exactly: buildQuery(input) -> map.
  • The pure-Tengo :pframes.build-query is unchanged and remains the entry point used by :pframes.build-table. Callers opt in to the wasm version by importing the new lib directly.

Why a sibling library, not an in-place swap

Earlier attempts inlined the wasm call directly in :pframes.build-query. That made every block transitively bundle the pframes-rs-wasip2 wasm bytes (via workflow/index.lib.tengo:pframes.table-builder:pframes.build-table.tpl:pframes.build-query). The bundled .plj.gz then exposed a divergence between pl-middle-layer's cached and legacy template upload paths — template-cache-v3.test.ts > cached and legacy templates deduplicate to same original (V3) failed deterministically because the two paths produce different content hashes for wasm-bundled packs.

Scoping the change to an opt-in sibling library avoids that. The pl-middle-layer template cache can be addressed separately.

Impl details

  • Lazy-init of the wasm api: renders that import the lib but never call buildQuery pay no Store-allocation cost. Within a render, repeated calls share one Store + Instance.
  • Wasm-side serde requires spec on every linker/filter step's ColumnIdAndSpec, but BuildQuery::execute() reads only columnId. The new lib stamps a synthetic placeholder spec on steps that omit it; matches the tolerance of the pure-Tengo lib.

Test plan

  • pnpm build --filter='@platforma-sdk/workflow-tengo' --filter='@platforma-sdk/workflow-tengo-tests' — green.
  • Added build-query-wasm.tpl.tengo + a parallel buildQuery (wasm lib) loop in tests/workflow-tengo/src/pframes/build-query.test.ts. Every existing fixture (direct column, qualified, single filter, linker chain, mixed paths, multi-filter right-fold, filter-then-linker, three-step chain) is now cross-checked against the wasm SpecDriver byte-for-byte for both libs.

@notion-workspace

Copy link
Copy Markdown

@changeset-bot

changeset-bot Bot commented Jun 5, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 750480e

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

This PR includes changesets to release 10 packages
Name Type
@platforma-sdk/workflow-tengo Minor
@milaboratories/pl-middle-layer Patch
@milaboratories/milaboratories.monetization-test.workflow Patch
@milaboratories/milaboratories.ui-examples.workflow Patch
@milaboratories/milaboratories.pool-explorer.workflow Patch
@platforma-sdk/pl-cli Patch
@platforma-sdk/test Patch
@milaboratories/milaboratories.monetization-test Patch
@milaboratories/milaboratories.ui-examples Patch
@milaboratories/milaboratories.pool-explorer 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

@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 migrates the buildQuery function from a pure-Tengo implementation to a WASM-based implementation calling into the @milaboratories/pframes-rs-wasip2 component, and removes the Tengo-side unit tests. A critical issue was identified in the new implementation where the multiple return values of json.encode and json.decode are not handled correctly, which will cause runtime or compilation errors.

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.

Comment thread sdk/workflow-tengo/src/pframes/build-query.lib.tengo Outdated
Comment thread .changeset/buildquery-wasm.md Outdated
Comment thread sdk/workflow-tengo/src/pframes/build-query.lib.tengo Outdated
@codecov

codecov Bot commented Jun 5, 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.22%. Comparing base (c9dccff) to head (750480e).
⚠️ Report is 48 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 ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1685      +/-   ##
==========================================
- Coverage   52.31%   52.22%   -0.09%     
==========================================
  Files         273      273              
  Lines       16201    16218      +17     
  Branches     3523     3524       +1     
==========================================
- Hits         8475     8470       -5     
- Misses       6588     6610      +22     
  Partials     1138     1138              

☔ 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.

…uery

Introduces a sibling library to `:pframes.build-query` that routes
through the `@milaboratories/pframes-rs-wasip2` wasm component, so the
SpecQueryJoinEntry tree is built by the rust source-of-truth
(pframes-rs/packages/spec/src/requests/build_query/{logic,request}.rs).
Public API mirrors the pure-Tengo lib exactly: `buildQuery(input) -> map`.

Why a separate lib rather than swapping the impl behind the same path:
`:pframes.build-query` is transitively imported by `:pframes.build-table`,
which is reachable from `workflow/index.lib.tengo`. Adding the wasm
import there bundles the pframes-rs-wasip2 wasm bytes into every block's
`.plj.gz`, which exposes a divergence between pl-middle-layer's cached
and legacy template upload paths (different content hashes for the
same wasm-bundled pack — confirmed by template-cache-v3.test.ts). Keep
the migration scoped: pure-Tengo entry point remains the default;
callers can opt in to the wasm-backed lib explicitly. The pl-middle-layer
template cache can be addressed separately.

Impl notes:
- Lazy-init the wasm api so renders that import the lib but never call
  buildQuery pay no Store-allocation cost.
- Wasm-side serde requires `spec` on every linker/filter step's
  ColumnIdAndSpec, but BuildQuery::execute() reads only columnId. Stamp
  a synthetic placeholder spec on steps that omit it; matches the
  tolerance of the pure-Tengo lib.
- Added build-query-wasm.tpl.tengo + a parallel "buildQuery (wasm lib)"
  loop in build-query.test.ts so every fixture is cross-checked against
  the SpecDriver byte-for-byte for both libs.
@blackcat blackcat force-pushed the MILAB-6145-buildQuery-wasm branch from 3211b9d to 4cb4fc0 Compare June 5, 2026 17:41
@blackcat blackcat changed the title MILAB-6145: route pframes.build-query through the wasm component MILAB-6145: add :pframes.build-query-wasm (opt-in wasm-backed buildQuery) Jun 5, 2026
Adds wasm.pframes-rs-inner — an outer template that delegates to
wasm.pframes-rs-inner-body via render.create. The inner template's body
makes the same assets.importWasm + frame.buildQuery call that
wasm.pframes-rs.tpl.tengo makes directly. Tengo-builder bundles the
same wasm bytes into the same pack.

The hypothesis: per-render Wasm map the workflow controller builds at
compileTemplate time is scoped to the outermost rendered template
only; nested renders launched via render.create see an empty Wasm map
even though tengo-builder declares the dep at the pack level. The
direct test passes because it makes the wasm call in the outer
template's own body. The nested test should fail with "alias … is not
a wasm dependency of this template".

Observed symptom in rarefaction (blocks/rarefaction adapted to call
:pframes.build-query-wasm in wf.body): same error message, same call
shape. If this test fails as predicted, the dep propagation through
nested renders is the right level to fix.
@blackcat blackcat marked this pull request as draft June 8, 2026 19:55
@blackcat blackcat changed the title MILAB-6145: add :pframes.build-query-wasm (opt-in wasm-backed buildQuery) MILAB-6145: !!!EXPERIMENTAL DON'T MERGE!!! add :pframes.build-query-wasm (opt-in wasm-backed buildQuery) Jun 8, 2026
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