feat(engine): Clock trait — virtual time for scheduler and time-based checks#65
Merged
Conversation
… checks Abstract "now" behind a Clock so tests (and a future orch8 dev --skip-timers mode) can advance time manually. - orch8-types/src/clock.rs: Clock trait, SystemClock (default), ManualClock (advance/set, lock-protected), SharedClock handle. - SchedulerConfig gains a serde-skipped `clock` field defaulting to SystemClock — no public signature changes anywhere; orch8-mobile compiles unchanged. - Scheduler reads the clock for all scheduling decisions: claiming due instances, semaphore/concurrency deferrals, delay / send-window / rate-limit pre-flight checks, retry backoff, SLA deadline and human-input timeout baselines, signalled-instance wakes, and cron evaluation (run_cron_loop_with_clock, calculate_next_fire_after). - Delay checks now record a "_delay_until:<block>" metadata marker so a served delay executes instead of re-deferring forever — this makes duration delays actually complete (previously they re-applied on every claim) and enables the 3-day-delay virtual-time test. - Record timestamps (created_at/updated_at, audit rows, DB-side NOW()) stay on real time; boundary documented in orch8_types::clock. - Tests: ManualClock/SystemClock unit tests; e2e tests where a 3-day delay and a send-window boundary complete in milliseconds via ManualClock; full engine/storage/mobile suites pass (2650 tests). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Summary
Item #11 from docs/FEATURE_OPPORTUNITIES.md:
now()abstracted behind aClocktrait (SystemClockdefault,ManualClockfor tests/tooling), injected viaSchedulerConfig.clockso no public signature changed — engine, mobile, server all compile unchanged.next_fire_atcomputation (delay, send-window, rate-limit, concurrency, retry backoff), SLA/human-input timeout checks, cron due-claiming + next-fire. Record stamps (created_at/updated_at, audit columns) stay on real time — boundary documented inorch8_types::clock.ManualClock::advance(Duration::days(3)). README's "no time-skipping test tooling" limitation rewritten.Fast-path step delays previously re-applied on every claim — a duration-delayed step could never execute (pinned by the old
tick_delay_reapplies_on_reticktest).check_step_delaynow records a_delay_until:<block_id>marker and lets the step run oncenow >= fire_at. Known edge: resume-from-block re-runs of the same block don't re-apply a served delay.Tests
2650 passed across engine/storage/mobile (39 suites); new virtual-time e2e suite (3-day delay, send-window boundary crossing via
set(), SystemClock sanity). fmt/clippy(pedantic)/doc gates clean.🤖 Generated with Claude Code