From ac11dddc92a5942b29bce4b75fc92b03a73c096f Mon Sep 17 00:00:00 2001 From: jgrusewski Date: Sun, 24 May 2026 23:11:03 +0200 Subject: [PATCH] fix(ml-features): imbalance bar cache on persistent PVC, not /tmp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cache path moved from /tmp/.foxhunt_imbalance_cache/ (ephemeral, lost between Argo pods) to /.cache/ (on the training-data PVC). Saves ~4 minutes per Argo submission by avoiding recomputation of 209M trade ticks → 17.8M imbalance bars. Co-Authored-By: Claude Opus 4.7 --- crates/ml-features/src/mbp10_loader.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/crates/ml-features/src/mbp10_loader.rs b/crates/ml-features/src/mbp10_loader.rs index 6e0fe775b..bcdb5a2f3 100644 --- a/crates/ml-features/src/mbp10_loader.rs +++ b/crates/ml-features/src/mbp10_loader.rs @@ -556,23 +556,27 @@ fn collect_dbn_files(dir: &Path) -> Vec { // // Computing imbalance bars from MBP-10 data requires decompressing ~19GB of // .dbn.zst files (~450s). This cache stores the resulting `Vec` to -// `/tmp/.foxhunt_imbalance_cache/.bars.bin` using bincode. +// `/.cache/.bars.bin` using bincode. Stored on the +// persistent training-data PVC so it survives across Argo pod restarts. // // Cache key: DefaultHasher of (mbp10_dir, symbol, threshold bits, alpha bits). // Invalidation: cache mtime vs. newest .dbn/.dbn.zst file in the source dir. // ══════════════════════════════════════════════════════════════════════════════ -/// Compute a cache path for an imbalance bar set. +/// Compute a cache path for an imbalance bar set. Stores alongside +/// the source data on the persistent volume so the cache survives +/// across Argo pod restarts. fn imbalance_cache_path(mbp10_dir: &Path, symbol: &str, threshold: f64, alpha: f64) -> std::path::PathBuf { use std::collections::hash_map::DefaultHasher; use std::hash::{Hash, Hasher}; let mut hasher = DefaultHasher::new(); - mbp10_dir.hash(&mut hasher); symbol.hash(&mut hasher); threshold.to_bits().hash(&mut hasher); alpha.to_bits().hash(&mut hasher); let hash = hasher.finish(); - std::path::PathBuf::from(format!("/tmp/.foxhunt_imbalance_cache/{:016x}.bars.bin", hash)) + let cache_dir = mbp10_dir.join(".cache"); + let _ = std::fs::create_dir_all(&cache_dir); + cache_dir.join(format!("{:016x}.bars.bin", hash)) } /// Check whether the cache file is newer than every `.dbn`/`.dbn.zst` file under `source_dir`. @@ -856,7 +860,7 @@ pub fn imbalance_bars_sequential(trades: &[Mbp10Trade], threshold: f64) -> Vec.bars.bin`. +/// Results are cached to `/.cache/.bars.bin`. /// Subsequent calls with the same parameters return in <1s if no source files /// have changed. ///