Skip to content

feat(chronos): add device clock models - #307

Merged
enkerewpo merged 3 commits into
syswonder:devfrom
ZZJJWarth:chronos-merge-pr3
Nov 14, 2026
Merged

enkerewpo merged 3 commits into
syswonder:devfrom
ZZJJWarth:chronos-merge-pr3

Conversation

@ZZJJWarth

Copy link
Copy Markdown
Collaborator

Device timestamps need a conversion to reference time that accounts for clock drift, counter wrap and resets. Add ChronosCore, a deterministic library that fits affine models from caller-supplied device/reference observation pairs and returns conversions with their model version, generations and uncertainty.

The estimator bounds its observation window, rejects outliers, tracks holdover and supports step or bounded slew updates. Outlier limits include elapsed drift allowance so permitted rate changes can update the model. Refreshing a later generation preserves the identity of retained models from an earlier generation. The library runs without a daemon and does not read host clocks.

Fitted coefficients outside the signed range return Overflow, including a floating-point rate rounded to the exclusive upper boundary, instead of silently saturating during conversion.

A strictly newer reference generation clears Fault to Reset and replaces its reason; retained models become Unsynced with their old generation identity. Equal-generation updates are idempotent, and reference availability recovery preserves Fault. The fault regression covers availability recovery, an equal generation, and a newer generation in that order.

Validation

Validated locally on Linux x86_64, based on dev at a7ec8606: 33 model tests passed, including the signed upper-bound regression. The format, workspace Clippy and portability checks below passed.

cargo fmt --all -- --check
cargo clippy --offline --locked --workspace --all-targets -- -D warnings
cargo test --offline --locked -p robonix-chronos --all-targets
python3 scripts/check_runtime_portability.py

Related: #298.

@ZZJJWarth
ZZJJWarth requested a review from enkerewpo as a code owner November 3, 2026 15:59
@github-actions github-actions Bot added comp:chronos system/chronos comp:docs docs/ and READMEs labels Nov 3, 2026
@enkerewpo

enkerewpo commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Tested a5c042fb2b6073a98becdd490f09489e18b528c6 on an AMD Ryzen 5 7600X (6 cores, 12 threads, x86_64), Debian 13, Rust/Cargo 1.95.0 and Python 3.13.5.

All 51 clock/model tests passed. A separate native probe used 24 real CLOCK_MONOTONIC and Chronos wall-clock observations. Conversion reached Tracking with 1481 ns reported uncertainty; real elapsed waits exercised Holdover and Unsynced, followed by an explicit generation-2 reset. No physical sensor calibration or ARM testing was performed.

The four Chronos PRs passed 450 workspace tests together on dev 76cfca2888933f4f16e219d857ccdf37ee0411dd. CI passed on the latest combined test commit, c26ce603aa61e3d84d51c5216ee6035eb8f67d41. Webots failed: post-restart object navigation hit a Nav2 planning timeout with ConceptGraphs, and a navigation verification failure followed by Pilot's duplicate-in-flight error with DualMap. These runtime failures remain unresolved; they have not been traced to a Chronos change. Integration is not fully green.

Test commands and log excerpts
cargo test --locked -p robonix-chronos-clock -p robonix-chronos -- --nocapture
test model::tests::integer_rounding_is_symmetric_at_half_values ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
test result: ok. 32 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
test result: ok. 12 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
test result: ok. 6 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.13s
PASS: real Linux CLOCK_MONOTONIC / Chronos wall samples, convert, real elapsed holdover/expiry, explicit process-local reset. No physical device clock tested.

@enkerewpo

Copy link
Copy Markdown
Member

Thanks! Both #307 and #309 now need a rebase onto the current dev. For #307, dev bumped the workspace to 1.1.0, so after merging, Cargo.lock still lists robonix-chronos as 1.1.0-beta.1 and cargo --locked fails ("cannot update the lock file … because --locked was passed"). Regenerating the lock file fixes it; with that one-line change, the chronos tests pass on top of dev 6e1a4d7c (33 passed, 0 failed). #309 conflicts with dev after #308 and #310. Once both are rebased, I'll rerun the tests and merge #307 first, then #309.

Device timestamps need a versioned conversion to reference time. Add a
deterministic model estimator with bounded observation windows, drift
and uncertainty limits, counter wrap handling, and generation-aware
resets. Support step and bounded slew updates and preserve retained
model identity when refreshing a later generation after a fault.

Validate 32 model tests, including the retained-model regression, and
workspace format, clippy, build and tests.

Assisted-by: Codex:gpt-6
Reject the floating-point upper boundary before converting fitted rates
to signed coefficients. Document and test that a newer reference
generation resets Fault while availability recovery preserves it.
The workspace now uses version 1.1.0. Refresh the Chronos lockfile entry
so locked builds resolve the rebased workspace without updating it.

@enkerewpo enkerewpo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks!

Tested locally with this branch merged into current dev (7540fe2):

cargo fmt --all -- --check                          exit 0
cargo clippy --workspace --tests -- -D warnings     exit 0
cargo build --workspace                             exit 0
cargo test --workspace --all-targets                exit 0  (25 suites, 466 passed, 0 failed, 3 ignored)

Chronos crates and Python bindings:

cargo clippy --locked -p robonix-chronos-clock --features python --all-targets -- -D warnings   exit 0
cargo test --locked -p robonix-chronos-clock --features python   12 + 6 passed
cargo test -p robonix-chronos                                    1 + 32 passed
maturin build --release + python -m unittest (test_python.py)    Ran 5 tests ... OK

@enkerewpo
enkerewpo merged commit 39ab370 into syswonder:dev Nov 14, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:chronos system/chronos comp:docs docs/ and READMEs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants