You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(api): add node.timestamp() accessor for the node's HLC (rescue of #1789)
Rescues @oceanusxiv's #1789 against current main. The PR sat for 18 days
with no reviews and trivially-clean cherry-pick against `main`, so this
is a near-verbatim re-application plus expanded docstrings and a
regression test.
Why
===
`DoraNode` already maintains an internal `uhlc::HLC` clock that stamps
every outgoing message, but user code had no way to read that clock
directly. Without this method, a node that wants to measure per-event
processing latency has to fall back to `std::time::SystemTime::now()` —
a different physical clock from the HLC, so subtracting that from
`event.metadata.timestamp` is meaningless across daemons.
Three concrete use cases motivated #1789:
1. `latency = node.timestamp() - event.metadata.timestamp` measured
against the same clock dora's data plane uses.
2. Correlating log lines / external observations with the HLC.
3. Profiling node processing time without introducing a second
clock source.
What's added
============
* `apis/rust/node/src/node/mod.rs` — `DoraNode::timestamp() ->
uhlc::Timestamp`. Single-line body: `self.clock.new_timestamp()`.
Docstring spells out the "use this against `event.metadata.timestamp`,
NOT against `SystemTime::now()`" rule.
* `apis/python/node/src/lib.rs` — `Node.timestamp() -> datetime.datetime`.
Converts HLC physical time to a UTC-aware `datetime`. The Python
docstring explicitly notes the resolution caveats (microsecond
precision, HLC logical counter dropped) and points strict-ordering
callers at the Rust API.
* `apis/python/operator/src/lib.rs` — promote `datetime_module()` from
private to `pub` so the node crate can reuse the cached
`PyModule::import("datetime")` instead of re-importing on every
call. Same cache pattern dora already uses for its own outgoing
metadata conversions in the operator crate.
* `apis/python/node/dora/__init__.pyi` — type stub for `timestamp()`.
What was added on top of #1789
==============================
* Expanded both docstrings to call out the load-bearing "use the HLC,
not SystemTime" guidance and the Python resolution caveats.
* New regression test
`node::tests::timestamp_uses_node_clock_and_is_monotonic` that
asserts two `timestamp()` calls share an HLC ID (i.e., they read
the *node's* clock, not a freshly-created one) AND are strictly
monotonic. Without this test, a refactor that gives `timestamp()`
its own clock would silently break the latency-measurement use case
in the docstring.
Verification
============
cargo fmt --all -- --check
cargo clippy --all --exclude dora-{node-api,operator-api,ros2-bridge}-python -- -D warnings
cargo test -p dora-node-api --lib
(83/83 pass; the new test runs in 0.11s)
cargo check --examples
Co-authored-by: oceanusxiv <oceanusxiv@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
0 commit comments