Skip to content

[T-002d] core.clock: Clock protocol with SystemClock and FakeClock #18

Closed

Description

@CodewithJha

Task T-002d · Milestone M1 — Foundation · Size XS · Priority P1 · Epic #1

Implements FR-RUN-002

Branch feat/t-002d-core-clock-clock-protocol-with — one task = one branch = one PR (doc 32 §6)

Summary

Provide an injectable Clock abstraction so domain/application code never calls time.time() directly and timing logic (heartbeats, reaper, stop rules) is testable with a fake clock.

Context / motivation

AGENTS.md §3 forbids wall-clock calls in domain code. FR-RUN-002's acceptance criterion is explicitly a fake-clock test.

Scope

In scope

  • Clock Protocol: now() -> datetime (UTC, tz-aware), monotonic() -> float, sleep(seconds: float) -> None.
  • SystemClock.
  • FakeClock(start: datetime) with advance(seconds); sleep advances instantly.
  • Re-export a NoopTracer-style Null Object is not part of this issue.

Implementation guidance

  • File backend/src/roboprobe/core/clock.py. FakeClock lives in src (not tests) because integration fixtures and the experiment runner use it.
  • Standards: respect the layering contracts (doc 16 §2) and conventions in doc 34; no hard-coded tunables — thresholds/defaults come from typed settings (doc 27); no magic numbers (ruff PLR2004); public APIs typed (mypy strict) and documented.

Acceptance criteria

  • SystemClock.now() is tz-aware UTC.
  • FakeClock deterministic; advance affects both now and monotonic.
  • 100 % coverage.
  • Tests listed below added and green in CI; coverage of new code meets the gate in doc 18 §3.
  • Docs, config reference and CHANGELOG Unreleased updated where behaviour, keys or interfaces changed.
  • Definition of Done (doc 32 §3) satisfied.

Tests required

  • tests/unit/core/test_clock.py.

Dependencies

Blocked by: #12 (T-001)

Blocks: #82 (T-042a)

Parallelization notes

Files / paths owned by this task — avoid editing other paths; shared files (pyproject.toml entry points, cli/main.py, api/routers/__init__.py, router.tsx, docker/compose.yaml, ci.yml) are append-only:

  • backend/src/roboprobe/core/clock.py
  • backend/tests/unit/core/test_clock.py

Independent single file.

Definition of Done

Per doc 32 §3 and AGENTS.md §5: lint, format, mypy strict and import-linter green; tests added and passing; docs updated; PR template completed with Closes #<this issue>; Conventional Commit messages referencing T-002d (doc 16 §6); commits authored only by the repository owner identity (AGENTS.md §4); CI green; reviewer checklist (doc 32 §5.1) satisfied.

References

Design docs: doc 05 §13 · doc 16 §3 · AGENTS.md §3

Requirements: FR-RUN-002 (traceability: doc 28)

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:coreDomain core, plugin registry, shared typesgood first issueGood for newcomersmilestone:M1M1 — Foundationpriority:P1Required for milestone exitsize:XS< 2 hourstaskChild task of a milestone epictype:featureNew functionality

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions