wangkun1210 opened issue #15141:
Feature
An Engine API that returns the precompile-compatibility contract as a
fixed-width value — something a build machine can write into artifact metadata
and a loader can compare before calling unsafe Module::deserialize.
To be clear about what this is not: I am not asking for a new loading
mechanism. I'm building a loader for applications delivered as several
independently-fetched artifacts, where each entry point fetches only the
subset it imports and instantiates them in dependency order. Every piece of
that already exists and works:
Engine::precompile_module / precompile_component at build time,
Module::deserialize / Component::deserialize at load time;Linker::instance with a per-provider namespace for core modules, and
component::Linker for components whose dependencies are declared as
imports rather than embedded;Component::component_type() → types::Component::imports()/exports(),
which is enough to check that a prospective wiring type-checks before
paying for instantiation.
So the shape is supported, and that's the part I expected to be the problem.
The gap is at one seam: the cache key.
Engine::precompile_compatibility_hash is the right thing to compare, but it
returns impl Hash + '_. Comparing two engines in one process is fine.
Comparing an artifact produced on the build machine against the engine on a
CDN edge is not: it requires picking a hasher (DefaultHasher in practice)
whose output stability is not documented, and whose result is not a value
anyone would want to store in a manifest.
Today I namespace the artifact cache by a hand-built string of my own —
wasmtime-<major>-<arch>-<profile> plus a hash of my Config — which is a
convention, not a guarantee. If I add a Config field that affects codegen
and forget to include it in that string, the result is not a cache miss. It's
an unsafe deserialize failure at request time, in production, discovered by
a user rather than by CI.
Concrete ask: a [u8; 32] (or hex String) representation of the same
contract, documented as stable across processes and between wasmtime versions
that agree on it, and guaranteed unchanged by any change that does not affect
deserialization compatibility. Keep precompile_compatibility_hash as it is
for in-process use.
Explicitly out of scope for this request: how to decide the split. Which
units exist is a producer-side decision; the engine only has to load them.Benefit
Anyone who precompiles off the build machine — which is the normal case for
anything larger than a single host, and the whole premise of shipping .cwasm
to a fleet — currently has to invent this value. A documented one turns two
things into checked facts instead of remembered conventions:
The safety precondition becomes verifiable. Module::deserialize is
unsafe because the artifact is only valid for a compatible Config,
wasmtime version, and target. With a fixed-width fingerprint, a loader can
return a Result on mismatch — "this artifact was built for a different
engine" — instead of relying on the caller having hashed the right things.
That is the difference between unsafe being justified and unsafe being
copy-pasted.Build pipelines can key on it. Artifact directories, CI caches, and OCI
layer annotations can be named by the real contract rather than by a
hand-rolled approximation of it.
The failure mode being prevented is quiet and expensive: a fingerprint that
drifts from Config produces an error only on the machines that actually run
the mismatched artifact.
Secondarily, a short example under examples/ would document the
split-artifact shape itself. I worked it out from component_type(),
Linker::instance naming rules, and the deserialize safety comments; as far
as I could tell it isn't written down anywhere, and I'd rather have pointed at
a 100-line example.Implementation
For the fingerprint, two levels of effort:
Minimal: document that running the existing
precompile_compatibility_hash through std::collections::hash_map::DefaultHasher
is the supported way to obtain a stable number, and state the stability
guarantee that currently isn't stated anywhere. Cheap, no API change — but
it makes DefaultHasher's output a compatibility contract, which is a
slightly odd thing to promise.Preferred: pub fn precompile_compatibility_fingerprint(&self) -> [u8; 32],
derived from the same internal state as precompile_compatibility_hash, with
a doc comment stating: stable for the life of a wasmtime major version, equal
across engines iff artifacts deserialize across them, and explicitly not a
build ID. Keep the Hash variant for in-process comparison so nothing breaks.
For the example, examples/split-deployment, two variants over the same little
dependency graph:
core modules — AOT-compile each with precompile_module, write to
<fingerprint>/<sha256 of input>, at load time deserialize only the modules
in one entry's closure, register each in a shared Linker under its
provider's namespace, instantiate in dependency order;components — the same, with each unit published as its own Component,
wired through component::Linker, and the closure checked with
component_type().imports() against each provider's exports() before
instantiation, so a bad closure fails at validation rather than at link.
I'm happy to send either as a PR if the shape is right; I'd rather not guess at
the naming or the docs placement.Alternatives
Keep hand-rolled fingerprints (status quo). Works until someone edits
Config. The failure is at deserialize time on a deployed edge, not at build
time. This is what everyone does today and it is the reason I'm filing.Key artifacts on wasmtime version + target triple only. The common
shortcut, and wrong on any non-default config — opt level, codegen flags, and
features that affect generated code all change the artifact's validity.Engine::detect_precompiled alone. Tells you the bytes are a wasmtime
artifact. Says nothing about whether this engine can load them, which is the
question that matters when a fleet is rolled out over hours.Treat the container image as the unit of deployment, so build and run
environments are committed together. Correct, and it's what a FROM
wasmtime/... does — but the artifact then stops being independently
portable, which defeats the point when the artifact is what gets distributed
to the edge.Compose everything into one artifact at build time (wasm-compose, or
just linking all the modules together). Removes the distribution problem
entirely, but gives up per-entry closures: the composed artifact contains
everything, so it is the single-binary case with extra steps.
pchickey closed issue #15141:
Feature
An Engine API that returns the precompile-compatibility contract as a
fixed-width value — something a build machine can write into artifact metadata
and a loader can compare before calling unsafe Module::deserialize.
To be clear about what this is not: I am not asking for a new loading
mechanism. I'm building a loader for applications delivered as several
independently-fetched artifacts, where each entry point fetches only the
subset it imports and instantiates them in dependency order. Every piece of
that already exists and works:
Engine::precompile_module / precompile_component at build time,
Module::deserialize / Component::deserialize at load time;Linker::instance with a per-provider namespace for core modules, and
component::Linker for components whose dependencies are declared as
imports rather than embedded;Component::component_type() → types::Component::imports()/exports(),
which is enough to check that a prospective wiring type-checks before
paying for instantiation.
So the shape is supported, and that's the part I expected to be the problem.
The gap is at one seam: the cache key.
Engine::precompile_compatibility_hash is the right thing to compare, but it
returns impl Hash + '_. Comparing two engines in one process is fine.
Comparing an artifact produced on the build machine against the engine on a
CDN edge is not: it requires picking a hasher (DefaultHasher in practice)
whose output stability is not documented, and whose result is not a value
anyone would want to store in a manifest.
Today I namespace the artifact cache by a hand-built string of my own —
wasmtime-<major>-<arch>-<profile> plus a hash of my Config — which is a
convention, not a guarantee. If I add a Config field that affects codegen
and forget to include it in that string, the result is not a cache miss. It's
an unsafe deserialize failure at request time, in production, discovered by
a user rather than by CI.
Concrete ask: a [u8; 32] (or hex String) representation of the same
contract, documented as stable across processes and between wasmtime versions
that agree on it, and guaranteed unchanged by any change that does not affect
deserialization compatibility. Keep precompile_compatibility_hash as it is
for in-process use.
Explicitly out of scope for this request: how to decide the split. Which
units exist is a producer-side decision; the engine only has to load them.Benefit
Anyone who precompiles off the build machine — which is the normal case for
anything larger than a single host, and the whole premise of shipping .cwasm
to a fleet — currently has to invent this value. A documented one turns two
things into checked facts instead of remembered conventions:
The safety precondition becomes verifiable. Module::deserialize is
unsafe because the artifact is only valid for a compatible Config,
wasmtime version, and target. With a fixed-width fingerprint, a loader can
return a Result on mismatch — "this artifact was built for a different
engine" — instead of relying on the caller having hashed the right things.
That is the difference between unsafe being justified and unsafe being
copy-pasted.Build pipelines can key on it. Artifact directories, CI caches, and OCI
layer annotations can be named by the real contract rather than by a
hand-rolled approximation of it.
The failure mode being prevented is quiet and expensive: a fingerprint that
drifts from Config produces an error only on the machines that actually run
the mismatched artifact.
Secondarily, a short example under examples/ would document the
split-artifact shape itself. I worked it out from component_type(),
Linker::instance naming rules, and the deserialize safety comments; as far
as I could tell it isn't written down anywhere, and I'd rather have pointed at
a 100-line example.Implementation
For the fingerprint, two levels of effort:
Minimal: document that running the existing
precompile_compatibility_hash through std::collections::hash_map::DefaultHasher
is the supported way to obtain a stable number, and state the stability
guarantee that currently isn't stated anywhere. Cheap, no API change — but
it makes DefaultHasher's output a compatibility contract, which is a
slightly odd thing to promise.Preferred: pub fn precompile_compatibility_fingerprint(&self) -> [u8; 32],
derived from the same internal state as precompile_compatibility_hash, with
a doc comment stating: stable for the life of a wasmtime major version, equal
across engines iff artifacts deserialize across them, and explicitly not a
build ID. Keep the Hash variant for in-process comparison so nothing breaks.
For the example, examples/split-deployment, two variants over the same little
dependency graph:
core modules — AOT-compile each with precompile_module, write to
<fingerprint>/<sha256 of input>, at load time deserialize only the modules
in one entry's closure, register each in a shared Linker under its
provider's namespace, instantiate in dependency order;components — the same, with each unit published as its own Component,
wired through component::Linker, and the closure checked with
component_type().imports() against each provider's exports() before
instantiation, so a bad closure fails at validation rather than at link.
I'm happy to send either as a PR if the shape is right; I'd rather not guess at
the naming or the docs placement.Alternatives
Keep hand-rolled fingerprints (status quo). Works until someone edits
Config. The failure is at deserialize time on a deployed edge, not at build
time. This is what everyone does today and it is the reason I'm filing.Key artifacts on wasmtime version + target triple only. The common
shortcut, and wrong on any non-default config — opt level, codegen flags, and
features that affect generated code all change the artifact's validity.Engine::detect_precompiled alone. Tells you the bytes are a wasmtime
artifact. Says nothing about whether this engine can load them, which is the
question that matters when a fleet is rolled out over hours.Treat the container image as the unit of deployment, so build and run
environments are committed together. Correct, and it's what a FROM
wasmtime/... does — but the artifact then stops being independently
portable, which defeats the point when the artifact is what gets distributed
to the edge.Compose everything into one artifact at build time (wasm-compose, or
just linking all the modules together). Removes the distribution problem
entirely, but gives up per-entry closures: the composed artifact contains
everything, so it is the single-binary case with extra steps.
pchickey commented on issue #15141:
This issue doesn't appear to comply with our policy on tool-generated content, and requires additional justification for why it is valuable enough to the project for us to review it. Please see our developer policy on AI-generated contributions: https://github.com/bytecodealliance/governance/blob/main/AI_TOOL_POLICY.md
We are happy to see the use of AI tools for translating to english for non-native-speakers, however, please include your human-written native language text before translation in a
<details>in order to demonstrate compliance with the rest of our policy.
Last updated: Nov 19 2026 at 20:05 UTC