From 220b1f3c6f19b55df66358a8d8838e55402e1b96 Mon Sep 17 00:00:00 2001 From: Mircea Livadariu Date: Wed, 25 Feb 2026 20:23:43 -0800 Subject: [PATCH] =?UTF-8?q?Remove=20now()=20from=20Clock=20trait=20?= =?UTF-8?q?=E2=80=94=20dead=20code=20in=20deterministic=20path?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TemporalClock::now() called Instant::now() (the real system clock) inside a deterministic Temporal workflow, but nothing in the workflow path actually used it. The only caller was ToolCallRuntime in parallel.rs, which is replaced by TemporalToolHandler under Temporal. Remove now() from the Clock trait, SystemClock, and TemporalClock. parallel.rs now calls Instant::now() directly. --- codex-rs/core/src/entropy.rs | 25 ------------------------- codex-rs/core/src/tools/parallel.rs | 5 ++--- 2 files changed, 2 insertions(+), 28 deletions(-) diff --git a/codex-rs/core/src/entropy.rs b/codex-rs/core/src/entropy.rs index 01c2e9b96ff..42a1676bcbb 100644 --- a/codex-rs/core/src/entropy.rs +++ b/codex-rs/core/src/entropy.rs @@ -6,7 +6,6 @@ use std::fmt::Debug; use std::ops::Range; use std::sync::Arc; -use std::time::Instant; use std::time::SystemTime; /// Source of randomness (UUIDs, random numbers). @@ -23,8 +22,6 @@ pub trait RandomSource: Send + Sync + Debug { /// Source of time. pub trait Clock: Send + Sync + Debug { - /// Returns a monotonic instant (for measuring durations). - fn now(&self) -> Instant; /// Returns wall-clock time. fn wall_time(&self) -> SystemTime; /// Returns milliseconds since Unix epoch. @@ -67,10 +64,6 @@ impl RandomSource for SystemRandomSource { pub struct SystemClock; impl Clock for SystemClock { - fn now(&self) -> Instant { - Instant::now() - } - fn wall_time(&self) -> SystemTime { SystemTime::now() } @@ -121,15 +114,6 @@ pub fn entropy_uuid() -> String { .unwrap_or_else(|_| uuid::Uuid::new_v4().to_string()) } -/// Helper to access the task-local monotonic clock. -/// -/// Falls back to `Instant::now()` when called outside a scoped context. -pub fn entropy_now() -> Instant { - ENTROPY - .try_with(|e| e.clock.now()) - .unwrap_or_else(|_| Instant::now()) -} - #[cfg(test)] mod tests { use super::*; @@ -163,14 +147,6 @@ mod tests { } } - #[test] - fn system_clock_now_is_monotonic() { - let clock = SystemClock; - let t1 = clock.now(); - let t2 = clock.now(); - assert!(t2 >= t1, "Clock should be monotonic"); - } - #[test] fn system_clock_unix_millis_is_reasonable() { let clock = SystemClock; @@ -186,7 +162,6 @@ mod tests { // Should not panic and should produce valid output let uuid = providers.random.uuid(); assert!(!uuid.is_empty()); - let _ = providers.clock.now(); } // Test helper for deterministic testing diff --git a/codex-rs/core/src/tools/parallel.rs b/codex-rs/core/src/tools/parallel.rs index c1cff4d4659..e915b791562 100644 --- a/codex-rs/core/src/tools/parallel.rs +++ b/codex-rs/core/src/tools/parallel.rs @@ -1,7 +1,6 @@ use std::future::Future; use std::sync::Arc; - -use crate::entropy::entropy_now; +use std::time::Instant; use futures::future::BoxFuture; use tokio::sync::RwLock; use tokio_util::either::Either; @@ -80,7 +79,7 @@ impl ToolCallRuntime { let turn = Arc::clone(&self.turn_context); let tracker = Arc::clone(&self.tracker); let lock = Arc::clone(&self.parallel_execution); - let started = entropy_now(); + let started = Instant::now(); let dispatch_span = trace_span!( "dispatch_tool_call",