Component output is not byte-reproducible for identical inputs
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Accessibilité débutants
- 35/100
- Type d'issue
- Bug
- Clarté
- À clarifier
- Activité
- Active
- Domaine
- build-system, tooling
Piste de recherche
Reproduisez le problème avec la commande sandbox.wit componentize-py et comparez les deux sorties complètes. Construisez ensuite une réduction minimale autour du chemin generated canonical-ABI post-return pour l’appel init imbriqué, en utilisant les différences relevées au niveau des sections et de la mémoire pour localiser la cause. Le travail est considéré comme terminé lorsqu’une cause racine est confirmée et que la portée du test de régression et du mode reproductible opt-in est approuvée par un maintainer.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Summary
Running componentize-py componentize twice with the same command and byte-identical
inputs can produce valid but byte-different WebAssembly components. This prevents use in
content-addressed build and artifact-verification pipelines.
I would like maintainer guidance on the shape of an opt-in reproducible-build mode before
opening the larger implementation PR. A small independent PR that makes WASI stub-adapter
emission deterministic is ready separately.
Reproduction
Using current main at aa3d6d1, Rust 1.95.0, WASI SDK 34, and the repository sandbox
example:
for output in first.wasm second.wasm; do
componentize-py \
-d sandbox.wit \
componentize \
--stub-wasi \
guest \
-o "$output"
done
shasum -a 256 first.wasm second.wasm
cmp first.wasm second.wasm
Expected: both files are byte-identical.
Actual: the files differ while remaining valid components.
Investigation
An experimental --reproducible implementation fixed or controlled all of the following:
- build-time secure and insecure randomness;
- build-time wall and monotonic clocks;
PYTHONHASHSEED;- CPython allocator initialization with
PYTHONMALLOC=malloc_debug; - bytecode cache writes;
- WASI stub-adapter map iteration order;
- metadata on generated helper, standard-library, bindings, and input trees.
Even with all of those controls, two current-main outputs still differed: one run produced
19,323,845 bytes, the other 19,325,725 bytes, with the first difference at component offset
9.
I then repeated the experiment with ambient user/system site-packages excluded and the
same input, generated bindings, bundled helpers, and standard library exposed through stable
host directories. The outputs still differed (292a9320... versus f35b0e6d...). Both had
the same 208-page memory and 1,710 data segments, but reconstructing linear memory from those
segments found roughly 4.1 million differing bytes across 141 pages.
The difference is localized more narrowly than an encoder or linker problem:
- both outputs contain 205 top-level component sections;
- 204 sections are byte-identical;
- only the first embedded core module differs;
- within that module, all type, import, function, table, global, export, and code sections are
byte-identical; - only the memory snapshot/data section differs.
Additional two-run probes showed identical values for Python string hashes, random, wall and
monotonic clocks, process/thread identity, visible directory ordering, generated Symbols, and
the component immediately before pre-initialization. Full linear-memory fingerprints taken
inside the guest were identical after app import and after every do_init phase (exports, type
tables, constructors, environment, runtime hooks, argv, and full-generation GC).
However, immediately after call_init returned through the Component Model boundary, before
component-init-transform measured globals or memory, the linear-memory fingerprints differed.
Disabling either or both WASI adapter/libc reset calls did not change that result. Ordering the
internal component-init-transform maps, reusing stable-inode directories, collecting Python
free lists after return through a second no-argument guest call, and retaining the Rust-level
app_name/Symbols values also did not fix it.
This localizes the remaining nondeterminism to the generated canonical-ABI post-return path for
the large nested init(app-name, symbols, stub-wasi) -> result<_, string> call (or allocator
state changed by that path), rather than Python initialization, component encoding, or snapshot
measurement. The current-main update moved from wit-bindgen 0.53.1 to 0.61.0 and Wasmtime 46.0.1
to 48.0.0; the exact responsible layer still needs a minimal reduction.
The experiment deliberately did not use post-generation byte rewriting or a volatile-byte
allowlist.
Proposed direction
- Add a regression test that componentizes one fixture twice and compares the complete
bytes. - Add an opt-in reproducible mode so existing build-time clock/random semantics do not
change by default. - Give pre-initialization fixed clocks, random sources, Python hash seed, allocator state,
and bytecode behavior in that mode. - Canonicalize generated directory metadata and provide input files through a staged or
virtualized tree. The implementation should not modify user source-file metadata. - Keep output ordering deterministic throughout stub generation and component encoding.
- Add a reduced test around the init canonical-ABI boundary. Candidate fixes include capturing
memory before post-return cleanup, making that cleanup allocator-deterministic, or changing
the private init protocol so the large nested argument graph does not leave volatile allocator
state in the captured memory. Any fix must preserve matching allocator globals and memory.
Would the maintainers prefer this as one opt-in feature PR, or as smaller PRs after the
stub-ordering fix?
Additional context
This was found while building a digest-pinned Python/WASI runtime. Reproducibility is a
supply-chain requirement there: the generated component digest is part of the runtime
identity, not merely a build-cache optimization.
- Langage dominant
- Rust
- Étoiles
- 284
- Forks
- 56
- Merge moyen
- 2 j 4 h
- PR mergées (30 j)
- 3
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Aucun modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de bytecodealliance/componentize-py
-
Difficulté 3/5 Une demi-journée Accessibilité débutants 40/100
bytecodealliance/componentize-py#259 · 1 commentaire ·
-
wasm32-wasip3 target uses WASI preview 2 bindingsPeut-être pris @Snowiiii l’a pris il y a 6 jours. Ouverte
Difficulté 4/5 3-5 jours Accessibilité débutants 25/100
-
Difficulté 3/5 1-2 jours Accessibilité débutants 57/100
bytecodealliance/componentize-py#253 · 1 commentaire ·
-
ModuleNotFoundError errorOuverte
Difficulté 3/5 1-2 jours Accessibilité débutants 68/100
bytecodealliance/componentize-py#217 · 6 commentaires ·
-
Difficulté 4/5 3-5 jours Accessibilité débutants 45/100
bytecodealliance/componentize-py#185 · 1 commentaire ·
Toutes les issues de bytecodealliance/componentize-py
Issues similaires
-
[Bug] AM Context Monitor (am-monitor): Session turns count is capped at 80 due to turns.slice(-80)Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 83/100
lbjlaq/Antigravity-Manager#4180 ·
Les mainteneurs répondent en général sous 1 jour
-
[BUG]: `unpinned-uses` reports a 64-character commit pin from a SHA-256 repository as unpinnedOuvertebug triage
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
zizmorcore/zizmor#2608 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 79/100
Les mainteneurs répondent en général sous 1 jour
-
RecompLauncher supportOuverte
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 83/100
longbridge/nsh#4201 ·
Les mainteneurs répondent en général sous 1 jour