test(wasm): cooperative-timer parity probes for sleep and actor periodic timers - #2869
test(wasm): cooperative-timer parity probes for sleep and actor periodic timers#2869gertybotbot wants to merge 1 commit into
Conversation
…dic timers WASM timers are cooperative: sleep parks at the message boundary and time advances through hew_wasm_timer_tick (hew-runtime/src/scheduler_wasm.rs). Nothing in the WASI e2e suite exercised that path. Add two native<->wasm probe pairs: * Top-level sleep parks and resumes, and the wasm program terminates with byte-identical stdout to native. Real parity. * An actor #[every] periodic handler DOES fire under wasm, but the program never reaches quiescence: with no host driving hew_wasm_timer_tick the periodic queue keeps the scheduler permanently non-quiescent, so hew run has to kill it via --timeout. Native runs the same program to completion. This is a genuine native<->wasm divergence, so the probe pins the divergence rather than asserting a parity that does not hold; the assertion message tells a future fixer to promote it to a stdout parity case in the same commit. Test-only; no runtime or compiler behaviour is changed. Refs hew-lang#1964
b575e9c to
72d6058
Compare
|
Head
Root cause is structural, not an assertion weakness: nothing drives Probe (b) is sound. Suggested resolution: drop the two sleep probes, ship probe (b) alone, and narrow #1964 accordingly — or hold this PR for a host-side harness that drives The 9/9 green checks are not evidence against this: a tautological assertion is green by construction. |
Closes #1964.
Venue correction
The issue asks for the probes in
hew-sandbox-wasm/tests/parity_ratchet.rs. That crate can't host them: it has nohew-runtimedependency and compiles Hew to sandbox bytecode for the TypeScript VM (hew-sandbox-vm), wheresleepis a virtual clock (sleepVirtual) with no host tick.hew_wasm_timer_tickis unreachable from there.The real wasm32 execution harness is
hew-cli/tests/wasi_run_e2e.rs(compiles towasm32-wasi, runs underwasmtime, links the actualhew-runtime). The probes go there, matching that file's existing pairedwasm_*_run_pass/native_*_matches_wasi_outputidiom.What's covered
(a) Plain
sleeptimeout — real parity. A top-levelsleep(50ms)parks at the message boundary and resumes; the wasm program terminates with stdout byte-identical to native.wasm_cooperative_sleep_parks_and_resumes+native_cooperative_sleep_matches_wasi_output.(b) Actor periodic timer — pinned divergence. An
#[every(20ms)]handler does fire under wasm (~249 ticks in 5s), but the program never reaches quiescence: with no host drivinghew_wasm_timer_tick, the periodic queue keeps the scheduler permanently non-quiescent andhew runmust kill it via--timeout. Native runs the same program to completion and exits 0.This is a genuine native↔wasm divergence, so I pinned the divergence instead of asserting a parity that doesn't hold. The failure message instructs a future fixer to promote the probe to a stdout-parity case in the same commit that fixes quiescence — the test fails loudly if the runtime is fixed, so it can't rot into a stale allowance.
The probe deliberately avoids
awaitinside the actor: that's still gated on wasm (WASM-TODO(#1451)—hew_await_cancel_schedule_deadline_ms), so an ask-based variant fails at codegen and proves nothing about the timer.Revert-control evidence
Both pairs were mutated to confirm they exercise the path rather than passing tautologically:
COOPERATIVE_SLEEP_EXPECTED→"before\n"(as if the park never resumed)#[every(20ms)]from the periodic actorthe native periodic handler never fired; wasm reaches quiescence so the divergence assertion breaks)Verification
cargo test -p hew-cli --test wasi_run_e2e— 14 passed, 0 failed; run twice, no flake.cargo fmt --check -p hew-cli— clean.cargo clippy -p hew-cli --tests— clean.Test-only diff (+187 lines, one file). No runtime or compiler behaviour changed.