docs: document the WallClockInstant alias exception in code-style rules#3879
Merged
docs: document the WallClockInstant alias exception in code-style rules#3879
Conversation
The Claude Rule Review agent correctly flagged that commit 1fc338d introduced a `use std::time::Instant as WallClockInstant;` alias exception in `crates/core/src/ring.rs` without updating `.claude/rules/code-style.md` to match. AGENTS.md rule says rule updates must land in the same PR as the pattern they describe. Add a dedicated "Exception" subsection under the time/rng/sockets rule that: - Names the *one* legitimate use case (suspend detection via `boot_time::Instant` vs. a real monotonic wall clock). - Explains why `TimeSource` is the wrong abstraction for this specific case (it returns simulation time in tests and can't reflect a real OS suspend). - Documents the exact mechanics: alias at the `use` line with a load-bearing comment, call via `WallClockInstant::now()`, keep clock samples back-to-back. - Points at `crates/core/src/ring.rs::connection_maintenance` and `classify_suspend_jump` as the canonical example so future code has a reference implementation to copy. - Explicitly narrows the exception: do NOT add new call sites for any other purpose — every other "I need real time" urge in `crates/core/` should still go through `TimeSource`. A future reviewer seeing `WallClockInstant::now()` in ring.rs now has a rule to cite as the accepted justification, closing the staleness gap the rule-review agent flagged. [AI-assisted - Claude]
Contributor
Rule Review: No issues foundRules checked: The PR adds documentation for the
No rule violations detected. Rule review against |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
PR #3871 (merged as
ac761dab) introduced ause std::time::Instant as WallClockInstant;alias exception incrates/core/src/ring.rs::connection_maintenanceto satisfy the suspend/resume detector's need for a real wall clock (comparingCLOCK_BOOTTIMEagainstCLOCK_MONOTONIC, whichTimeSourcecannot express in tests). The Claude Rule Review agent on that PR correctly flagged that the rule documentation in.claude/rules/code-style.mdstill reads "DO NOT use:std::time::Instant::now()" with no carve-outs — leaving a future reviewer with no rule to cite as justification for the existingWallClockInstant::now()call sites.AGENTS.md rule says documentation updates must land in the same PR as the pattern they describe. The doc commit was ready on the
fix/nightly-sim-cm-racebranch locally, but by the time the rule-review agent flagged it, the merge queue had already frozen the branch (GH006: Protected branch update failed ... A pull request for this branch has been added to a merge queue), so it lands here as a fast-follow instead.Solution
Add a dedicated "Exception: real wall-clock comparison against
boot_time::Instant" subsection under the existingWHEN you need time/rng/sockets in crates/core/rule. The exception:TimeSourceis the wrong abstraction for this specific case (it returns simulation time in tests and can't reflect a real suspend).useline with a load-bearing comment, call viaWallClockInstant::now(), keep clock samples back-to-back with no intervening.await.crates/core/src/ring.rs::connection_maintenanceandclassify_suspend_jumpas the canonical example.crates/core/should still go throughTimeSource.A future reviewer seeing
WallClockInstant::now()now has a rule to cite; a future contributor tempted to reach forstd::time::Instant::now()under a different justification will see the rule refuses it.Testing
Docs-only change. No code paths modified.
cargo fmt/clippy/testnot re-run since nothing Rust changed.Follow-up to
#3871 (merged as
ac761dab).[AI-assisted - Claude]