Skip to content

Refactor orchestration timing to use Effect Clock and add deterministic test clock#102

Open
danielbdyer wants to merge 1 commit into
mainfrom
codex/refactor-timing-calculations-with-clock-service
Open

Refactor orchestration timing to use Effect Clock and add deterministic test clock#102
danielbdyer wants to merge 1 commit into
mainfrom
codex/refactor-timing-calculations-with-clock-service

Conversation

@danielbdyer
Copy link
Copy Markdown
Owner

Motivation

  • Make orchestration timing injectable and deterministic by replacing ad-hoc Date.now() calls with an Effect Clock-backed abstraction so progress/elapsed assertions are not flaky.
  • Preserve existing emitted telemetry/artifact schema fields (elapsed, wallClockMs, durationMs, phaseDurationMs) while sourcing values through the injected clock.

Description

  • Add a small time abstraction lib/application/time.ts that exposes nowMillis and elapsedSince backed by Clock.currentTimeMillis.
  • Replace direct Date.now() usages with the new abstraction in runPipelineStage (lib/application/pipeline/stage.ts) so stage lifecycle events emit durationMs using the Effect clock.
  • Refactor lib/application/speedrun.ts to compute speedrunStart, phase starts, and phase durations using nowMillis/elapsedSince, preserving the original progress payload fields.
  • Refactor lib/application/dogfood.ts to thread the loop startedAt from runDogfoodLoop, compute iteration start/duration via the clock, and make progress-event construction read time through the abstraction (returned as an Effect) to keep elapsed/wall-clock deterministic.
  • Add a deterministic test clock helper tests/support/test-clock.ts which supplies a Clock implementation and helpers (advanceBy, setTime) for tests.
  • Add a deterministic timing law test to tests/dashboard-projection.laws.spec.ts that injects the test clock and asserts runPipelineStage reports the exact elapsed duration (25 ms) when the test clock is advanced.

Testing

  • Ran the focused dashboard projection laws: npx playwright test tests/dashboard-projection.laws.spec.ts, and the file's tests passed (11/11).
  • Ran typecheck with npm run typecheck; typecheck failed due to pre-existing missing generated module declarations (../generated/tesseract-knowledge) which are unrelated to the timing refactor.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant