Skip to content

feat(providers)!: put in-process backends on the platform clock - #80

Merged
joaovitoriasilva merged 2 commits into
mainfrom
feat/platform-clock
Nov 24, 2026
Merged

joaovitoriasilva merged 2 commits into
mainfrom
feat/platform-clock

Conversation

@joaovitoriasilva

@joaovitoriasilva joaovitoriasilva commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

MemoryState checked rate-gate turns against real time.monotonic(), while the geocoder sets retry_at from the platform clock. A host test that advanced its FixedClock to a booked geocoding turn was still refused, so it had to sleep the interval out in real time.

Every in-process backend now reads the clock build_platform wires in:

  • memory:// state (MemoryState(clock)): key and index expiry, the sweep, reserve_slot / reserve_send, and the record_tiered_failure lockout deadline.
  • ClockProvider.sleep(seconds) (new protocol method): SystemClock calls time.sleep; jasil.testing.FixedClock.sleep advances the clock and refuses a negative length as time.sleep does. The HTTP geocoder's wait for a turn within max_wait_seconds goes through it.
  • Local storage (LocalStorage(..., clock=...)): stamps a resumable upload session's start time, which cleanup_uploads compares with its cutoff.
  • Runtime sources: the retry of mail or geocoding settings that could not be verified is timed on the clock.

It also releases 0.25.0: version bump in pyproject.toml, uv.lock, README.md, docs/index.md, and the dated changelog entry.

Related issue

No issue. This came from a hand-off found while removing the last real sleep() from Endurain's in-process test suite.

Type of change

  • Bug fix
  • New feature (exception during freeze; link prior discussion/acknowledgment)
  • Documentation
  • Refactor / code quality
  • Translation
  • Other (describe below): release 0.25.0

Checklist

  • This PR is focused on a single concern
  • An issue was opened and acknowledged before writing this code (if not a small fix)
  • If this PR introduces a new feature during freeze, it was discussed and explicitly acknowledged first
  • The PR is under ~300 lines changed, excluding lock files, migrations, and generated code (about 400 insertions and 260 deletions, mostly tests moving from patching the time module to a FixedClock)
  • Tests have been added or updated where applicable
  • Documentation has been updated where applicable
  • Commit messages follow Conventional Commits format

Notes for the reviewer

  • Breaking:
    • A host that implements its own ClockProvider must add sleep.
    • Under install_test_platform, memory:// state stands still until the test advances the clock.
    • Both are under Upgrading in the changelog.
  • Required clock arguments: MemoryState and LocalStorage constructors now require the clock, as every other internal component does. Backend classes are not covered by SemVer.
  • Alternative not taken: the hand-off proposed a monotonic callable on MemoryState for the host to build itself. That would not reach the gate the platform's geocoder holds, and it leaves the two clocks disagreeing.
  • Deliberately unchanged:
    • The S3 upload created_epoch is stored but never compared; its cleanup uses S3's LastModified.
    • RedisState keeps the server clock and time.time(), as documented in providers-and-backends.md.
  • Checks run locally:
    • ruff check and ruff format --check
    • lint-imports (5 contracts kept)
    • mypy
    • pytest: 4386 passed, 149 skipped, coverage 97.93%
    • check_module_coverage.py
    • check_docs_api.py

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Clock providers can now manage timed waits as well as wall-clock and monotonic time. In-process state expiry, rate limits, local upload timing, and retry delays use the configured clock.
    • Test clocks can advance time without blocking, making time-dependent behavior easier to control.
  • Documentation
    • Updated setup guidance for hosts implementing the clock provider and for constructing in-memory state and local storage, which now require a clock.
    • Updated the documented version to 0.25.0.

joaovitoriasilva and others added 2 commits November 24, 2026 11:56
MemoryState checked rate-gate turns against real time.monotonic() while
the geocoder set retry_at from the platform clock, so a host test that
advanced its FixedClock to a booked turn was still refused and had to
sleep. Every in-process backend now reads the clock build_platform
wires in: memory state expiry, both rate gates and the tiered lockout,
the local upload-session stamp, the geocoder's in-wait sleep and the
reloading retry.

