feat(runtime): pluggable WASI clocks for deterministic guest time#200
Open
mfw78 wants to merge 1 commit into
Open
feat(runtime): pluggable WASI clocks for deterministic guest time#200mfw78 wants to merge 1 commit into
mfw78 wants to merge 1 commit into
Conversation
…t paths Add WasiClockOverride, a shared wall and monotonic clock source applied to every module store including the ones rebuilt on restart, so a test handle can drive guest-visible time. Omitting it leaves the ambient host clocks, keeping the default behaviour-neutral; RunId start stamps stay on the host wall clock. Expose it on the typed and preset builders via with_wasi_clocks, and ship a manually-driven ManualClock under a new test-utils feature.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #198. Part of the epic #80 train; merges in stack order behind
feat/m0-mock-backends.WasiCtxBuilder::{wall_clock, monotonic_clock}is the documented per-store virtualization point for deterministic guest time, butSupervisor::build_storealways took the ambient host defaults, so there was no way to run a module against a controlled clock. This becomes more load-bearing oncewasi:clocksis the only guest time source. This PR threads an optional clock override from the assembly through to every module store, defaulting to ambient behaviour, and ships aManualClocktest double.Changes
WasiClockOverride(Arc<dyn HostWallClock + Send + Sync>plusArc<dyn HostMonotonicClock + Send + Sync>) threaded from the builder assembly (AssembledRuntime.clocks, awith_wasi_clocksstage method onPresetBuilder/TypedBuilder) throughSupervisor::boot,boot_single,load_one, andreinstantiate_one.build_storeto every module store'sWasiCtxBuildervia by-valueSharedWallClock/SharedMonotonicClockadapters; the default isNoneeverywhere, leaving ambient host clocks untouched.reinstantiate_oneclones the stored override before the mutable reborrow so a restarted module reuses the same clock as the one it replaces.RunId::started_atcontinues to useSystemTime::now()on the host side, unchanged.ManualClockintest_utils/clock.rs(behind thetest-utilsfeature) withset(SystemTime)andadvance(Duration); monotonic time is non-decreasing (advanceonly, saturating), wall time clamps pre-epoch values to zero.bootstrap.rs,shepherd-cow-host/tests/cow_boot.rs, the ~13 sites insupervisor/tests.rs) to passNonefor the new parameter, and adde2e_manual_clock_override_boots_and_dispatchescovering the override path end to end.Test plan
cargo fmt --all --checkcargo clippy --workspace --all-targets --all-features -- -D warningscargo clippyon the crate withouttest-utils(confirms the new types add nothing to a production build)cargo test --workspace --all-features --no-fail-fast, includinge2e_manual_clock_override_boots_and_dispatches, the fourtest_utils::clockunit tests, and the pre-existingsupervisorsuite (184 passed, 0 failed innexum-runtime)Notes for reviewer
Nonefor the override, so behaviour is unchanged unless a caller opts in; the feature is inert by default.test_utils(andManualClockwithin it) stays behind thetest-utilsfeature, so it never reaches a normal build.mock_components_fromand the deletedempty_for_test, and extending the clock e2e test to assert guest-observed time (via a module that readswasi:clocksand reports it back) rather than only the host-side handle.AI Assistance: Claude Code (Opus 4.8 implementation and adversarial review, Sonnet 5 PR authoring) used for the full change.