Skip to content

docs: document the WallClockInstant alias exception in code-style rules#3879

Merged
sanity merged 1 commit intomainfrom
docs/wallclock-alias-exception
Apr 14, 2026
Merged

docs: document the WallClockInstant alias exception in code-style rules#3879
sanity merged 1 commit intomainfrom
docs/wallclock-alias-exception

Conversation

@sanity
Copy link
Copy Markdown
Collaborator

@sanity sanity commented Apr 14, 2026

Problem

PR #3871 (merged as ac761dab) introduced a use std::time::Instant as WallClockInstant; alias exception in crates/core/src/ring.rs::connection_maintenance to satisfy the suspend/resume detector's need for a real wall clock (comparing CLOCK_BOOTTIME against CLOCK_MONOTONIC, which TimeSource cannot express in tests). The Claude Rule Review agent on that PR correctly flagged that the rule documentation in .claude/rules/code-style.md still 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 existing WallClockInstant::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-race branch 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 existing WHEN you need time/rng/sockets in crates/core/ rule. The exception:

  • Names the one legitimate use case (OS suspend/resume detection).
  • Explains why TimeSource is the wrong abstraction for this specific case (it returns simulation time in tests and can't reflect a real 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 with no intervening .await.
  • Points at crates/core/src/ring.rs::connection_maintenance and classify_suspend_jump as the canonical example.
  • 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() now has a rule to cite; a future contributor tempted to reach for std::time::Instant::now() under a different justification will see the rule refuses it.

Testing

Docs-only change. No code paths modified. cargo fmt/clippy/test not re-run since nothing Rust changed.

Follow-up to

#3871 (merged as ac761dab).

[AI-assisted - Claude]

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]
@sanity sanity enabled auto-merge April 14, 2026 20:58
@github-actions
Copy link
Copy Markdown
Contributor

Rule Review: No issues found

Rules checked: git-workflow.md, code-style.md
Files reviewed: 1 (.claude/rules/code-style.md)

The PR adds documentation for the WallClockInstant alias exception. I verified:

  • Commit subject follows conventional commits (docs:) and is under 72 characters
  • The canonical example referenced (crates/core/src/ring.rsWallClockInstant, connection_maintenance, classify_suspend_jump) all exist in the codebase at the cited locations
  • The documented procedure (alias at use line, load-bearing comment, WallClockInstant::now() at call sites, back-to-back clock samples) accurately describes the pattern already in production code
  • No code changes — docs only, so no .unwrap(), spawn, retry, or test-coverage checks apply
  • This is a docs: PR, not a fix:, so the regression-test requirement does not apply

No rule violations detected.


Rule review against .claude/rules/. WARNING findings block merge.

@sanity sanity added this pull request to the merge queue Apr 14, 2026
Merged via the queue into main with commit 0b1db7b Apr 14, 2026
12 checks passed
@sanity sanity deleted the docs/wallclock-alias-exception branch April 14, 2026 21:24
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.

1 participant