Skip to content

wasm: read the clock through one helper, and test a commit on wasm32 - #41

Open
EnRaiha wants to merge 1 commit into
mainfrom
fix/wasm-commit-clock
Open

EnRaiha wants to merge 1 commit into
mainfrom
fix/wasm-commit-clock

Conversation

@EnRaiha

@EnRaiha EnRaiha commented Sep 23, 2026

Copy link
Copy Markdown

Problem

wasm32-unknown-unknown has no std clock. Two sites read it directly, and both sit in the commit path, so the first write from an embedded build panicked:

  • WriteTxn::commit builds CommitHistoryMeta, whose timestamp is the history entry's unix_seconds (src/txn/write/commit.rs:113).
  • The age-based retention policy computes its pruning threshold from the clock on every commit (src/txn/db/catalog/history.rs:151).

Observed under wasm-bindgen-test:

panicked at library/std/src/sys/time/unsupported.rs:35:9:
time not implemented on this platform

A consumer hits this today: NodeDB-Lite's WASM test array::create_put_slice_roundtrip fails at its first write for this reason.

Change

  • clock::unix_seconds() owns the target split: js_sys::Date::now() on the OPFS build, std everywhere else (wasm32-wasip1 included), and 0 for a wasm build without the JS bindings — the history ordering tolerates that instead of panicking.
  • The btree allocation-cost test keeps its loop on every target but runs the wall-clock bound only where a clock exists.
  • wasm-smoke/ is a separate crate because the pagedb dev-dependencies (tokio rt-multi-thread, tempfile) do not compile for wasm32, and Cargo builds every dev-dependency for a crate's test targets. Two tests: a commit, and a commit under age retention.
  • A wasm-tests CI job runs them under node, so the compile-only wasm job is no longer the last line of defence.

Crash point

Per CONTRIBUTING: the timestamp is metadata on the commit-history entry; the commit point is the A/B header write and is unchanged. A crash before the history write leaves the previous entry, after it the new one. Recovery does not read the clock.

Evidence

Check Result
Red: both smoke tests before the fix 2 failed, time not implemented on this platform
Green: both smoke tests after 2 passed
cargo check native / --target wasm32-unknown-unknown --features opfs / --target wasm32-wasip1 all clean
Graph: unix_seconds callers (c2g, exact) exactly the two sites named above, nothing else

Fixes #40.

wasm32-unknown-unknown has no std clock: SystemTime::now() panics with
"time not implemented on this platform". Two sites read it directly and
both sit in the commit path, so the first write from an embedded build
panicked:

- WriteTxn::commit builds CommitHistoryMeta, whose timestamp is the
  history entry's unix_seconds.
- The age-based retention policy computes its pruning threshold from the
  clock on every commit.

Route both through crate::clock::unix_seconds(): js_sys on the OPFS
build, std elsewhere (wasm32-wasip1 included), and 0 for a wasm build
without the JS bindings — the history ordering tolerates that instead of
panicking.

The btree allocation-cost test keeps its loop on every target but runs
the wall-clock bound only where a clock exists.

wasm-smoke/ is a separate crate because the pagedb dev-dependencies
(tokio rt-multi-thread, tempfile) do not compile for wasm32, and Cargo
builds every dev-dependency for a crate's test targets. Its two tests
fail with the panic above before this change and pass after; the new
`wasm-tests` CI job runs them under node, so the compile-only wasm job is
no longer the last line of defence.
Copilot AI lite review requested due to automatic review settings September 23, 2026 02:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wasm: every commit reads SystemTime::now() for the history entry \u2014 the first write panics

2 participants