From 7bee269c4d6c48c805bba45859c8df48e27ea856 Mon Sep 17 00:00:00 2001 From: Trevor Brown Date: Sat, 31 Oct 2026 10:58:09 -0400 Subject: [PATCH 1/2] M8: posting a comment in the browser no longer stops the app (#1764) The event log read the clock through std::time::SystemTime and Instant, which panic on wasm32-unknown-unknown ("time not implemented on this platform"). Every mutating comment.* command appends an event, so the first comment posted in the web build hit it. The log now takes SystemTime, UNIX_EPOCH and Instant from web_time, as the rest of the engine does. A test checks the stamp is a current Unix time read through the same clock. Co-Authored-By: Claude Fable 5.1 --- crates/engine/src/events.rs | 6 +++++- crates/engine/src/events_tests.rs | 12 ++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/events.rs b/crates/engine/src/events.rs index fbc1b9b6c..328d6ba5e 100644 --- a/crates/engine/src/events.rs +++ b/crates/engine/src/events.rs @@ -7,10 +7,14 @@ use std::collections::VecDeque; use std::sync::{Condvar, Mutex, PoisonError}; -use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH}; +use std::time::Duration; use serde::Serialize; use serde_json::Value; +// The browser build has no `std` clock: `std::time::SystemTime::now()` panics on +// wasm32-unknown-unknown ("time not implemented on this platform"), and every `comment.*` command +// stamps an event. `web_time` is `std::time` on native targets and the JavaScript clock on wasm. +use web_time::{Instant, SystemTime, UNIX_EPOCH}; /// Most events kept; the oldest are dropped. pub const MAX_EVENTS: usize = 1024; diff --git a/crates/engine/src/events_tests.rs b/crates/engine/src/events_tests.rs index 36b118a79..ad20974c5 100644 --- a/crates/engine/src/events_tests.rs +++ b/crates/engine/src/events_tests.rs @@ -44,6 +44,18 @@ fn events_keep_sequence_and_filter_topics() { assert_eq!(r.events[0].kind, "document.changed"); } +#[test] +fn events_are_stamped_with_the_wall_clock() { + // The stamp is read through `web_time`, the clock the browser build has as well: with + // `std::time::SystemTime` every comment posted on the web panicked (#1764). + let log = EventLog::default(); + log.push("comment.added", "Doc", None, json!({"commentId": 1})); + let r = log.poll(0, &comments(), 10, Duration::ZERO); + let now = web_time::SystemTime::now().duration_since(web_time::UNIX_EPOCH).unwrap().as_secs_f64(); + let time = r.events[0].time; + assert!(time > 1_700_000_000.0 && time <= now, "{time} is seconds since the Unix epoch, read just before {now}"); +} + #[test] fn a_poll_wakes_for_a_push() { let log = Arc::new(EventLog::default()); From 12c9acbf0cf4a12d632c7a73617161aa3e02f6bb Mon Sep 17 00:00:00 2001 From: Trevor Brown Date: Sun, 1 Nov 2026 00:17:54 -0400 Subject: [PATCH 2/2] events test: the stamp is within a minute of a second clock read, not ordered against it Review follow-up on #1766: a backward wall-clock step between the push and the test read made the ordering assertion flaky. Co-Authored-By: Claude Fable 5.1 --- crates/engine/src/events_tests.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/events_tests.rs b/crates/engine/src/events_tests.rs index ad20974c5..304a8f8d1 100644 --- a/crates/engine/src/events_tests.rs +++ b/crates/engine/src/events_tests.rs @@ -53,7 +53,8 @@ fn events_are_stamped_with_the_wall_clock() { let r = log.poll(0, &comments(), 10, Duration::ZERO); let now = web_time::SystemTime::now().duration_since(web_time::UNIX_EPOCH).unwrap().as_secs_f64(); let time = r.events[0].time; - assert!(time > 1_700_000_000.0 && time <= now, "{time} is seconds since the Unix epoch, read just before {now}"); + // Within a minute of the same clock read afterwards (not ordered: the wall clock can step). + assert!(time > 1_700_000_000.0 && (time - now).abs() < 60.0, "{time} is seconds since the Unix epoch, read next to {now}"); } #[test]