diff --git a/Cargo.lock b/Cargo.lock index 5f8b6c37..eaf30dd0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -545,10 +545,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c673075a2e0e5f4a1dde27ce9dee1ea4558c7ffe648f576438a20ca1d2acc4b0" dependencies = [ "iana-time-zone", - "js-sys", "num-traits", "serde", - "wasm-bindgen", "windows-link", ] @@ -640,7 +638,7 @@ version = "3.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "faf9468729b8cbcea668e36183cb69d317348c2e08e994829fb56ebfdfbaac34" dependencies = [ - "windows-sys 0.52.0", + "windows-sys 0.61.2", ] [[package]] @@ -946,6 +944,15 @@ dependencies = [ "zeroize", ] +[[package]] +name = "deranged" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e9de72ce2ad1f90dc62fa25f0f430ef85eb4b0d8fa0be4f30373bc40a21d28e" +dependencies = [ + "serde_core", +] + [[package]] name = "derive_builder" version = "0.20.2" @@ -1030,7 +1037,6 @@ dependencies = [ "async-trait", "axum", "blake3", - "chrono", "ciborium", "clap", "colored", @@ -1058,6 +1064,7 @@ dependencies = [ "strum 0.28.0", "tempfile", "thiserror", + "time", "tiny-keccak", "tokio", "tokio-test", @@ -1246,7 +1253,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys 0.61.2", ] [[package]] @@ -1302,9 +1309,9 @@ checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" [[package]] name = "form_urlencoded" -version = "1.2.2" +version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +checksum = "afa489199eaffb1211795df1c6236ce1ad0d41a6fa45250add73e3b02420f06e" dependencies = [ "percent-encoding", ] @@ -2125,6 +2132,12 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-conv" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "521739c6d2bac4aa25192232afe6841231376b2b26d4d9fae5ecf8ca5772e441" + [[package]] name = "num-integer" version = "0.1.46" @@ -2385,6 +2398,12 @@ dependencies = [ "zerovec", ] +[[package]] +name = "powerfmt" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a6394b9e965e73d0a289ee54f589087e2c676aedf60885baf52c76b771e4958" + [[package]] name = "ppv-lite86" version = "0.2.21" @@ -2592,7 +2611,7 @@ dependencies = [ "once_cell", "socket2", "tracing", - "windows-sys 0.52.0", + "windows-sys 0.61.2", ] [[package]] @@ -2912,7 +2931,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys 0.52.0", + "windows-sys 0.61.2", ] [[package]] @@ -3393,10 +3412,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" dependencies = [ "fastrand", - "getrandom 0.3.4", + "getrandom 0.4.2", "once_cell", "rustix", - "windows-sys 0.52.0", + "windows-sys 0.61.2", ] [[package]] @@ -3428,6 +3447,36 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "time" +version = "0.3.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb87b95ec50ddfa440816d227a17b2ccbdda963a316a727fda0fc4334f7d134" +dependencies = [ + "deranged", + "num-conv", + "powerfmt", + "serde_core", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1c906769ad99c88eaa54e728060edef082f8e358ff32030cb7c7d315e81109" + +[[package]] +name = "time-macros" +version = "0.2.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e689342a48d2ea927c87ea50cabf8594854bf940e9310208848d680d668ed85" +dependencies = [ + "num-conv", + "time-core", +] + [[package]] name = "tiny-keccak" version = "2.0.2" @@ -3907,9 +3956,9 @@ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" [[package]] name = "url" -version = "2.5.8" +version = "2.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" +checksum = "f00cd2407bb42c0ef17be88d4cf020f5cceffd121665bac9b8b9493a369b3b1a" dependencies = [ "form_urlencoded", "idna", @@ -4200,7 +4249,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.52.0", + "windows-sys 0.61.2", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index b4c1f0e5..c4424249 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -75,7 +75,7 @@ strum = { version = "0.28.0", features = ["derive"] } ciborium = { version = "0.2", optional = true } # Chrono for timestamps -chrono = { version = "0.4", features = ["serde"] } +time = { version = "0.3", features = ["formatting", "parsing", "serde", "std"] } # Random number generation (for resilience jitter) rand = "0.10" diff --git a/fuzz/Cargo.lock b/fuzz/Cargo.lock index 9d2d44b6..dbb0afeb 100644 --- a/fuzz/Cargo.lock +++ b/fuzz/Cargo.lock @@ -67,15 +67,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "android_system_properties" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" -dependencies = [ - "libc", -] - [[package]] name = "anstream" version = "1.0.0" @@ -352,20 +343,6 @@ dependencies = [ "rand_core 0.10.1", ] -[[package]] -name = "chrono" -version = "0.4.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c673075a2e0e5f4a1dde27ce9dee1ea4558c7ffe648f576438a20ca1d2acc4b0" -dependencies = [ - "iana-time-zone", - "js-sys", - "num-traits", - "serde", - "wasm-bindgen", - "windows-link", -] - [[package]] name = "clap" version = "4.6.1" @@ -427,7 +404,7 @@ version = "3.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "faf9468729b8cbcea668e36183cb69d317348c2e08e994829fb56ebfdfbaac34" dependencies = [ - "windows-sys 0.52.0", + "windows-sys 0.61.2", ] [[package]] @@ -460,12 +437,6 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d52eff69cd5e647efe296129160853a42795992097e8af39800e1060caeea9b" -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "cpufeatures" version = "0.2.17" @@ -561,6 +532,15 @@ dependencies = [ "zeroize", ] +[[package]] +name = "deranged" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e9de72ce2ad1f90dc62fa25f0f430ef85eb4b0d8fa0be4f30373bc40a21d28e" +dependencies = [ + "serde_core", +] + [[package]] name = "derive_arbitrary" version = "1.4.2" @@ -613,7 +593,6 @@ dependencies = [ "async-trait", "axum", "blake3", - "chrono", "clap", "colored", "echidna-core", @@ -637,6 +616,7 @@ dependencies = [ "strum", "tempfile", "thiserror", + "time", "tiny-keccak", "tokio", "toml", @@ -726,7 +706,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys 0.61.2", ] [[package]] @@ -761,9 +741,9 @@ checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" [[package]] name = "form_urlencoded" -version = "1.2.2" +version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +checksum = "afa489199eaffb1211795df1c6236ce1ad0d41a6fa45250add73e3b02420f06e" dependencies = [ "percent-encoding", ] @@ -1075,30 +1055,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "iana-time-zone" -version = "0.1.65" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470" -dependencies = [ - "android_system_properties", - "core-foundation-sys", - "iana-time-zone-haiku", - "js-sys", - "log", - "wasm-bindgen", - "windows-core", -] - -[[package]] -name = "iana-time-zone-haiku" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" -dependencies = [ - "cc", -] - [[package]] name = "icu_collections" version = "2.2.0" @@ -1491,6 +1447,12 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-conv" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "521739c6d2bac4aa25192232afe6841231376b2b26d4d9fae5ecf8ca5772e441" + [[package]] name = "num-integer" version = "0.1.47" @@ -1592,6 +1554,12 @@ dependencies = [ "zerovec", ] +[[package]] +name = "powerfmt" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a6394b9e965e73d0a289ee54f589087e2c676aedf60885baf52c76b771e4958" + [[package]] name = "prettyplease" version = "0.2.37" @@ -1673,7 +1641,7 @@ dependencies = [ "once_cell", "socket2", "tracing", - "windows-sys 0.52.0", + "windows-sys 0.61.2", ] [[package]] @@ -1865,7 +1833,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys 0.52.0", + "windows-sys 0.61.2", ] [[package]] @@ -2235,7 +2203,7 @@ dependencies = [ "getrandom 0.4.2", "once_cell", "rustix", - "windows-sys 0.52.0", + "windows-sys 0.61.2", ] [[package]] @@ -2267,6 +2235,36 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "time" +version = "0.3.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb87b95ec50ddfa440816d227a17b2ccbdda963a316a727fda0fc4334f7d134" +dependencies = [ + "deranged", + "num-conv", + "powerfmt", + "serde_core", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1c906769ad99c88eaa54e728060edef082f8e358ff32030cb7c7d315e81109" + +[[package]] +name = "time-macros" +version = "0.2.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e689342a48d2ea927c87ea50cabf8594854bf940e9310208848d680d668ed85" +dependencies = [ + "num-conv", + "time-core", +] + [[package]] name = "tiny-keccak" version = "2.0.2" @@ -2583,9 +2581,9 @@ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" [[package]] name = "url" -version = "2.5.8" +version = "2.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" +checksum = "f00cd2407bb42c0ef17be88d4cf020f5cceffd121665bac9b8b9493a369b3b1a" dependencies = [ "form_urlencoded", "idna", @@ -2790,65 +2788,12 @@ dependencies = [ "safe_arch", ] -[[package]] -name = "windows-core" -version = "0.62.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" -dependencies = [ - "windows-implement", - "windows-interface", - "windows-link", - "windows-result", - "windows-strings", -] - -[[package]] -name = "windows-implement" -version = "0.60.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "windows-interface" -version = "0.59.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "windows-link" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" -[[package]] -name = "windows-result" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" -dependencies = [ - "windows-link", -] - -[[package]] -name = "windows-strings" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" -dependencies = [ - "windows-link", -] - [[package]] name = "windows-sys" version = "0.52.0" diff --git a/src/rust/agent/memory.rs b/src/rust/agent/memory.rs index ae5d21e7..416c1077 100644 --- a/src/rust/agent/memory.rs +++ b/src/rust/agent/memory.rs @@ -142,7 +142,7 @@ impl ProofMemory for SqliteMemory { proof: proof.clone(), prover, time_ms, - timestamp: chrono::Utc::now().timestamp(), + timestamp: crate::clock::unix_now(), aspects: goal.aspects.clone(), }; @@ -158,7 +158,7 @@ impl ProofMemory for SqliteMemory { goal_id: goal.goal.id.clone(), prover: goal.preferred_prover, reason, - timestamp: chrono::Utc::now().timestamp(), + timestamp: crate::clock::unix_now(), aspects: goal.aspects.clone(), }; @@ -344,7 +344,7 @@ impl ProofMemory for VeriSimDBProofStore { proof: proof.clone(), prover, time_ms, - timestamp: chrono::Utc::now().timestamp(), + timestamp: crate::clock::unix_now(), aspects: goal.aspects.clone(), }; @@ -392,7 +392,7 @@ impl ProofMemory for VeriSimDBProofStore { goal_id: goal.goal.id.clone(), prover: goal.preferred_prover, reason: reason.clone(), - timestamp: chrono::Utc::now().timestamp(), + timestamp: crate::clock::unix_now(), aspects: goal.aspects.clone(), }; diff --git a/src/rust/cli/corpus.rs b/src/rust/cli/corpus.rs index eca0240d..0fea57c7 100644 --- a/src/rust/cli/corpus.rs +++ b/src/rust/cli/corpus.rs @@ -402,7 +402,7 @@ pub(crate) fn corpus_command(op: CorpusOp, formatter: &OutputFormatter) -> Resul CorpusOp::ExportOctads { index, out } => { let corpus = Corpus::load_json(&index) .with_context(|| format!("load corpus index {}", index.display()))?; - let timestamp = chrono::Utc::now().to_rfc3339(); + let timestamp = echidna::clock::now_rfc3339(); corpus.save_octads_jsonl(&out, ×tamp)?; formatter.info(&format!( "exported {} octad(s) → {}", diff --git a/src/rust/clock.rs b/src/rust/clock.rs new file mode 100644 index 00000000..f2d04b21 --- /dev/null +++ b/src/rust/clock.rs @@ -0,0 +1,62 @@ +// SPDX-License-Identifier: MPL-2.0 +// SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell + +//! The single wall-clock module: UTC "now", RFC 3339 strings and Unix seconds. +//! +//! Every timestamp in the crate comes through here, so the date library is +//! chosen in one place. The chosen library is `time`; `chrono` is unmaintained +//! (RUSTSEC-2026-0543) and is no longer a dependency. + +use time::format_description::well_known::Rfc3339; +use time::OffsetDateTime; + +/// The current instant, in UTC. +pub fn now() -> OffsetDateTime { + OffsetDateTime::now_utc() +} + +/// Format an instant as RFC 3339 (`2026-11-26T11:40:00.123456789Z`). +/// +/// Formatting only fails for years outside 0000..=9999, which no clock reading +/// produces; the empty-string fallback keeps this infallible for callers. +pub fn to_rfc3339(t: OffsetDateTime) -> String { + t.format(&Rfc3339).unwrap_or_default() +} + +/// The current instant as an RFC 3339 string. +pub fn now_rfc3339() -> String { + to_rfc3339(now()) +} + +/// Seconds since the Unix epoch. +pub fn unix_now() -> i64 { + now().unix_timestamp() +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn rfc3339_round_trips_through_the_parser() { + let t = now(); + let parsed = OffsetDateTime::parse(&to_rfc3339(t), &Rfc3339).expect("parse"); + assert_eq!(parsed, t); + } + + #[test] + fn rfc3339_is_utc_zulu() { + assert!(now_rfc3339().ends_with('Z')); + } + + #[test] + fn unix_now_is_after_2026() { + assert!(unix_now() > 1_767_225_600); // 2026-01-01T00:00:00Z + } + + #[test] + fn known_instant_formats_exactly() { + let t = OffsetDateTime::from_unix_timestamp(0).expect("epoch"); + assert_eq!(to_rfc3339(t), "1970-01-01T00:00:00Z"); + } +} diff --git a/src/rust/diagnostics/corpus_monitor.rs b/src/rust/diagnostics/corpus_monitor.rs index 10c40138..52a84f16 100644 --- a/src/rust/diagnostics/corpus_monitor.rs +++ b/src/rust/diagnostics/corpus_monitor.rs @@ -1,11 +1,11 @@ // SPDX-License-Identifier: MPL-2.0 // Monitor corpus health: proofs, premises, size metrics -use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use std::fs; use std::path::Path; use std::sync::{Arc, Mutex}; +use time::OffsetDateTime; /// Snapshot of corpus metrics at a point in time #[derive(Debug, Clone, Serialize, Deserialize)] @@ -19,7 +19,8 @@ pub struct CorpusMetrics { /// Percentage change since last check pub size_change_percent: f64, /// Timestamp of last update - pub last_updated: DateTime, + #[serde(with = "time::serde::rfc3339")] + pub last_updated: OffsetDateTime, } impl Default for CorpusMetrics { @@ -29,7 +30,7 @@ impl Default for CorpusMetrics { total_premises: 0, size_mb: 0.0, size_change_percent: 0.0, - last_updated: Utc::now(), + last_updated: crate::clock::now(), } } } @@ -118,7 +119,7 @@ impl CorpusMonitor { total_premises, size_mb, size_change_percent, - last_updated: Utc::now(), + last_updated: crate::clock::now(), }; // Update internal state @@ -146,7 +147,7 @@ impl CorpusMonitor { if let Ok(mut metrics) = self.current.lock() { metrics.total_proofs += 1; metrics.total_premises += premise_count; - metrics.last_updated = Utc::now(); + metrics.last_updated = crate::clock::now(); } } @@ -158,7 +159,7 @@ impl CorpusMonitor { if prev_size > 0.0 { metrics.size_change_percent = ((size_mb - prev_size) / prev_size) * 100.0; } - metrics.last_updated = Utc::now(); + metrics.last_updated = crate::clock::now(); } } @@ -269,10 +270,10 @@ mod tests { monitor.add_proof(1); let metrics = monitor.metrics(); - let now = Utc::now(); - let diff = now.signed_duration_since(metrics.last_updated); + let now = crate::clock::now(); + let diff = now - metrics.last_updated; // Timestamp should be recent (within a few seconds) - assert!(diff.num_seconds() < 5); + assert!(diff.whole_seconds() < 5); } #[test] @@ -282,7 +283,7 @@ mod tests { total_premises: 3000, size_mb: 512.5, size_change_percent: 5.5, - last_updated: Utc::now(), + last_updated: crate::clock::now(), }; // Verify metrics can be serialized to JSON diff --git a/src/rust/diagnostics/gnn_training.rs b/src/rust/diagnostics/gnn_training.rs index 2b800fa8..2c95b252 100644 --- a/src/rust/diagnostics/gnn_training.rs +++ b/src/rust/diagnostics/gnn_training.rs @@ -1,9 +1,10 @@ // SPDX-License-Identifier: MPL-2.0 // GNN model training integration with health monitoring -use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use std::path::Path; +use time::format_description::well_known::Rfc3339; +use time::{OffsetDateTime, UtcOffset}; /// Metrics exported from GNN training pipeline. // @@ -50,8 +51,8 @@ pub fn update_health_with_metrics( health.gnn_model_health.nDCG_meets_threshold = metrics.nDCG >= 0.65; // Update last_trained timestamp - if let Ok(ts) = DateTime::parse_from_rfc3339(&metrics.timestamp) { - health.gnn_model_health.last_trained = Some(ts.with_timezone(&Utc)); + if let Ok(ts) = OffsetDateTime::parse(&metrics.timestamp, &Rfc3339) { + health.gnn_model_health.last_trained = Some(ts.to_offset(UtcOffset::UTC)); } // Recompute degradation with updated GNN metrics diff --git a/src/rust/diagnostics/health.rs b/src/rust/diagnostics/health.rs index 0a109b46..d0199584 100644 --- a/src/rust/diagnostics/health.rs +++ b/src/rust/diagnostics/health.rs @@ -1,9 +1,9 @@ // SPDX-License-Identifier: MPL-2.0 // Health status monitoring for echidna services -use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use std::collections::HashMap; +use time::OffsetDateTime; use super::fallback_monitor::FallbackMonitor; use super::nesy_validation::NeSyMetrics; @@ -12,7 +12,8 @@ use crate::fault_tolerance::CircuitState; /// Overall system health status #[derive(Debug, Clone, Serialize, Deserialize)] pub struct HealthStatus { - pub timestamp: DateTime, + #[serde(with = "time::serde::rfc3339")] + pub timestamp: OffsetDateTime, pub prover_health: HashMap, pub gnn_model_health: ModelHealth, pub corpus_health: CorpusHealth, @@ -25,7 +26,8 @@ pub struct ProverHealth { pub name: String, pub is_available: bool, pub circuit_breaker_state: CircuitBreakerStateSnapshot, - pub last_successful_proof: Option>, + #[serde(default, with = "time::serde::rfc3339::option")] + pub last_successful_proof: Option, pub consecutive_failures: usize, pub avg_latency_ms: f64, pub success_rate: f64, // 0.0 to 1.0 @@ -62,7 +64,8 @@ impl From for CircuitBreakerStateSnapshot { pub struct ModelHealth { pub is_loaded: bool, pub model_checksum: Option, - pub last_trained: Option>, + #[serde(default, with = "time::serde::rfc3339::option")] + pub last_trained: Option, pub last_validation_nDCG: f32, pub last_validation_MRR: f32, pub nDCG_meets_threshold: bool, @@ -84,7 +87,8 @@ pub struct ModelHealth { pub struct CorpusHealth { pub total_proofs: usize, pub total_premises: usize, - pub last_updated: Option>, + #[serde(default, with = "time::serde::rfc3339::option")] + pub last_updated: Option, pub size_mb: f64, pub size_change_percent: f64, // % change since last check } @@ -107,7 +111,7 @@ pub enum DegradationMode { impl HealthStatus { pub fn new() -> Self { HealthStatus { - timestamp: Utc::now(), + timestamp: crate::clock::now(), prover_health: HashMap::new(), gnn_model_health: ModelHealth { is_loaded: false, diff --git a/src/rust/dispatch.rs b/src/rust/dispatch.rs index 49229511..30973a6e 100644 --- a/src/rust/dispatch.rs +++ b/src/rust/dispatch.rs @@ -7,7 +7,6 @@ //! axiom scan -> confidence scoring. use anyhow::{anyhow, Context, Result}; -use chrono::Utc; use serde::{Deserialize, Serialize}; #[cfg(feature = "verisim")] use std::collections::HashMap; @@ -435,7 +434,7 @@ impl ProverDispatcher { match outcome { ProverOutcome::Proved { .. } => { entry.consecutive_failures = 0; - entry.last_successful_proof = Some(Utc::now()); + entry.last_successful_proof = Some(crate::clock::now()); entry.is_available = true; entry.success_rate = (entry.success_rate * 0.9) + (1.0 * 0.1); }, @@ -1158,7 +1157,7 @@ fn build_proof_attempt( ) -> crate::verisim_bridge::ProofAttempt { use crate::verisim_bridge::{prover_kind_to_str, ProofAttempt}; - let now = chrono::Utc::now(); + let now = crate::clock::now(); let obligation_id = goal .map(|g| crate::proof_encoding::goal_identity("dispatch", g)) .unwrap_or_else(|| "unknown".to_string()); @@ -1177,7 +1176,7 @@ fn build_proof_attempt( } else { 0.0 }; - let started_at = now - chrono::Duration::milliseconds(duration_ms as i64); + let started_at = now - time::Duration::milliseconds(duration_ms as i64); ProofAttempt { attempt_id: crate::ids::new_record_id().to_string(), @@ -1192,8 +1191,8 @@ fn build_proof_attempt( confidence, parent_attempt_id: None, strategy_tag: "dispatch".to_string(), - started_at: started_at.to_rfc3339(), - completed_at: now.to_rfc3339(), + started_at: crate::clock::to_rfc3339(started_at), + completed_at: crate::clock::to_rfc3339(now), prover_output: String::new(), error_message: None, } diff --git a/src/rust/integrity/solver_integrity.rs b/src/rust/integrity/solver_integrity.rs index 4c17b61e..2df1deee 100644 --- a/src/rust/integrity/solver_integrity.rs +++ b/src/rust/integrity/solver_integrity.rs @@ -67,7 +67,8 @@ pub struct SolverIntegrityReport { /// Expected hash from manifest pub expected_shake3_512: Option, /// Timestamp of last check - pub last_checked: chrono::DateTime, + #[serde(with = "time::serde::rfc3339")] + pub last_checked: time::OffsetDateTime, } /// Integrity checker for solver binaries @@ -214,7 +215,7 @@ impl IntegrityChecker { name: &str, entry: &SolverManifestEntry, ) -> SolverIntegrityReport { - let now = chrono::Utc::now(); + let now = crate::clock::now(); // Find the binary let actual_path = match Self::find_solver_binary(entry) { diff --git a/src/rust/learning/daemon.rs b/src/rust/learning/daemon.rs index e40e9d6f..d8c431b7 100644 --- a/src/rust/learning/daemon.rs +++ b/src/rust/learning/daemon.rs @@ -178,7 +178,7 @@ impl Daemon { .iter() .map(|t| format!("{:?}", t)) .collect(), - ts: chrono::Utc::now().to_rfc3339(), + ts: crate::clock::now_rfc3339(), rationale: &variant.rationale, }; let url = format!( diff --git a/src/rust/lib.rs b/src/rust/lib.rs index ec514d67..0b3949c9 100644 --- a/src/rust/lib.rs +++ b/src/rust/lib.rs @@ -9,6 +9,7 @@ pub mod agent; pub mod anomaly_detection; pub mod aspect; +pub mod clock; // The single wall-clock module (UTC now, RFC 3339, Unix seconds) pub mod coprocessor; // Math/Physics/DSP/FPGA/Tensor/Vector/Crypto/Graphics/Audio/IO compute (Phase 0: Math) pub mod corpus; // Project-corpus indexer (named decls + dependency DAG; first adapter: Agda) // `core` and `types` live in the `echidna-core` crate so vcl-ut and other diff --git a/src/rust/verification/proof.rs b/src/rust/verification/proof.rs index bc901918..cb47b85a 100644 --- a/src/rust/verification/proof.rs +++ b/src/rust/verification/proof.rs @@ -31,7 +31,6 @@ //! working while downstream consumers start reading the new FK-structured //! tables. -use chrono::Utc; use serde::{Deserialize, Serialize}; use sha2::{Digest, Sha256}; @@ -95,7 +94,7 @@ impl Proof { theorem_hash: theorem_identity(theorem_name), theorem_name: theorem_name.to_string(), prover, - first_seen: Utc::now().to_rfc3339(), + first_seen: crate::clock::now_rfc3339(), } } } @@ -162,7 +161,7 @@ impl TacticApplication { status, goals_after, duration_ms, - applied_at: Utc::now().to_rfc3339(), + applied_at: crate::clock::now_rfc3339(), } } } @@ -198,7 +197,7 @@ pub struct ProofVersion { impl ProofVersion { /// Initial snapshot (`version = 0`) of a newly-created proof. pub fn initial(proof: &Proof, state: &ProofState, actor: &str) -> Self { - let ts = Utc::now().timestamp(); + let ts = crate::clock::unix_now(); let seed = format!("{}:v0", proof.id); ProofVersion { proof_id: proof.id.clone(), @@ -207,7 +206,7 @@ impl ProofVersion { goals_remaining: state.goals.len() as u32, is_qed: state.is_complete(), actor: actor.to_string(), - recorded_at: Utc::now().to_rfc3339(), + recorded_at: crate::clock::now_rfc3339(), } } @@ -215,7 +214,7 @@ impl ProofVersion { /// counter. Passing a stale `prev` will produce a correctly-chained /// `version + 1` regardless of real-world timing drift. pub fn next(prev: &ProofVersion, state: &ProofState, actor: &str) -> Self { - let ts = Utc::now().timestamp(); + let ts = crate::clock::unix_now(); let next_version = prev.version + 1; let seed = format!("{}:v{}", prev.proof_id, next_version); ProofVersion { @@ -225,7 +224,7 @@ impl ProofVersion { goals_remaining: state.goals.len() as u32, is_qed: state.is_complete(), actor: actor.to_string(), - recorded_at: Utc::now().to_rfc3339(), + recorded_at: crate::clock::now_rfc3339(), } } } diff --git a/src/rust/verisim_bridge.rs b/src/rust/verisim_bridge.rs index f2382f4c..0b61812d 100644 --- a/src/rust/verisim_bridge.rs +++ b/src/rust/verisim_bridge.rs @@ -36,7 +36,6 @@ //! (CI gate planned, see schema doc "Drift detection" section). use anyhow::{Context, Result}; -use chrono::Utc; use serde::{Deserialize, Serialize}; use std::collections::HashMap; use tracing::{debug, warn}; @@ -375,8 +374,8 @@ impl ProofOctadBuilder { /// Build the octad payload. pub fn build(self) -> Result { - let now = Utc::now(); - let timestamp = now.to_rfc3339(); + let now = crate::clock::now(); + let timestamp = crate::clock::to_rfc3339(now); // Generate identities let octad_key = proof_encoding::proof_identity(&self.theorem_name, &self.goal, self.prover); diff --git a/tests/corpus_health_integration_test.rs b/tests/corpus_health_integration_test.rs index d8472299..fd6cec36 100644 --- a/tests/corpus_health_integration_test.rs +++ b/tests/corpus_health_integration_test.rs @@ -110,7 +110,6 @@ fn test_corpus_reset() { #[test] fn test_corpus_metrics_serialization() { - use chrono::Utc; use echidna::diagnostics::CorpusMetrics; let metrics = CorpusMetrics { @@ -118,7 +117,7 @@ fn test_corpus_metrics_serialization() { total_premises: 15000, size_mb: 2048.5, size_change_percent: 12.5, - last_updated: Utc::now(), + last_updated: echidna::clock::now(), }; // Verify metrics can be serialized to JSON diff --git a/tests/full_health_system_test.rs b/tests/full_health_system_test.rs index 6b19cf2e..61a41ee4 100644 --- a/tests/full_health_system_test.rs +++ b/tests/full_health_system_test.rs @@ -213,7 +213,7 @@ mod full_health_system_tests { name: format!("Prover{}", i), is_available: true, circuit_breaker_state: CircuitBreakerStateSnapshot::Closed, - last_successful_proof: Some(chrono::Utc::now()), + last_successful_proof: Some(echidna::clock::now()), consecutive_failures: 0, avg_latency_ms: 40.0, success_rate: 0.98, diff --git a/tests/live_prover_suite.rs b/tests/live_prover_suite.rs index 2a226bd0..dbbe581c 100644 --- a/tests/live_prover_suite.rs +++ b/tests/live_prover_suite.rs @@ -109,11 +109,10 @@ async fn emit_live_result(kind: ProverKind, exe: &str, version: Option<&str>, el confidence: if version.is_some() { 1.0 } else { 0.0 }, parent_attempt_id: None, strategy_tag: "live_version_check".to_string(), - started_at: chrono::Utc::now() - .checked_sub_signed(chrono::Duration::milliseconds(elapsed_ms as i64)) - .unwrap_or_else(chrono::Utc::now) - .to_rfc3339(), - completed_at: chrono::Utc::now().to_rfc3339(), + started_at: echidna::clock::to_rfc3339( + echidna::clock::now() - time::Duration::milliseconds(elapsed_ms as i64), + ), + completed_at: echidna::clock::now_rfc3339(), prover_output: version.unwrap_or("").to_string(), error_message: error_msg, }; diff --git a/tests/s4_loop_closure.rs b/tests/s4_loop_closure.rs index bcc8851c..a3a847b5 100644 --- a/tests/s4_loop_closure.rs +++ b/tests/s4_loop_closure.rs @@ -36,7 +36,7 @@ use echidna::verisim_bridge::{prover_kind_to_str, ProofAttempt, VeriSimDBClient} /// Build a minimal `ProofAttempt` row with a unique obligation_id so each /// test run is independent (no collisions with prior runs in the table). fn fresh_attempt(obligation_class: &str, prover: ProverKind, outcome: &str) -> ProofAttempt { - let now = chrono::Utc::now(); + let now = echidna::clock::now(); ProofAttempt { attempt_id: echidna::ids::new_record_id().to_string(), // Tag the obligation_id with the test name so we can find our own @@ -52,8 +52,8 @@ fn fresh_attempt(obligation_class: &str, prover: ProverKind, outcome: &str) -> P confidence: if outcome == "success" { 1.0 } else { 0.0 }, parent_attempt_id: None, strategy_tag: "test".to_string(), - started_at: now.to_rfc3339(), - completed_at: now.to_rfc3339(), + started_at: echidna::clock::to_rfc3339(now), + completed_at: echidna::clock::to_rfc3339(now), prover_output: String::new(), error_message: None, }