WASI clocks: let embedders supply the wall and monotonic clocks, and the timer behind `subscribe-instant`/`subscribe-duration`, through the C API (for deterministic replay)
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 12/100
Línea de trabajo
Start at crates/c-api/include/wasi.h and the existing wasi_config_* code, comparing them with the Rust WasiCtxBuilder wall_clock/monotonic_clock methods. Read crates/wasi/src/p2/host/clocks.rs to see how subscribe_instant and subscribe_duration schedule waits and where the configured clock is not used for the sleep. Done means either C API clock setters plus a timer hook so subscriptions follow the configured clock, or a supported C API way to create/wrap the host pollable; verify with a replaying component.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
The use case. We embed wasmtime, through the C API and the Go bindings, to run components (CPython built with componentize-py, and .NET built with componentize-dotnet) that are replayed: an execution is re-run from a recorded history, and must observe exactly what it observed the first time. For that, every source of non-determinism the guest can reach has to be supplied by the host. Today we handle wasi:clocks/wall-clock and wasi:random/* by defining replacement functions on the component linker. wasi:clocks/monotonic-clock is the gap. A guest's time.monotonic() or Stopwatch reads the host's real monotonic clock, so a replay observes different values. For example, two runs of the same execution read 0.5029 s and 0.5021 s across the same 0.5 s sleep, and a "loop until a deadline" ran 41 times and then 42.
Why an embedder can't fix this from the C API today.
- There is no clock setter in the C API. The Rust
WasiCtxBuilderhaswall_clock(impl HostWallClock)andmonotonic_clock(impl HostMonotonicClock). The C API'swasi_config_*functions (crates/c-api/include/wasi.hon main) cover argv, env, stdio, preopens and the network, but not clocks. - Shadowing the interface on the linker doesn't work for monotonic-clock. We tried defining replacements with
wasmtime_component_linker_instance_add_func. Replacingnowandresolutionalone fails at instantiation for a CPython component (component imports instance wasi:clocks/[email protected], but a matching implementation was not found in the linker), because the guest also importssubscribe-instantandsubscribe-duration. Those returnwasi:io/poll'spollable, a resource owned by wasmtime-wasi's own implementation. The C API'swasmtime_component_linker_instance_add_resourcelets an embedder define its own resource type, but not construct the host'spollablethatwasi:io/poll#polland the stream types consume. Replacing monotonic-clock therefore means replacingwasi:io/polland everything that produces pollables. - A custom monotonic clock wouldn't make sleeps consistent anyway, even in Rust. Reading
crates/wasi/src/p2/host/clocks.rson main:subscribe_instantuses the configured clock'snow()to compute a duration, but the wait itself issubscribe_to_duration, which builds atokio::time::Instantdeadline andsleep_untils on real time.subscribe_durationdoesn't consult the configured clock at all. So with a virtual clock, a guest that sleeps 0.5 s still waits 0.5 s of real time while its clock reports something else. We hit the same inconsistency in our preview1 integration: a virtual clock that advanced one fixed step per read made a Go guest's 500 ms sleep take 62.5 s of real time, because the guest slept in real time and woke believing only one step had passed.
The ask, in increasing order of scope:
- C API clock setters on
wasi_config_t, mirroring the Rust builder:wasi_config_set_wall_clock(config, now_cb, resolution_cb, data, finalizer)andwasi_config_set_monotonic_clock(config, now_cb, resolution_cb, data, finalizer). - Make monotonic-clock subscriptions follow the configured clock. One way is an optional timer hook alongside
HostMonotonicClock, for example "when should a pollable subscribed for instant/duration X become ready". An embedder with a virtual clock could then make a sleep complete immediately while advancing the clock by its duration, or complete it at a recorded point. The default would stay as today, a tokio sleep on real time. A C-callback form of the hook would be needed for (1) to be useful to C API embedders. - Alternatively, a supported way for an embedder to create, or wrap, the host's
wasi:io/pollpollablefrom the C API, so a replacement monotonic-clock interface can return pollables the rest of WASI accepts.
Any of (1)+(2) or (3) would let C API embedders run replayable components without forking wasmtime-wasi. We're happy to test a branch.
Environment. wasmtime 48 through the Go bindings (wasmtime-go); the statements about main are from reading the source on 2026-11-23. The guests are componentize-py 0.25.1 (CPython 3.14) and componentize-dotnet (NativeAOT-LLVM). aarch64 and x86_64 Linux.
- Lenguaje dominante
- Rust
- Estrellas
- 18.9k
- Forks
- 2k
- Merge medio
- 1 d 6 h
- PR fusionados (30 d)
- 238
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de bytecodealliance/wasmtime
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
bytecodealliance/wasmtime#15536 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
bytecodealliance/wasmtime#15455 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
wasi-preview1-component-adapter: fd_write does not invalidate cached InputStream, causing stale readsPosiblemente ocupada @dpfens la tomó hace 13 días. Abiertowasi
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
bytecodealliance/wasmtime#15296 ·
Los mantenedores suelen responder en 1 día
-
bug wasm-proposal:exceptions wasmtime:debugging
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
bytecodealliance/wasmtime#14102 ·
Los mantenedores suelen responder en 1 día
-
wasm-proposal:gc
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
bytecodealliance/wasmtime#13808 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de bytecodealliance/wasmtime
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
area: plugins bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
clipy-recorder/clipy#1039 ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
valkey-io/valkey-glide#7975 ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
gofractally/psibase#2379 ·
Los mantenedores suelen responder en 3 días
-
Qwen stream parser: a chunk with "error": null is treated as a stream errorPosiblemente ocupada @Beehtrix la tomó hoy. Abiertoarea:models bug good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
brekkylab/ailoy#681 · 1 comentario ·
Los mantenedores suelen responder en 2 días