BREAKING CHANGE: ClockProvider has a new method, sleep(seconds); a host
that implements its own clock must add it. Under install_test_platform,
memory:// state stands still until the test advances the FixedClock.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Bumps the version and dates the platform-clock changelog entry as
0.25.0, with the breaking ClockProvider method and the FixedClock
behavior for host tests under Upgrading.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The platform clock now supports sleeping and supplies time to in-process state, local storage, geocoding rate-limit waits, and runtime-source retries. Constructors and tests were updated to pass or advance clocks. Documentation and release metadata were updated for version 0.25.0.

Changes: Platform clock integration

Layer / File(s) Summary
Clock contract and implementations
jasil/providers.py, jasil/backends/clock_system.py, jasil/testing.py, tests/test_testing.py, CHANGELOG.md, docs/providers-and-backends.md, README.md, docs/index.md, pyproject.toml
ClockProvider adds sleep(seconds). SystemClock.sleep blocks, and FixedClock.sleep advances wall and monotonic time. The release version and related API documentation are updated.
Clock-driven state and storage
jasil/backends/state_memory.py, jasil/backends/storage_local.py, jasil/container.py, tests/test_container.py, tests/test_state_backends.py, tests/test_retention_and_storage.py, tests/test_storage_contract.py, tests/test_testing.py, CHANGELOG.md, docs/index.md, docs/providers-and-backends.md
MemoryState uses the supplied clock for expiry, rate gates, and lockout deadlines. LocalStorage uses it for upload timestamps. Platform construction passes the clock to both backends, and tests use explicit or fixed clocks.
Geocoding waits and runtime retries
jasil/backends/geocoding_http.py, jasil/_reloading.py, jasil/container.py, tests/test_geocoding.py, tests/test_reloading.py, docs/providers-and-backends.md
Geocoding rate-limit waits use the supplied clock’s sleep. Reloading backends use its monotonic reading for retry scheduling and checks. Related tests and examples use injected clocks.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Possibly related PRs

Merge Risk: Minimal · up to 2d086 · assessed changes only

Path filters excluded changed files. This rating applies only to the assessed changes.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title uses the conventional commit form and names the main change: in-process backends now use the platform clock supplied by build_platform. The changeset matches this, including the new ClockPro…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title uses the conventional commit form and names the main change: in-process backends now use the platform clock supplied by build_platform. The changeset matches this, including the new ClockProvider.sleep method, the clock arguments added to MemoryState and LocalStorage, and the geocoder's wait through the platform clock. The breaking change is signaled by the '!' marker. The title is 63 characters, within a reasonable length for a single-line subject.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 991b6497-5194-4034-9910-97d2b55dbd2b
Commits

Reviewing files that changed from the base of the PR and between 03ed20e and 2d086ab.

Files ignored due to path filters: 1

  • uv.lock is excluded by !**/*.lock
Files selected for processing: 21

  • CHANGELOG.md
  • README.md
  • docs/index.md
  • docs/providers-and-backends.md
  • jasil/_reloading.py
  • jasil/backends/clock_system.py
  • jasil/backends/geocoding_http.py
  • jasil/backends/state_memory.py
  • jasil/backends/storage_local.py
  • jasil/container.py
  • jasil/providers.py
  • jasil/testing.py
  • pyproject.toml
  • tests/test_container.py
  • tests/test_geocoding.py
  • tests/test_optional_deps.py
  • tests/test_reloading.py
  • tests/test_retention_and_storage.py
  • tests/test_state_backends.py
  • tests/test_storage_contract.py
  • tests/test_testing.py

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@joaovitoriasilva
joaovitoriasilva merged commit 6b9006a into main Nov 24, 2026
22 checks passed
@joaovitoriasilva
joaovitoriasilva deleted the feat/platform-clock branch November 24, 2026 12:08
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