From 4ef1da301daf0f26594ce79081ecb0b60ed13eb2 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 00:37:50 +0300 Subject: [PATCH 001/119] refactor(cli): move standalone CLI binaries into a dedicated crate The tinyjuice and tinyjuice-reduce binaries, their tests, and the cli-disk-tier cache module now live in the new tinyjuice-cli crate, which is added to the workspace. The disk tier is dropped from the core cache store so persistence is handled solely by the host-provided durable tier, and the binaries no longer require the cli-disk-tier feature. Auto-committed-on: dragonfly --- Cargo.toml | 6 ++--- .../tinyjuice-cli/src/bin/tinyjuice-reduce.rs | 0 .../tinyjuice-cli/src}/bin/tinyjuice.rs | 0 .../src/bin/tinyjuice_reduce_tests.rs | 0 {tests => crates/tinyjuice-cli/tests}/cli.rs | 0 .../tinyjuice-cli/tests}/host_cli.rs | 0 src/cache/mod.rs | 10 ------- src/cache/store.rs | 26 +++---------------- 8 files changed, 6 insertions(+), 36 deletions(-) rename src/main.rs => crates/tinyjuice-cli/src/bin/tinyjuice-reduce.rs (100%) rename {src => crates/tinyjuice-cli/src}/bin/tinyjuice.rs (100%) rename src/main_tests.rs => crates/tinyjuice-cli/src/bin/tinyjuice_reduce_tests.rs (100%) rename {tests => crates/tinyjuice-cli/tests}/cli.rs (100%) rename {tests => crates/tinyjuice-cli/tests}/host_cli.rs (100%) diff --git a/Cargo.toml b/Cargo.toml index 9a90398d..7e73e0ad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,8 +21,8 @@ exclude = [ ] [workspace] -members = ["crates/tinyjuice-bus", "crates/tinyjuice-module", "crates/tinyjuice-drivers"] -default-members = [".", "crates/tinyjuice-bus", "crates/tinyjuice-module", "crates/tinyjuice-drivers"] +members = ["crates/tinyjuice-bus", "crates/tinyjuice-module", "crates/tinyjuice-drivers", "crates/tinyjuice-cli"] +default-members = [".", "crates/tinyjuice-bus", "crates/tinyjuice-module", "crates/tinyjuice-drivers", "crates/tinyjuice-cli"] exclude = ["vendor/tinybus", "vendor/tinyagents", "crates/tinyjuice-examples"] resolver = "3" @@ -76,12 +76,10 @@ tokio = { version = "1", features = ["macros", "rt", "test-util"] } [[bin]] name = "tinyjuice" path = "src/bin/tinyjuice.rs" -required-features = ["cli-disk-tier"] [[bin]] name = "tinyjuice-reduce" path = "src/main.rs" -required-features = ["cli-disk-tier"] # These integration suites launch the CLI binaries, which are unavailable in # the default host build without the standalone CLI disk-tier feature. diff --git a/src/main.rs b/crates/tinyjuice-cli/src/bin/tinyjuice-reduce.rs similarity index 100% rename from src/main.rs rename to crates/tinyjuice-cli/src/bin/tinyjuice-reduce.rs diff --git a/src/bin/tinyjuice.rs b/crates/tinyjuice-cli/src/bin/tinyjuice.rs similarity index 100% rename from src/bin/tinyjuice.rs rename to crates/tinyjuice-cli/src/bin/tinyjuice.rs diff --git a/src/main_tests.rs b/crates/tinyjuice-cli/src/bin/tinyjuice_reduce_tests.rs similarity index 100% rename from src/main_tests.rs rename to crates/tinyjuice-cli/src/bin/tinyjuice_reduce_tests.rs diff --git a/tests/cli.rs b/crates/tinyjuice-cli/tests/cli.rs similarity index 100% rename from tests/cli.rs rename to crates/tinyjuice-cli/tests/cli.rs diff --git a/tests/host_cli.rs b/crates/tinyjuice-cli/tests/host_cli.rs similarity index 100% rename from tests/host_cli.rs rename to crates/tinyjuice-cli/tests/host_cli.rs diff --git a/src/cache/mod.rs b/src/cache/mod.rs index 336fbadc..759f9f1e 100644 --- a/src/cache/mod.rs +++ b/src/cache/mod.rs @@ -1,10 +1,5 @@ //! CCR (Compress-Cache-Retrieve) — original storage + retrieval markers. -#[cfg(all(test, feature = "cli-disk-tier"))] -pub(crate) static DISK_TIER_TEST_LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(()); - -#[cfg(feature = "cli-disk-tier")] -mod disk_tier; pub mod marker; pub mod store; @@ -18,8 +13,3 @@ pub use store::{ retrieve_range, set_durable_tier, short_hash, stats, }; -#[cfg(feature = "cli-disk-tier")] -pub use disk_tier::{ - DEFAULT_DISK_MAX_BYTES, GcStats, configure_disk_cap, disable_disk_tier, enable_disk_tier, - gc_disk_dir, gc_disk_tier, -}; diff --git a/src/cache/store.rs b/src/cache/store.rs index b202b4a1..0672e12e 100644 --- a/src/cache/store.rs +++ b/src/cache/store.rs @@ -9,8 +9,7 @@ //! //! Process-global and bounded by **both** an entry count and a total byte cap, //! with an optional TTL. Keyed by content hash, so re-offloading identical -//! content is idempotent. Hosted persistence is supplied through [`CcrStore`]; -//! only standalone CLI builds can opt into a filesystem tier. +//! content is idempotent. Persistence is supplied through [`CcrStore`]. use sha2::{Digest, Sha256}; use std::collections::{HashMap, VecDeque}; @@ -288,7 +287,7 @@ pub fn offload_checked(content: &str) -> (String, bool) { /// Like [`offload_checked`] but takes the precomputed `short_hash(content)` /// so callers that already have it (e.g. the router builds the footer from the /// hash before deciding to store) don't pay for a second SHA-256 pass. -/// Returns whether the original was retained (memory or disk). +/// Returns whether the original was retained (memory or the host's durable store). pub fn offload_checked_with_hash(hash: &str, content: &str) -> bool { debug_assert_eq!(hash, short_hash(content), "hash must match content"); let (max_entries, max_bytes, ttl) = { @@ -302,16 +301,6 @@ pub fn offload_checked_with_hash(hash: &str, content: &str) -> bool { max_bytes, ); - // Mirror to the standalone CLI disk tier when enabled (best-effort). A successful write - // write keeps the original recoverable even when it was too big for memory. - // Rewriting an existing hash intentionally refreshes the file mtime, which - // is the TTL clock for disk-backed CCR entries. - #[cfg(feature = "cli-disk-tier")] - let disk_retained = crate::cache::disk_tier::put(hash, content, ttl); - #[cfg(not(feature = "cli-disk-tier"))] - let disk_retained = false; - #[cfg(not(feature = "cli-disk-tier"))] - let _ = ttl; // Mirror to the host-provided durable tier (best-effort). let durable = durable_tier() .read() @@ -329,7 +318,7 @@ pub fn offload_checked_with_hash(hash: &str, content: &str) -> bool { } put.retained() && same_token }); - mem_retained || disk_retained || durable_retained + mem_retained || durable_retained } /// True if `hash` is a well-formed CCR token (exactly the generated hex digest). @@ -340,7 +329,7 @@ pub(super) fn is_valid_token(hash: &str) -> bool { } /// Retrieve a previously-offloaded original by hash, if still available -/// (memory first, then a host durable store or the standalone CLI disk tier). +/// (memory first, then a host durable store). /// Honours the in-memory TTL; durable stores own their own expiry. pub fn retrieve(hash: &str) -> Option { // Reject anything that isn't the generated token shape up front. @@ -368,13 +357,6 @@ pub fn retrieve(hash: &str) -> Option { if let Some(found) = durable.and_then(|store| store.get(hash)) { return Some(found); } - // Filesystem fallback, available only to standalone CLI builds. - #[cfg(feature = "cli-disk-tier")] - { - if let Some(found) = crate::cache::disk_tier::get(hash, ttl) { - return Some(found); - } - } None } From da2a8842b5691cfa293d861ef82a1655062eb4a9 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 00:37:58 +0300 Subject: [PATCH 002/119] refactor(tinyjuice-cli): move cli tests into the crate Relocate the tinyjuice binary's test module into the tinyjuice-cli crate so it lives alongside the code it exercises. The file contents are unchanged. Auto-committed-on: dragonfly --- .../tinyjuice-cli/src}/bin/tinyjuice/tinyjuice_tests.rs | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {src => crates/tinyjuice-cli/src}/bin/tinyjuice/tinyjuice_tests.rs (100%) diff --git a/src/bin/tinyjuice/tinyjuice_tests.rs b/crates/tinyjuice-cli/src/bin/tinyjuice/tinyjuice_tests.rs similarity index 100% rename from src/bin/tinyjuice/tinyjuice_tests.rs rename to crates/tinyjuice-cli/src/bin/tinyjuice/tinyjuice_tests.rs From 876287e5d72bb13bb59218e1e4aee0f65400b5d4 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 00:38:35 +0300 Subject: [PATCH 003/119] chore: remove standalone cli binaries and disk-tier feature The root package no longer declares the tinyjuice and tinyjuice-reduce binaries, their integration test targets, or the cli-disk-tier feature, since the CLI now lives in its own crate. Auto-committed-on: dragonfly --- Cargo.toml | 23 ----------------------- crates/tinyjuice-cli/Cargo.toml | 28 ++++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 23 deletions(-) create mode 100644 crates/tinyjuice-cli/Cargo.toml diff --git a/Cargo.toml b/Cargo.toml index 7e73e0ad..8293e334 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -73,26 +73,6 @@ criterion = "0.8" tempfile = "3" tokio = { version = "1", features = ["macros", "rt", "test-util"] } -[[bin]] -name = "tinyjuice" -path = "src/bin/tinyjuice.rs" - -[[bin]] -name = "tinyjuice-reduce" -path = "src/main.rs" - -# These integration suites launch the CLI binaries, which are unavailable in -# the default host build without the standalone CLI disk-tier feature. -[[test]] -name = "cli" -path = "tests/cli.rs" -required-features = ["cli-disk-tier"] - -[[test]] -name = "host_cli" -path = "tests/host_cli.rs" -required-features = ["cli-disk-tier"] - [[bench]] name = "compression" harness = false @@ -101,9 +81,6 @@ harness = false default = ["tinyjuice-treesitter"] # Exposes the REPL ops as `tinytools::Tool` impls (see src/repl/tools.rs). tinytools = ["dep:tinytools", "dep:anyhow", "jq"] -# File-backed CCR cache commands for the standalone CLI only. Hosts use their -# own durable CcrStore implementation through the storage bus. -cli-disk-tier = [] # Turn-bound `MlHost.Generate` registry (src/host/generate.rs). host = ["dep:anyhow", "dep:uuid"] # jq-style queries over JSON outputs (the `jq` REPL op and `juice_jq` tool). diff --git a/crates/tinyjuice-cli/Cargo.toml b/crates/tinyjuice-cli/Cargo.toml new file mode 100644 index 00000000..1ae93eb3 --- /dev/null +++ b/crates/tinyjuice-cli/Cargo.toml @@ -0,0 +1,28 @@ +[package] +name = "tinyjuice-cli" +version = "0.11.0" +edition = "2024" +rust-version = "1.88" +publish = false +license = "GPL-3.0-only" +description = "Standalone TinyJuice command-line tools." +repository = "https://github.com/tinyhumansai/tinyjuice" + +[dependencies] +tinyjuice = { path = "../.." } +tinyjuice-drivers = { path = "../tinyjuice-drivers" } +tinystoragedrivers = { version = "2.0.1", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.1", features = ["file"] } +dirs = "7" +serde_json = "1" +tokio = { version = "1", features = ["rt-multi-thread"] } + +[dev-dependencies] +tempfile = "3" + +[[bin]] +name = "tinyjuice" +path = "src/bin/tinyjuice.rs" + +[[bin]] +name = "tinyjuice-reduce" +path = "src/bin/tinyjuice-reduce.rs" From d2362108b2f89102443119ca0f0c94528ebe1956 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 00:38:39 +0300 Subject: [PATCH 004/119] chore(cache): remove standalone CLI disk tier The filesystem-backed CCR used by standalone CLI builds is gone, along with its tests. The disk tier is no longer needed now that the CLI relies on the in-memory store. Auto-committed-on: dragonfly --- src/cache/disk_tier.rs | 194 ---------------------------- src/cache/disk_tier_tests.rs | 241 ----------------------------------- 2 files changed, 435 deletions(-) delete mode 100644 src/cache/disk_tier.rs delete mode 100644 src/cache/disk_tier_tests.rs diff --git a/src/cache/disk_tier.rs b/src/cache/disk_tier.rs deleted file mode 100644 index 97268364..00000000 --- a/src/cache/disk_tier.rs +++ /dev/null @@ -1,194 +0,0 @@ -//! Optional filesystem-backed CCR for standalone CLI builds. - -use super::store::{DEFAULT_MAX_BYTES, is_valid_token}; -use std::io; -use std::path::{Path, PathBuf}; -use std::sync::atomic::{AtomicU64, Ordering}; -use std::sync::{OnceLock, RwLock}; -use std::time::{Duration, SystemTime}; - -/// Default total-bytes cap for the CLI disk tier (matches the memory cap). -pub const DEFAULT_DISK_MAX_BYTES: u64 = DEFAULT_MAX_BYTES as u64; -const DISK_CAP_ENFORCE_EVERY: u64 = 128; - -fn root() -> &'static RwLock> { - static ROOT: OnceLock>> = OnceLock::new(); - ROOT.get_or_init(|| RwLock::new(None)) -} - -fn cap() -> &'static RwLock> { - static CAP: OnceLock>> = OnceLock::new(); - CAP.get_or_init(|| RwLock::new(Some(DEFAULT_DISK_MAX_BYTES))) -} - -/// Configure the maximum disk-tier bytes enforced during offload. -pub fn configure_disk_cap(max_bytes: Option) { - *cap().write().unwrap_or_else(|p| p.into_inner()) = max_bytes; -} - -/// Enable the file-backed tier used by standalone CLI commands. -pub fn enable_disk_tier(path: PathBuf) { - if std::fs::create_dir_all(&path).is_ok() { - *root().write().unwrap_or_else(|p| p.into_inner()) = Some(path); - } else { - log::warn!("[tinyjuice][ccr] could not create CLI disk tier at {path:?}"); - } -} - -/// Disable new filesystem writes and lookups for the standalone CLI. -pub fn disable_disk_tier() { - *root().write().unwrap_or_else(|p| p.into_inner()) = None; -} - -/// Disk-tier garbage-collection outcome. -#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)] -pub struct GcStats { - pub removed: usize, - pub freed_bytes: u64, - pub kept: usize, - pub kept_bytes: u64, -} - -/// Store an original in the configured CLI disk tier. -pub(super) fn put(token: &str, content: &str, ttl: Option) -> bool { - let Some(root) = root().read().unwrap_or_else(|p| p.into_inner()).clone() else { - return false; - }; - if std::fs::write(root.join(token), content).is_err() { - return false; - } - static WRITES: AtomicU64 = AtomicU64::new(0); - let n = WRITES.fetch_add(1, Ordering::Relaxed) + 1; - if n.is_multiple_of(DISK_CAP_ENFORCE_EVERY) { - let max_bytes = *cap().read().unwrap_or_else(|p| p.into_inner()); - if (ttl.is_some() || max_bytes.is_some()) - && let Err(error) = gc_dir_protecting(&root, ttl, max_bytes, Some(token)) - { - log::debug!("[tinyjuice][ccr] disk-tier sweep failed: {error}"); - } - } - true -} - -/// Read a token from the CLI disk tier, respecting the configured TTL. -pub(super) fn get(token: &str, ttl: Option) -> Option { - let root = root().read().unwrap_or_else(|p| p.into_inner()).clone()?; - get_from(&root, token, ttl) -} - -fn get_from(root: &Path, token: &str, ttl: Option) -> Option { - let path = root.join(token); - if disk_entry_expired(&path, ttl) { - log::debug!("[tinyjuice][ccr] disk entry expired for {token}"); - let _ = std::fs::remove_file(path); - return None; - } - std::fs::read_to_string(path).ok() -} - -/// Sweep the configured CLI disk tier. -pub fn gc_disk_tier(ttl: Option, max_bytes: Option) -> io::Result { - gc_disk_tier_at( - root().read().unwrap_or_else(|p| p.into_inner()).clone(), - ttl, - max_bytes, - ) -} - -fn gc_disk_tier_at( - path: Option, - ttl: Option, - max_bytes: Option, -) -> io::Result { - let Some(path) = path else { - return Ok(GcStats::default()); - }; - gc_disk_dir(&path, ttl, max_bytes) -} - -/// Sweep one explicit directory, considering files named by valid CCR tokens. -pub fn gc_disk_dir( - path: &Path, - ttl: Option, - max_bytes: Option, -) -> io::Result { - gc_dir_protecting(path, ttl, max_bytes, None) -} - -fn gc_dir_protecting( - root: &Path, - ttl: Option, - max_bytes: Option, - protect: Option<&str>, -) -> io::Result { - let entries = match std::fs::read_dir(root) { - Ok(entries) => entries, - Err(error) if error.kind() == io::ErrorKind::NotFound => return Ok(GcStats::default()), - Err(error) => return Err(error), - }; - let mut stats = GcStats::default(); - let mut kept: Vec<(PathBuf, u64, SystemTime)> = Vec::new(); - let now = SystemTime::now(); - for entry in entries { - let entry = entry?; - let name = entry.file_name(); - let Some(name) = name.to_str() else { continue }; - if !is_valid_token(name) { - continue; - } - let Ok(metadata) = entry.metadata() else { - continue; - }; - if !metadata.is_file() { - continue; - } - let bytes = metadata.len(); - let modified = metadata.modified().unwrap_or(now); - let expired = ttl.is_some_and(|ttl| { - now.duration_since(modified) - .is_ok_and(|elapsed| elapsed >= ttl) - }); - if expired && std::fs::remove_file(entry.path()).is_ok() { - stats.removed += 1; - stats.freed_bytes += bytes; - } else { - kept.push((entry.path(), bytes, modified)); - } - } - let mut total: u64 = kept.iter().map(|(_, bytes, _)| bytes).sum(); - if let Some(max_bytes) = max_bytes { - kept.sort_by_key(|(_, _, modified)| *modified); - let mut index = 0; - while total > max_bytes && index < kept.len() { - let (path, bytes, _) = &kept[index]; - let protected = - protect.is_some_and(|token| path.file_name().is_some_and(|name| name == token)); - if !protected && std::fs::remove_file(path).is_ok() { - stats.removed += 1; - stats.freed_bytes += bytes; - total -= bytes; - kept.remove(index); - } else { - index += 1; - } - } - } - stats.kept = kept.len(); - stats.kept_bytes = total; - Ok(stats) -} - -fn disk_entry_expired(path: &Path, ttl: Option) -> bool { - let Some(ttl) = ttl else { return false }; - let Ok(metadata) = std::fs::metadata(path) else { - return false; - }; - let Ok(modified) = metadata.modified() else { - return false; - }; - modified.elapsed().is_ok_and(|elapsed| elapsed >= ttl) -} - -#[cfg(test)] -#[path = "disk_tier_tests.rs"] -mod tests; diff --git a/src/cache/disk_tier_tests.rs b/src/cache/disk_tier_tests.rs deleted file mode 100644 index 7330817c..00000000 --- a/src/cache/disk_tier_tests.rs +++ /dev/null @@ -1,241 +0,0 @@ -use super::*; -use crate::cache::{CcrStore, GlobalCcrStore, RangeUnit, disable_disk_tier, short_hash, stats}; - -/// Write a token-named file with a back-dated mtime. -fn write_aged(dir: &Path, name: &str, bytes: usize, age: Duration) -> PathBuf { - let path = dir.join(name); - std::fs::write(&path, "x".repeat(bytes)).unwrap(); - let file = std::fs::File::options().write(true).open(&path).unwrap(); - file.set_modified(SystemTime::now() - age).unwrap(); - path -} - -fn token(fill: char) -> String { - fill.to_string().repeat(32) -} - -#[test] -fn gc_removes_expired_keeps_fresh() { - let dir = tempfile::tempdir().unwrap(); - let old = write_aged(dir.path(), &token('a'), 10, Duration::from_secs(600)); - let fresh = write_aged(dir.path(), &token('b'), 20, Duration::ZERO); - - let stats = gc_disk_dir(dir.path(), Some(Duration::from_secs(60)), None).unwrap(); - assert_eq!(stats.removed, 1); - assert_eq!(stats.freed_bytes, 10); - assert_eq!(stats.kept, 1); - assert_eq!(stats.kept_bytes, 20); - assert!(!old.exists()); - assert!(fresh.exists()); -} - -#[test] -fn gc_evicts_oldest_over_budget() { - let dir = tempfile::tempdir().unwrap(); - let oldest = write_aged(dir.path(), &token('a'), 100, Duration::from_secs(30)); - let middle = write_aged(dir.path(), &token('b'), 100, Duration::from_secs(20)); - let newest = write_aged(dir.path(), &token('c'), 100, Duration::from_secs(10)); - - let stats = gc_disk_dir(dir.path(), None, Some(250)).unwrap(); - assert_eq!(stats.removed, 1, "one eviction brings 300 under 250"); - assert_eq!(stats.freed_bytes, 100); - assert_eq!(stats.kept, 2); - assert!(!oldest.exists(), "oldest-by-mtime goes first"); - assert!(middle.exists()); - assert!(newest.exists()); -} - -#[test] -fn gc_ignores_non_token_files_and_missing_dir() { - let dir = tempfile::tempdir().unwrap(); - let stray = dir.path().join("README.txt"); - std::fs::write(&stray, "not a ccr entry").unwrap(); - - let stats = gc_disk_dir(dir.path(), Some(Duration::ZERO), Some(0)).unwrap(); - assert_eq!(stats, GcStats::default()); - assert!(stray.exists(), "non-token files are never touched"); - - let missing = dir.path().join("does-not-exist"); - assert_eq!( - gc_disk_dir(&missing, None, None).unwrap(), - GcStats::default() - ); -} - -#[test] -fn gc_protects_named_entry_from_budget_eviction() { - let dir = tempfile::tempdir().unwrap(); - let protected_name = token('a'); - let protected = write_aged(dir.path(), &protected_name, 100, Duration::from_secs(30)); - let newer = write_aged(dir.path(), &token('b'), 100, Duration::from_secs(10)); - - let stats = gc_dir_protecting(dir.path(), None, Some(150), Some(&protected_name)).unwrap(); - assert!( - protected.exists(), - "protected entry survives even when oldest" - ); - assert!(!newer.exists(), "eviction falls through to the next-oldest"); - assert_eq!(stats.removed, 1); - assert_eq!(stats.kept, 1); -} - -#[test] -fn disk_entry_ttl_uses_file_mtime() { - let dir = std::env::temp_dir().join(format!("tj-ccr-ttl-{}", short_hash("disk-ttl"))); - let _ = std::fs::remove_dir_all(&dir); - std::fs::create_dir_all(&dir).unwrap(); - let path = dir.join("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); - std::fs::write(&path, "disk ttl payload").unwrap(); - - assert!(!disk_entry_expired(&path, None)); - assert!(!disk_entry_expired(&path, Some(Duration::from_secs(60)))); - assert!(disk_entry_expired(&path, Some(Duration::ZERO))); - - let _ = std::fs::remove_dir_all(&dir); -} - -#[test] -fn configured_tier_reads_entries_expires_them_and_runs_gc() { - let dir = tempfile::tempdir().unwrap(); - let name = token('d'); - let path = dir.path().join(&name); - std::fs::write(&path, "disk-backed payload").unwrap(); - - assert_eq!( - get_from(dir.path(), &name, None).as_deref(), - Some("disk-backed payload") - ); - let sweep = gc_disk_dir(dir.path(), None, None).unwrap(); - assert_eq!(sweep.kept, 1); - - let file = std::fs::File::options().write(true).open(&path).unwrap(); - file.set_modified(SystemTime::now() - Duration::from_secs(5)) - .unwrap(); - assert_eq!( - get_from(dir.path(), &name, Some(Duration::from_secs(1))), - None - ); - assert!(!path.exists(), "expired reads remove the disk entry"); -} - -#[test] -fn configured_gc_sweeps_the_selected_directory() { - let dir = tempfile::tempdir().unwrap(); - let path = dir.path().join(token('a')); - std::fs::write(&path, "remove me").unwrap(); - - let stats = gc_disk_tier_at(Some(dir.path().to_path_buf()), None, Some(0)).unwrap(); - assert_eq!(stats.removed, 1); - assert_eq!(stats.freed_bytes, 9); - assert!(!path.exists()); - assert_eq!( - gc_disk_tier_at(None, None, None).unwrap(), - GcStats::default() - ); -} - -#[test] -fn enabling_tier_with_a_file_as_root_is_best_effort() { - let _guard = crate::cache::DISK_TIER_TEST_LOCK - .lock() - .unwrap_or_else(|poisoned| poisoned.into_inner()); - let dir = tempfile::tempdir().unwrap(); - let file = dir.path().join("not-a-directory"); - std::fs::write(&file, "keep this file").unwrap(); - - enable_disk_tier(file.clone()); - - assert_eq!(std::fs::read_to_string(file).unwrap(), "keep this file"); - let memory = crate::cache::MemoryCcrStore::new(4, 1024); - let stored = memory.put("memory remains available"); - assert!(stored.retained()); - assert_eq!( - memory.get(stored.token()).as_deref(), - Some("memory remains available") - ); - disable_disk_tier(); -} - -#[test] -fn periodic_write_sweep_removes_expired_entries() { - let _guard = crate::cache::DISK_TIER_TEST_LOCK - .lock() - .unwrap_or_else(|poisoned| poisoned.into_inner()); - let dir = tempfile::tempdir().unwrap(); - enable_disk_tier(dir.path().to_path_buf()); - const TTL_SECS: u64 = 30 * 24 * 60 * 60; - crate::cache::configure(usize::MAX, usize::MAX, Some(TTL_SECS)); - configure_disk_cap(None); - - let expired = write_aged( - dir.path(), - &token('a'), - 10, - Duration::from_secs(TTL_SECS + 60), - ); - // A full interval guarantees that the process-wide write counter reaches a - // sweep regardless of where other tests left it. - for index in 0..DISK_CAP_ENFORCE_EVERY { - let content = format!("fresh original {index}"); - let (_, retained) = crate::cache::offload_checked(&content); - assert!(retained, "fixture write {index} must succeed"); - } - - let expired_remains = expired.exists(); - disable_disk_tier(); - crate::cache::configure( - crate::cache::DEFAULT_MAX_ENTRIES, - crate::cache::DEFAULT_MAX_BYTES, - None, - ); - configure_disk_cap(Some(DEFAULT_DISK_MAX_BYTES)); - assert!( - !expired_remains, - "periodic sweep must enforce the configured TTL" - ); -} - -#[test] -fn garbage_collection_skips_nonentries_and_protects_inflight_original() { - let dir = tempfile::tempdir().unwrap(); - std::fs::write(dir.path().join("notes"), "unrelated").unwrap(); - std::fs::create_dir(dir.path().join("a".repeat(32))).unwrap(); - let protected = short_hash("protected"); - std::fs::write(dir.path().join(&protected), "protected").unwrap(); - let removed = short_hash("removed"); - std::fs::write(dir.path().join(&removed), "removed").unwrap(); - let stats = gc_dir_protecting(dir.path(), None, Some(0), Some(&protected)).unwrap(); - assert_eq!(stats.removed, 1); - assert_eq!(stats.kept, 1); - assert_eq!(stats.kept_bytes, 9); - assert!(dir.path().join(&protected).exists()); - assert!(dir.path().join("notes").exists()); - assert_eq!( - gc_disk_dir(&dir.path().join("absent"), None, None).unwrap(), - GcStats::default() - ); - assert!(gc_disk_dir(&dir.path().join("notes"), None, None).is_err()); -} - -#[test] -fn global_adapter_supports_ranges_and_unconfigured_disk_gc() { - let _guard = crate::cache::DISK_TIER_TEST_LOCK - .lock() - .unwrap_or_else(|poisoned| poisoned.into_inner()); - let store = GlobalCcrStore; - let put = store.put("global ranged retrieval fixture\nsecond"); - assert!(put.retained()); - assert_eq!( - store - .get_range(put.token(), 1, 2, RangeUnit::Lines) - .as_deref(), - Some("second") - ); - assert!(stats().0 > 0); - disable_disk_tier(); - assert!(gc_disk_tier(None, None).is_ok()); - assert!(!disk_entry_expired( - &PathBuf::from("/nonexistent-tinyjuice-fixture"), - Some(Duration::ZERO) - )); -} From 1990a864b32a4f9da45d8b805c84c890b835623b Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 00:39:04 +0300 Subject: [PATCH 005/119] test(cache): remove disk tier fallback test The disk tier survives memory miss test and its feature-gated imports were dropped, leaving the store tests without coverage of the disk fallback path. Auto-committed-on: dragonfly --- src/cache/store_tests.rs | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/src/cache/store_tests.rs b/src/cache/store_tests.rs index 25e60aa2..5abadced 100644 --- a/src/cache/store_tests.rs +++ b/src/cache/store_tests.rs @@ -1,6 +1,4 @@ use super::*; -#[cfg(feature = "cli-disk-tier")] -use crate::cache::{disable_disk_tier, enable_disk_tier}; #[test] fn round_trips() { @@ -150,32 +148,6 @@ fn memory_store_rejects_malformed_tokens() { ); } -#[test] -#[cfg(feature = "cli-disk-tier")] -fn disk_tier_survives_memory_miss() { - let _guard = crate::cache::DISK_TIER_TEST_LOCK - .lock() - .unwrap_or_else(|poisoned| poisoned.into_inner()); - let dir = std::env::temp_dir().join(format!("tj-ccr-{}", short_hash("disk-test-seed"))); - let _ = std::fs::remove_dir_all(&dir); - enable_disk_tier(dir.clone()); - let original = "disk tier unique payload charlie ".repeat(40); - let hash = offload(&original); - // Simulate memory eviction by clearing the in-memory map directly. - { - let mut inner = global().lock().unwrap_or_else(|p| p.into_inner()); - inner.map.remove(&hash); - } - assert_eq!( - retrieve(&hash).as_deref(), - Some(original.as_str()), - "disk fallback" - ); - // Disable the tier for other tests and clean up. - disable_disk_tier(); - let _ = std::fs::remove_dir_all(&dir); -} - #[test] fn offload_with_hash_round_trips() { let original = "ccr precomputed-hash unique payload delta ".repeat(30); From 59bd0d331d55587231eeb40436460ebbfc262942 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 00:39:21 +0300 Subject: [PATCH 006/119] chore(drivers): migrate to tinystoragedrivers v2 crates The drivers crate now depends on the split tinystoragedrivers-api and tinystoragedrivers-types crates at v2.0.1 instead of the monolithic tinystoragedrivers-core, and blob_store imports Blocking from the local module since the new API no longer provides it. The reduce binary's test module path was also corrected to match its actual file name. Auto-committed-on: dragonfly --- crates/tinyjuice-cli/src/bin/tinyjuice-reduce.rs | 2 +- crates/tinyjuice-drivers/Cargo.toml | 5 +++-- crates/tinyjuice-drivers/src/blob_store.rs | 5 ++++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/tinyjuice-cli/src/bin/tinyjuice-reduce.rs b/crates/tinyjuice-cli/src/bin/tinyjuice-reduce.rs index cc47989c..bd0d6e6e 100644 --- a/crates/tinyjuice-cli/src/bin/tinyjuice-reduce.rs +++ b/crates/tinyjuice-cli/src/bin/tinyjuice-reduce.rs @@ -1305,5 +1305,5 @@ fn print_uninstall_usage() { } #[cfg(test)] -#[path = "main_tests.rs"] +#[path = "tinyjuice_reduce_tests.rs"] mod tests; diff --git a/crates/tinyjuice-drivers/Cargo.toml b/crates/tinyjuice-drivers/Cargo.toml index b71f6377..c92ff992 100644 --- a/crates/tinyjuice-drivers/Cargo.toml +++ b/crates/tinyjuice-drivers/Cargo.toml @@ -12,9 +12,10 @@ repository = "https://github.com/tinyhumansai/tinyjuice" publish = false [dependencies] -tinyjuice-bus = { path = "../tinyjuice-bus", features = ["storage"] } +tinyjuice-bus = { path = "../tinyjuice-bus" } tinyjuice = { path = "../..", default-features = false } -tinystoragedrivers-core = { version = "1.0.0", git = "https://github.com/tinyhumansai/tinystoragedrivers", tag = "v1.0.0", features = ["blocking"] } +tinystoragedrivers-api = { version = "2.0.1", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.1" } +tinystoragedrivers-types = { version = "2.0.1", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.1" } log = "0.4" [dev-dependencies] diff --git a/crates/tinyjuice-drivers/src/blob_store.rs b/crates/tinyjuice-drivers/src/blob_store.rs index 8103b887..4f84a54e 100644 --- a/crates/tinyjuice-drivers/src/blob_store.rs +++ b/crates/tinyjuice-drivers/src/blob_store.rs @@ -4,7 +4,10 @@ use std::sync::Arc; use std::time::Duration; use tinyjuice::cache::store::{CcrPutResult, CcrStore, RangeUnit, range_from_original, short_hash}; -use tinystoragedrivers_core::{BlobStore, Blocking, Capability, StorageError}; +use tinystoragedrivers_api::BlobStore; +use tinystoragedrivers_types::{Capability, StorageError}; + +use crate::blocking::Blocking; pub use tinyjuice_bus::storage::CCR_PREFIX; From d5081c3d437240ace65f644c6c4e12ade54a22a0 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 00:39:35 +0300 Subject: [PATCH 007/119] docs(tinyjuice-drivers): update intra-doc links to current crate paths The rustdoc links for BlobStore and Blocking still pointed at the old tinystoragedrivers_core paths, so they no longer resolved. They now point at tinystoragedrivers_api and the local blocking module respectively, and the stale storage_schema re-export was dropped. Auto-committed-on: dragonfly --- crates/tinyjuice-drivers/src/blocking.rs | 66 ++++++++++++++++++++++++ crates/tinyjuice-drivers/src/lib.rs | 6 +-- 2 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 crates/tinyjuice-drivers/src/blocking.rs diff --git a/crates/tinyjuice-drivers/src/blocking.rs b/crates/tinyjuice-drivers/src/blocking.rs new file mode 100644 index 00000000..d99bedf4 --- /dev/null +++ b/crates/tinyjuice-drivers/src/blocking.rs @@ -0,0 +1,66 @@ +//! Runtime bridge for the synchronous CCR cache port. + +use std::fmt; +use std::future::Future; +use std::sync::mpsc::{self, Sender}; +use std::thread; + +use tinystoragedrivers_types::StorageError; + +type Job = Box; + +thread_local! { + static ON_BRIDGE: std::cell::Cell = const { std::cell::Cell::new(false) }; +} + +/// Runs asynchronous storage operations for the synchronous `CcrStore` trait. +#[derive(Clone)] +pub(crate) struct Blocking { + jobs: Sender, +} + +impl fmt::Debug for Blocking { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Blocking").finish_non_exhaustive() + } +} + +impl Blocking { + pub(crate) fn new() -> Result { + let (jobs, receiver) = mpsc::channel::(); + thread::Builder::new() + .name("tinyjuice-storage-bridge".into()) + .spawn(move || { + let Ok(runtime) = tokio::runtime::Builder::new_current_thread() + .enable_all() + .build() + else { + return; + }; + ON_BRIDGE.with(|active| active.set(true)); + while let Ok(job) = receiver.recv() { + job(&runtime); + } + }) + .map_err(|error| StorageError::backend("cannot start the storage bridge").with_source(error))?; + Ok(Self { jobs }) + } + + pub(crate) fn run(&self, future: F) -> Result + where + F: Future + Send + 'static, + T: Send + 'static, + { + if ON_BRIDGE.with(std::cell::Cell::get) { + return Err(StorageError::backend("storage bridge re-entered")); + } + let (reply, wait) = mpsc::sync_channel(1); + self.jobs + .send(Box::new(move |runtime| { + let _ = reply.send(runtime.block_on(future)); + })) + .map_err(|_| StorageError::backend("storage bridge stopped"))?; + wait.recv() + .map_err(|_| StorageError::backend("storage bridge dropped a call")) + } +} diff --git a/crates/tinyjuice-drivers/src/lib.rs b/crates/tinyjuice-drivers/src/lib.rs index 07b99801..23a70dde 100644 --- a/crates/tinyjuice-drivers/src/lib.rs +++ b/crates/tinyjuice-drivers/src/lib.rs @@ -11,13 +11,13 @@ //! [`Blocking`] bridge that runs the port's futures on a dedicated runtime //! thread. That works from inside or outside a tokio runtime. //! -//! [`BlobStore`]: tinystoragedrivers_core::BlobStore -//! [`Blocking`]: tinystoragedrivers_core::Blocking +//! [`BlobStore`]: tinystoragedrivers_api::BlobStore +//! [`Blocking`]: crate::blocking::Blocking +mod blocking; mod blob_store; pub use blob_store::{BlobCcrStore, CCR_PREFIX}; -pub use tinyjuice_bus::storage::storage_schema; #[cfg(test)] #[path = "faulty_tests.rs"] From 30754be459017c3342aface032e865767bff67a1 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 00:40:08 +0300 Subject: [PATCH 008/119] feat(tinyjuice-cli): add storage module Add a new storage module to the CLI crate. The diff is empty, so the file is being introduced as a new, currently empty source file. Auto-committed-on: dragonfly --- crates/tinyjuice-cli/src/storage.rs | 170 ++++++++++++++++++++++++++++ 1 file changed, 170 insertions(+) create mode 100644 crates/tinyjuice-cli/src/storage.rs diff --git a/crates/tinyjuice-cli/src/storage.rs b/crates/tinyjuice-cli/src/storage.rs new file mode 100644 index 00000000..ef997ba0 --- /dev/null +++ b/crates/tinyjuice-cli/src/storage.rs @@ -0,0 +1,170 @@ +//! CLI-owned composition of CCR over Tiny Storage Drivers' file backend. + +use std::path::Path; +use std::sync::Arc; +use std::time::Duration; + +use tinyjuice::cache::{CcrStore, set_durable_tier}; +use tinyjuice_drivers::{BlobCcrStore, CCR_PREFIX}; +use tinystoragedrivers::{Scope, StorageConfig, open}; +use tinystoragedrivers_api::BlobStore; +use tinystoragedrivers_types::BlobMeta; + +const PAGE_SIZE: usize = 1000; + +pub(crate) struct Inventory { + pub entries: Vec, + pub ignored_entries: usize, +} + +pub(crate) fn configure(root: &Path, ttl: Option) -> Result<(), String> { + let (blobs, _runtime) = open_file_blobs(root)?; + import_legacy_files(root, &blobs, ttl)?; + let store = BlobCcrStore::new(blobs, ttl).map_err(|error| error.to_string())?; + set_durable_tier(Some(Arc::new(store))); + Ok(()) +} + +pub(crate) fn inventory(root: &Path) -> Result { + let (blobs, _runtime) = open_file_blobs(root)?; + let mut entries = Vec::new(); + let mut after = None; + loop { + let page = run_blob(&blobs, { + let after = after.clone(); + async move { blobs.list_page(&format!("{CCR_PREFIX}/"), after.as_deref(), PAGE_SIZE).await } + })?; + entries.extend(page.items.into_iter().map(|item| item.meta)); + after = page.next_after; + if after.is_none() { + break; + } + } + Ok(Inventory { entries, ignored_entries: 0 }) +} + +pub(crate) fn collect( + root: &Path, + ttl: Option, + max_bytes: Option, +) -> Result<(usize, u64, usize, u64), String> { + let (blobs, _runtime) = open_file_blobs(root)?; + let mut entries = list_all(Arc::clone(&blobs))?; + let now_ms = std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .unwrap_or_default() + .as_millis() as u64; + let ttl_ms = ttl.map(|ttl| ttl.as_millis().min(u64::MAX as u128) as u64); + let mut remove = Vec::new(); + for entry in &entries { + if ttl_ms.is_some_and(|ttl| { + entry.written_at_ms.is_some_and(|written| now_ms.saturating_sub(written) >= ttl) + }) { + remove.push(entry.meta.key.clone()); + } + } + for key in &remove { + delete_blob(Arc::clone(&blobs), key)?; + } + entries.retain(|entry| !remove.contains(&entry.meta.key)); + let mut total = entries.iter().map(|entry| entry.meta.len).sum::(); + if let Some(budget) = max_bytes { + entries.sort_by_key(|entry| entry.written_at_ms.unwrap_or(0)); + for entry in entries { + if total <= budget { + break; + } + delete_blob(Arc::clone(&blobs), &entry.meta.key)?; + total = total.saturating_sub(entry.meta.len); + remove.push(entry.meta.key); + } + } + let remaining = list_all(blobs)?; + let remaining_bytes = remaining.iter().map(|entry| entry.meta.len).sum(); + Ok((remove.len(), remaining_bytes, remaining.len(), remaining_bytes)) +} + +fn open_file_blobs(root: &Path) -> Result<(Arc, tokio::runtime::Runtime), String> { + let runtime = tokio::runtime::Builder::new_current_thread() + .enable_all() + .build() + .map_err(|error| format!("cannot start storage runtime: {error}"))?; + let url = format!("file:{}", root.display()); + let config = StorageConfig::parse(&url).map_err(|error| error.to_string())?; + let backend = runtime.block_on(open(&config)).map_err(|error| error.to_string())?; + let scope = Scope::new("tinyjuice-cli").map_err(|error| error.to_string())?; + let storage = backend.for_scope(&scope).map_err(|error| error.to_string())?; + Ok((Arc::clone(storage.blobs()), runtime)) +} + +fn import_legacy_files( + root: &Path, + blobs: &Arc, + ttl: Option, +) -> Result<(), String> { + let entries = std::fs::read_dir(root) + .map_err(|error| format!("failed to inspect legacy CCR directory {}: {error}", root.display()))?; + let store = BlobCcrStore::new(Arc::clone(blobs), ttl).map_err(|error| error.to_string())?; + for entry in entries { + let entry = entry.map_err(|error| format!("failed to inspect legacy CCR entry: {error}"))?; + if !entry.file_type().map_err(|error| error.to_string())?.is_file() { + continue; + } + let token = entry.file_name().to_string_lossy().into_owned(); + if !is_token(&token) { + continue; + } + let content = match std::fs::read_to_string(entry.path()) { + Ok(content) => content, + Err(error) => return Err(format!("cannot import legacy CCR entry {token}: {error}")), + }; + let put = store.put(&content); + if put.token() != token || !put.retained() { + return Err(format!("legacy CCR entry {token} was not durably retained")); + } + std::fs::remove_file(entry.path()) + .map_err(|error| format!("cannot remove imported CCR entry {token}: {error}"))?; + } + Ok(()) +} + +fn list_all(blobs: Arc) -> Result, String> { + let mut entries = Vec::new(); + let mut after = None; + loop { + let page = run_blob(&blobs, { + let after = after.clone(); + async move { blobs.list_page(&format!("{CCR_PREFIX}/"), after.as_deref(), PAGE_SIZE).await } + })?; + entries.extend(page.items); + after = page.next_after; + if after.is_none() { + return Ok(entries); + } + } +} + +fn delete_blob(blobs: Arc, key: &str) -> Result<(), String> { + let key = key.to_owned(); + run_blob(&blobs, async move { blobs.delete(&key).await })? + .map(|_| ()) + .map_err(|error| error.to_string()) +} + +fn run_blob( + blobs: &Arc, + future: impl std::future::Future> + Send + 'static, +) -> Result { + // Each helper owns a separate current-thread runtime. Blob engines in this + // CLI are self-contained and do not depend on work from another runtime. + let _ = blobs; + let runtime = tokio::runtime::Builder::new_current_thread() + .enable_all() + .build() + .map_err(|error| format!("cannot start storage runtime: {error}"))?; + runtime.block_on(future).map_err(|error| error.to_string()) +} + +fn is_token(token: &str) -> bool { + token.len() == 32 && token.bytes().all(|byte| byte.is_ascii_hexdigit()) +} From 90c913e9a8aa7ecbf77ffdc128635d06f83fc3b2 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 00:40:25 +0300 Subject: [PATCH 009/119] refactor(storage): drop runtime from blob store handle The blob store handle no longer carries the tokio runtime it was created on, so callers only receive the store itself. Each helper still builds its own current-thread runtime, and inventory now configures storage before listing so the runtime is not needed to keep the backend alive. Auto-committed-on: dragonfly --- crates/tinyjuice-cli/src/storage.rs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/crates/tinyjuice-cli/src/storage.rs b/crates/tinyjuice-cli/src/storage.rs index ef997ba0..d238bbd5 100644 --- a/crates/tinyjuice-cli/src/storage.rs +++ b/crates/tinyjuice-cli/src/storage.rs @@ -26,12 +26,14 @@ pub(crate) fn configure(root: &Path, ttl: Option) -> Result<(), String } pub(crate) fn inventory(root: &Path) -> Result { - let (blobs, _runtime) = open_file_blobs(root)?; + configure(root, None)?; + let blobs = open_file_blobs(root)?; let mut entries = Vec::new(); let mut after = None; loop { - let page = run_blob(&blobs, { + let page = run_blob({ let after = after.clone(); + let blobs = Arc::clone(&blobs); async move { blobs.list_page(&format!("{CCR_PREFIX}/"), after.as_deref(), PAGE_SIZE).await } })?; entries.extend(page.items.into_iter().map(|item| item.meta)); @@ -48,7 +50,7 @@ pub(crate) fn collect( ttl: Option, max_bytes: Option, ) -> Result<(usize, u64, usize, u64), String> { - let (blobs, _runtime) = open_file_blobs(root)?; + let blobs = open_file_blobs(root)?; let mut entries = list_all(Arc::clone(&blobs))?; let now_ms = std::time::SystemTime::now() .duration_since(std::time::UNIX_EPOCH) @@ -84,7 +86,7 @@ pub(crate) fn collect( Ok((remove.len(), remaining_bytes, remaining.len(), remaining_bytes)) } -fn open_file_blobs(root: &Path) -> Result<(Arc, tokio::runtime::Runtime), String> { +fn open_file_blobs(root: &Path) -> Result, String> { let runtime = tokio::runtime::Builder::new_current_thread() .enable_all() .build() @@ -94,7 +96,9 @@ fn open_file_blobs(root: &Path) -> Result<(Arc, tokio::runtime::R let backend = runtime.block_on(open(&config)).map_err(|error| error.to_string())?; let scope = Scope::new("tinyjuice-cli").map_err(|error| error.to_string())?; let storage = backend.for_scope(&scope).map_err(|error| error.to_string())?; - Ok((Arc::clone(storage.blobs()), runtime)) + let blobs = Arc::clone(storage.blobs()); + drop(runtime); + Ok(blobs) } fn import_legacy_files( @@ -132,8 +136,9 @@ fn list_all(blobs: Arc) -> Result) -> Result, key: &str) -> Result<(), String> { let key = key.to_owned(); - run_blob(&blobs, async move { blobs.delete(&key).await })? + let handle = Arc::clone(&blobs); + run_blob(async move { handle.delete(&key).await })? .map(|_| ()) .map_err(|error| error.to_string()) } fn run_blob( - blobs: &Arc, future: impl std::future::Future> + Send + 'static, ) -> Result { // Each helper owns a separate current-thread runtime. Blob engines in this // CLI are self-contained and do not depend on work from another runtime. - let _ = blobs; let runtime = tokio::runtime::Builder::new_current_thread() .enable_all() .build() From cc09d1534c533c01fb2e5a3370a1a0bf38da0d45 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 00:40:45 +0300 Subject: [PATCH 010/119] fix(tinyjuice-cli): create storage directory before opening blobs The storage configuration now creates the CCR root directory if it is missing, so opening blobs no longer fails on a fresh install. The collect path also configures storage first, and blob deletion no longer unwraps a result that was already flattened. Auto-committed-on: dragonfly --- crates/tinyjuice-cli/Cargo.toml | 2 ++ crates/tinyjuice-cli/src/storage.rs | 9 +++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/crates/tinyjuice-cli/Cargo.toml b/crates/tinyjuice-cli/Cargo.toml index 1ae93eb3..54db8706 100644 --- a/crates/tinyjuice-cli/Cargo.toml +++ b/crates/tinyjuice-cli/Cargo.toml @@ -12,6 +12,8 @@ repository = "https://github.com/tinyhumansai/tinyjuice" tinyjuice = { path = "../.." } tinyjuice-drivers = { path = "../tinyjuice-drivers" } tinystoragedrivers = { version = "2.0.1", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.1", features = ["file"] } +tinystoragedrivers-api = { version = "2.0.1", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.1" } +tinystoragedrivers-types = { version = "2.0.1", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.1" } dirs = "7" serde_json = "1" tokio = { version = "1", features = ["rt-multi-thread"] } diff --git a/crates/tinyjuice-cli/src/storage.rs b/crates/tinyjuice-cli/src/storage.rs index d238bbd5..9f0f2e2c 100644 --- a/crates/tinyjuice-cli/src/storage.rs +++ b/crates/tinyjuice-cli/src/storage.rs @@ -18,7 +18,9 @@ pub(crate) struct Inventory { } pub(crate) fn configure(root: &Path, ttl: Option) -> Result<(), String> { - let (blobs, _runtime) = open_file_blobs(root)?; + std::fs::create_dir_all(root) + .map_err(|error| format!("cannot create CCR storage directory {}: {error}", root.display()))?; + let blobs = open_file_blobs(root)?; import_legacy_files(root, &blobs, ttl)?; let store = BlobCcrStore::new(blobs, ttl).map_err(|error| error.to_string())?; set_durable_tier(Some(Arc::new(store))); @@ -50,6 +52,7 @@ pub(crate) fn collect( ttl: Option, max_bytes: Option, ) -> Result<(usize, u64, usize, u64), String> { + configure(root, ttl)?; let blobs = open_file_blobs(root)?; let mut entries = list_all(Arc::clone(&blobs))?; let now_ms = std::time::SystemTime::now() @@ -152,9 +155,7 @@ fn list_all(blobs: Arc) -> Result, key: &str) -> Result<(), String> { let key = key.to_owned(); let handle = Arc::clone(&blobs); - run_blob(async move { handle.delete(&key).await })? - .map(|_| ()) - .map_err(|error| error.to_string()) + run_blob(async move { handle.delete(&key).await }).map(|_| ()) } fn run_blob( From 093bae3e260895a1aea3e5854cc0422bfaa4d7d2 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 00:41:12 +0300 Subject: [PATCH 011/119] refactor(cli): route cache storage through shared storage module The CLI binaries now configure and query the cache through the shared storage module instead of calling the disk-tier helpers directly, so inventory and garbage collection share one implementation. Cache configuration now returns a result so setup failures surface instead of being silently ignored. Auto-committed-on: dragonfly --- .../tinyjuice-cli/src/bin/tinyjuice-reduce.rs | 49 +++++++------------ crates/tinyjuice-cli/src/bin/tinyjuice.rs | 30 +++++++----- 2 files changed, 36 insertions(+), 43 deletions(-) diff --git a/crates/tinyjuice-cli/src/bin/tinyjuice-reduce.rs b/crates/tinyjuice-cli/src/bin/tinyjuice-reduce.rs index bd0d6e6e..88cce01a 100644 --- a/crates/tinyjuice-cli/src/bin/tinyjuice-reduce.rs +++ b/crates/tinyjuice-cli/src/bin/tinyjuice-reduce.rs @@ -11,6 +11,9 @@ use tinyjuice::{ verify_rules, }; +#[path = "../storage.rs"] +mod storage; + const TINYJUICE_MANAGED_BEGIN: &str = ""; const TINYJUICE_MANAGED_END: &str = ""; @@ -747,7 +750,12 @@ fn run_cat(args: &[String]) -> Result<(), String> { return Err("cat token must be a 32-character hex CCR token".to_owned()); } - tinyjuice::cache::enable_disk_tier(store_dir); + tinyjuice::cache::configure( + tinyjuice::cache::DEFAULT_MAX_ENTRIES, + tinyjuice::cache::DEFAULT_MAX_BYTES, + None, + ); + storage::configure(&store_dir, None)?; let content = match range { Some((unit, (start, end))) => tinyjuice::cache::retrieve_range(&token, start, end, unit), None => tinyjuice::cache::retrieve(&token), @@ -809,37 +817,18 @@ struct CcrStoreEntry { } fn read_ccr_store_inventory(store_dir: &Path) -> Result { - let mut entries = Vec::new(); - let mut ignored_entries = 0; - - for entry in fs::read_dir(store_dir) - .map_err(|error| format!("failed to read {}: {error}", store_dir.display()))? - { - let entry = entry.map_err(|error| format!("failed to read store entry: {error}"))?; - if !entry - .file_type() - .map_err(|error| format!("failed to inspect store entry: {error}"))? - .is_file() - { - ignored_entries += 1; - continue; - } - let name = entry.file_name().to_string_lossy().into_owned(); - if is_cli_ccr_token(&name) { - let bytes = entry - .metadata() - .map_err(|error| format!("failed to inspect store entry {name}: {error}"))? - .len(); - entries.push(CcrStoreEntry { token: name, bytes }); - } else { - ignored_entries += 1; - } - } - - entries.sort_by(|left, right| left.token.cmp(&right.token)); + let inventory = storage::inventory(store_dir)?; + let entries = inventory + .entries + .into_iter() + .filter_map(|entry| { + let token = entry.key.strip_prefix("juice/ccr/")?.to_owned(); + is_cli_ccr_token(&token).then_some(CcrStoreEntry { token, bytes: entry.len }) + }) + .collect(); Ok(CcrStoreInventory { entries, - ignored_entries, + ignored_entries: inventory.ignored_entries, }) } diff --git a/crates/tinyjuice-cli/src/bin/tinyjuice.rs b/crates/tinyjuice-cli/src/bin/tinyjuice.rs index ad5a24f9..02cc2b92 100644 --- a/crates/tinyjuice-cli/src/bin/tinyjuice.rs +++ b/crates/tinyjuice-cli/src/bin/tinyjuice.rs @@ -11,6 +11,9 @@ use tinyjuice::{ host_install_specs, host_template, request_from_json_value, }; +#[path = "../storage.rs"] +mod storage; + const SUPPORT_GIT_TRAILER: &str = "Co-Authored-By: TinyJuice "; const CODEX_SUPPORT_ATTRIBUTION: &str = "TinyJuice "; const CLAUDE_DEFAULT_COMMIT_ATTRIBUTION: &str = @@ -75,7 +78,7 @@ fn run() -> Result<(), String> { } fn reduce_json(args: Vec) -> Result<(), String> { - configure_cli_cache(); + configure_cli_cache()?; let mut host_override = None; let mut path = None; let mut index = 0; @@ -128,7 +131,7 @@ fn reduce_json(args: Vec) -> Result<(), String> { } fn post_tool_use_hook(host: TinyJuiceHost) -> Result<(), String> { - configure_cli_cache(); + configure_cli_cache()?; let input = read_input(None)?; let runtime = tokio::runtime::Builder::new_current_thread() .enable_all() @@ -524,7 +527,7 @@ fn finish_toml_lines(lines: Vec) -> String { } fn retrieve_command(args: Vec) -> Result<(), String> { - configure_cli_cache(); + configure_cli_cache()?; let token = args .first() .ok_or_else(|| "retrieve requires a CCR token".to_string())?; @@ -592,16 +595,18 @@ fn gc_command(args: Vec) -> Result<(), String> { }; let root = cli_cache_root(); - let stats = - tinyjuice::cache::gc_disk_dir(&root, ttl.map(std::time::Duration::from_secs), budget) - .map_err(|error| error.to_string())?; + let (removed, freed_bytes, kept, kept_bytes) = storage::collect( + &root, + ttl.map(std::time::Duration::from_secs), + budget, + )?; println!( "gc {}: removed {} entries, freed {} bytes, kept {} ({} bytes)", root.display(), - stats.removed, - stats.freed_bytes, - stats.kept, - stats.kept_bytes + removed, + freed_bytes, + kept, + kept_bytes ); Ok(()) } @@ -693,11 +698,10 @@ fn cli_cache_limits_from_env() -> (usize, usize, Option) { ) } -fn configure_cli_cache() { +fn configure_cli_cache() -> Result<(), String> { let (max_entries, max_bytes, ttl_secs) = cli_cache_limits_from_env(); tinyjuice::cache::configure(max_entries, max_bytes, ttl_secs); - tinyjuice::cache::configure_disk_cap(Some(max_bytes as u64)); - tinyjuice::cache::enable_disk_tier(cli_cache_root()); + storage::configure(&cli_cache_root(), ttl_secs.map(std::time::Duration::from_secs)) } fn cli_cache_root() -> PathBuf { From e8a96ad9586a90de802a0319c4762df80e84ffab Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 00:42:12 +0300 Subject: [PATCH 012/119] refactor(tinyjuice-bus): replace storage schema with collection vocabulary The bus crate now exposes a plain list of document collections instead of a full storage schema, and it depends on the v2 tinystoragedrivers types crate rather than the v1 core crate. Hosts compose their own schema from this vocabulary, so the migration step and blob prefix declarations are no longer needed here. Auto-committed-on: dragonfly --- Cargo.lock | 142 +++++++++++++++++++++++++++- crates/tinyjuice-bus/Cargo.toml | 6 +- crates/tinyjuice-bus/src/storage.rs | 66 +++---------- src/cache/store.rs | 4 +- 4 files changed, 155 insertions(+), 63 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b4c9f2c1..bda682f9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1559,6 +1559,21 @@ dependencies = [ "tokio", ] +[[package]] +name = "tinyjuice-cli" +version = "0.11.0" +dependencies = [ + "dirs", + "serde_json", + "tempfile", + "tinyjuice", + "tinyjuice-drivers", + "tinystoragedrivers", + "tinystoragedrivers-api", + "tinystoragedrivers-types", + "tokio", +] + [[package]] name = "tinyjuice-drivers" version = "0.9.0" @@ -1567,7 +1582,8 @@ dependencies = [ "log", "tinyjuice", "tinyjuice-bus", - "tinystoragedrivers-core", + "tinystoragedrivers-api", + "tinystoragedrivers-types", "tokio", ] @@ -1590,6 +1606,50 @@ dependencies = [ "tokio", ] +[[package]] +name = "tinystoragedrivers" +version = "2.0.1" +source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.1#e3224a8262193e7466b230a59ef1c4769e44bf02" +dependencies = [ + "tinystoragedrivers-api", + "tinystoragedrivers-blob", + "tinystoragedrivers-connect", + "tinystoragedrivers-document", + "tinystoragedrivers-kv", + "tinystoragedrivers-queue", + "tinystoragedrivers-secrets 2.0.1", + "tinystoragedrivers-types", +] + +[[package]] +name = "tinystoragedrivers-api" +version = "2.0.1" +source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.1#e3224a8262193e7466b230a59ef1c4769e44bf02" +dependencies = [ + "async-trait", + "bytes", + "futures-core", + "serde", + "serde_json", + "tinystoragedrivers-types", + "zeroize", +] + +[[package]] +name = "tinystoragedrivers-blob" +version = "2.0.1" +source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.1#e3224a8262193e7466b230a59ef1c4769e44bf02" +dependencies = [ + "async-trait", + "bytes", + "futures-core", + "serde", + "serde_json", + "tinystoragedrivers-api", + "tinystoragedrivers-connect", + "tinystoragedrivers-types", +] + [[package]] name = "tinystoragedrivers-bus" version = "1.0.0" @@ -1625,7 +1685,16 @@ dependencies = [ "serde_json", "tinystoragedrivers-bus", "tinystoragedrivers-core", - "tinystoragedrivers-secrets", + "tinystoragedrivers-secrets 1.0.0", + "tokio", +] + +[[package]] +name = "tinystoragedrivers-connect" +version = "2.0.1" +source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.1#e3224a8262193e7466b230a59ef1c4769e44bf02" +dependencies = [ + "tinystoragedrivers-types", "tokio", ] @@ -1645,6 +1714,54 @@ dependencies = [ "zstd", ] +[[package]] +name = "tinystoragedrivers-document" +version = "2.0.1" +source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.1#e3224a8262193e7466b230a59ef1c4769e44bf02" +dependencies = [ + "async-trait", + "data-encoding", + "libc", + "serde", + "serde_json", + "sha2 0.10.9", + "tinystoragedrivers-api", + "tinystoragedrivers-connect", + "tinystoragedrivers-types", + "tokio", + "zstd", +] + +[[package]] +name = "tinystoragedrivers-kv" +version = "2.0.1" +source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.1#e3224a8262193e7466b230a59ef1c4769e44bf02" +dependencies = [ + "async-trait", + "libc", + "serde", + "serde_json", + "tinystoragedrivers-api", + "tinystoragedrivers-connect", + "tinystoragedrivers-types", +] + +[[package]] +name = "tinystoragedrivers-queue" +version = "2.0.1" +source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.1#e3224a8262193e7466b230a59ef1c4769e44bf02" +dependencies = [ + "async-trait", + "data-encoding", + "serde", + "serde_json", + "sha2 0.10.9", + "tinystoragedrivers-api", + "tinystoragedrivers-types", + "tokio", + "ulid", +] + [[package]] name = "tinystoragedrivers-secrets" version = "1.0.0" @@ -1668,6 +1785,27 @@ dependencies = [ "zeroize", ] +[[package]] +name = "tinystoragedrivers-secrets" +version = "2.0.1" +source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.1#e3224a8262193e7466b230a59ef1c4769e44bf02" +dependencies = [ + "async-trait", + "tinystoragedrivers-api", + "tinystoragedrivers-types", + "zeroize", +] + +[[package]] +name = "tinystoragedrivers-types" +version = "2.0.1" +source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.1#e3224a8262193e7466b230a59ef1c4769e44bf02" +dependencies = [ + "serde", + "serde_json", + "thiserror", +] + [[package]] name = "tinytemplate" version = "1.2.1" diff --git a/crates/tinyjuice-bus/Cargo.toml b/crates/tinyjuice-bus/Cargo.toml index 113eec81..4912bc32 100644 --- a/crates/tinyjuice-bus/Cargo.toml +++ b/crates/tinyjuice-bus/Cargo.toml @@ -19,14 +19,10 @@ serde = { version = "1", features = ["derive"] } serde_json = "1" # Shared REPL error vocabulary; no execution dependencies. thiserror = "2" -# Optional (`storage` feature, off by default). Storage ports only (no I/O or runtime of its own): the schema the host composes -# lives in the contract so the host never links the implementation crate. -tinystoragedrivers-core = { version = "1.0.0", git = "https://github.com/tinyhumansai/tinystoragedrivers", tag = "v1.0.0", default-features = false, optional = true } +tinystoragedrivers-types = { version = "2.0.1", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.1" } [features] default = [] -# `storage_schema()` for the host's schema composition. Hosts enable this. -storage = ["dep:tinystoragedrivers-core"] [dev-dependencies] # The migration tests run the schema over the in-memory backend. diff --git a/crates/tinyjuice-bus/src/storage.rs b/crates/tinyjuice-bus/src/storage.rs index 3540c589..a0651651 100644 --- a/crates/tinyjuice-bus/src/storage.rs +++ b/crates/tinyjuice-bus/src/storage.rs @@ -1,65 +1,23 @@ -//! What TinyJuice stores, as a schema the host composes. -//! -//! The savings totals are one document in `juice.savings`. -//! -//! The CCR store's originals are blobs under `juice/ccr/`. The module -//! runs for one tenant at a time, so they live at [`ScopeClass::Module`], and a -//! host derives the module's storage grant from this schema rather than -//! spelling the prefix out a second time. -//! -//! Before schema v2 the same blobs lived under `tinyjuice_ccr/`. One -//! blob step moves them; the bytes and content type are untouched. The steps -//! are pure: no I/O happens until the host's registry runs them. +//! TinyJuice's storage vocabulary for hosts composing its owner ports. -use tinystoragedrivers_core::Result; -use tinystoragedrivers_core::schema::{BlobOutput, Owner, Schema, ScopeClass, Step}; +use tinystoragedrivers_types::CollectionSpec; -/// Where the CCR store keeps originals, `juice/ccr/` (no trailing slash). +/// CCR originals are stored below `juice/ccr/`. pub const CCR_PREFIX: &str = "juice/ccr"; -/// The savings totals: one document (`savings::SAVINGS_DOC_ID`) per module -/// scope, a snake_case body with `updated_ms`. Schema v2 introduced it; before -/// that the host kept `state/tokenjuice_savings.json`. -pub const SAVINGS_COLLECTION: &str = "juice.savings"; - -/// Where schema v1 kept the originals, `tinyjuice_ccr/`. -const LEGACY_PREFIX: &str = "tinyjuice_ccr/"; +/// Legacy prefix used before the owner moved originals into `juice/ccr`. +pub const LEGACY_CCR_PREFIX: &str = "tinyjuice_ccr/"; -/// The schema owner, and the first path segment of every blob key. -const OWNER: &str = "juice"; +/// The owner-scoped savings totals document collection. +pub const SAVINGS_COLLECTION: &str = "juice.savings"; -/// Everything TinyJuice stores, for the host's `Registry::compose`. -/// -/// # Panics +/// Collections a host should provision when it composes TinyJuice storage. /// -/// Never in practice: the owner name is a constant that satisfies the owner -/// grammar, which the tests pin. +/// Blob prefixes are provisioned by the blob engine itself; only document +/// collections need a declaration in this vocabulary. #[must_use] -pub fn storage_schema() -> Schema { - let prefix = format!("{CCR_PREFIX}/"); - Schema::new(Owner::new(OWNER).expect("`juice` is a valid schema owner")) - .blobs(&prefix, ScopeClass::Module) - .collection(SAVINGS_COLLECTION, 1, ScopeClass::Module) - .step(ccr_prefix_step()) -} - -/// v1 to v2: `tinyjuice_ccr/` becomes `juice/ccr/`. -fn ccr_prefix_step() -> Step { - Step::blobs("ccr_prefix_v2", "juice/ccr/", 1, 2, move_ccr_blob).source_prefix(LEGACY_PREFIX) -} - -/// One blob of the v1 prefix, re-keyed. Bytes and content type are untouched. -fn move_ccr_blob( - key: String, - content_type: Option, - bytes: Vec, -) -> Result> { - // The runner lists by the legacy prefix, so every key carries it; a key - // that somehow does not has nothing to move. - let Some(rest) = key.strip_prefix(LEGACY_PREFIX) else { - return Ok(None); - }; - Ok(Some((format!("{CCR_PREFIX}/{rest}"), content_type, bytes))) +pub fn collections() -> Vec { + vec![CollectionSpec::new(SAVINGS_COLLECTION)] } #[cfg(test)] diff --git a/src/cache/store.rs b/src/cache/store.rs index 0672e12e..fd0e6e3c 100644 --- a/src/cache/store.rs +++ b/src/cache/store.rs @@ -290,9 +290,9 @@ pub fn offload_checked(content: &str) -> (String, bool) { /// Returns whether the original was retained (memory or the host's durable store). pub fn offload_checked_with_hash(hash: &str, content: &str) -> bool { debug_assert_eq!(hash, short_hash(content), "hash must match content"); - let (max_entries, max_bytes, ttl) = { + let (max_entries, max_bytes) = { let l = limits().read().unwrap_or_else(|p| p.into_inner()); - (l.max_entries, l.max_bytes, l.ttl) + (l.max_entries, l.max_bytes) }; let mem_retained = global().lock().unwrap_or_else(|p| p.into_inner()).insert( hash.to_string(), From 519d5653ae207bb408819dfe643f3ebcfd38ee75 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 00:42:26 +0300 Subject: [PATCH 013/119] refactor(storage): drop storage feature gate and trim storage tests The storage module is now always compiled instead of being hidden behind the storage feature, and the storage tests were reduced to a single check that the owner collections declare savings without engine or migration policy. The removed tests covered schema composition and legacy prefix migration that no longer reflect the module's behaviour. Auto-committed-on: dragonfly --- crates/tinyjuice-bus/src/lib.rs | 1 - crates/tinyjuice-bus/src/storage_tests.rs | 109 +--------------------- 2 files changed, 4 insertions(+), 106 deletions(-) diff --git a/crates/tinyjuice-bus/src/lib.rs b/crates/tinyjuice-bus/src/lib.rs index 89a0fbec..e35a6173 100644 --- a/crates/tinyjuice-bus/src/lib.rs +++ b/crates/tinyjuice-bus/src/lib.rs @@ -15,7 +15,6 @@ pub mod handle; pub mod names; pub mod repl; pub mod savings; -#[cfg(feature = "storage")] pub mod storage; pub mod summary; pub mod tools; diff --git a/crates/tinyjuice-bus/src/storage_tests.rs b/crates/tinyjuice-bus/src/storage_tests.rs index 40cbf167..939cb4d0 100644 --- a/crates/tinyjuice-bus/src/storage_tests.rs +++ b/crates/tinyjuice-bus/src/storage_tests.rs @@ -1,111 +1,10 @@ use super::*; -use tinystoragedrivers_core::schema::{Item, MigrateOptions, Registry, ScopeClass}; -use tinystoragedrivers_core::{MemoryStorage, Scope, StorageBackend}; - -const LEGACY: &str = "tinyjuice_ccr/"; - -#[test] -fn the_schema_declares_the_ccr_blobs_and_the_savings_collection_at_module_scope() { - let schema = storage_schema(); - let items: Vec<_> = schema.items.iter().collect(); - assert_eq!(items.len(), 2, "CCR blobs and savings are all juice stores"); - match items[0] { - Item::Blobs { prefix, scope } => { - assert_eq!(prefix, "juice/ccr/"); - assert_eq!(*scope, ScopeClass::Module); - } - other => panic!("expected a blob prefix, got {other:?}"), - } - match items[1] { - Item::Collection { - name, - version, - scope, - .. - } => { - assert_eq!(name, "juice.savings"); - assert_eq!(*version, 1); - assert_eq!(*scope, ScopeClass::Module); - } - other => panic!("expected the savings collection, got {other:?}"), - } - assert!( - format!("{CCR_PREFIX}/token").starts_with("juice/ccr/"), - "keys the store writes sit under the declared prefix" - ); - Registry::compose([schema]).expect("the schema composes"); -} - -#[tokio::test] -async fn migration_moves_v1_ccr_blobs_under_the_v2_prefix() { - let backend = MemoryStorage::new(); - let storage = backend.for_scope(&Scope::local()).unwrap(); - let blobs = storage.blobs(); - blobs - .put( - "tinyjuice_ccr/0123456789abcdef", - b"original text".to_vec(), - Some("text/plain; charset=utf-8"), - ) - .await - .unwrap(); - blobs - .put("tinyjuice_ccr/fedcba9876543210", b"two".to_vec(), None) - .await - .unwrap(); - // Not ours: must be left alone. - blobs - .put("other/keep", b"keep".to_vec(), None) - .await - .unwrap(); - - let registry = Registry::compose([storage_schema()]).unwrap(); - let report = registry - .migrate(&storage, &MigrateOptions::new()) - .await - .unwrap(); - assert_eq!(report.ran[0].written, 2); - - assert!(blobs.list(LEGACY).await.unwrap().is_empty()); - let moved = blobs - .get("juice/ccr/0123456789abcdef") - .await - .unwrap() - .unwrap(); - assert_eq!(moved.bytes, b"original text"); - assert_eq!( - moved.meta.content_type.as_deref(), - Some("text/plain; charset=utf-8") - ); - let moved = blobs - .get("juice/ccr/fedcba9876543210") - .await - .unwrap() - .unwrap(); - assert_eq!(moved.meta.content_type, None); - assert!(blobs.get("other/keep").await.unwrap().is_some()); - - let again = registry - .migrate(&storage, &MigrateOptions::new()) - .await - .unwrap(); - assert!(again.ran.is_empty(), "a finished step does not run again"); -} #[test] -fn a_key_outside_the_legacy_prefix_has_nothing_to_move() { - let moved = move_ccr_blob("elsewhere/x".into(), None, b"x".to_vec()).unwrap(); - assert!(moved.is_none()); - let (key, content_type, bytes) = move_ccr_blob( - "tinyjuice_ccr/ab".into(), - Some("text/plain".into()), - b"x".to_vec(), - ) - .unwrap() - .unwrap(); - assert_eq!(key, "juice/ccr/ab"); - assert_eq!(content_type.as_deref(), Some("text/plain")); - assert_eq!(bytes, b"x"); +fn owner_collections_declare_savings_without_engine_or_migration_policy() { + assert_eq!(collections(), vec![CollectionSpec::new("juice.savings")]); + assert_eq!(CCR_PREFIX, "juice/ccr"); + assert_eq!(LEGACY_CCR_PREFIX, "tinyjuice_ccr/"); } #[test] From c7514b4d0e6f49e2b84572f256f22817a2e6f056 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 00:42:54 +0300 Subject: [PATCH 014/119] chore(deps): rename tinystoragedrivers-core to tinystoragedrivers-types The lockfile now records the renamed dependency for the affected package, keeping the resolved dependency graph in sync with the crate's new name. Auto-committed-on: dragonfly --- Cargo.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index bda682f9..1ae39182 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1555,7 +1555,7 @@ dependencies = [ "serde", "serde_json", "thiserror", - "tinystoragedrivers-core", + "tinystoragedrivers-types", "tokio", ] From ae41779e7e5a673329e1907673302f34d127b115 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 00:43:17 +0300 Subject: [PATCH 015/119] chore(deps): upgrade tinystoragedrivers to v2.0.1 The module now depends on the v2.0.1 storage crates from the senamakel fork, replacing the older core, busproxy and client packages, and the drivers crate gains a tokio runtime dependency. The storage bridge runtime is now built before the worker thread is spawned so that a construction failure surfaces as a StorageError instead of silently leaving the bridge dead. Auto-committed-on: dragonfly --- crates/tinyjuice-drivers/Cargo.toml | 1 + crates/tinyjuice-drivers/src/blocking.rs | 10 ++++------ crates/tinyjuice-module/Cargo.toml | 7 ++++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/tinyjuice-drivers/Cargo.toml b/crates/tinyjuice-drivers/Cargo.toml index c92ff992..b40d197e 100644 --- a/crates/tinyjuice-drivers/Cargo.toml +++ b/crates/tinyjuice-drivers/Cargo.toml @@ -17,6 +17,7 @@ tinyjuice = { path = "../..", default-features = false } tinystoragedrivers-api = { version = "2.0.1", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.1" } tinystoragedrivers-types = { version = "2.0.1", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.1" } log = "0.4" +tokio = { version = "1", features = ["rt"] } [dev-dependencies] tokio = { version = "1", features = ["macros", "rt-multi-thread", "time"] } diff --git a/crates/tinyjuice-drivers/src/blocking.rs b/crates/tinyjuice-drivers/src/blocking.rs index d99bedf4..d0ff235b 100644 --- a/crates/tinyjuice-drivers/src/blocking.rs +++ b/crates/tinyjuice-drivers/src/blocking.rs @@ -28,15 +28,13 @@ impl fmt::Debug for Blocking { impl Blocking { pub(crate) fn new() -> Result { let (jobs, receiver) = mpsc::channel::(); + let runtime = tokio::runtime::Builder::new_current_thread() + .enable_all() + .build() + .map_err(|error| StorageError::backend("cannot build the storage bridge runtime").with_source(error))?; thread::Builder::new() .name("tinyjuice-storage-bridge".into()) .spawn(move || { - let Ok(runtime) = tokio::runtime::Builder::new_current_thread() - .enable_all() - .build() - else { - return; - }; ON_BRIDGE.with(|active| active.set(true)); while let Ok(job) = receiver.recv() { job(&runtime); diff --git a/crates/tinyjuice-module/Cargo.toml b/crates/tinyjuice-module/Cargo.toml index 043c5082..32d7f95f 100644 --- a/crates/tinyjuice-module/Cargo.toml +++ b/crates/tinyjuice-module/Cargo.toml @@ -28,13 +28,14 @@ serde_json = "1" # The CCR store's durable tier is blobs on the host's storage ports, reached # over the storage bus. The module has no storage backend or file of its own. tinyjuice-drivers = { path = "../tinyjuice-drivers" } -tinystoragedrivers-core = { version = "1.0.0", git = "https://github.com/tinyhumansai/tinystoragedrivers", tag = "v1.0.0" } -tinystoragedrivers-busproxy = { version = "1.0.0", git = "https://github.com/tinyhumansai/tinystoragedrivers", tag = "v1.0.0" } +tinystoragedrivers-api = { version = "2.0.1", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.1" } +tinystoragedrivers-types = { version = "2.0.1", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.1" } +tinystoragedrivers-busproxy = { version = "2.0.1", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.1" } log = "0.4" [dev-dependencies] # Tests serve the storage objects on the in-memory broker the module connects to. -tinystoragedrivers-client = { version = "1.0.0", git = "https://github.com/tinyhumansai/tinystoragedrivers", tag = "v1.0.0" } +tinystoragedrivers-testkit = { version = "2.0.1", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.1" } tinybus = { version = ">=0.1.3, <0.2", default-features = false, features = ["test-support"] } tempfile = "3" async-trait = "0.1" From af72481629b40f86ea42c6098bae6c147a7ae77f Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 00:43:34 +0300 Subject: [PATCH 016/119] refactor(storage): use storage api types for host ports The storage helpers now import BlobStore, DocumentStore and Storage from tinystoragedrivers_api instead of the core crate, and the scoped helper returns the bus connection directly rather than resolving a module scope label, since the bus proxy already hands back a scoped storage handle. Auto-committed-on: dragonfly --- crates/tinyjuice-module/src/storage.rs | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/crates/tinyjuice-module/src/storage.rs b/crates/tinyjuice-module/src/storage.rs index ef2d4d7a..7b4eb0a5 100644 --- a/crates/tinyjuice-module/src/storage.rs +++ b/crates/tinyjuice-module/src/storage.rs @@ -12,24 +12,20 @@ use std::time::Duration; use tinybus::Connection; use tinyjuice::cache::store::{CcrPutResult, CcrStore, RangeUnit}; use tinyjuice_drivers::BlobCcrStore; -use tinystoragedrivers_core::{BlobStore, DocumentStore, StorageBackend}; +use tinystoragedrivers_api::{BlobStore, DocumentStore, Storage}; /// The host's blob port, connected through `connection`, when it serves one. async fn blobs(connection: Connection) -> Option> { - scoped(connection) - .await - .map(|scoped| Arc::clone(scoped.blobs())) + scoped(connection).await.map(|storage| Arc::clone(storage.blobs())) } /// The host's document port, connected through `connection`, when it serves one. pub(crate) async fn documents(connection: Connection) -> Option> { - scoped(connection) - .await - .map(|scoped| Arc::clone(scoped.documents())) + scoped(connection).await.map(|storage| Arc::clone(storage.documents())) } /// The module's scope of the host's storage, when the host serves one. -async fn scoped(connection: Connection) -> Option { +async fn scoped(connection: Connection) -> Option { let bus = match tinystoragedrivers_busproxy::connect_storage(connection).await { Ok(bus) => bus, Err(error) => { @@ -37,13 +33,7 @@ async fn scoped(connection: Connection) -> Option Some(scoped), - Err(error) => { - log::warn!("[tinyjuice_module] storage bus scope refused: {error}"); - None - } - } + Some(bus) } /// The CCR durable tier on the host's blob port, or `None` when the host From 38d2e8680c4dd6ff00e18569ebfe0f22c1b5fe5a Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 00:43:40 +0300 Subject: [PATCH 017/119] refactor(savings_store): import storage traits from their defining crates The DocumentStore and DocumentStoreExt traits now come from tinystoragedrivers_api and Precondition from tinystoragedrivers_types, matching where each item is actually defined. Auto-committed-on: dragonfly --- crates/tinyjuice-module/src/savings_store.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/tinyjuice-module/src/savings_store.rs b/crates/tinyjuice-module/src/savings_store.rs index ec123021..275b8586 100644 --- a/crates/tinyjuice-module/src/savings_store.rs +++ b/crates/tinyjuice-module/src/savings_store.rs @@ -13,7 +13,8 @@ use tinyjuice_bus::savings::{ RecordSavingsRequest, SAVINGS_DOC_ID, SavingsAggregate, StoredSavings, }; use tinyjuice_bus::storage::SAVINGS_COLLECTION; -use tinystoragedrivers_core::{DocumentStore, DocumentStoreExt, Precondition}; +use tinystoragedrivers_api::{DocumentStore, DocumentStoreExt}; +use tinystoragedrivers_types::Precondition; /// Working state behind one lock, so load, change and write never interleave. #[derive(Default)] From 2e7d01cb70ed6205539b9e901069d745846619a9 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 00:44:13 +0300 Subject: [PATCH 018/119] chore(deps): upgrade tinystoragedrivers to v2.0.1 Moves the tinystoragedrivers dependency from the v1.0.0 tag to v2.0.1, which replaces the client and core crates with the api, types and testkit crates and pulls in rusqlite for the connect and document backends. The module re-exports the storage collections from tinyjuice-bus instead of the removed storage_schema helper. Auto-committed-on: dragonfly --- Cargo.lock | 363 +++++++++++------------------ crates/tinyjuice-module/src/lib.rs | 6 +- 2 files changed, 139 insertions(+), 230 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1ae39182..d4eebd47 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,16 +8,6 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" -[[package]] -name = "aead" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d122413f284cf2d62fb1b7db97e02edb8cda96d769b16e443a4f6195e35662b0" -dependencies = [ - "crypto-common 0.1.7", - "generic-array", -] - [[package]] name = "aho-corasick" version = "1.1.4" @@ -74,17 +64,6 @@ dependencies = [ "syn 3.0.0", ] -[[package]] -name = "atomicwrites" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ef1bb8d1b645fe38d51dfc331d720fb5fc2c94b440c76cc79c80ff265ca33e3" -dependencies = [ - "rustix 0.38.44", - "tempfile", - "windows-sys 0.52.0", -] - [[package]] name = "autocfg" version = "1.5.1" @@ -180,30 +159,6 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" -[[package]] -name = "chacha20" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3613f74bd2eac03dad61bd53dbe620703d4371614fe0bc3b9f04dd36fe4e818" -dependencies = [ - "cfg-if", - "cipher", - "cpufeatures 0.2.17", -] - -[[package]] -name = "chacha20poly1305" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10cd79432192d1c0f4e1a0fef9527696cc039165d729fb41b3f4f4f354c2dc35" -dependencies = [ - "aead", - "chacha20", - "cipher", - "poly1305", - "zeroize", -] - [[package]] name = "ciborium" version = "0.2.2" @@ -231,26 +186,6 @@ dependencies = [ "half", ] -[[package]] -name = "cipher" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" -dependencies = [ - "crypto-common 0.1.7", - "inout", - "zeroize", -] - -[[package]] -name = "clack-private-fs" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fcca21d8096fca7f1c3a22c3109e38927c9b587007c9c7a13b327e5a955baba" -dependencies = [ - "windows-sys 0.61.2", -] - [[package]] name = "clap" version = "4.6.1" @@ -382,7 +317,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" dependencies = [ "generic-array", - "rand_core 0.6.4", "typenum", ] @@ -451,7 +385,6 @@ checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer 0.10.4", "crypto-common 0.1.7", - "subtle", ] [[package]] @@ -525,6 +458,18 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "fallible-iterator" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649" + +[[package]] +name = "fallible-streaming-iterator" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a" + [[package]] name = "fastrand" version = "2.4.1" @@ -564,14 +509,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" [[package]] -name = "fs4" -version = "1.1.0" +name = "foldhash" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e72ed92b67c146290f88e9c89d60ca163ea417a446f61ffd7b72df3e7f1dfd5" -dependencies = [ - "rustix 1.1.4", - "windows-sys 0.61.2", -] +checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb" [[package]] name = "futures-core" @@ -579,6 +520,17 @@ version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d" +[[package]] +name = "futures-macro" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e835b70203e41293343137df5c0664546da5745f82ec9b84d40be8336958447b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.118", +] + [[package]] name = "futures-task" version = "0.3.32" @@ -592,6 +544,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6" dependencies = [ "futures-core", + "futures-macro", "futures-task", "pin-project-lite", "slab", @@ -652,11 +605,32 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "hashbrown" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" +dependencies = [ + "foldhash 0.2.0", +] + [[package]] name = "hashbrown" version = "0.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" +dependencies = [ + "foldhash 0.2.0", +] + +[[package]] +name = "hashlink" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a596f1b20ed2cc5ecac41a164aaebc7258057060f06c0cf7a2ba3991ee7990fb" +dependencies = [ + "hashbrown 0.17.1", +] [[package]] name = "hex" @@ -670,24 +644,6 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "242402749acf71e6f32f5857598b7002c4058a4e3c3b22b4c7d51cab9aea754e" -[[package]] -name = "hkdf" -version = "0.12.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7" -dependencies = [ - "hmac", -] - -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest 0.10.7", -] - [[package]] name = "http" version = "1.5.0" @@ -720,16 +676,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" dependencies = [ "equivalent", - "hashbrown", -] - -[[package]] -name = "inout" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01" -dependencies = [ - "generic-array", + "hashbrown 0.17.1", ] [[package]] @@ -766,7 +713,7 @@ checksum = "4be2f53207ffb1313a2d2ad819cfa8bfaa7936cb85a110eda10fd5da822cec94" dependencies = [ "bstr", "bytes", - "foldhash", + "foldhash 0.1.5", "hifijson", "indexmap", "jaq-core", @@ -891,10 +838,15 @@ dependencies = [ ] [[package]] -name = "linux-raw-sys" -version = "0.4.15" +name = "libsqlite3-sys" +version = "0.38.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab" +checksum = "f1d20bef17f513b9b3004532233187769cd072d790971f4e4da0e346eb6401e8" +dependencies = [ + "cc", + "pkg-config", + "vcpkg", +] [[package]] name = "linux-raw-sys" @@ -964,12 +916,6 @@ version = "11.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6790f58c7ff633d8771f42965289203411a5e5c68388703c06e14f24770b41e" -[[package]] -name = "opaque-debug" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" - [[package]] name = "option-ext" version = "0.2.0" @@ -1032,17 +978,6 @@ dependencies = [ "plotters-backend", ] -[[package]] -name = "poly1305" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8159bd90725d2df49889a078b54f4f79e87f1f8a8444194cdca81d38f5393abf" -dependencies = [ - "cpufeatures 0.2.17", - "opaque-debug", - "universal-hash", -] - [[package]] name = "portable-atomic" version = "1.15.0" @@ -1104,7 +1039,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9ef1d0d795eb7d84685bca4f72f3649f064e6641543d3a8c415898726a57b41" dependencies = [ "rand_chacha", - "rand_core 0.9.5", + "rand_core", ] [[package]] @@ -1114,16 +1049,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" dependencies = [ "ppv-lite86", - "rand_core 0.9.5", -] - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom 0.2.17", + "rand_core", ] [[package]] @@ -1216,16 +1142,28 @@ dependencies = [ ] [[package]] -name = "rustix" -version = "0.38.44" +name = "rsqlite-vfs" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c51c9ae4df8a7fba42103df5c621fa3c37eccf3a3c650879e90fc48b11cc192c" +dependencies = [ + "hashbrown 0.16.1", + "thiserror", +] + +[[package]] +name = "rusqlite" +version = "0.40.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fdb5bc1ae2baa591800df16c9ca78619bf65c0488b41b96ccec5d11220d8c154" +checksum = "23f2a97da3e3873c73cb2a2e71b35c40ff95e0b1eefa8d72d8499a6928c3b5b3" dependencies = [ "bitflags 2.13.0", - "errno", - "libc", - "linux-raw-sys 0.4.15", - "windows-sys 0.52.0", + "fallible-iterator", + "fallible-streaming-iterator", + "hashlink", + "libsqlite3-sys", + "smallvec", + "sqlite-wasm-rs", ] [[package]] @@ -1237,7 +1175,7 @@ dependencies = [ "bitflags 2.13.0", "errno", "libc", - "linux-raw-sys 0.12.1", + "linux-raw-sys", "windows-sys 0.61.2", ] @@ -1396,6 +1334,24 @@ version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" +[[package]] +name = "smallvec" +version = "1.16.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3dc8af474f516a851ff4bd12db780f948b9250ad37211e4eec0bccea54e01b" + +[[package]] +name = "sqlite-wasm-rs" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc3efc0da82635d7e1ced0053bbbfa8c7ab9645d0bf36ceb4f7127bb85315d75" +dependencies = [ + "cc", + "js-sys", + "rsqlite-vfs", + "wasm-bindgen", +] + [[package]] name = "streaming-iterator" version = "0.1.9" @@ -1450,7 +1406,7 @@ dependencies = [ "fastrand", "getrandom 0.4.3", "once_cell", - "rustix 1.1.4", + "rustix", "windows-sys 0.61.2", ] @@ -1600,9 +1556,10 @@ dependencies = [ "tinyjuice", "tinyjuice-bus", "tinyjuice-drivers", + "tinystoragedrivers-api", "tinystoragedrivers-busproxy", - "tinystoragedrivers-client", - "tinystoragedrivers-core", + "tinystoragedrivers-testkit", + "tinystoragedrivers-types", "tokio", ] @@ -1617,7 +1574,7 @@ dependencies = [ "tinystoragedrivers-document", "tinystoragedrivers-kv", "tinystoragedrivers-queue", - "tinystoragedrivers-secrets 2.0.1", + "tinystoragedrivers-secrets", "tinystoragedrivers-types", ] @@ -1652,41 +1609,31 @@ dependencies = [ [[package]] name = "tinystoragedrivers-bus" -version = "1.0.0" -source = "git+https://github.com/tinyhumansai/tinystoragedrivers?tag=v1.0.0#141fd9ed0ad5d14a8fb5a1b3e837a719e81ac08d" +version = "2.0.1" +source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.1#e3224a8262193e7466b230a59ef1c4769e44bf02" dependencies = [ "serde", "serde_json", "tinybus", + "tinystoragedrivers-types", ] [[package]] name = "tinystoragedrivers-busproxy" -version = "1.0.0" -source = "git+https://github.com/tinyhumansai/tinystoragedrivers?tag=v1.0.0#141fd9ed0ad5d14a8fb5a1b3e837a719e81ac08d" +version = "2.0.1" +source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.1#e3224a8262193e7466b230a59ef1c4769e44bf02" dependencies = [ "async-trait", + "bytes", + "futures-core", "serde", "serde_json", "tinybus", + "tinystoragedrivers-api", "tinystoragedrivers-bus", - "tinystoragedrivers-client", - "tinystoragedrivers-core", - "tokio", -] - -[[package]] -name = "tinystoragedrivers-client" -version = "1.0.0" -source = "git+https://github.com/tinyhumansai/tinystoragedrivers?tag=v1.0.0#141fd9ed0ad5d14a8fb5a1b3e837a719e81ac08d" -dependencies = [ - "async-trait", - "serde", - "serde_json", - "tinystoragedrivers-bus", - "tinystoragedrivers-core", - "tinystoragedrivers-secrets 1.0.0", + "tinystoragedrivers-types", "tokio", + "zeroize", ] [[package]] @@ -1694,26 +1641,11 @@ name = "tinystoragedrivers-connect" version = "2.0.1" source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.1#e3224a8262193e7466b230a59ef1c4769e44bf02" dependencies = [ + "rusqlite", "tinystoragedrivers-types", "tokio", ] -[[package]] -name = "tinystoragedrivers-core" -version = "1.0.0" -source = "git+https://github.com/tinyhumansai/tinystoragedrivers?tag=v1.0.0#141fd9ed0ad5d14a8fb5a1b3e837a719e81ac08d" -dependencies = [ - "async-trait", - "data-encoding", - "serde", - "serde_json", - "sha2 0.10.9", - "thiserror", - "tokio", - "ulid", - "zstd", -] - [[package]] name = "tinystoragedrivers-document" version = "2.0.1" @@ -1722,6 +1654,7 @@ dependencies = [ "async-trait", "data-encoding", "libc", + "rusqlite", "serde", "serde_json", "sha2 0.10.9", @@ -1764,35 +1697,33 @@ dependencies = [ [[package]] name = "tinystoragedrivers-secrets" -version = "1.0.0" -source = "git+https://github.com/tinyhumansai/tinystoragedrivers?tag=v1.0.0#141fd9ed0ad5d14a8fb5a1b3e837a719e81ac08d" +version = "2.0.1" +source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.1#e3224a8262193e7466b230a59ef1c4769e44bf02" dependencies = [ "async-trait", - "atomicwrites", - "chacha20poly1305", - "clack-private-fs", - "fs4", - "hkdf", - "rustix 1.1.4", - "serde", - "serde_json", - "sha2 0.10.9", - "tinystoragedrivers-core", - "tokio", - "winapi-util", - "windows-permissions", - "winsafe", + "tinystoragedrivers-api", + "tinystoragedrivers-types", "zeroize", ] [[package]] -name = "tinystoragedrivers-secrets" +name = "tinystoragedrivers-testkit" version = "2.0.1" source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.1#e3224a8262193e7466b230a59ef1c4769e44bf02" dependencies = [ "async-trait", + "bytes", + "futures-util", + "serde_json", "tinystoragedrivers-api", + "tinystoragedrivers-blob", + "tinystoragedrivers-document", + "tinystoragedrivers-kv", + "tinystoragedrivers-queue", + "tinystoragedrivers-secrets", "tinystoragedrivers-types", + "tokio", + "ulid", "zeroize", ] @@ -2008,16 +1939,6 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254" -[[package]] -name = "universal-hash" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc1de2c688dc15305988b563c3854064043356019f97a4b46276fe734c4f07ea" -dependencies = [ - "crypto-common 0.1.7", - "subtle", -] - [[package]] name = "untrusted" version = "0.9.0" @@ -2076,6 +1997,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + [[package]] name = "version_check" version = "0.9.5" @@ -2218,16 +2145,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" -[[package]] -name = "windows-permissions" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e2ccdc3c6bf4d4a094e031b63fadd08d8e42abd259940eb8aa5fdc09d4bf9be" -dependencies = [ - "bitflags 1.3.2", - "winapi", -] - [[package]] name = "windows-sys" version = "0.52.0" @@ -2316,12 +2233,6 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23b97319f7b8343df12cc98938e5c3eb436064524c8d2b4e30a1d3a36eecdf81" -[[package]] -name = "winsafe" -version = "0.0.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ef0ffc427f045c0cc9ebffd6f4f91153dcd2a1547b5c3c29ee3f541e16e95c6" - [[package]] name = "wit-bindgen" version = "0.57.1" @@ -2335,7 +2246,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32e45ad4206f6d2479085147f02bc2ef834ac85886624a23575ae137c8aa8156" dependencies = [ "libc", - "rustix 1.1.4", + "rustix", ] [[package]] diff --git a/crates/tinyjuice-module/src/lib.rs b/crates/tinyjuice-module/src/lib.rs index 7ff93b86..c7136f59 100644 --- a/crates/tinyjuice-module/src/lib.rs +++ b/crates/tinyjuice-module/src/lib.rs @@ -21,7 +21,5 @@ pub use service::exports::linked_module; pub use service::{BUS_NAME, OBJECT_PATH}; -/// What the module stores. A host composes it into its schema registry and -/// derives the module's storage grant from it, so the grant never repeats the -/// blob prefix by hand. -pub use tinyjuice_drivers::storage_schema; +/// Collections declared by TinyJuice's storage contract. +pub use tinyjuice_bus::storage::collections; From bb595f70d5485c74926300f32e4286c42684a4b8 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 00:55:09 +0300 Subject: [PATCH 019/119] test: migrate blob store tests to the split storage crates The blob store tests now build their handles from the tinystoragedrivers-blob and tinystoragedrivers-testkit crates instead of the removed core MemoryStorage, and the faulty wrapper forwards max_key_len to its inner store. The migration test was dropped because the schema registry it exercised no longer exists in the new layout. Auto-committed-on: dragonfly --- Cargo.lock | 2 + crates/tinyjuice-drivers/Cargo.toml | 2 + .../tinyjuice-drivers/src/blob_store_tests.rs | 111 ++++++------------ crates/tinyjuice-drivers/src/faulty_tests.rs | 6 +- 4 files changed, 48 insertions(+), 73 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d4eebd47..c4c4cf1e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1539,6 +1539,8 @@ dependencies = [ "tinyjuice", "tinyjuice-bus", "tinystoragedrivers-api", + "tinystoragedrivers-blob", + "tinystoragedrivers-testkit", "tinystoragedrivers-types", "tokio", ] diff --git a/crates/tinyjuice-drivers/Cargo.toml b/crates/tinyjuice-drivers/Cargo.toml index b40d197e..cb506fb9 100644 --- a/crates/tinyjuice-drivers/Cargo.toml +++ b/crates/tinyjuice-drivers/Cargo.toml @@ -22,3 +22,5 @@ tokio = { version = "1", features = ["rt"] } [dev-dependencies] tokio = { version = "1", features = ["macros", "rt-multi-thread", "time"] } async-trait = "0.1" +tinystoragedrivers-testkit = { version = "2.0.1", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.1" } +tinystoragedrivers-blob = { version = "2.0.1", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.1" } diff --git a/crates/tinyjuice-drivers/src/blob_store_tests.rs b/crates/tinyjuice-drivers/src/blob_store_tests.rs index 9a1cdc0d..66c34bce 100644 --- a/crates/tinyjuice-drivers/src/blob_store_tests.rs +++ b/crates/tinyjuice-drivers/src/blob_store_tests.rs @@ -1,26 +1,33 @@ use super::*; use std::sync::atomic::{AtomicBool, AtomicU64, Ordering}; -use tinystoragedrivers_core::{Capability, MemoryStorage, Scope, StorageBackend}; +use tinystoragedrivers_api::BlobStore; +use tinystoragedrivers_types::{Capability, ErrorKind, Scope}; use crate::faulty::Faulty; -fn clocked() -> (MemoryStorage, Arc) { - let now = Arc::new(AtomicU64::new(1_000)); - let reading = Arc::clone(&now); +static TEST_NOW: AtomicU64 = AtomicU64::new(1_000); +static CLOCK_TEST_LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(()); + +fn test_now_ms() -> u64 { + TEST_NOW.load(Ordering::SeqCst) +} + +fn clocked() -> (Arc, &'static AtomicU64) { + let scope = Scope::new("local").unwrap(); ( - MemoryStorage::with_clock(Arc::new(move || reading.load(Ordering::SeqCst))), - now, + Arc::new(tinystoragedrivers_blob::MemoryBlobStore::with_clock(scope, test_now_ms)), + &TEST_NOW, ) } -fn handle(storage: &MemoryStorage) -> Arc { - Arc::clone(storage.for_scope(&Scope::local()).unwrap().blobs()) +fn handle() -> Arc { + Arc::clone(tinystoragedrivers_testkit::memory_storage(&Scope::new("local").unwrap()).blobs()) } -fn faulty(storage: &MemoryStorage, ttl: bool) -> (Arc, Arc) { +fn faulty(ttl: bool) -> (Arc, Arc) { let fail = Arc::new(AtomicBool::new(false)); let blobs: Arc = Arc::new(Faulty { - inner: handle(storage), + inner: handle(), fail: Arc::clone(&fail), ttl, }); @@ -29,16 +36,16 @@ fn faulty(storage: &MemoryStorage, ttl: bool) -> (Arc, Arc usize { + self.inner.max_key_len() + } async fn put(&self, key: &str, bytes: Vec, ct: Option<&str>) -> Result { self.check()?; self.inner.put(key, bytes, ct).await From 0a7d28a3996871eca5611d40ce36ed07c3f38fbf Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 00:58:42 +0300 Subject: [PATCH 020/119] test(storage): migrate storage tests to the testkit backends Replace the hand-rolled FlakyDocs and NoExpiry wrappers with the testkit's Failing fault plan and MemoryBackend, and update the tests to the api/types crate split. The module grant test now asserts against collections() instead of walking the schema. Auto-committed-on: dragonfly --- .../src/savings_store_tests.rs | 113 +++--------------- crates/tinyjuice-module/src/storage_tests.rs | 72 ++++++----- 2 files changed, 48 insertions(+), 137 deletions(-) diff --git a/crates/tinyjuice-module/src/savings_store_tests.rs b/crates/tinyjuice-module/src/savings_store_tests.rs index 56dd0968..6d8156be 100644 --- a/crates/tinyjuice-module/src/savings_store_tests.rs +++ b/crates/tinyjuice-module/src/savings_store_tests.rs @@ -1,7 +1,9 @@ use super::*; use crate::storage::tests::rig; use tinyjuice_bus::savings::SavingsBucket; -use tinystoragedrivers_core::{Scope, StorageBackend}; +use tinystoragedrivers_api::{DocumentStore, StorageBackend}; +use tinystoragedrivers_testkit::{Failing, FaultPlan}; +use tinystoragedrivers_types::{ErrorKind, Scope}; type TestResult = Result<(), Box>; @@ -18,7 +20,7 @@ fn req(original: u64, compacted: u64) -> RecordSavingsRequest { async fn stored( rig: &crate::storage::tests::Rig, ) -> Result, Box> { - let docs = Arc::clone(rig.backend.for_scope(&Scope::local())?.documents()); + let docs = Arc::clone(rig.backend.for_scope(&Scope::new("local")?)?.documents()); Ok(docs .get(SAVINGS_COLLECTION, SAVINGS_DOC_ID) .await? @@ -156,102 +158,18 @@ async fn a_host_without_storage_is_not_asked_again_within_the_cooldown() -> Test Ok(()) } -/// The real document store, except that writes fail while `fail_puts` is set. -#[derive(Debug)] -struct FlakyDocs { - inner: Arc, - fail_puts: std::sync::atomic::AtomicBool, -} - -#[tinystoragedrivers_core::async_trait] -impl DocumentStore for FlakyDocs { - fn capabilities(&self) -> tinystoragedrivers_core::Capabilities { - self.inner.capabilities() - } - async fn ensure_collection( - &self, - spec: &tinystoragedrivers_core::CollectionSpec, - ) -> tinystoragedrivers_core::Result<()> { - self.inner.ensure_collection(spec).await - } - async fn get( - &self, - collection: &str, - id: &str, - ) -> tinystoragedrivers_core::Result< - Option>, - > { - self.inner.get(collection, id).await - } - async fn put( - &self, - collection: &str, - id: &str, - doc: serde_json::Value, - precondition: Precondition, - ) -> tinystoragedrivers_core::Result { - if self.fail_puts.load(std::sync::atomic::Ordering::SeqCst) { - return Err(tinystoragedrivers_core::StorageError::unavailable( - "writes are down", - )); - } - self.inner.put(collection, id, doc, precondition).await - } - async fn delete( - &self, - collection: &str, - id: &str, - precondition: Precondition, - ) -> tinystoragedrivers_core::Result { - self.inner.delete(collection, id, precondition).await - } - async fn query( - &self, - collection: &str, - query: &tinystoragedrivers_core::Query, - ) -> tinystoragedrivers_core::Result< - tinystoragedrivers_core::Page>, - > { - self.inner.query(collection, query).await - } - async fn count( - &self, - collection: &str, - filter: &tinystoragedrivers_core::Filter, - ) -> tinystoragedrivers_core::Result { - self.inner.count(collection, filter).await - } - async fn delete_where( - &self, - collection: &str, - filter: &tinystoragedrivers_core::Filter, - ) -> tinystoragedrivers_core::Result { - self.inner.delete_where(collection, filter).await - } - async fn claim( - &self, - collection: &str, - filter: &tinystoragedrivers_core::Filter, - sort: &[tinystoragedrivers_core::Sort], - patch: &serde_json::Value, - ) -> tinystoragedrivers_core::Result< - Option>, - > { - self.inner.claim(collection, filter, sort, patch).await - } - async fn drop_collection(&self, collection: &str) -> tinystoragedrivers_core::Result<()> { - self.inner.drop_collection(collection).await - } -} - #[tokio::test] async fn an_import_whose_write_fails_is_an_error_leaves_totals_alone_and_can_retry() { - let backend = tinystoragedrivers_core::MemoryStorage::new(); - let inner = Arc::clone(backend.for_scope(&Scope::local()).unwrap().documents()); - let flaky = Arc::new(FlakyDocs { - inner, - fail_puts: std::sync::atomic::AtomicBool::new(true), - }); + let backend = tinystoragedrivers_testkit::memory_backend(); + let inner = Arc::clone( + backend + .for_scope(&Scope::new("local").unwrap()) + .unwrap() + .documents(), + ); + let faults = FaultPlan::new(); + faults.fail_operation_nth("documents.put", 1, ErrorKind::Unavailable); + let flaky = Arc::new(Failing::with_plan(inner, faults)); let savings = Savings::new(); { let mut state = savings.state.lock().await; @@ -277,9 +195,6 @@ async fn an_import_whose_write_fails_is_an_error_leaves_totals_alone_and_can_ret "totals roll back" ); - flaky - .fail_puts - .store(false, std::sync::atomic::Ordering::SeqCst); assert!(savings.import(None, legacy).await.unwrap()); assert_eq!(savings.stats(None).await.total.tokens_saved, 20); let stored = flaky.get(SAVINGS_COLLECTION, SAVINGS_DOC_ID).await.unwrap(); diff --git a/crates/tinyjuice-module/src/storage_tests.rs b/crates/tinyjuice-module/src/storage_tests.rs index c0ff7713..8c880f8c 100644 --- a/crates/tinyjuice-module/src/storage_tests.rs +++ b/crates/tinyjuice-module/src/storage_tests.rs @@ -5,9 +5,10 @@ use super::*; use tinybus::broker::Broker; use tinybus::transport::memory::MemoryBus; use tinyjuice::cache::store::short_hash; -use tinystoragedrivers_busproxy::{PerCallerEndpoint, ServedStorage, serve}; -use tinystoragedrivers_client::StorageServer; -use tinystoragedrivers_core::{MemoryStorage, Scope, ScopedStorage}; +use tinystoragedrivers_api::{BlobStore, StorageBackend}; +use tinystoragedrivers_busproxy::{PerCallerEndpoint, ServedStorage, StorageServer, serve}; +use tinystoragedrivers_testkit::MemoryBackend; +use tinystoragedrivers_types::{Blob, BlobMeta, Capabilities, Capability, Result as StorageResult, Scope, StorageError}; /// Serializes the tests that `install`, which reconfigures process-global cache /// state. @@ -17,7 +18,7 @@ type TestResult = Result<(), Box>; pub(crate) struct Rig { pub(crate) module: Connection, - pub(crate) backend: MemoryStorage, + pub(crate) backend: Arc, host: Connection, _served: Option, } @@ -25,9 +26,9 @@ pub(crate) struct Rig { impl Rig { /// Start serving storage on a rig built without it. pub(crate) async fn serve_storage(&mut self) -> Result<(), Box> { - let bound = self.backend.clone(); + let bound = Arc::clone(&self.backend); let endpoint = PerCallerEndpoint::new(move |_sender| { - let scoped: ScopedStorage = bound.for_scope(&Scope::local()).ok()?; + let scoped = bound.for_scope(&Scope::new("local").ok()?).ok()?; Some(StorageServer::new(scoped)) }); self._served = Some(serve(&self.host, Arc::new(endpoint)).await?); @@ -38,12 +39,12 @@ impl Rig { pub(crate) async fn rig(serve_storage: bool) -> Result> { let bus = MemoryBus::new(); Broker::new().spawn(bus.clone()); - let backend = MemoryStorage::new(); + let backend = Arc::new(MemoryBackend::new()); let host = Connection::connect(bus.connect().await?).await?; let served = if serve_storage { - let bound = backend.clone(); + let bound = Arc::clone(&backend); let endpoint = PerCallerEndpoint::new(move |_sender| { - let scoped: ScopedStorage = bound.for_scope(&Scope::local()).ok()?; + let scoped = bound.for_scope(&Scope::new("local").ok()?).ok()?; Some(StorageServer::new(scoped)) }); Some(serve(&host, Arc::new(endpoint)).await?) @@ -69,7 +70,7 @@ async fn originals_land_as_blobs_on_the_host_port() -> TestResult { let put = store.put(content); assert!(put.retained()); - let host_blobs = Arc::clone(rig.backend.for_scope(&Scope::local())?.blobs()); + let host_blobs = Arc::clone(rig.backend.for_scope(&Scope::new("local")?)?.blobs()); let key = format!("{}/{}", tinyjuice_drivers::CCR_PREFIX, short_hash(content)); let blob = host_blobs.get(&key).await?.ok_or("blob is on the host")?; assert_eq!(blob.bytes, content.as_bytes()); @@ -129,7 +130,7 @@ async fn install_moves_the_disk_tier_onto_host_blobs_and_off_again() -> TestResu let service = Compression { connection: Some(rig.module.clone()), }; - let host_blobs = Arc::clone(rig.backend.for_scope(&Scope::local())?.blobs()); + let host_blobs = Arc::clone(rig.backend.for_scope(&Scope::new("local")?)?.blobs()); service.install(install_request(true)).await?; let content = "install wired durable tier fixture original"; @@ -151,23 +152,31 @@ async fn install_moves_the_disk_tier_onto_host_blobs_and_off_again() -> TestResu /// A blob handle that reports no optional abilities (no expiry), over memory. #[derive(Debug)] -struct NoExpiry(Arc); +struct NoBlobExpiry(Arc); #[async_trait::async_trait] -impl BlobStore for NoExpiry { +impl BlobStore for NoBlobExpiry { + fn capabilities(&self) -> Capabilities { + self.0.capabilities().without(Capability::BlobTtl) + } + + fn max_key_len(&self) -> usize { + self.0.max_key_len() + } + async fn put( &self, key: &str, bytes: Vec, content_type: Option<&str>, - ) -> tinystoragedrivers_core::Result { + ) -> StorageResult { self.0.put(key, bytes, content_type).await } async fn get( &self, key: &str, - ) -> tinystoragedrivers_core::Result> { + ) -> StorageResult> { self.0.get(key).await } @@ -175,34 +184,34 @@ impl BlobStore for NoExpiry { &self, key: &str, range: std::ops::Range, - ) -> tinystoragedrivers_core::Result>> { + ) -> StorageResult>> { self.0.get_range(key, range).await } async fn head( &self, key: &str, - ) -> tinystoragedrivers_core::Result> { + ) -> StorageResult> { self.0.head(key).await } - async fn delete(&self, key: &str) -> tinystoragedrivers_core::Result { + async fn delete(&self, key: &str) -> StorageResult { self.0.delete(key).await } async fn list( &self, prefix: &str, - ) -> tinystoragedrivers_core::Result> { + ) -> StorageResult> { self.0.list(prefix).await } } #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn a_handle_that_cannot_expire_blobs_gets_no_ttl_tier_but_a_keep_forever_one() -> TestResult { - let backend = MemoryStorage::new(); - let blobs: Arc = Arc::new(NoExpiry(Arc::clone( - backend.for_scope(&Scope::local())?.blobs(), + let backend = MemoryBackend::new(); + let blobs: Arc = Arc::new(NoBlobExpiry(Arc::clone( + backend.for_scope(&Scope::new("local")?)?.blobs(), ))); assert!( tier_on(Arc::clone(&blobs), Some(Duration::from_secs(60))) @@ -240,22 +249,9 @@ async fn store_calls_run_in_place_on_a_current_thread_runtime() { #[test] fn the_module_grant_is_its_schema_at_module_scope() { - use tinystoragedrivers_core::schema::{Item, ScopeClass}; - let schema = crate::storage_schema(); - let grant: Vec<(&str, ScopeClass)> = schema - .items - .iter() - .map(|item| match item { - Item::Blobs { prefix, scope } => (prefix.as_str(), *scope), - Item::Collection { name, scope, .. } => (name.as_str(), *scope), - other => panic!("the module stores blobs and collections only, got {other:?}"), - }) - .collect(); + use tinystoragedrivers_types::CollectionSpec; assert_eq!( - grant, - [ - ("juice/ccr/", ScopeClass::Module), - ("juice.savings", ScopeClass::Module) - ] + crate::collections(), + vec![CollectionSpec::new("juice.savings")] ); } From 584fbf571d47bda6182f4656f6172e4854d6c5d6 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 01:00:03 +0300 Subject: [PATCH 021/119] test(storage): rename module grant test to describe provisioning Renamed the test to reflect that it now covers the document collection declared for host provisioning, and reformatted the types import to fit the line width. Auto-committed-on: dragonfly --- crates/tinyjuice-module/src/storage_tests.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/tinyjuice-module/src/storage_tests.rs b/crates/tinyjuice-module/src/storage_tests.rs index 8c880f8c..7533c3ac 100644 --- a/crates/tinyjuice-module/src/storage_tests.rs +++ b/crates/tinyjuice-module/src/storage_tests.rs @@ -8,7 +8,9 @@ use tinyjuice::cache::store::short_hash; use tinystoragedrivers_api::{BlobStore, StorageBackend}; use tinystoragedrivers_busproxy::{PerCallerEndpoint, ServedStorage, StorageServer, serve}; use tinystoragedrivers_testkit::MemoryBackend; -use tinystoragedrivers_types::{Blob, BlobMeta, Capabilities, Capability, Result as StorageResult, Scope, StorageError}; +use tinystoragedrivers_types::{ + Blob, BlobMeta, Capabilities, Capability, Result as StorageResult, Scope, +}; /// Serializes the tests that `install`, which reconfigures process-global cache /// state. @@ -248,7 +250,7 @@ async fn store_calls_run_in_place_on_a_current_thread_runtime() { } #[test] -fn the_module_grant_is_its_schema_at_module_scope() { +fn declares_document_collection_for_host_provisioning() { use tinystoragedrivers_types::CollectionSpec; assert_eq!( crate::collections(), From 1ee1df62379df1fe525eea100a67e0ea94e197da Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 02:40:08 +0300 Subject: [PATCH 022/119] feat(cli): move standalone CLI into its own package with file-backed CCR store The standalone CLI now lives in the tinyjuice-cli package and composes a host-provided file blob store for ls, cat, stats, and gc, so the library and hosted module no longer carry a file-backed persistence tier. Legacy cache files are imported into the configured store with their original write chronology preserved, and the CLI enforces TTL and byte budgets when storing new entries. Auto-committed-on: dragonfly --- Cargo.lock | 3 + README.md | 51 +- crates/tinyjuice-bus/src/storage.rs | 7 +- crates/tinyjuice-bus/src/storage_tests.rs | 3 +- crates/tinyjuice-cli/Cargo.toml | 3 + .../tinyjuice-cli/src/bin/tinyjuice-reduce.rs | 17 +- .../tinyjuice_reduce_tests.rs | 4 +- crates/tinyjuice-cli/src/bin/tinyjuice.rs | 13 +- crates/tinyjuice-cli/src/storage.rs | 470 ++++++++++++++++-- crates/tinyjuice-cli/src/storage_tests.rs | 344 +++++++++++++ crates/tinyjuice-cli/tests/cli.rs | 44 +- .../v0.10.10/1e66b4cff1835002102d821ffee64f75 | 1 + .../fixtures/legacy-ccr/v0.10.10/README.md | 32 ++ .../legacy-ccr/v0.10.10/write_ccr_fixture.rs | 12 + .../tinyjuice-drivers/src/blob_store_tests.rs | 43 +- crates/tinyjuice-drivers/src/blocking.rs | 8 +- crates/tinyjuice-drivers/src/lib.rs | 2 +- crates/tinyjuice-module/src/storage.rs | 25 +- crates/tinyjuice-module/src/storage_tests.rs | 55 +- .../tests/module_e2e_tests.rs | 46 +- docs/agent-hooks/README.md | 18 +- docs/architecture.md | 10 +- src/cache/mod.rs | 1 - 23 files changed, 1059 insertions(+), 153 deletions(-) rename crates/tinyjuice-cli/src/bin/{ => tinyjuice-reduce}/tinyjuice_reduce_tests.rs (98%) create mode 100644 crates/tinyjuice-cli/src/storage_tests.rs create mode 100644 crates/tinyjuice-cli/tests/fixtures/legacy-ccr/v0.10.10/1e66b4cff1835002102d821ffee64f75 create mode 100644 crates/tinyjuice-cli/tests/fixtures/legacy-ccr/v0.10.10/README.md create mode 100644 crates/tinyjuice-cli/tests/fixtures/legacy-ccr/v0.10.10/write_ccr_fixture.rs diff --git a/Cargo.lock b/Cargo.lock index c4c4cf1e..87474b24 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1519,13 +1519,16 @@ dependencies = [ name = "tinyjuice-cli" version = "0.11.0" dependencies = [ + "async-trait", "dirs", + "log", "serde_json", "tempfile", "tinyjuice", "tinyjuice-drivers", "tinystoragedrivers", "tinystoragedrivers-api", + "tinystoragedrivers-testkit", "tinystoragedrivers-types", "tokio", ] diff --git a/README.md b/README.md index c371b460..96e83831 100644 --- a/README.md +++ b/README.md @@ -222,25 +222,25 @@ tool-output adapter leaves the output unchanged and reports Install the CLI: ```sh -cargo install tinyjuice --features cli-disk-tier --locked +cargo install --path crates/tinyjuice-cli --locked --bin tinyjuice ``` Run the minimal reducer CLI: ```sh -cargo run --features cli-disk-tier --bin tinyjuice-reduce -- reduce --tool-name bash --command "git status" status.txt -cargo run --features cli-disk-tier --bin tinyjuice-reduce -- reduce-json payload.json -cargo run --features cli-disk-tier --bin tinyjuice-reduce -- verify --rules --fixtures -cargo run --features cli-disk-tier --bin tinyjuice-reduce -- discover executions.ndjson -cargo run --features cli-disk-tier --bin tinyjuice-reduce -- wrap -- cargo test -cargo run --features cli-disk-tier --bin tinyjuice-reduce -- ls --store-dir .tokenjuice/ccr -cargo run --features cli-disk-tier --bin tinyjuice-reduce -- cat --store-dir .tokenjuice/ccr -cargo run --features cli-disk-tier --bin tinyjuice-reduce -- stats --store-dir .tokenjuice/ccr -cargo run --features cli-disk-tier --bin tinyjuice-reduce -- doctor --store-dir .tokenjuice/ccr -cargo run --features cli-disk-tier --bin tinyjuice-reduce -- doctor codex -cargo run --features cli-disk-tier --bin tinyjuice-reduce -- doctor hooks -cargo run --features cli-disk-tier --bin tinyjuice-reduce -- install codex --local target/debug/tinyjuice -cargo run --features cli-disk-tier --bin tinyjuice-reduce -- uninstall codex +cargo run --manifest-path crates/tinyjuice-cli/Cargo.toml --bin tinyjuice-reduce -- reduce --tool-name bash --command "git status" status.txt +cargo run --manifest-path crates/tinyjuice-cli/Cargo.toml --bin tinyjuice-reduce -- reduce-json payload.json +cargo run --manifest-path crates/tinyjuice-cli/Cargo.toml --bin tinyjuice-reduce -- verify --rules --fixtures +cargo run --manifest-path crates/tinyjuice-cli/Cargo.toml --bin tinyjuice-reduce -- discover executions.ndjson +cargo run --manifest-path crates/tinyjuice-cli/Cargo.toml --bin tinyjuice-reduce -- wrap -- cargo test +cargo run --manifest-path crates/tinyjuice-cli/Cargo.toml --bin tinyjuice-reduce -- ls --store-dir .tokenjuice/ccr +cargo run --manifest-path crates/tinyjuice-cli/Cargo.toml --bin tinyjuice-reduce -- cat --store-dir .tokenjuice/ccr +cargo run --manifest-path crates/tinyjuice-cli/Cargo.toml --bin tinyjuice-reduce -- stats --store-dir .tokenjuice/ccr +cargo run --manifest-path crates/tinyjuice-cli/Cargo.toml --bin tinyjuice-reduce -- doctor --store-dir .tokenjuice/ccr +cargo run --manifest-path crates/tinyjuice-cli/Cargo.toml --bin tinyjuice-reduce -- doctor codex +cargo run --manifest-path crates/tinyjuice-cli/Cargo.toml --bin tinyjuice-reduce -- doctor hooks +cargo run --manifest-path crates/tinyjuice-cli/Cargo.toml --bin tinyjuice-reduce -- install codex --local target/debug/tinyjuice +cargo run --manifest-path crates/tinyjuice-cli/Cargo.toml --bin tinyjuice-reduce -- uninstall codex ``` Run hot-path benchmarks: @@ -272,18 +272,17 @@ helpers still use the process-global `GlobalCcrStore` for compatibility. New tests and host adapters can use `MemoryCcrStore` to assert CCR behavior without touching the global cache. -The standalone CLI's `ls`, `cat`, `stats`, and `gc` commands are compiled with -the opt-in `cli-disk-tier` feature; `ls`, `cat`, and `stats` can inspect an -explicit directory with `--store-dir`. `gc` and normal CLI or hook compression -runs use `TINYJUICE_CCR_DIR`, falling back to the platform cache directory. -Library and hosted module builds do not contain this tier. It is a disposable -recovery cache, not durable user data. Hosted persistence is owned by the host's -BlobCcrStore. Existing standalone cache files are not imported into hosted -storage. The REPL's former `repl_save_dir` text snapshots are no longer written; -the CCR token and its configured store are authoritative. TinyBus contract 3.0 -rejects 2.x hosts because the old disk-path request cannot express host -durability. These commands do not imply access to another process's in-memory -cache. `cat` supports +The standalone CLI lives in the separate `tinyjuice-cli` package and uses a +host-composed file blob store for `ls`, `cat`, `stats`, and `gc`; the library +and hosted module contain no file-backed persistence tier. These commands can +inspect an explicit directory with `--store-dir`, while normal CLI and hook +compression runs use `TINYJUICE_CCR_DIR` or the platform cache directory. It is +a disposable recovery cache, not durable user data. Hosted persistence is +owned by the host's BlobCcrStore. Existing standalone cache files are imported +by the CLI into its configured store. The REPL's former `repl_save_dir` text +snapshots are no longer written; the CCR token and its configured store are +authoritative. These commands do not imply access to another process's +in-memory cache. `cat` supports `--lines START:END` and `--bytes START:END` ranges. `stats` reports metadata-only counts and byte totals without reading token content. diff --git a/crates/tinyjuice-bus/src/storage.rs b/crates/tinyjuice-bus/src/storage.rs index a0651651..362f33e3 100644 --- a/crates/tinyjuice-bus/src/storage.rs +++ b/crates/tinyjuice-bus/src/storage.rs @@ -2,11 +2,8 @@ use tinystoragedrivers_types::CollectionSpec; -/// CCR originals are stored below `juice/ccr/`. -pub const CCR_PREFIX: &str = "juice/ccr"; - -/// Legacy prefix used before the owner moved originals into `juice/ccr`. -pub const LEGACY_CCR_PREFIX: &str = "tinyjuice_ccr/"; +/// CCR originals retain the released `tinyjuice_ccr/` blob keys. +pub const CCR_PREFIX: &str = "tinyjuice_ccr"; /// The owner-scoped savings totals document collection. pub const SAVINGS_COLLECTION: &str = "juice.savings"; diff --git a/crates/tinyjuice-bus/src/storage_tests.rs b/crates/tinyjuice-bus/src/storage_tests.rs index 939cb4d0..236f840d 100644 --- a/crates/tinyjuice-bus/src/storage_tests.rs +++ b/crates/tinyjuice-bus/src/storage_tests.rs @@ -3,8 +3,7 @@ use super::*; #[test] fn owner_collections_declare_savings_without_engine_or_migration_policy() { assert_eq!(collections(), vec![CollectionSpec::new("juice.savings")]); - assert_eq!(CCR_PREFIX, "juice/ccr"); - assert_eq!(LEGACY_CCR_PREFIX, "tinyjuice_ccr/"); + assert_eq!(CCR_PREFIX, "tinyjuice_ccr"); } #[test] diff --git a/crates/tinyjuice-cli/Cargo.toml b/crates/tinyjuice-cli/Cargo.toml index 54db8706..07b578e5 100644 --- a/crates/tinyjuice-cli/Cargo.toml +++ b/crates/tinyjuice-cli/Cargo.toml @@ -15,11 +15,14 @@ tinystoragedrivers = { version = "2.0.1", git = "https://github.com/senamakel/ti tinystoragedrivers-api = { version = "2.0.1", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.1" } tinystoragedrivers-types = { version = "2.0.1", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.1" } dirs = "7" +log = "0.4" serde_json = "1" tokio = { version = "1", features = ["rt-multi-thread"] } [dev-dependencies] +async-trait = "0.1" tempfile = "3" +tinystoragedrivers-testkit = { version = "2.0.1", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.1" } [[bin]] name = "tinyjuice" diff --git a/crates/tinyjuice-cli/src/bin/tinyjuice-reduce.rs b/crates/tinyjuice-cli/src/bin/tinyjuice-reduce.rs index 88cce01a..33b64633 100644 --- a/crates/tinyjuice-cli/src/bin/tinyjuice-reduce.rs +++ b/crates/tinyjuice-cli/src/bin/tinyjuice-reduce.rs @@ -10,6 +10,7 @@ use tinyjuice::{ load_builtin_rules, reduce_execution_with_rules, reduce_json_str, verify_rule_fixtures, verify_rules, }; +use tinyjuice_drivers::CCR_PREFIX; #[path = "../storage.rs"] mod storage; @@ -755,7 +756,7 @@ fn run_cat(args: &[String]) -> Result<(), String> { tinyjuice::cache::DEFAULT_MAX_BYTES, None, ); - storage::configure(&store_dir, None)?; + storage::configure(&store_dir, storage::configured_ttl(), None)?; let content = match range { Some((unit, (start, end))) => tinyjuice::cache::retrieve_range(&token, start, end, unit), None => tinyjuice::cache::retrieve(&token), @@ -817,13 +818,19 @@ struct CcrStoreEntry { } fn read_ccr_store_inventory(store_dir: &Path) -> Result { - let inventory = storage::inventory(store_dir)?; + let inventory = storage::inventory(store_dir, storage::configured_ttl())?; let entries = inventory .entries .into_iter() .filter_map(|entry| { - let token = entry.key.strip_prefix("juice/ccr/")?.to_owned(); - is_cli_ccr_token(&token).then_some(CcrStoreEntry { token, bytes: entry.len }) + let token = entry + .key + .strip_prefix(&format!("{CCR_PREFIX}/"))? + .to_owned(); + is_cli_ccr_token(&token).then_some(CcrStoreEntry { + token, + bytes: entry.len, + }) }) .collect(); Ok(CcrStoreInventory { @@ -1294,5 +1301,5 @@ fn print_uninstall_usage() { } #[cfg(test)] -#[path = "tinyjuice_reduce_tests.rs"] +#[path = "tinyjuice-reduce/tinyjuice_reduce_tests.rs"] mod tests; diff --git a/crates/tinyjuice-cli/src/bin/tinyjuice_reduce_tests.rs b/crates/tinyjuice-cli/src/bin/tinyjuice-reduce/tinyjuice_reduce_tests.rs similarity index 98% rename from crates/tinyjuice-cli/src/bin/tinyjuice_reduce_tests.rs rename to crates/tinyjuice-cli/src/bin/tinyjuice-reduce/tinyjuice_reduce_tests.rs index f1897799..e8be2104 100644 --- a/crates/tinyjuice-cli/src/bin/tinyjuice_reduce_tests.rs +++ b/crates/tinyjuice-cli/src/bin/tinyjuice-reduce/tinyjuice_reduce_tests.rs @@ -225,7 +225,9 @@ fn install_and_uninstall_dispatch_with_explicit_host_paths() { #[test] fn store_inventory_counts_only_tokens_and_stats_formats_both_modes() { let dir = tempfile::tempdir().unwrap(); - fs::write(dir.path().join("a".repeat(32)), "original").unwrap(); + let content = "original"; + let token = tinyjuice::cache::short_hash(content); + fs::write(dir.path().join(token), content).unwrap(); fs::write(dir.path().join("notes"), "unrelated").unwrap(); fs::create_dir(dir.path().join("nested")).unwrap(); let inventory = read_ccr_store_inventory(dir.path()).unwrap(); diff --git a/crates/tinyjuice-cli/src/bin/tinyjuice.rs b/crates/tinyjuice-cli/src/bin/tinyjuice.rs index 02cc2b92..0cf562c0 100644 --- a/crates/tinyjuice-cli/src/bin/tinyjuice.rs +++ b/crates/tinyjuice-cli/src/bin/tinyjuice.rs @@ -595,11 +595,8 @@ fn gc_command(args: Vec) -> Result<(), String> { }; let root = cli_cache_root(); - let (removed, freed_bytes, kept, kept_bytes) = storage::collect( - &root, - ttl.map(std::time::Duration::from_secs), - budget, - )?; + let (removed, freed_bytes, kept, kept_bytes) = + storage::collect(&root, ttl.map(std::time::Duration::from_secs), budget)?; println!( "gc {}: removed {} entries, freed {} bytes, kept {} ({} bytes)", root.display(), @@ -701,7 +698,11 @@ fn cli_cache_limits_from_env() -> (usize, usize, Option) { fn configure_cli_cache() -> Result<(), String> { let (max_entries, max_bytes, ttl_secs) = cli_cache_limits_from_env(); tinyjuice::cache::configure(max_entries, max_bytes, ttl_secs); - storage::configure(&cli_cache_root(), ttl_secs.map(std::time::Duration::from_secs)) + storage::configure( + &cli_cache_root(), + ttl_secs.map(std::time::Duration::from_secs), + Some(max_bytes as u64), + ) } fn cli_cache_root() -> PathBuf { diff --git a/crates/tinyjuice-cli/src/storage.rs b/crates/tinyjuice-cli/src/storage.rs index 9f0f2e2c..220e55e0 100644 --- a/crates/tinyjuice-cli/src/storage.rs +++ b/crates/tinyjuice-cli/src/storage.rs @@ -1,34 +1,83 @@ //! CLI-owned composition of CCR over Tiny Storage Drivers' file backend. +use std::collections::{HashMap, HashSet}; use std::path::Path; use std::sync::Arc; -use std::time::Duration; +use std::time::{Duration, SystemTime}; -use tinyjuice::cache::{CcrStore, set_durable_tier}; +use tinyjuice::cache::{CcrPutResult, CcrStore, set_durable_tier}; use tinyjuice_drivers::{BlobCcrStore, CCR_PREFIX}; use tinystoragedrivers::{Scope, StorageConfig, open}; use tinystoragedrivers_api::BlobStore; use tinystoragedrivers_types::BlobMeta; const PAGE_SIZE: usize = 1000; +const DEFAULT_CLI_CCR_TTL_SECS: u64 = 7 * 24 * 60 * 60; +// The blob port has no caller metadata field. Keep legacy/file write chronology +// in a sibling key so the raw CCR body and its content token remain unchanged. +const CCR_METADATA_PREFIX: &str = "tinyjuice/ccr-metadata/"; +const CCR_METADATA_CONTENT_TYPE: &str = "application/vnd.tinyjuice.ccr-metadata"; +const CCR_IMPORT_PREFIX: &str = "tinyjuice/ccr-import-intent/"; +#[allow(dead_code)] // The reducer binary uses inventory; the hook binary shares this module. pub(crate) struct Inventory { pub entries: Vec, pub ignored_entries: usize, } -pub(crate) fn configure(root: &Path, ttl: Option) -> Result<(), String> { - std::fs::create_dir_all(root) - .map_err(|error| format!("cannot create CCR storage directory {}: {error}", root.display()))?; +pub(crate) fn configure( + root: &Path, + ttl: Option, + max_bytes: Option, +) -> Result<(), String> { + std::fs::create_dir_all(root).map_err(|error| { + format!( + "cannot create CCR storage directory {}: {error}", + root.display() + ) + })?; let blobs = open_file_blobs(root)?; import_legacy_files(root, &blobs, ttl)?; - let store = BlobCcrStore::new(blobs, ttl).map_err(|error| error.to_string())?; - set_durable_tier(Some(Arc::new(store))); + let store = BlobCcrStore::new(Arc::clone(&blobs), ttl).map_err(|error| error.to_string())?; + let capped = CappedCcrStore { + store, + blobs: Arc::clone(&blobs), + ttl, + max_bytes, + }; + if max_bytes.is_some() { + prune(&blobs, ttl, max_bytes, None)?; + } + set_durable_tier(Some(Arc::new(capped))); Ok(()) } -pub(crate) fn inventory(root: &Path) -> Result { - configure(root, None)?; +#[allow(dead_code)] // The reducer binary uses inventory; the hook binary shares this module. +pub(crate) fn inventory(root: &Path, ttl: Option) -> Result { + if !root.is_dir() { + return Err(format!( + "CCR storage directory does not exist: {}", + root.display() + )); + } + let mut ignored_entries = 0; + for entry in std::fs::read_dir(root).map_err(|error| { + format!( + "failed to inspect CCR storage directory {}: {error}", + root.display() + ) + })? { + let entry = entry.map_err(|error| format!("failed to inspect CCR entry: {error}"))?; + if !entry + .file_type() + .map_err(|error| format!("failed to inspect CCR entry type: {error}"))? + .is_file() + || !is_token(&entry.file_name().to_string_lossy()) + { + ignored_entries += 1; + } + } + configure(root, ttl, None)?; let blobs = open_file_blobs(root)?; let mut entries = Vec::new(); let mut after = None; @@ -36,7 +85,11 @@ pub(crate) fn inventory(root: &Path) -> Result { let page = run_blob({ let after = after.clone(); let blobs = Arc::clone(&blobs); - async move { blobs.list_page(&format!("{CCR_PREFIX}/"), after.as_deref(), PAGE_SIZE).await } + async move { + blobs + .list_page(&format!("{CCR_PREFIX}/"), after.as_deref(), PAGE_SIZE) + .await + } })?; entries.extend(page.items.into_iter().map(|item| item.meta)); after = page.next_after; @@ -44,32 +97,68 @@ pub(crate) fn inventory(root: &Path) -> Result { break; } } - Ok(Inventory { entries, ignored_entries: 0 }) + Ok(Inventory { + entries, + ignored_entries, + }) +} + +#[allow(dead_code)] // The reducer binary shares this storage module. +pub(crate) fn configured_ttl() -> Option { + let seconds = std::env::var("TINYJUICE_CCR_TTL_SECS") + .ok() + .and_then(|value| value.trim().parse::().ok()) + .unwrap_or(DEFAULT_CLI_CCR_TTL_SECS); + (seconds > 0).then(|| Duration::from_secs(seconds)) } +#[allow(dead_code)] // The hook binary shares this CLI-only collector. pub(crate) fn collect( root: &Path, ttl: Option, max_bytes: Option, ) -> Result<(usize, u64, usize, u64), String> { - configure(root, ttl)?; + configure(root, ttl, None)?; let blobs = open_file_blobs(root)?; - let mut entries = list_all(Arc::clone(&blobs))?; - let now_ms = std::time::SystemTime::now() + prune(&blobs, ttl, max_bytes, None) +} + +fn prune( + blobs: &Arc, + ttl: Option, + max_bytes: Option, + protect: Option<&str>, +) -> Result<(usize, u64, usize, u64), String> { + let mut entries = list_all(Arc::clone(blobs))?; + let semantic_times = list_semantic_times(Arc::clone(blobs))?; + for entry in &mut entries { + if let Some(token) = entry.meta.key.strip_prefix(&format!("{CCR_PREFIX}/")) + && let Some(written_at_ms) = semantic_times.get(token) + { + entry.written_at_ms = Some(*written_at_ms); + } + } + let now_ms = SystemTime::now() .duration_since(std::time::UNIX_EPOCH) .unwrap_or_default() .as_millis() as u64; let ttl_ms = ttl.map(|ttl| ttl.as_millis().min(u64::MAX as u128) as u64); let mut remove = Vec::new(); + let mut removed_bytes = 0_u64; for entry in &entries { if ttl_ms.is_some_and(|ttl| { - entry.written_at_ms.is_some_and(|written| now_ms.saturating_sub(written) >= ttl) + entry + .written_at_ms + .is_some_and(|written| now_ms.saturating_sub(written) >= ttl) }) { remove.push(entry.meta.key.clone()); } } for key in &remove { - delete_blob(Arc::clone(&blobs), key)?; + if let Some(entry) = entries.iter().find(|entry| &entry.meta.key == key) { + removed_bytes = removed_bytes.saturating_add(entry.meta.len); + } + delete_blob_and_metadata(Arc::clone(blobs), key)?; } entries.retain(|entry| !remove.contains(&entry.meta.key)); let mut total = entries.iter().map(|entry| entry.meta.len).sum::(); @@ -79,14 +168,37 @@ pub(crate) fn collect( if total <= budget { break; } - delete_blob(Arc::clone(&blobs), &entry.meta.key)?; + if protect.is_some_and(|token| entry.meta.key == format!("{CCR_PREFIX}/{token}")) { + continue; + } + delete_blob_and_metadata(Arc::clone(blobs), &entry.meta.key)?; + removed_bytes = removed_bytes.saturating_add(entry.meta.len); total = total.saturating_sub(entry.meta.len); remove.push(entry.meta.key); } } - let remaining = list_all(blobs)?; + let remaining = list_all(Arc::clone(blobs))?; let remaining_bytes = remaining.iter().map(|entry| entry.meta.len).sum(); - Ok((remove.len(), remaining_bytes, remaining.len(), remaining_bytes)) + let remaining_tokens = remaining + .iter() + .filter_map(|entry| entry.meta.key.strip_prefix(&format!("{CCR_PREFIX}/"))) + .collect::>(); + for token in semantic_times.keys() { + if !remaining_tokens.contains(token.as_str()) { + delete_metadata(Arc::clone(blobs), token)?; + } + } + for token in list_timestamps(Arc::clone(blobs), CCR_IMPORT_PREFIX)?.keys() { + if !remaining_tokens.contains(token.as_str()) { + delete_import_intent(Arc::clone(blobs), token)?; + } + } + Ok(( + remove.len(), + removed_bytes, + remaining.len(), + remaining_bytes, + )) } fn open_file_blobs(root: &Path) -> Result, String> { @@ -96,9 +208,13 @@ fn open_file_blobs(root: &Path) -> Result, String> { .map_err(|error| format!("cannot start storage runtime: {error}"))?; let url = format!("file:{}", root.display()); let config = StorageConfig::parse(&url).map_err(|error| error.to_string())?; - let backend = runtime.block_on(open(&config)).map_err(|error| error.to_string())?; + let backend = runtime + .block_on(open(&config)) + .map_err(|error| error.to_string())?; let scope = Scope::new("tinyjuice-cli").map_err(|error| error.to_string())?; - let storage = backend.for_scope(&scope).map_err(|error| error.to_string())?; + let storage = backend + .for_scope(&scope) + .map_err(|error| error.to_string())?; let blobs = Arc::clone(storage.blobs()); drop(runtime); Ok(blobs) @@ -109,12 +225,20 @@ fn import_legacy_files( blobs: &Arc, ttl: Option, ) -> Result<(), String> { - let entries = std::fs::read_dir(root) - .map_err(|error| format!("failed to inspect legacy CCR directory {}: {error}", root.display()))?; - let store = BlobCcrStore::new(Arc::clone(blobs), ttl).map_err(|error| error.to_string())?; + let entries = std::fs::read_dir(root).map_err(|error| { + format!( + "failed to inspect legacy CCR directory {}: {error}", + root.display() + ) + })?; for entry in entries { - let entry = entry.map_err(|error| format!("failed to inspect legacy CCR entry: {error}"))?; - if !entry.file_type().map_err(|error| error.to_string())?.is_file() { + let entry = + entry.map_err(|error| format!("failed to inspect legacy CCR entry: {error}"))?; + if !entry + .file_type() + .map_err(|error| error.to_string())? + .is_file() + { continue; } let token = entry.file_name().to_string_lossy().into_owned(); @@ -125,24 +249,172 @@ fn import_legacy_files( Ok(content) => content, Err(error) => return Err(format!("cannot import legacy CCR entry {token}: {error}")), }; - let put = store.put(&content); - if put.token() != token || !put.retained() { - return Err(format!("legacy CCR entry {token} was not durably retained")); + let modified = entry + .metadata() + .and_then(|metadata| metadata.modified()) + .map_err(|error| { + format!("cannot read modification time for legacy CCR entry {token}: {error}") + })?; + let source_written_at_ms = unix_epoch_ms(modified); + let import_ttl = match ttl { + Some(ttl) => { + let remaining = remaining_ttl(modified, SystemTime::now(), ttl); + if remaining.is_none() { + std::fs::remove_file(entry.path()).map_err(|error| { + format!("cannot remove expired legacy CCR entry {token}: {error}") + })?; + continue; + } + remaining + } + None => None, + }; + let store = + BlobCcrStore::new(Arc::clone(blobs), import_ttl).map_err(|error| error.to_string())?; + let existing = store.get(&token); + if existing + .as_deref() + .is_some_and(|existing| existing != content) + { + return Err(format!( + "legacy CCR entry {token} conflicts with different stored content" + )); + } + let recorded_time = read_semantic_time(Arc::clone(blobs), &token)?; + let import_intent = read_import_intent(Arc::clone(blobs), &token)?; + let existing_written_at_ms = if existing.is_some() { + recorded_time.or(import_intent).or(backend_written_at( + Arc::clone(blobs), + &format!("{CCR_PREFIX}/{token}"), + )?) + } else { + import_intent + }; + let semantic_written_at_ms = existing_written_at_ms + .filter(|existing| *existing >= source_written_at_ms) + .unwrap_or(source_written_at_ms); + if existing.is_none() && import_intent.is_none() { + // Mark source chronology before publishing its body. If the body + // succeeds but the timestamp write is interrupted, retry can + // distinguish this partial import from a newer normal store write. + write_import_intent(Arc::clone(blobs), &token, source_written_at_ms, import_ttl)?; + } + if existing.is_none() || semantic_written_at_ms == source_written_at_ms { + let put = store.put(&content); + if put.token() != token || !put.retained() { + return Err(format!("legacy CCR entry {token} was not durably retained")); + } + } + if store.get(&token).as_deref() != Some(content.as_str()) { + return Err(format!("legacy CCR entry {token} failed content readback")); } + let metadata_ttl = ttl.and_then(|ttl| { + remaining_ttl_from_epoch_ms(semantic_written_at_ms, SystemTime::now(), ttl) + }); + write_semantic_time( + Arc::clone(blobs), + &token, + semantic_written_at_ms, + metadata_ttl, + )?; + if read_semantic_time(Arc::clone(blobs), &token)? != Some(semantic_written_at_ms) { + return Err(format!( + "legacy CCR entry {token} failed timestamp readback" + )); + } + delete_import_intent(Arc::clone(blobs), &token)?; std::fs::remove_file(entry.path()) .map_err(|error| format!("cannot remove imported CCR entry {token}: {error}"))?; } Ok(()) } -fn list_all(blobs: Arc) -> Result, String> { +fn remaining_ttl(modified: SystemTime, now: SystemTime, ttl: Duration) -> Option { + let elapsed = now.duration_since(modified).unwrap_or_default(); + let remaining = ttl.saturating_sub(elapsed); + (!remaining.is_zero()).then_some(remaining) +} + +fn remaining_ttl_from_epoch_ms( + written_at_ms: u64, + now: SystemTime, + ttl: Duration, +) -> Option { + let written_at = std::time::UNIX_EPOCH.checked_add(Duration::from_millis(written_at_ms))?; + remaining_ttl(written_at, now, ttl) +} + +struct CappedCcrStore { + store: BlobCcrStore, + blobs: Arc, + ttl: Option, + max_bytes: Option, +} + +impl CcrStore for CappedCcrStore { + fn put(&self, content: &str) -> CcrPutResult { + let result = self.store.put(content); + if result.retained() { + if let Err(error) = write_semantic_time( + Arc::clone(&self.blobs), + result.token(), + unix_epoch_ms(SystemTime::now()), + self.ttl, + ) { + log::debug!("[tinyjuice_cli] CCR timestamp write failed: {error}"); + if let Err(error) = delete_metadata(Arc::clone(&self.blobs), result.token()) { + log::debug!("[tinyjuice_cli] stale CCR timestamp cleanup failed: {error}"); + } + if let Err(error) = delete_import_intent(Arc::clone(&self.blobs), result.token()) { + log::debug!("[tinyjuice_cli] stale CCR import intent cleanup failed: {error}"); + } + } else if let Err(error) = delete_import_intent(Arc::clone(&self.blobs), result.token()) + { + log::debug!("[tinyjuice_cli] CCR import intent cleanup failed: {error}"); + } + } + if result.retained() + && (self.ttl.is_some() || self.max_bytes.is_some()) + && let Err(error) = prune(&self.blobs, self.ttl, self.max_bytes, Some(result.token())) + { + log::debug!("[tinyjuice_cli] CCR sweep failed: {error}"); + } + result + } + + fn get(&self, token: &str) -> Option { + self.store.get(token) + } + + fn get_range( + &self, + token: &str, + start: usize, + end: usize, + unit: tinyjuice::cache::RangeUnit, + ) -> Option { + self.store.get_range(token, start, end, unit) + } +} + +fn list_all( + blobs: Arc, +) -> Result, String> { + list_all_prefix(blobs, &format!("{CCR_PREFIX}/")) +} + +fn list_all_prefix( + blobs: Arc, + prefix: &str, +) -> Result, String> { let mut entries = Vec::new(); let mut after = None; loop { let page = run_blob({ let after = after.clone(); let blobs = Arc::clone(&blobs); - async move { blobs.list_page(&format!("{CCR_PREFIX}/"), after.as_deref(), PAGE_SIZE).await } + let prefix = prefix.to_owned(); + async move { blobs.list_page(&prefix, after.as_deref(), PAGE_SIZE).await } })?; entries.extend(page.items); after = page.next_after; @@ -158,6 +430,131 @@ fn delete_blob(blobs: Arc, key: &str) -> Result<(), String> { run_blob(async move { handle.delete(&key).await }).map(|_| ()) } +fn delete_blob_and_metadata(blobs: Arc, key: &str) -> Result<(), String> { + delete_blob(Arc::clone(&blobs), key)?; + let Some(token) = key.strip_prefix(&format!("{CCR_PREFIX}/")) else { + return Ok(()); + }; + delete_metadata(blobs, token) +} + +fn delete_metadata(blobs: Arc, token: &str) -> Result<(), String> { + let key = format!("{CCR_METADATA_PREFIX}{token}"); + let handle = Arc::clone(&blobs); + run_blob(async move { handle.delete(&key).await }).map(|_| ()) +} + +fn write_semantic_time( + blobs: Arc, + token: &str, + written_at_ms: u64, + ttl: Option, +) -> Result<(), String> { + write_timestamp(blobs, CCR_METADATA_PREFIX, token, written_at_ms, ttl) +} + +fn write_import_intent( + blobs: Arc, + token: &str, + written_at_ms: u64, + ttl: Option, +) -> Result<(), String> { + write_timestamp(blobs, CCR_IMPORT_PREFIX, token, written_at_ms, ttl) +} + +fn read_import_intent(blobs: Arc, token: &str) -> Result, String> { + read_timestamp(blobs, CCR_IMPORT_PREFIX, token) +} + +fn delete_import_intent(blobs: Arc, token: &str) -> Result<(), String> { + let key = format!("{CCR_IMPORT_PREFIX}{token}"); + run_blob(async move { blobs.delete(&key).await }).map(|_| ()) +} + +fn write_timestamp( + blobs: Arc, + prefix: &str, + token: &str, + written_at_ms: u64, + ttl: Option, +) -> Result<(), String> { + let key = format!("{prefix}{token}"); + let bytes = written_at_ms.to_string().into_bytes(); + run_blob(async move { + // The port accepts relative TTLs, not absolute expiration timestamps. + // This sibling write uses the same remaining TTL as the CCR body, with + // only the small skew between the two backend writes. + match ttl { + Some(ttl) => { + blobs + .put_expiring(&key, bytes, Some(CCR_METADATA_CONTENT_TYPE), ttl) + .await + } + None => { + blobs + .put(&key, bytes, Some(CCR_METADATA_CONTENT_TYPE)) + .await + } + } + }) + .map(|_| ()) +} + +fn read_semantic_time(blobs: Arc, token: &str) -> Result, String> { + read_timestamp(blobs, CCR_METADATA_PREFIX, token) +} + +fn read_timestamp( + blobs: Arc, + prefix: &str, + token: &str, +) -> Result, String> { + let key = format!("{prefix}{token}"); + run_blob(async move { blobs.get(&key).await })? + .map(|blob| { + std::str::from_utf8(&blob.bytes) + .map_err(|error| format!("invalid CCR timestamp metadata: {error}"))? + .parse::() + .map_err(|error| format!("invalid CCR timestamp metadata: {error}")) + }) + .transpose() +} + +fn backend_written_at(blobs: Arc, key: &str) -> Result, String> { + let key = key.to_owned(); + let lookup_key = key.clone(); + let page = run_blob(async move { blobs.list_page(&lookup_key, None, 1).await })?; + Ok(page + .items + .into_iter() + .find(|entry| entry.meta.key == key) + .and_then(|entry| entry.written_at_ms)) +} + +fn list_semantic_times(blobs: Arc) -> Result, String> { + list_timestamps(blobs, CCR_METADATA_PREFIX) +} + +fn list_timestamps( + blobs: Arc, + prefix: &str, +) -> Result, String> { + let entries = list_all_prefix(Arc::clone(&blobs), prefix)?; + let mut times = HashMap::new(); + for entry in entries { + let Some(token) = entry.meta.key.strip_prefix(prefix) else { + continue; + }; + if !is_token(token) { + continue; + } + if let Some(timestamp) = read_timestamp(Arc::clone(&blobs), prefix, token)? { + times.insert(token.to_owned(), timestamp); + } + } + Ok(times) +} + fn run_blob( future: impl std::future::Future> + Send + 'static, ) -> Result { @@ -173,3 +570,14 @@ fn run_blob( fn is_token(token: &str) -> bool { token.len() == 32 && token.bytes().all(|byte| byte.is_ascii_hexdigit()) } + +fn unix_epoch_ms(time: SystemTime) -> u64 { + time.duration_since(std::time::UNIX_EPOCH) + .unwrap_or_default() + .as_millis() + .min(u64::MAX as u128) as u64 +} + +#[cfg(test)] +#[path = "storage_tests.rs"] +mod tests; diff --git a/crates/tinyjuice-cli/src/storage_tests.rs b/crates/tinyjuice-cli/src/storage_tests.rs new file mode 100644 index 00000000..5ef3fa76 --- /dev/null +++ b/crates/tinyjuice-cli/src/storage_tests.rs @@ -0,0 +1,344 @@ +use super::*; +use tinyjuice::cache::CcrStore; +use tinystoragedrivers_api::BlobStore; +use tinystoragedrivers_testkit::FaultPlan; +use tinystoragedrivers_types::{ + Blob, BlobListPage, BlobMeta, Capabilities, ErrorKind, Result as StorageResult, +}; + +#[derive(Debug)] +struct FailMetadataWrite { + inner: Arc, + faults: FaultPlan, +} + +#[async_trait::async_trait] +impl BlobStore for FailMetadataWrite { + fn capabilities(&self) -> Capabilities { + self.inner.capabilities() + } + + fn max_key_len(&self) -> usize { + self.inner.max_key_len() + } + + async fn put( + &self, + key: &str, + bytes: Vec, + content_type: Option<&str>, + ) -> StorageResult { + if key.starts_with(CCR_METADATA_PREFIX) { + self.faults.check("metadata_put")?; + } + self.inner.put(key, bytes, content_type).await + } + + async fn get(&self, key: &str) -> StorageResult> { + self.inner.get(key).await + } + + async fn get_range( + &self, + key: &str, + range: std::ops::Range, + ) -> StorageResult>> { + self.inner.get_range(key, range).await + } + + async fn head(&self, key: &str) -> StorageResult> { + self.inner.head(key).await + } + + async fn delete(&self, key: &str) -> StorageResult { + self.inner.delete(key).await + } + + async fn list(&self, prefix: &str) -> StorageResult> { + self.inner.list(prefix).await + } + + async fn list_page( + &self, + prefix: &str, + after: Option<&str>, + limit: usize, + ) -> StorageResult { + self.inner.list_page(prefix, after, limit).await + } +} + +#[test] +fn collection_reports_bytes_removed_by_the_budget() { + let dir = tempfile::tempdir().unwrap(); + let blobs = open_file_blobs(dir.path()).unwrap(); + let store = BlobCcrStore::new(blobs, None).unwrap(); + assert!(store.put("first").retained()); + assert!(store.put("second").retained()); + + assert_eq!(collect(dir.path(), None, Some(0)).unwrap(), (2, 11, 0, 0)); +} + +#[test] +fn durable_cli_writes_enforce_the_configured_byte_budget() { + let dir = tempfile::tempdir().unwrap(); + let blobs = open_file_blobs(dir.path()).unwrap(); + let store = CappedCcrStore { + store: BlobCcrStore::new(Arc::clone(&blobs), None).unwrap(), + blobs: Arc::clone(&blobs), + ttl: None, + max_bytes: Some(9), + }; + + assert!(store.put("first").retained()); + assert!(store.put("second").retained()); + let current = store.put("tri"); + assert!(current.retained()); + + let entries = run_blob({ + let blobs = Arc::clone(&blobs); + async move { blobs.list(&format!("{CCR_PREFIX}/")).await } + }) + .unwrap(); + assert_eq!(entries.iter().map(|entry| entry.len).sum::(), 9); + assert!(store.get(current.token()).is_some()); +} + +#[test] +fn migration_ttl_uses_the_source_file_age() { + let now = SystemTime::UNIX_EPOCH + Duration::from_secs(100); + let modified = SystemTime::UNIX_EPOCH + Duration::from_secs(95); + assert_eq!( + remaining_ttl(modified, now, Duration::from_secs(10)), + Some(Duration::from_secs(5)) + ); + assert_eq!(remaining_ttl(modified, now, Duration::from_secs(5)), None); + assert_eq!( + remaining_ttl(now + Duration::from_secs(1), now, Duration::from_secs(5)), + Some(Duration::from_secs(5)) + ); +} + +#[test] +fn collection_uses_imported_write_time_for_ttl() { + let dir = tempfile::tempdir().unwrap(); + let blobs = open_file_blobs(dir.path()).unwrap(); + let content = "legacy ccr with an old semantic timestamp"; + let store = BlobCcrStore::new(Arc::clone(&blobs), None).unwrap(); + let put = store.put(content); + assert!(put.retained()); + let old_time = unix_epoch_ms(SystemTime::UNIX_EPOCH + Duration::from_secs(1)); + write_semantic_time(Arc::clone(&blobs), put.token(), old_time, None).unwrap(); + + assert_eq!( + prune(&blobs, Some(Duration::from_secs(1)), None, None).unwrap(), + (1, content.len() as u64, 0, 0) + ); + assert!(store.get(put.token()).is_none()); + assert_eq!( + read_semantic_time(Arc::clone(&blobs), put.token()).unwrap(), + None + ); +} + +#[test] +fn collection_orders_by_imported_write_time_under_the_byte_budget() { + let dir = tempfile::tempdir().unwrap(); + let blobs = open_file_blobs(dir.path()).unwrap(); + let store = BlobCcrStore::new(Arc::clone(&blobs), None).unwrap(); + let older = "older legacy ccr"; + let newer = "newer legacy ccr body"; + let older_put = store.put(older); + let newer_put = store.put(newer); + assert!(older_put.retained() && newer_put.retained()); + write_semantic_time( + Arc::clone(&blobs), + older_put.token(), + unix_epoch_ms(SystemTime::UNIX_EPOCH + Duration::from_secs(1)), + None, + ) + .unwrap(); + write_semantic_time( + Arc::clone(&blobs), + newer_put.token(), + unix_epoch_ms(SystemTime::UNIX_EPOCH + Duration::from_secs(2)), + None, + ) + .unwrap(); + + assert_eq!( + prune(&blobs, None, Some(newer.len() as u64), None).unwrap(), + (1, older.len() as u64, 1, newer.len() as u64) + ); + assert!(store.get(older_put.token()).is_none()); + assert_eq!(store.get(newer_put.token()).as_deref(), Some(newer)); +} + +#[test] +fn gc_removes_import_intents_that_have_no_ccr_body() { + let dir = tempfile::tempdir().unwrap(); + let blobs = open_file_blobs(dir.path()).unwrap(); + let token = "0123456789abcdef0123456789abcdef"; + write_import_intent( + Arc::clone(&blobs), + token, + unix_epoch_ms(SystemTime::now()), + None, + ) + .unwrap(); + + assert_eq!(prune(&blobs, None, None, None).unwrap(), (0, 0, 0, 0)); + assert_eq!(read_import_intent(blobs, token).unwrap(), None); +} + +#[test] +fn failed_timestamp_refresh_does_not_leave_an_old_age_for_gc() { + let dir = tempfile::tempdir().unwrap(); + let content = "a normal re-offload of imported content"; + let token = tinyjuice::cache::short_hash(content); + let inner = open_file_blobs(dir.path()).unwrap(); + let original = BlobCcrStore::new(Arc::clone(&inner), None).unwrap(); + assert!(original.put(content).retained()); + let old_time = unix_epoch_ms(SystemTime::now() - Duration::from_secs(86_400)); + write_semantic_time(Arc::clone(&inner), &token, old_time, None).unwrap(); + + let faults = FaultPlan::new(); + faults.fail_operation_nth("metadata_put", 1, ErrorKind::Backend); + let failing: Arc = Arc::new(FailMetadataWrite { + inner: Arc::clone(&inner), + faults, + }); + let refreshed = CappedCcrStore { + store: BlobCcrStore::new(Arc::clone(&failing), None).unwrap(), + blobs: failing, + ttl: None, + max_bytes: None, + }; + + assert!(refreshed.put(content).retained()); + assert_eq!( + read_semantic_time(Arc::clone(&inner), &token).unwrap(), + None + ); + assert_eq!( + read_import_intent(Arc::clone(&inner), &token).unwrap(), + None + ); + assert_eq!( + prune(&inner, Some(Duration::from_secs(3_600)), None, None).unwrap(), + (0, 0, 1, content.len() as u64), + "the physical write time must replace stale imported age when timestamp refresh fails" + ); + assert_eq!(original.get(&token).as_deref(), Some(content)); +} + +#[test] +fn import_refuses_to_replace_different_content_at_a_legacy_token() { + let dir = tempfile::tempdir().unwrap(); + let content = "source legacy content"; + let token = tinyjuice::cache::short_hash(content); + let source_path = dir.path().join(&token); + std::fs::write(&source_path, content).unwrap(); + let blobs = open_file_blobs(dir.path()).unwrap(); + let key = format!("{CCR_PREFIX}/{token}"); + run_blob({ + let blobs = Arc::clone(&blobs); + let key = key.clone(); + async move { + blobs + .put(&key, b"different target content".to_vec(), None) + .await + } + }) + .unwrap(); + + let error = import_legacy_files(dir.path(), &blobs, None).unwrap_err(); + assert!(error.contains("conflicts with different stored content")); + assert!(source_path.exists(), "the unimported source is retained"); + let existing = run_blob({ + let blobs = Arc::clone(&blobs); + async move { blobs.get(&key).await } + }) + .unwrap() + .unwrap(); + assert_eq!(existing.bytes, b"different target content"); +} + +#[test] +fn retry_after_timestamp_write_failure_preserves_the_source_file_age() { + let dir = tempfile::tempdir().unwrap(); + let content = "legacy ccr whose age must survive an interrupted import"; + let token = tinyjuice::cache::short_hash(content); + let source_path = dir.path().join(&token); + std::fs::write(&source_path, content).unwrap(); + let source_time = SystemTime::now() - Duration::from_secs(20); + std::fs::File::open(&source_path) + .unwrap() + .set_times(std::fs::FileTimes::new().set_modified(source_time)) + .unwrap(); + + let inner = open_file_blobs(dir.path()).unwrap(); + let faults = FaultPlan::new(); + faults.fail_operation_nth("metadata_put", 1, ErrorKind::Backend); + let failing: Arc = Arc::new(FailMetadataWrite { + inner: Arc::clone(&inner), + faults: faults.clone(), + }); + + assert!(import_legacy_files(dir.path(), &failing, None).is_err()); + assert!(source_path.exists(), "failed import must retain its source"); + let body_key = format!("{CCR_PREFIX}/{token}"); + assert!( + run_blob({ + let inner = Arc::clone(&inner); + let body_key = body_key.clone(); + async move { inner.get(&body_key).await } + }) + .unwrap() + .is_some(), + "the fault occurs after the body has been stored" + ); + + faults.clear(); + import_legacy_files(dir.path(), &failing, None).unwrap(); + assert!( + !source_path.exists(), + "retry completes and retires the source" + ); + assert_eq!( + read_semantic_time(Arc::clone(&inner), &token).unwrap(), + Some(unix_epoch_ms(source_time)) + ); + assert_eq!( + read_import_intent(Arc::clone(&inner), &token).unwrap(), + None + ); +} + +#[test] +fn imports_released_v01010_disk_tier_file_and_preserves_its_age() { + const TOKEN: &str = "1e66b4cff1835002102d821ffee64f75"; + const CONTENT: &str = + include_str!("../tests/fixtures/legacy-ccr/v0.10.10/1e66b4cff1835002102d821ffee64f75"); + + let dir = tempfile::tempdir().unwrap(); + let source_path = dir.path().join(TOKEN); + std::fs::write(&source_path, CONTENT).unwrap(); + let source_time = SystemTime::now() - Duration::from_secs(5); + std::fs::File::open(&source_path) + .unwrap() + .set_times(std::fs::FileTimes::new().set_modified(source_time)) + .unwrap(); + + assert_eq!(tinyjuice::cache::short_hash(CONTENT), TOKEN); + let blobs = open_file_blobs(dir.path()).unwrap(); + import_legacy_files(dir.path(), &blobs, Some(Duration::from_secs(3600))).unwrap(); + + assert!(!source_path.exists(), "the verified legacy file is retired"); + let store = BlobCcrStore::new(Arc::clone(&blobs), None).unwrap(); + assert_eq!(store.get(TOKEN).as_deref(), Some(CONTENT)); + assert_eq!( + read_semantic_time(Arc::clone(&blobs), TOKEN).unwrap(), + Some(unix_epoch_ms(source_time)) + ); +} diff --git a/crates/tinyjuice-cli/tests/cli.rs b/crates/tinyjuice-cli/tests/cli.rs index 6934fb2b..7398ac23 100644 --- a/crates/tinyjuice-cli/tests/cli.rs +++ b/crates/tinyjuice-cli/tests/cli.rs @@ -3,7 +3,15 @@ use std::io::Write; use std::process::{Command, Stdio}; fn tinyjuice() -> Command { - Command::new(env!("CARGO_BIN_EXE_tinyjuice-reduce")) + let mut command = Command::new(env!("CARGO_BIN_EXE_tinyjuice-reduce")); + command.current_dir(std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../..")); + command +} + +fn write_legacy_entry(directory: &std::path::Path, content: &str) -> String { + let token = tinyjuice::cache::short_hash(content); + fs::write(directory.join(&token), content).expect("write legacy CCR entry"); + token } #[test] @@ -183,7 +191,7 @@ fn wrap_preserves_wrapped_exit_code() { #[test] fn ls_lists_only_token_shaped_store_entries() { let dir = tempfile::tempdir().expect("temp store"); - fs::write(dir.path().join("0123456789abcdef0123456789abcdef"), "one").expect("write token"); + let token = write_legacy_entry(dir.path(), "one"); fs::write(dir.path().join("not-a-token"), "ignored").expect("write ignored"); let output = tinyjuice() @@ -194,18 +202,22 @@ fn ls_lists_only_token_shaped_store_entries() { assert!(output.status.success(), "{output:#?}"); assert_eq!( String::from_utf8(output.stdout).expect("utf8 stdout"), - "0123456789abcdef0123456789abcdef\n" + format!("{token}\n") ); } #[test] fn cat_reads_token_from_explicit_store_dir() { let dir = tempfile::tempdir().expect("temp store"); - let token = "0123456789abcdef0123456789abcdef"; - fs::write(dir.path().join(token), "alpha\nbeta\ngamma\n").expect("write token"); + let token = write_legacy_entry(dir.path(), "alpha\nbeta\ngamma\n"); let output = tinyjuice() - .args(["cat", "--store-dir", &dir.path().to_string_lossy(), token]) + .args([ + "cat", + "--store-dir", + &dir.path().to_string_lossy(), + token.as_str(), + ]) .output() .expect("run tinyjuice cat"); @@ -219,8 +231,7 @@ fn cat_reads_token_from_explicit_store_dir() { #[test] fn cat_reads_line_range_from_explicit_store_dir() { let dir = tempfile::tempdir().expect("temp store"); - let token = "0123456789abcdef0123456789abcdef"; - fs::write(dir.path().join(token), "alpha\nbeta\ngamma\ndelta\n").expect("write token"); + let token = write_legacy_entry(dir.path(), "alpha\nbeta\ngamma\ndelta\n"); let output = tinyjuice() .args([ @@ -229,7 +240,7 @@ fn cat_reads_line_range_from_explicit_store_dir() { &dir.path().to_string_lossy(), "--lines", "1:3", - token, + token.as_str(), ]) .output() .expect("run tinyjuice cat lines"); @@ -244,8 +255,7 @@ fn cat_reads_line_range_from_explicit_store_dir() { #[test] fn cat_reads_byte_range_from_explicit_store_dir() { let dir = tempfile::tempdir().expect("temp store"); - let token = "0123456789abcdef0123456789abcdef"; - fs::write(dir.path().join(token), "alpha beta gamma").expect("write token"); + let token = write_legacy_entry(dir.path(), "alpha beta gamma"); let output = tinyjuice() .args([ @@ -254,7 +264,7 @@ fn cat_reads_byte_range_from_explicit_store_dir() { &dir.path().to_string_lossy(), "--bytes", "6:10", - token, + token.as_str(), ]) .output() .expect("run tinyjuice cat bytes"); @@ -269,8 +279,7 @@ fn cat_reads_byte_range_from_explicit_store_dir() { #[test] fn cat_rejects_multiple_range_flags() { let dir = tempfile::tempdir().expect("temp store"); - let token = "0123456789abcdef0123456789abcdef"; - fs::write(dir.path().join(token), "alpha\nbeta\n").expect("write token"); + let token = write_legacy_entry(dir.path(), "alpha\nbeta\n"); let output = tinyjuice() .args([ @@ -281,7 +290,7 @@ fn cat_rejects_multiple_range_flags() { "0:1", "--bytes", "0:5", - token, + token.as_str(), ]) .output() .expect("run tinyjuice cat conflicting ranges"); @@ -297,9 +306,8 @@ fn cat_rejects_multiple_range_flags() { #[test] fn stats_reports_metadata_for_explicit_store_dir() { let dir = tempfile::tempdir().expect("temp store"); - fs::write(dir.path().join("0123456789abcdef0123456789abcdef"), "one").expect("write token"); - fs::write(dir.path().join("fedcba9876543210fedcba9876543210"), "three") - .expect("write second token"); + write_legacy_entry(dir.path(), "one"); + write_legacy_entry(dir.path(), "three"); fs::write(dir.path().join("not-a-token"), "ignored raw content").expect("write ignored"); fs::create_dir(dir.path().join("subdir")).expect("create ignored dir"); diff --git a/crates/tinyjuice-cli/tests/fixtures/legacy-ccr/v0.10.10/1e66b4cff1835002102d821ffee64f75 b/crates/tinyjuice-cli/tests/fixtures/legacy-ccr/v0.10.10/1e66b4cff1835002102d821ffee64f75 new file mode 100644 index 00000000..85425b7c --- /dev/null +++ b/crates/tinyjuice-cli/tests/fixtures/legacy-ccr/v0.10.10/1e66b4cff1835002102d821ffee64f75 @@ -0,0 +1 @@ +Fixture written by TinyJuice v0.10.10 public disk-tier API. \ No newline at end of file diff --git a/crates/tinyjuice-cli/tests/fixtures/legacy-ccr/v0.10.10/README.md b/crates/tinyjuice-cli/tests/fixtures/legacy-ccr/v0.10.10/README.md new file mode 100644 index 00000000..80501e63 --- /dev/null +++ b/crates/tinyjuice-cli/tests/fixtures/legacy-ccr/v0.10.10/README.md @@ -0,0 +1,32 @@ +# TinyJuice v0.10.10 disk-tier CCR fixture + +This file was produced by the public CCR writer in released TinyJuice `v0.10.10`, +not reconstructed from the current implementation. The tag resolves to +`4db24354d0e883f6a0aefe96e5cc0c76073fd76e`. Its root `Cargo.toml` and +`Cargo.lock` hashes are respectively +`689e3b78858fbf65a33b8b56e01134a49698bb835f00c2f0b5e05b93e6a9eb95` and +`62b38e108654d0b4b97009c6cd6cd412e954a5d9dc46bedc24b1767f3a51ba4c`. + +The archived writer was injected with `examples/write_ccr_fixture.rs` +(`ab050f31a019797b5e5d05aa33ad315a61b5ffa6ec3b3b465644f1caaa5ee2bc`). It +calls `tinyjuice::cache::{configure, configure_disk_cap, enable_disk_tier, +offload_checked}`. The recorded TinyBus and TinyAgents gitlinks were restored +at `207a9a7df15e44fdba00a807d0f7eaf21904ba0e` and +`aa5476fa48092d9bf051fbd2d1bf07f14cc9f331`; neither archived manifest nor +lockfile was changed. Reproduce from the native repository root with: + +```sh +mkdir -p target/legacy-writer-v0.10.10 +git archive --format=tar 4db24354d0e883f6a0aefe96e5cc0c76073fd76e | tar -x -C target/legacy-writer-v0.10.10 +mkdir -p target/legacy-writer-v0.10.10/vendor/tinybus target/legacy-writer-v0.10.10/vendor/tinyagents target/legacy-writer-v0.10.10/examples target/legacy-writer-v0.10.10/legacy-output +git -C vendor/tinybus archive 207a9a7df15e44fdba00a807d0f7eaf21904ba0e | tar -x -C target/legacy-writer-v0.10.10/vendor/tinybus +git -C vendor/tinyagents archive aa5476fa48092d9bf051fbd2d1bf07f14cc9f331 | tar -x -C target/legacy-writer-v0.10.10/vendor/tinyagents +cp crates/tinyjuice-cli/tests/fixtures/legacy-ccr/v0.10.10/write_ccr_fixture.rs target/legacy-writer-v0.10.10/examples/ +cargo run --locked --manifest-path target/legacy-writer-v0.10.10/Cargo.toml -p tinyjuice --example write_ccr_fixture -- target/legacy-writer-v0.10.10/legacy-output "Fixture written by TinyJuice v0.10.10 public disk-tier API." +``` + +The writer emitted token `1e66b4cff1835002102d821ffee64f75`. The checked-in +raw body is 59 bytes with SHA-256 +`1e66b4cff1835002102d821ffee64f751d1c89efe286027d815bfdd8c25827b5`. Its timestamp is set by the import test +on a temporary copy so the test can check preserved semantic age without +changing the writer-produced bytes. diff --git a/crates/tinyjuice-cli/tests/fixtures/legacy-ccr/v0.10.10/write_ccr_fixture.rs b/crates/tinyjuice-cli/tests/fixtures/legacy-ccr/v0.10.10/write_ccr_fixture.rs new file mode 100644 index 00000000..5892a787 --- /dev/null +++ b/crates/tinyjuice-cli/tests/fixtures/legacy-ccr/v0.10.10/write_ccr_fixture.rs @@ -0,0 +1,12 @@ +use std::{env, path::PathBuf}; +fn main() { + let mut args = env::args().skip(1); + let root = PathBuf::from(args.next().expect("output directory")); + let content = args.next().expect("fixture content"); + tinyjuice::cache::configure(256, 1024 * 1024, Some(604800)); + tinyjuice::cache::configure_disk_cap(Some(1024 * 1024)); + tinyjuice::cache::enable_disk_tier(root); + let (token, retained) = tinyjuice::cache::offload_checked(&content); + assert!(retained, "released CCR writer must retain its original"); + println!("{token}"); +} diff --git a/crates/tinyjuice-drivers/src/blob_store_tests.rs b/crates/tinyjuice-drivers/src/blob_store_tests.rs index 66c34bce..54f42360 100644 --- a/crates/tinyjuice-drivers/src/blob_store_tests.rs +++ b/crates/tinyjuice-drivers/src/blob_store_tests.rs @@ -15,7 +15,10 @@ fn test_now_ms() -> u64 { fn clocked() -> (Arc, &'static AtomicU64) { let scope = Scope::new("local").unwrap(); ( - Arc::new(tinystoragedrivers_blob::MemoryBlobStore::with_clock(scope, test_now_ms)), + Arc::new(tinystoragedrivers_blob::MemoryBlobStore::with_clock( + scope, + test_now_ms, + )), &TEST_NOW, ) } @@ -54,6 +57,36 @@ fn an_original_round_trips_under_its_content_token() { assert_eq!(listed[0].key, format!("{CCR_PREFIX}/{}", put.token())); } +#[test] +fn released_blob_keys_are_read_in_place_without_copying_them() { + let blobs = handle(); + let token = short_hash("released original"); + let key = format!("tinyjuice_ccr/{token}"); + crate::blocking::Blocking::new() + .unwrap() + .run({ + let blobs = Arc::clone(&blobs); + let key = key.clone(); + async move { + blobs + .put(&key, b"released original".to_vec(), Some(CONTENT_TYPE)) + .await + } + }) + .unwrap() + .unwrap(); + + let store = BlobCcrStore::new(Arc::clone(&blobs), None).unwrap(); + assert_eq!(store.get(&token).as_deref(), Some("released original")); + let keys = crate::blocking::Blocking::new() + .unwrap() + .run(async move { blobs.list("tinyjuice_ccr/").await }) + .unwrap() + .unwrap(); + assert_eq!(keys.len(), 1); + assert_eq!(keys[0].key, key); +} + #[test] fn identical_content_is_idempotent_and_distinct_content_is_separate() { let store = BlobCcrStore::new(handle(), None).unwrap(); @@ -69,6 +102,7 @@ fn identical_content_is_idempotent_and_distinct_content_is_separate() { fn an_original_expires_when_its_ttl_has_elapsed() { let _guard = CLOCK_TEST_LOCK.lock().unwrap(); let (blobs, now) = clocked(); + now.store(1_000, Ordering::SeqCst); let store = BlobCcrStore::new(blobs, Some(Duration::from_millis(500))).unwrap(); let put = store.put("short lived"); assert!(put.retained()); @@ -82,6 +116,7 @@ fn an_original_expires_when_its_ttl_has_elapsed() { fn re_offloading_restarts_the_lifetime() { let _guard = CLOCK_TEST_LOCK.lock().unwrap(); let (blobs, now) = clocked(); + now.store(1_000, Ordering::SeqCst); let store = BlobCcrStore::new(blobs, Some(Duration::from_millis(500))).unwrap(); let put = store.put("refreshed"); now.store(1_400, Ordering::SeqCst); @@ -104,10 +139,7 @@ fn a_zero_ttl_is_never_advertised_as_retained() { fn a_ttl_needs_a_handle_that_can_expire_blobs() { let (blobs, _) = faulty(false); let err = BlobCcrStore::new(Arc::clone(&blobs), Some(Duration::from_secs(5))).unwrap_err(); - assert_eq!( - err.kind(), - ErrorKind::Unsupported(Capability::BlobTtl) - ); + assert_eq!(err.kind(), ErrorKind::Unsupported(Capability::BlobTtl)); assert!(BlobCcrStore::new(blobs, None).is_ok()); } @@ -206,4 +238,3 @@ fn debug_hides_the_handle() { let store = BlobCcrStore::new(handle(), None).unwrap(); assert!(format!("{store:?}").starts_with("BlobCcrStore")); } - diff --git a/crates/tinyjuice-drivers/src/blocking.rs b/crates/tinyjuice-drivers/src/blocking.rs index d0ff235b..319debdd 100644 --- a/crates/tinyjuice-drivers/src/blocking.rs +++ b/crates/tinyjuice-drivers/src/blocking.rs @@ -31,7 +31,9 @@ impl Blocking { let runtime = tokio::runtime::Builder::new_current_thread() .enable_all() .build() - .map_err(|error| StorageError::backend("cannot build the storage bridge runtime").with_source(error))?; + .map_err(|error| { + StorageError::backend("cannot build the storage bridge runtime").with_source(error) + })?; thread::Builder::new() .name("tinyjuice-storage-bridge".into()) .spawn(move || { @@ -40,7 +42,9 @@ impl Blocking { job(&runtime); } }) - .map_err(|error| StorageError::backend("cannot start the storage bridge").with_source(error))?; + .map_err(|error| { + StorageError::backend("cannot start the storage bridge").with_source(error) + })?; Ok(Self { jobs }) } diff --git a/crates/tinyjuice-drivers/src/lib.rs b/crates/tinyjuice-drivers/src/lib.rs index 23a70dde..46cc83d5 100644 --- a/crates/tinyjuice-drivers/src/lib.rs +++ b/crates/tinyjuice-drivers/src/lib.rs @@ -14,8 +14,8 @@ //! [`BlobStore`]: tinystoragedrivers_api::BlobStore //! [`Blocking`]: crate::blocking::Blocking -mod blocking; mod blob_store; +mod blocking; pub use blob_store::{BlobCcrStore, CCR_PREFIX}; diff --git a/crates/tinyjuice-module/src/storage.rs b/crates/tinyjuice-module/src/storage.rs index 7b4eb0a5..ff010e1d 100644 --- a/crates/tinyjuice-module/src/storage.rs +++ b/crates/tinyjuice-module/src/storage.rs @@ -10,18 +10,22 @@ use std::sync::Arc; use std::time::Duration; use tinybus::Connection; -use tinyjuice::cache::store::{CcrPutResult, CcrStore, RangeUnit}; +use tinyjuice::cache::store::{CcrPutResult, CcrStore, RangeUnit, short_hash}; use tinyjuice_drivers::BlobCcrStore; use tinystoragedrivers_api::{BlobStore, DocumentStore, Storage}; /// The host's blob port, connected through `connection`, when it serves one. async fn blobs(connection: Connection) -> Option> { - scoped(connection).await.map(|storage| Arc::clone(storage.blobs())) + scoped(connection) + .await + .map(|storage| Arc::clone(storage.blobs())) } /// The host's document port, connected through `connection`, when it serves one. pub(crate) async fn documents(connection: Connection) -> Option> { - scoped(connection).await.map(|storage| Arc::clone(storage.documents())) + scoped(connection) + .await + .map(|storage| Arc::clone(storage.documents())) } /// The module's scope of the host's storage, when the host serves one. @@ -71,16 +75,18 @@ async fn tier_on(blobs: Arc, ttl: Option) -> Option(S); impl OffWorker { - fn off_worker(call: impl FnOnce() -> T) -> T { + fn off_worker(call: impl FnOnce() -> T) -> Option { match tokio::runtime::Handle::try_current() { Ok(handle) if handle.runtime_flavor() == tokio::runtime::RuntimeFlavor::MultiThread => { - tokio::task::block_in_place(call) + Some(tokio::task::block_in_place(call)) } - _ => call(), + Ok(_) => None, + Err(_) => Some(call()), } } } @@ -88,14 +94,15 @@ impl OffWorker { impl CcrStore for OffWorker { fn put(&self, content: &str) -> CcrPutResult { Self::off_worker(|| self.0.put(content)) + .unwrap_or_else(|| CcrPutResult::new(short_hash(content), false)) } fn get(&self, token: &str) -> Option { - Self::off_worker(|| self.0.get(token)) + Self::off_worker(|| self.0.get(token)).flatten() } fn get_range(&self, token: &str, start: usize, end: usize, unit: RangeUnit) -> Option { - Self::off_worker(|| self.0.get_range(token, start, end, unit)) + Self::off_worker(|| self.0.get_range(token, start, end, unit)).flatten() } } diff --git a/crates/tinyjuice-module/src/storage_tests.rs b/crates/tinyjuice-module/src/storage_tests.rs index 7533c3ac..e8c8b0a0 100644 --- a/crates/tinyjuice-module/src/storage_tests.rs +++ b/crates/tinyjuice-module/src/storage_tests.rs @@ -114,6 +114,31 @@ async fn store_calls_on_the_only_worker_do_not_deadlock() -> TestResult { Ok(()) } +#[tokio::test(flavor = "current_thread")] +async fn durable_calls_fail_closed_on_a_current_thread_runtime() -> TestResult { + let rig = rig(true).await?; + let store = durable_tier(rig.module.clone(), None) + .await + .ok_or("host serves storage")?; + let put = store.put("current thread must not block its bus runtime"); + assert!(!put.retained()); + assert!(store.get(put.token()).is_none()); + + let blobs = rig.backend.for_scope(&Scope::new("local")?)?; + assert!( + blobs + .blobs() + .get(&format!( + "{}/{}", + tinyjuice_drivers::CCR_PREFIX, + put.token() + )) + .await? + .is_none() + ); + Ok(()) +} + fn install_request(durable: bool) -> tinyjuice_bus::wire::InstallRequest { tinyjuice_bus::wire::InstallRequest { options: tinyjuice::types::CompressOptions::default(), @@ -175,10 +200,7 @@ impl BlobStore for NoBlobExpiry { self.0.put(key, bytes, content_type).await } - async fn get( - &self, - key: &str, - ) -> StorageResult> { + async fn get(&self, key: &str) -> StorageResult> { self.0.get(key).await } @@ -190,10 +212,7 @@ impl BlobStore for NoBlobExpiry { self.0.get_range(key, range).await } - async fn head( - &self, - key: &str, - ) -> StorageResult> { + async fn head(&self, key: &str) -> StorageResult> { self.0.head(key).await } @@ -201,10 +220,7 @@ impl BlobStore for NoBlobExpiry { self.0.delete(key).await } - async fn list( - &self, - prefix: &str, - ) -> StorageResult> { + async fn list(&self, prefix: &str) -> StorageResult> { self.0.list(prefix).await } } @@ -224,10 +240,10 @@ async fn a_handle_that_cannot_expire_blobs_gets_no_ttl_tier_but_a_keep_forever_o Ok(()) } -/// Off a multi-thread runtime there is no worker to hand off, so the call runs -/// in place. +/// On a current-thread runtime the synchronous bridge cannot safely wait for +/// the same executor to deliver its reply, so it refuses durable calls. #[tokio::test(flavor = "current_thread")] -async fn store_calls_run_in_place_on_a_current_thread_runtime() { +async fn off_worker_refuses_calls_on_a_current_thread_runtime() { struct Fixed; impl CcrStore for Fixed { fn put(&self, content: &str) -> CcrPutResult { @@ -241,12 +257,9 @@ async fn store_calls_run_in_place_on_a_current_thread_runtime() { } } let store = OffWorker(Fixed); - assert!(store.put("x").retained()); - assert_eq!(store.get("t").as_deref(), Some("fixed")); - assert_eq!( - store.get_range("t", 0, 1, RangeUnit::Lines).as_deref(), - Some("range") - ); + assert!(!store.put("x").retained()); + assert_eq!(store.get("t"), None); + assert_eq!(store.get_range("t", 0, 1, RangeUnit::Lines), None); } #[test] diff --git a/crates/tinyjuice-module/tests/module_e2e_tests.rs b/crates/tinyjuice-module/tests/module_e2e_tests.rs index 0074d5b2..0ef00990 100644 --- a/crates/tinyjuice-module/tests/module_e2e_tests.rs +++ b/crates/tinyjuice-module/tests/module_e2e_tests.rs @@ -1,6 +1,7 @@ //! End-to-end proof that the built TinyJuice cdylib is admitted and serves //! compression and CCR retrieval through a real TinyBus broker. +use std::sync::Arc; use std::time::Duration; use tinybus::Connection; @@ -9,6 +10,10 @@ use tinybus::test_support::{admit_module, start_bus, wait_until_serving}; use tinyjuice::types::{AgentTokenjuiceCompression, CompressedOutput, ContentHint, ContentKind}; use tinyjuice_bus::wire::CompactResponse; use tinyjuice_module::{BUS_NAME, OBJECT_PATH}; +use tinystoragedrivers_api::{BlobStore, StorageBackend}; +use tinystoragedrivers_busproxy::{PerCallerEndpoint, StorageServer, serve}; +use tinystoragedrivers_testkit::MemoryBackend; +use tinystoragedrivers_types::Scope; const EXPECTED_METHODS: &[&str] = tinyjuice_bus::METHODS; @@ -16,6 +21,16 @@ const EXPECTED_METHODS: &[&str] = tinyjuice_bus::METHODS; #[ignore = "requires TINYJUICE_TEST_MODULE to point at the built cdylib"] async fn the_built_module_compresses_and_recovers_over_a_real_broker() { let (modules, client, broker_task) = start_bus().await.expect("memory bus should start"); + let storage_backend = Arc::new(MemoryBackend::new()); + let endpoint_backend = Arc::clone(&storage_backend); + let storage_endpoint = PerCallerEndpoint::new(move |_sender| { + let scope = Scope::new("tinyjuice-module-test").ok()?; + let storage = endpoint_backend.for_scope(&scope).ok()?; + Some(StorageServer::new(storage)) + }); + let _served_storage = serve(&client, Arc::new(storage_endpoint)) + .await + .expect("host storage should be served before module setup"); let loaded = admit_module(&modules, "TINYJUICE_TEST_MODULE", "tinyjuice-module") .expect("module should load"); assert_eq!(loaded.name, "tinyjuice-module"); @@ -56,10 +71,10 @@ async fn the_built_module_compresses_and_recovers_over_a_real_broker() { "codeTargetRatio": null, "charsPerToken": 4.0 }, - "maxCacheEntries": 8, + "maxCacheEntries": 1, "maxCacheBytes": 1048576, "ccrTtlSecs": null, - "ccrDurable": false + "ccrDurable": true }),), ) .await @@ -116,6 +131,33 @@ async fn the_built_module_compresses_and_recovers_over_a_real_broker() { .expect("compress should succeed"); assert!(output.applied); let token = output.ccr_token.expect("compression should be recoverable"); + + let scope = Scope::new("tinyjuice-module-test").expect("valid test scope"); + let host_blobs: Arc = + Arc::clone(storage_backend.for_scope(&scope).unwrap().blobs()); + let durable_key = format!("{}/{}", tinyjuice_drivers::CCR_PREFIX, token); + let durable_blob = host_blobs + .get(&durable_key) + .await + .expect("host blob lookup should succeed") + .expect("the module should write its CCR original to host storage"); + assert_eq!(durable_blob.bytes, content.as_bytes()); + + // A second distinct retained original evicts the first from the one-entry + // module cache. Retrieval below must therefore use the host BlobStore. + let eviction_content = (0..200) + .map(|index| format!("WARN independent request queued id={index}\n")) + .collect::(); + let eviction_output: CompressedOutput = proxy + .call( + "Compress", + (eviction_content, serde_json::json!({ "explicit": "log" })), + ) + .await + .expect("second compression should succeed"); + assert!(eviction_output.applied); + assert!(eviction_output.ccr_token.is_some()); + let recovered: Option = proxy .call( "Retrieve", diff --git a/docs/agent-hooks/README.md b/docs/agent-hooks/README.md index 320621de..b9e4ed88 100644 --- a/docs/agent-hooks/README.md +++ b/docs/agent-hooks/README.md @@ -12,23 +12,11 @@ Use `tinyjuice update ` to refresh an installed hook and ## Install The CLI -Install from crates.io: +Install the CLI from a local TinyJuice checkout (the CLI package is not +published separately): ```sh -cargo install tinyjuice --features cli-disk-tier --locked -``` - -For development builds, install from Git: - -```sh -cargo install --git https://github.com/tinyhumansai/tinyjuice \ - --features cli-disk-tier --locked --bin tinyjuice -``` - -Or install the exact code in a local checkout: - -```sh -cargo install --path . --features cli-disk-tier --locked --bin tinyjuice +cargo install --path crates/tinyjuice-cli --locked --bin tinyjuice ``` Make sure Cargo's bin directory is on `PATH` before installing hooks: diff --git a/docs/architecture.md b/docs/architecture.md index 73a57e35..7b6e126e 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -25,8 +25,14 @@ on whatever backend it has. `tinyjuice-module` uses the host storage bus retaining an original only when it reports success under the content hash that callers advertise as the recovery token. - A memory miss in `retrieve` / `retrieve_range` falls through to the tier. -- The library has no file-backed persistence tier. Standalone CLI cache - commands use their separate `cli-disk-tier` feature. +- The library has no file-backed persistence tier. The separate + `tinyjuice-cli` package composes the file backend for standalone cache + commands. +- The CLI stores the original CCR write time in a sibling metadata blob because + the BlobStore port has no caller-supplied timestamp. TTLs use the remaining + relative duration when the content and metadata blobs are written separately, + so their backend expiration times can differ by a small write-time skew; + collection ordering and age checks use the preserved original timestamp. - Store calls may block, so a host must not call them from a single-threaded runtime that also drives the store's transport. diff --git a/src/cache/mod.rs b/src/cache/mod.rs index 759f9f1e..2c973665 100644 --- a/src/cache/mod.rs +++ b/src/cache/mod.rs @@ -12,4 +12,3 @@ pub use store::{ RangeUnit, configure, offload, offload_checked, offload_checked_with_hash, retrieve, retrieve_range, set_durable_tier, short_hash, stats, }; - From 29cbfa0fdeb1c63af84160c51c54fb333cf811a6 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 02:41:29 +0300 Subject: [PATCH 023/119] chore(deps): update dependency versions This change updates several dependencies across the project to version 2.0.2 for tinystoragedrivers and related crates. It also pins specific versions for tinybus in module and driver crates for consistency. Auto-committed-on: dragonfly --- Cargo.toml | 12 ------------ crates/tinyjuice-bus/Cargo.toml | 2 +- crates/tinyjuice-cli/Cargo.toml | 8 ++++---- crates/tinyjuice-drivers/Cargo.toml | 8 ++++---- crates/tinyjuice-module/Cargo.toml | 14 +++++++------- 5 files changed, 16 insertions(+), 28 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8293e334..46108263 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -100,15 +100,3 @@ strip = "debuginfo" [[example]] name = "repl_tool_schema" required-features = ["tinytools"] - -# tinystoragedrivers names tinybus by git rev; point that source at the same -# vendored checkout so the module and the storage proxy share one `Connection`. -[patch."https://github.com/tinyhumansai/tinybus"] -tinybus = { path = "vendor/tinybus/crates/tinybus" } - -# tinybus is not on crates.io; modules name it by version range so a host can -# unify it, and standalone builds resolve it to the nested checkout. -[patch.crates-io] -tinybus = { path = "vendor/tinybus/crates/tinybus" } -tinybus-module = { path = "vendor/tinybus/crates/tinybus-module" } -tinybus-macros = { path = "vendor/tinybus/crates/tinybus-macros" } diff --git a/crates/tinyjuice-bus/Cargo.toml b/crates/tinyjuice-bus/Cargo.toml index 4912bc32..f5a4eec6 100644 --- a/crates/tinyjuice-bus/Cargo.toml +++ b/crates/tinyjuice-bus/Cargo.toml @@ -19,7 +19,7 @@ serde = { version = "1", features = ["derive"] } serde_json = "1" # Shared REPL error vocabulary; no execution dependencies. thiserror = "2" -tinystoragedrivers-types = { version = "2.0.1", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.1" } +tinystoragedrivers-types = { version = "2.0.2", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.2" } [features] default = [] diff --git a/crates/tinyjuice-cli/Cargo.toml b/crates/tinyjuice-cli/Cargo.toml index 07b578e5..3d23cacf 100644 --- a/crates/tinyjuice-cli/Cargo.toml +++ b/crates/tinyjuice-cli/Cargo.toml @@ -11,9 +11,9 @@ repository = "https://github.com/tinyhumansai/tinyjuice" [dependencies] tinyjuice = { path = "../.." } tinyjuice-drivers = { path = "../tinyjuice-drivers" } -tinystoragedrivers = { version = "2.0.1", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.1", features = ["file"] } -tinystoragedrivers-api = { version = "2.0.1", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.1" } -tinystoragedrivers-types = { version = "2.0.1", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.1" } +tinystoragedrivers = { version = "2.0.2", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.2", features = ["file"] } +tinystoragedrivers-api = { version = "2.0.2", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.2" } +tinystoragedrivers-types = { version = "2.0.2", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.2" } dirs = "7" log = "0.4" serde_json = "1" @@ -22,7 +22,7 @@ tokio = { version = "1", features = ["rt-multi-thread"] } [dev-dependencies] async-trait = "0.1" tempfile = "3" -tinystoragedrivers-testkit = { version = "2.0.1", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.1" } +tinystoragedrivers-testkit = { version = "2.0.2", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.2" } [[bin]] name = "tinyjuice" diff --git a/crates/tinyjuice-drivers/Cargo.toml b/crates/tinyjuice-drivers/Cargo.toml index cb506fb9..9506b03b 100644 --- a/crates/tinyjuice-drivers/Cargo.toml +++ b/crates/tinyjuice-drivers/Cargo.toml @@ -14,13 +14,13 @@ publish = false [dependencies] tinyjuice-bus = { path = "../tinyjuice-bus" } tinyjuice = { path = "../..", default-features = false } -tinystoragedrivers-api = { version = "2.0.1", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.1" } -tinystoragedrivers-types = { version = "2.0.1", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.1" } +tinystoragedrivers-api = { version = "2.0.2", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.2" } +tinystoragedrivers-types = { version = "2.0.2", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.2" } log = "0.4" tokio = { version = "1", features = ["rt"] } [dev-dependencies] tokio = { version = "1", features = ["macros", "rt-multi-thread", "time"] } async-trait = "0.1" -tinystoragedrivers-testkit = { version = "2.0.1", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.1" } -tinystoragedrivers-blob = { version = "2.0.1", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.1" } +tinystoragedrivers-testkit = { version = "2.0.2", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.2" } +tinystoragedrivers-blob = { version = "2.0.2", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.2" } diff --git a/crates/tinyjuice-module/Cargo.toml b/crates/tinyjuice-module/Cargo.toml index 32d7f95f..019c60d7 100644 --- a/crates/tinyjuice-module/Cargo.toml +++ b/crates/tinyjuice-module/Cargo.toml @@ -21,22 +21,22 @@ tinyjuice = { path = "../..", default-features = false, features = ["jq"] } # The interface vocabulary. Shared with hosts, so this adapter cannot drift # from what a caller was compiled against. tinyjuice-bus = { path = "../tinyjuice-bus" } -tinybus = { version = ">=0.1.3, <0.2", default-features = false, features = ["macros", "modules"] } -tinybus-module = ">=0.1.3, <0.2" +tinybus = { version = "=0.1.6", git = "https://github.com/senamakel/tinybus", rev = "1d0aa34104c84f6817f398b0abe164df6c5e7b82", default-features = false, features = ["macros", "modules"] } +tinybus-module = { version = "=0.1.6", git = "https://github.com/senamakel/tinybus", rev = "1d0aa34104c84f6817f398b0abe164df6c5e7b82" } tokio = { version = "1", features = ["macros", "rt-multi-thread", "sync"] } serde_json = "1" # The CCR store's durable tier is blobs on the host's storage ports, reached # over the storage bus. The module has no storage backend or file of its own. tinyjuice-drivers = { path = "../tinyjuice-drivers" } -tinystoragedrivers-api = { version = "2.0.1", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.1" } -tinystoragedrivers-types = { version = "2.0.1", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.1" } -tinystoragedrivers-busproxy = { version = "2.0.1", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.1" } +tinystoragedrivers-api = { version = "2.0.2", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.2" } +tinystoragedrivers-types = { version = "2.0.2", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.2" } +tinystoragedrivers-busproxy = { version = "2.0.2", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.2" } log = "0.4" [dev-dependencies] # Tests serve the storage objects on the in-memory broker the module connects to. -tinystoragedrivers-testkit = { version = "2.0.1", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.1" } -tinybus = { version = ">=0.1.3, <0.2", default-features = false, features = ["test-support"] } +tinystoragedrivers-testkit = { version = "2.0.2", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.2" } +tinybus = { version = "=0.1.6", git = "https://github.com/senamakel/tinybus", rev = "1d0aa34104c84f6817f398b0abe164df6c5e7b82", default-features = false, features = ["test-support"] } tempfile = "3" async-trait = "0.1" tokio = { version = "1", features = ["macros", "rt-multi-thread", "time"] } From 71404b33c62ad8de5bf9710af4bafb50f49b924d Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 02:42:04 +0300 Subject: [PATCH 024/119] chore: files changed Cargo.lock Auto-committed-on: dragonfly --- Cargo.lock | 135 +++++++++++++++++++++++------------------------------ 1 file changed, 58 insertions(+), 77 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 87474b24..24d3ab63 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -44,15 +44,6 @@ version = "1.0.104" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470" -[[package]] -name = "arbitrary" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3d036a3c4ab069c7b410a2ce876bd74808d2d0888a82667669f8e783a898bf1" -dependencies = [ - "derive_arbitrary", -] - [[package]] name = "async-trait" version = "0.1.92" @@ -159,6 +150,12 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" +[[package]] +name = "cfg_aliases" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f079e83a288787bcd14a6aea84cee5c87a67c5a3e660c30f557a3d24761b3527" + [[package]] name = "ciborium" version = "0.2.2" @@ -366,17 +363,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "derive_arbitrary" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e567bd82dcff979e4b03460c307b3cdc9e96fde3d73bed1496d2bc75d9dd62a" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.118", -] - [[package]] name = "digest" version = "0.10.7" @@ -419,17 +405,6 @@ dependencies = [ "windows-sys 0.61.2", ] -[[package]] -name = "displaydoc" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6232dd377dcc64799954cbd3a9bb882e9cdc1308ccd87b1c098f1fb2eaf82a8" -dependencies = [ - "proc-macro2", - "quote", - "syn 3.0.0", -] - [[package]] name = "dyn-clone" version = "1.0.20" @@ -876,6 +851,18 @@ dependencies = [ "simd-adler32", ] +[[package]] +name = "nix" +version = "0.31.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf20d2fde8ff38632c426f1165ed7436270b44f199fc55284c38276f9db47c3d" +dependencies = [ + "bitflags 2.13.0", + "cfg-if", + "cfg_aliases", + "libc", +] + [[package]] name = "num-bigint" version = "0.4.8" @@ -1432,7 +1419,8 @@ dependencies = [ [[package]] name = "tinybus" -version = "0.1.5" +version = "0.1.6" +source = "git+https://github.com/senamakel/tinybus?rev=1d0aa34104c84f6817f398b0abe164df6c5e7b82#1d0aa34104c84f6817f398b0abe164df6c5e7b82" dependencies = [ "async-trait", "flate2", @@ -1453,7 +1441,8 @@ dependencies = [ [[package]] name = "tinybus-macros" -version = "0.1.5" +version = "0.1.6" +source = "git+https://github.com/senamakel/tinybus?rev=1d0aa34104c84f6817f398b0abe164df6c5e7b82#1d0aa34104c84f6817f398b0abe164df6c5e7b82" dependencies = [ "proc-macro2", "quote", @@ -1462,7 +1451,8 @@ dependencies = [ [[package]] name = "tinybus-module" -version = "0.1.5" +version = "0.1.6" +source = "git+https://github.com/senamakel/tinybus?rev=1d0aa34104c84f6817f398b0abe164df6c5e7b82#1d0aa34104c84f6817f398b0abe164df6c5e7b82" dependencies = [ "async-trait", "serde", @@ -1570,8 +1560,8 @@ dependencies = [ [[package]] name = "tinystoragedrivers" -version = "2.0.1" -source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.1#e3224a8262193e7466b230a59ef1c4769e44bf02" +version = "2.0.2" +source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.2#7acd22d8e8061edf7ef8cc4976c666b198a203c7" dependencies = [ "tinystoragedrivers-api", "tinystoragedrivers-blob", @@ -1585,8 +1575,8 @@ dependencies = [ [[package]] name = "tinystoragedrivers-api" -version = "2.0.1" -source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.1#e3224a8262193e7466b230a59ef1c4769e44bf02" +version = "2.0.2" +source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.2#7acd22d8e8061edf7ef8cc4976c666b198a203c7" dependencies = [ "async-trait", "bytes", @@ -1599,8 +1589,8 @@ dependencies = [ [[package]] name = "tinystoragedrivers-blob" -version = "2.0.1" -source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.1#e3224a8262193e7466b230a59ef1c4769e44bf02" +version = "2.0.2" +source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.2#7acd22d8e8061edf7ef8cc4976c666b198a203c7" dependencies = [ "async-trait", "bytes", @@ -1614,8 +1604,8 @@ dependencies = [ [[package]] name = "tinystoragedrivers-bus" -version = "2.0.1" -source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.1#e3224a8262193e7466b230a59ef1c4769e44bf02" +version = "2.0.2" +source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.2#7acd22d8e8061edf7ef8cc4976c666b198a203c7" dependencies = [ "serde", "serde_json", @@ -1625,8 +1615,8 @@ dependencies = [ [[package]] name = "tinystoragedrivers-busproxy" -version = "2.0.1" -source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.1#e3224a8262193e7466b230a59ef1c4769e44bf02" +version = "2.0.2" +source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.2#7acd22d8e8061edf7ef8cc4976c666b198a203c7" dependencies = [ "async-trait", "bytes", @@ -1643,8 +1633,8 @@ dependencies = [ [[package]] name = "tinystoragedrivers-connect" -version = "2.0.1" -source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.1#e3224a8262193e7466b230a59ef1c4769e44bf02" +version = "2.0.2" +source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.2#7acd22d8e8061edf7ef8cc4976c666b198a203c7" dependencies = [ "rusqlite", "tinystoragedrivers-types", @@ -1653,8 +1643,8 @@ dependencies = [ [[package]] name = "tinystoragedrivers-document" -version = "2.0.1" -source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.1#e3224a8262193e7466b230a59ef1c4769e44bf02" +version = "2.0.2" +source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.2#7acd22d8e8061edf7ef8cc4976c666b198a203c7" dependencies = [ "async-trait", "data-encoding", @@ -1672,8 +1662,8 @@ dependencies = [ [[package]] name = "tinystoragedrivers-kv" -version = "2.0.1" -source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.1#e3224a8262193e7466b230a59ef1c4769e44bf02" +version = "2.0.2" +source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.2#7acd22d8e8061edf7ef8cc4976c666b198a203c7" dependencies = [ "async-trait", "libc", @@ -1686,8 +1676,8 @@ dependencies = [ [[package]] name = "tinystoragedrivers-queue" -version = "2.0.1" -source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.1#e3224a8262193e7466b230a59ef1c4769e44bf02" +version = "2.0.2" +source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.2#7acd22d8e8061edf7ef8cc4976c666b198a203c7" dependencies = [ "async-trait", "data-encoding", @@ -1702,8 +1692,8 @@ dependencies = [ [[package]] name = "tinystoragedrivers-secrets" -version = "2.0.1" -source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.1#e3224a8262193e7466b230a59ef1c4769e44bf02" +version = "2.0.2" +source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.2#7acd22d8e8061edf7ef8cc4976c666b198a203c7" dependencies = [ "async-trait", "tinystoragedrivers-api", @@ -1713,8 +1703,8 @@ dependencies = [ [[package]] name = "tinystoragedrivers-testkit" -version = "2.0.1" -source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.1#e3224a8262193e7466b230a59ef1c4769e44bf02" +version = "2.0.2" +source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.2#7acd22d8e8061edf7ef8cc4976c666b198a203c7" dependencies = [ "async-trait", "bytes", @@ -1734,8 +1724,8 @@ dependencies = [ [[package]] name = "tinystoragedrivers-types" -version = "2.0.1" -source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.1#e3224a8262193e7466b230a59ef1c4769e44bf02" +version = "2.0.2" +source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.2#7acd22d8e8061edf7ef8cc4976c666b198a203c7" dependencies = [ "serde", "serde_json", @@ -1910,6 +1900,12 @@ version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6af6ae20167a9ece4bcb41af5b80f8a1f1df981f6391189ce00fd257af04126a" +[[package]] +name = "typed-path" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54ec2755506471f54baf5e4bb5499d8e510cc1caf271270e778a736bd2d7336c" + [[package]] name = "typenum" version = "1.20.1" @@ -2282,19 +2278,16 @@ checksum = "e13c156562582aa81c60cb29407084cdb54c4164760106ab78e6c5b0858cf64e" [[package]] name = "zip" -version = "2.4.2" +version = "9.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fabe6324e908f85a1c52063ce7aa26b68dcb7eb6dbc83a2d148403c9bc3eba50" +checksum = "6e04976da629d3b04204ba8105b396a193af8ad2583b2c79bfb3ab8af580a11e" dependencies = [ - "arbitrary", "crc32fast", - "crossbeam-utils", - "displaydoc", "flate2", "indexmap", "memchr", - "thiserror", - "zopfli", + "nix", + "typed-path", ] [[package]] @@ -2303,18 +2296,6 @@ version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" -[[package]] -name = "zopfli" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f05cd8797d63865425ff89b5c4a48804f35ba0ce8d125800027ad6017d2b5249" -dependencies = [ - "bumpalo", - "crc32fast", - "log", - "simd-adler32", -] - [[package]] name = "zstd" version = "0.13.3" From 74da9ee0a9515177d80cd09feb534c7b50898119 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 02:43:07 +0300 Subject: [PATCH 025/119] chore(deps): update dependencies and submodules This updates several dependencies across the project, including minor version bumps for various crates and updating the submodule URL for `vendor/tinybus`. This ensures compatibility with newer library versions and maintains correct repository references. Auto-committed-on: dragonfly --- .gitmodules | 2 +- crates/tinyjuice-examples/Cargo.lock | 177 +++++++++++++++------------ 2 files changed, 103 insertions(+), 76 deletions(-) diff --git a/.gitmodules b/.gitmodules index e98360d6..e13b65db 100644 --- a/.gitmodules +++ b/.gitmodules @@ -3,7 +3,7 @@ url = https://github.com/tinyhumansai/tinyjuice.wiki.git [submodule "vendor/tinybus"] path = vendor/tinybus - url = https://github.com/tinyhumansai/tinybus.git + url = https://github.com/senamakel/tinybus.git [submodule "vendor/tinyagents"] path = vendor/tinyagents url = https://github.com/tinyhumansai/tinyagents diff --git a/crates/tinyjuice-examples/Cargo.lock b/crates/tinyjuice-examples/Cargo.lock index 17b7338d..500c9699 100644 --- a/crates/tinyjuice-examples/Cargo.lock +++ b/crates/tinyjuice-examples/Cargo.lock @@ -44,7 +44,7 @@ checksum = "82f6aeea286b8eb4dd3431a1be1b59d290ace00f5bfd8e2a159bc2a05e2c1667" dependencies = [ "proc-macro2", "quote", - "syn 3.0.6", + "syn 3.0.9", ] [[package]] @@ -137,9 +137,9 @@ checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04" [[package]] name = "cc" -version = "1.5.1" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f360145194ee8e21db5ee7f3fcd4fe52210864c75c985dae33218202c8bbe040" +checksum = "877bf67ac8e52449eb2f9e98a344ea163beb70dd1f9eebe3cc5357dcfeaee4df" dependencies = [ "find-msvc-tools", "shlex", @@ -278,9 +278,9 @@ dependencies = [ [[package]] name = "defmt" -version = "1.1.1" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2953bfe4f93bbd20cc71198842756f77d161884c99ebbabc41d80231ded88d1" +checksum = "e4a0795ac740cb54d7b3775c9c17345f6aaecf884c01733b39d6017738e0e3e1" dependencies = [ "bitflags 1.3.2", "defmt-macros", @@ -288,21 +288,21 @@ dependencies = [ [[package]] name = "defmt-macros" -version = "1.1.1" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bad9c72e7ca2137e0dc3813245a0d282fd6daad32fd800af018306a9169b5fe8" +checksum = "840bb056bd99c495c9188198a258ab787c79f306d864db3e6e8451442d6d8366" dependencies = [ "defmt-parser", "proc-macro2", "quote", - "syn 2.0.119", + "syn 3.0.9", ] [[package]] name = "defmt-parser" -version = "1.0.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10d60334b3b2e7c9d91ef8150abfb6fa4c1c39ebbcf4a81c2e346aad939fee3e" +checksum = "71958f69fb2de856c5dd51ac9377e986ca1aa5919f931bf5395a807277f889a0" dependencies = [ "thiserror", ] @@ -367,7 +367,7 @@ checksum = "c6232dd377dcc64799954cbd3a9bb882e9cdc1308ccd87b1c098f1fb2eaf82a8" dependencies = [ "proc-macro2", "quote", - "syn 3.0.6", + "syn 3.0.9", ] [[package]] @@ -378,9 +378,9 @@ checksum = "d0881ea181b1df73ff77ffaaf9c7544ecc11e82fba9b5f27b262a3c73a332555" [[package]] name = "equivalent" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" +checksum = "00d174d5400e5e8fd687ad1049e2f578285fa914201b1af7e8b112a4546bd826" [[package]] name = "errno" @@ -400,9 +400,9 @@ checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223" [[package]] name = "find-msvc-tools" -version = "0.1.14" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aedcfb3409746eddb02b9e19ebda1c3394f759a152e48ee875a0844d1b955484" +checksum = "1c66915cc5391097de7a2b0b972e8505aa33c0df401fd3a6811dbdb32881ba48" [[package]] name = "fnv" @@ -416,6 +416,12 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" +[[package]] +name = "foldhash" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb" + [[package]] name = "form_urlencoded" version = "1.2.2" @@ -491,7 +497,7 @@ checksum = "9fb9654ba8355388abeb8dcb4fc62f511300867002afc858860463bdd9fe0c44" dependencies = [ "proc-macro2", "quote", - "syn 3.0.6", + "syn 3.0.9", ] [[package]] @@ -562,9 +568,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.4.19" +version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef8e5e5a340588f4452631496976cf8636d4a7ecf600239fdc27615d2530bc16" +checksum = "7d29020232d6aa3fb1daca64c1127cf662cf97f254ae16c18c05b8ab635fc118" dependencies = [ "atomic-waker", "bytes", @@ -671,9 +677,9 @@ dependencies = [ [[package]] name = "hyper" -version = "1.11.1" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27b501faa50e7a26c3d3560ca625132f4078a17771f4810baf70475ae48cbe43" +checksum = "2c3e324da4c95177d6291d4c8730197c0d1822f8a9766814a4a44fa5ab797c9c" dependencies = [ "atomic-waker", "bytes", @@ -908,7 +914,7 @@ checksum = "4be2f53207ffb1313a2d2ad819cfa8bfaa7936cb85a110eda10fd5da822cec94" dependencies = [ "bstr", "bytes", - "foldhash", + "foldhash 0.1.5", "hifijson", "indexmap", "jaq-core", @@ -938,9 +944,9 @@ dependencies = [ [[package]] name = "jiff" -version = "0.2.37" +version = "0.2.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ab1baf72f08796de0260609515130699b890ac25f30e610ad894bc5856cafdb" +checksum = "b2b005715dcbeb0089a3c0dab99f2ff1cc3b2525323552703d648585d342a383" dependencies = [ "defmt", "jiff-core", @@ -965,9 +971,9 @@ dependencies = [ [[package]] name = "jiff-static" -version = "0.2.37" +version = "0.2.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "378268a1116ad67ae6228701118ac9f491d78fda38a40a1f1a9e1348de6f7212" +checksum = "2cc9817253cf7c7ee4684451bd327e88d6f3658014e54a29198625590650695c" dependencies = [ "jiff-core", "proc-macro2", @@ -977,9 +983,9 @@ dependencies = [ [[package]] name = "jiff-tzdb" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "142bd39932ad231f10513df9ab62661fead8719872150b7ad02a2df79f4e141e" +checksum = "fa8377070c6bae868759445e5a77f66d84f0b72f3a054bfb00e6d038b8282da7" [[package]] name = "jiff-tzdb-platform" @@ -1003,9 +1009,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.189" +version = "0.2.191" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2" +checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a" [[package]] name = "libm" @@ -1060,9 +1066,9 @@ checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" [[package]] name = "mio" -version = "1.2.3" +version = "1.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b18443e9c262bfe8fa82f51666e2642c53393f7e5c27b3e1aeab922cff5b9d8" +checksum = "1788edb87fdc09c7e26304471e2f5be8cdefb1b6930d6e3985fc02ff53bf86ee" dependencies = [ "libc", "wasi", @@ -1394,7 +1400,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.4.15", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -1412,9 +1418,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.45" +version = "0.23.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d41d731c7d2f962d1ccc364cec258de3c0e93b38c2fb3ba97ac74513048d634" +checksum = "48e13bd8c0e9365c43cfa5c9e8f9ad49d3c8444926c9aac819e0e4dc503c8fdf" dependencies = [ "once_cell", "ring", @@ -1436,9 +1442,9 @@ dependencies = [ [[package]] name = "rustls-webpki" -version = "0.103.15" +version = "0.103.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3c3cf1d8b1e7d4927e2d154c3fcb02979afb9939629c62cd9048d4f07b60ac2" +checksum = "4443b1b6d39d7c663139942cc4558262562d2c84123bb6282ef177009ca8b281" dependencies = [ "ring", "rustls-pki-types", @@ -1490,15 +1496,16 @@ checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" dependencies = [ "proc-macro2", "quote", - "syn 3.0.6", + "syn 3.0.9", ] [[package]] name = "serde_json" -version = "1.0.151" +version = "1.0.154" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c841b55ecdae098c80dcae9cf767f6f8a0c2cdb3416bbef72181df4d0fe73f14" +checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6" dependencies = [ + "foldhash 0.2.0", "indexmap", "itoa", "memchr", @@ -1541,9 +1548,9 @@ dependencies = [ [[package]] name = "sha2" -version = "0.11.0" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "446ba717509524cb3f22f17ecc096f10f4822d76ab5c0b9822c5f9c284e825f4" +checksum = "47d7069beb7d6ac7b9acd1039986e73443f24234f41074da099d6f994ac9ad19" dependencies = [ "cfg-if", "cpufeatures 0.3.1", @@ -1574,9 +1581,9 @@ checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" [[package]] name = "smallvec" -version = "1.16.2" +version = "1.16.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9395f0f0eee849a9b707b2f06bb92a6a422090e2123bb2ef8e87a0e61892a8e" +checksum = "5b3dc8af474f516a851ff4bd12db780f948b9250ad37211e4eec0bccea54e01b" [[package]] name = "socket2" @@ -1619,9 +1626,9 @@ dependencies = [ [[package]] name = "syn" -version = "3.0.6" +version = "3.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8593e8e72159ed2257d083c7a454a85cbf854f37a0966d8d483aff8c8a3ebcee" +checksum = "d78c8dee4c7bf0e14673097256fed6142ce9d3b85a408189d07482442145823b" dependencies = [ "proc-macro2", "quote", @@ -1645,7 +1652,7 @@ checksum = "901704edd0dfe137f1987838ee4f259e4e063c31371bdb423f7ae38ec6f77f02" dependencies = [ "proc-macro2", "quote", - "syn 3.0.6", + "syn 3.0.9", ] [[package]] @@ -1678,7 +1685,7 @@ checksum = "fe5197923287db20a58125f0bc85c062f7f2c892de97b18c356f9efb14b28524" dependencies = [ "proc-macro2", "quote", - "syn 3.0.6", + "syn 3.0.9", ] [[package]] @@ -1708,7 +1715,7 @@ dependencies = [ "reqwest", "serde", "serde_json", - "sha2 0.11.0", + "sha2 0.11.1", "tempfile", "thiserror", "tinyagents-definition", @@ -1780,7 +1787,7 @@ dependencies = [ "reqwest", "serde", "serde_json", - "sha2 0.11.0", + "sha2 0.11.1", "tinystoragedrivers-secrets", "tracing", "url", @@ -1789,7 +1796,7 @@ dependencies = [ [[package]] name = "tinyjuice" -version = "0.10.4" +version = "0.11.0" dependencies = [ "anyhow", "async-trait", @@ -1803,7 +1810,7 @@ dependencies = [ "regex", "serde", "serde_json", - "sha2 0.11.0", + "sha2 0.11.1", "thiserror", "tinyjuice-bus", "tinytools", @@ -1818,11 +1825,12 @@ dependencies = [ [[package]] name = "tinyjuice-bus" -version = "0.10.4" +version = "0.11.0" dependencies = [ "serde", "serde_json", "thiserror", + "tinystoragedrivers-types", ] [[package]] @@ -1874,6 +1882,16 @@ dependencies = [ "zeroize", ] +[[package]] +name = "tinystoragedrivers-types" +version = "2.0.2" +source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.2#7acd22d8e8061edf7ef8cc4976c666b198a203c7" +dependencies = [ + "serde", + "serde_json", + "thiserror", +] + [[package]] name = "tinystr" version = "0.8.4" @@ -1912,9 +1930,9 @@ checksum = "fd3ca314f692efd6c868f8408f53fe444634a845f96c028b97d35f6a1f79f0ee" [[package]] name = "tokio" -version = "1.53.1" +version = "1.54.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "202caea871b69668250d242070849eb495be178ed697a3e98aebce5bc81a0bed" +checksum = "a0c168a474b95bfecfe908a65d4bdffc523144b649a74c09c286afb35d53e0bc" dependencies = [ "bytes", "libc", @@ -1934,7 +1952,7 @@ checksum = "78773a2a397f451582ce068015985c33193cf6dea8b74d2a639fe457b2f07b0e" dependencies = [ "proc-macro2", "quote", - "syn 3.0.6", + "syn 3.0.9", ] [[package]] @@ -1949,9 +1967,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.19" +version = "0.7.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "494815d09bf52b5548659851081238f0ca39ff638363907596da739561c62c52" +checksum = "e464cf451ba96ebfc6f9b6542f17ee8b8956e33f1e40d9690624e59d7a7f8a4b" dependencies = [ "bytes", "futures-core", @@ -2080,9 +2098,9 @@ dependencies = [ [[package]] name = "tree-sitter" -version = "0.27.0" +version = "0.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2038684e0058edba0d17302619f62eabce4a8e11c6ac59506996a8d79848851d" +checksum = "a5129de2ccc97808c4583d48f1fb44576d015cf241e432800572bda11ef30c3b" dependencies = [ "cc", "regex", @@ -2093,9 +2111,9 @@ dependencies = [ [[package]] name = "tree-sitter-language" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca0d1bf6fdd806e43ae5198f82f527056d359def39e54e67a0f478ac09dac081" +checksum = "d0af592be68c579aa78a16846bd19422978c3c52e438523d45ff5d1bff1f9d4a" [[package]] name = "tree-sitter-python" @@ -2147,9 +2165,9 @@ checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" [[package]] name = "unicode-ident" -version = "1.0.26" +version = "1.0.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d245f478577f809a851594d02313b640fb437e0bb33866753cff937863096954" +checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563" [[package]] name = "unicode-segmentation" @@ -2231,9 +2249,9 @@ dependencies = [ [[package]] name = "want" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +checksum = "ec4cdd0dd910afe868b7ef477227d8d538b46b3075031afee8a9f2acb0a2ed0b" dependencies = [ "try-lock", ] @@ -2287,7 +2305,7 @@ dependencies = [ "bumpalo", "proc-macro2", "quote", - "syn 3.0.6", + "syn 3.0.9", "wasm-bindgen-shared", ] @@ -2335,9 +2353,9 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "1.0.9" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dcd9d09a39985f5344844e66b0c530a33843579125f23e21e9f0f220850f22a" +checksum = "1c1c8e20c8a38fc7d65abfe74eb7280e4aa667e8eec8bc84996d2874810748d9" dependencies = [ "rustls-pki-types", ] @@ -2451,6 +2469,15 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-sys" version = "0.61.2" @@ -2558,13 +2585,13 @@ dependencies = [ [[package]] name = "yoke-derive" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33811428bee40dbceb6d545e95754741d17a6aef9a4849f0fd62e2ba4f412a78" +checksum = "ec8ebde2db3681e8c9980cc27822030e68752690ddfa9473e739aeb4dbde6d71" dependencies = [ "proc-macro2", "quote", - "syn 3.0.6", + "syn 3.0.9", "synstructure", ] @@ -2585,15 +2612,15 @@ checksum = "f75b4683f6c7f45248d4d64056a24298c6281e0993356d7d1b4a1a962ef10d4a" dependencies = [ "proc-macro2", "quote", - "syn 3.0.6", + "syn 3.0.9", "synstructure", ] [[package]] name = "zeroize" -version = "1.9.0" +version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e13c156562582aa81c60cb29407084cdb54c4164760106ab78e6c5b0858cf64e" +checksum = "e13084392c5e4bc371903e2935a5eaeed24905a7511356b883835e18a78f6879" [[package]] name = "zerotrie" @@ -2625,7 +2652,7 @@ checksum = "34df6fc39dbd26ddc9c10e6a2984476e13acce22e64e4487636ef494369225da" dependencies = [ "proc-macro2", "quote", - "syn 3.0.6", + "syn 3.0.9", ] [[package]] From f25bf60371c2a481d0764cf71f0984520ab27e2e Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 02:43:19 +0300 Subject: [PATCH 026/119] chore(deps): update windows-sys versions This updates the version of the windows-sys dependency across several examples to align with current requirements. Auto-committed-on: dragonfly --- crates/tinyjuice-examples/Cargo.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/tinyjuice-examples/Cargo.lock b/crates/tinyjuice-examples/Cargo.lock index 500c9699..ed9c8738 100644 --- a/crates/tinyjuice-examples/Cargo.lock +++ b/crates/tinyjuice-examples/Cargo.lock @@ -356,7 +356,7 @@ dependencies = [ "libc", "option-ext", "redox_users", - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -389,7 +389,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -1230,7 +1230,7 @@ dependencies = [ "once_cell", "socket2", "tracing", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -1413,7 +1413,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.12.1", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -1665,7 +1665,7 @@ dependencies = [ "getrandom 0.4.3", "once_cell", "rustix 1.1.5", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -2382,7 +2382,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] From 2f109c2ea7fdde081a583444ac0aef1b99e0aaf8 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 02:43:57 +0300 Subject: [PATCH 027/119] chore(deps): update dependencies versions This updates several dependencies across the examples crate to newer or specific versions to ensure compatibility and address potential issues. This includes updates to `syn`, `cc`, `defmt`, and various other crates. Auto-committed-on: dragonfly --- crates/tinyjuice-examples/Cargo.lock | 164 ++++++++++++--------------- 1 file changed, 74 insertions(+), 90 deletions(-) diff --git a/crates/tinyjuice-examples/Cargo.lock b/crates/tinyjuice-examples/Cargo.lock index ed9c8738..05de815e 100644 --- a/crates/tinyjuice-examples/Cargo.lock +++ b/crates/tinyjuice-examples/Cargo.lock @@ -44,7 +44,7 @@ checksum = "82f6aeea286b8eb4dd3431a1be1b59d290ace00f5bfd8e2a159bc2a05e2c1667" dependencies = [ "proc-macro2", "quote", - "syn 3.0.9", + "syn 3.0.6", ] [[package]] @@ -137,9 +137,9 @@ checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04" [[package]] name = "cc" -version = "1.9.0" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "877bf67ac8e52449eb2f9e98a344ea163beb70dd1f9eebe3cc5357dcfeaee4df" +checksum = "f360145194ee8e21db5ee7f3fcd4fe52210864c75c985dae33218202c8bbe040" dependencies = [ "find-msvc-tools", "shlex", @@ -278,9 +278,9 @@ dependencies = [ [[package]] name = "defmt" -version = "1.2.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4a0795ac740cb54d7b3775c9c17345f6aaecf884c01733b39d6017738e0e3e1" +checksum = "e2953bfe4f93bbd20cc71198842756f77d161884c99ebbabc41d80231ded88d1" dependencies = [ "bitflags 1.3.2", "defmt-macros", @@ -288,21 +288,21 @@ dependencies = [ [[package]] name = "defmt-macros" -version = "1.2.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "840bb056bd99c495c9188198a258ab787c79f306d864db3e6e8451442d6d8366" +checksum = "bad9c72e7ca2137e0dc3813245a0d282fd6daad32fd800af018306a9169b5fe8" dependencies = [ "defmt-parser", "proc-macro2", "quote", - "syn 3.0.9", + "syn 2.0.119", ] [[package]] name = "defmt-parser" -version = "1.1.0" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71958f69fb2de856c5dd51ac9377e986ca1aa5919f931bf5395a807277f889a0" +checksum = "10d60334b3b2e7c9d91ef8150abfb6fa4c1c39ebbcf4a81c2e346aad939fee3e" dependencies = [ "thiserror", ] @@ -356,7 +356,7 @@ dependencies = [ "libc", "option-ext", "redox_users", - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] [[package]] @@ -367,7 +367,7 @@ checksum = "c6232dd377dcc64799954cbd3a9bb882e9cdc1308ccd87b1c098f1fb2eaf82a8" dependencies = [ "proc-macro2", "quote", - "syn 3.0.9", + "syn 3.0.6", ] [[package]] @@ -378,9 +378,9 @@ checksum = "d0881ea181b1df73ff77ffaaf9c7544ecc11e82fba9b5f27b262a3c73a332555" [[package]] name = "equivalent" -version = "1.0.3" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00d174d5400e5e8fd687ad1049e2f578285fa914201b1af7e8b112a4546bd826" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" [[package]] name = "errno" @@ -400,9 +400,9 @@ checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223" [[package]] name = "find-msvc-tools" -version = "0.1.15" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c66915cc5391097de7a2b0b972e8505aa33c0df401fd3a6811dbdb32881ba48" +checksum = "aedcfb3409746eddb02b9e19ebda1c3394f759a152e48ee875a0844d1b955484" [[package]] name = "fnv" @@ -416,12 +416,6 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" -[[package]] -name = "foldhash" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb" - [[package]] name = "form_urlencoded" version = "1.2.2" @@ -497,7 +491,7 @@ checksum = "9fb9654ba8355388abeb8dcb4fc62f511300867002afc858860463bdd9fe0c44" dependencies = [ "proc-macro2", "quote", - "syn 3.0.9", + "syn 3.0.6", ] [[package]] @@ -568,9 +562,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.4.20" +version = "0.4.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d29020232d6aa3fb1daca64c1127cf662cf97f254ae16c18c05b8ab635fc118" +checksum = "ef8e5e5a340588f4452631496976cf8636d4a7ecf600239fdc27615d2530bc16" dependencies = [ "atomic-waker", "bytes", @@ -677,9 +671,9 @@ dependencies = [ [[package]] name = "hyper" -version = "1.12.0" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c3e324da4c95177d6291d4c8730197c0d1822f8a9766814a4a44fa5ab797c9c" +checksum = "27b501faa50e7a26c3d3560ca625132f4078a17771f4810baf70475ae48cbe43" dependencies = [ "atomic-waker", "bytes", @@ -914,7 +908,7 @@ checksum = "4be2f53207ffb1313a2d2ad819cfa8bfaa7936cb85a110eda10fd5da822cec94" dependencies = [ "bstr", "bytes", - "foldhash 0.1.5", + "foldhash", "hifijson", "indexmap", "jaq-core", @@ -944,9 +938,9 @@ dependencies = [ [[package]] name = "jiff" -version = "0.2.38" +version = "0.2.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2b005715dcbeb0089a3c0dab99f2ff1cc3b2525323552703d648585d342a383" +checksum = "0ab1baf72f08796de0260609515130699b890ac25f30e610ad894bc5856cafdb" dependencies = [ "defmt", "jiff-core", @@ -971,9 +965,9 @@ dependencies = [ [[package]] name = "jiff-static" -version = "0.2.38" +version = "0.2.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cc9817253cf7c7ee4684451bd327e88d6f3658014e54a29198625590650695c" +checksum = "378268a1116ad67ae6228701118ac9f491d78fda38a40a1f1a9e1348de6f7212" dependencies = [ "jiff-core", "proc-macro2", @@ -983,9 +977,9 @@ dependencies = [ [[package]] name = "jiff-tzdb" -version = "0.1.9" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa8377070c6bae868759445e5a77f66d84f0b72f3a054bfb00e6d038b8282da7" +checksum = "142bd39932ad231f10513df9ab62661fead8719872150b7ad02a2df79f4e141e" [[package]] name = "jiff-tzdb-platform" @@ -1009,9 +1003,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.191" +version = "0.2.189" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a" +checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2" [[package]] name = "libm" @@ -1066,9 +1060,9 @@ checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" [[package]] name = "mio" -version = "1.2.4" +version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1788edb87fdc09c7e26304471e2f5be8cdefb1b6930d6e3985fc02ff53bf86ee" +checksum = "4b18443e9c262bfe8fa82f51666e2642c53393f7e5c27b3e1aeab922cff5b9d8" dependencies = [ "libc", "wasi", @@ -1400,7 +1394,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.4.15", - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] @@ -1418,9 +1412,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.46" +version = "0.23.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48e13bd8c0e9365c43cfa5c9e8f9ad49d3c8444926c9aac819e0e4dc503c8fdf" +checksum = "0d41d731c7d2f962d1ccc364cec258de3c0e93b38c2fb3ba97ac74513048d634" dependencies = [ "once_cell", "ring", @@ -1442,9 +1436,9 @@ dependencies = [ [[package]] name = "rustls-webpki" -version = "0.103.16" +version = "0.103.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4443b1b6d39d7c663139942cc4558262562d2c84123bb6282ef177009ca8b281" +checksum = "f3c3cf1d8b1e7d4927e2d154c3fcb02979afb9939629c62cd9048d4f07b60ac2" dependencies = [ "ring", "rustls-pki-types", @@ -1496,16 +1490,15 @@ checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" dependencies = [ "proc-macro2", "quote", - "syn 3.0.9", + "syn 3.0.6", ] [[package]] name = "serde_json" -version = "1.0.154" +version = "1.0.151" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6" +checksum = "c841b55ecdae098c80dcae9cf767f6f8a0c2cdb3416bbef72181df4d0fe73f14" dependencies = [ - "foldhash 0.2.0", "indexmap", "itoa", "memchr", @@ -1548,9 +1541,9 @@ dependencies = [ [[package]] name = "sha2" -version = "0.11.1" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47d7069beb7d6ac7b9acd1039986e73443f24234f41074da099d6f994ac9ad19" +checksum = "446ba717509524cb3f22f17ecc096f10f4822d76ab5c0b9822c5f9c284e825f4" dependencies = [ "cfg-if", "cpufeatures 0.3.1", @@ -1581,9 +1574,9 @@ checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" [[package]] name = "smallvec" -version = "1.16.3" +version = "1.16.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b3dc8af474f516a851ff4bd12db780f948b9250ad37211e4eec0bccea54e01b" +checksum = "f9395f0f0eee849a9b707b2f06bb92a6a422090e2123bb2ef8e87a0e61892a8e" [[package]] name = "socket2" @@ -1626,9 +1619,9 @@ dependencies = [ [[package]] name = "syn" -version = "3.0.9" +version = "3.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d78c8dee4c7bf0e14673097256fed6142ce9d3b85a408189d07482442145823b" +checksum = "8593e8e72159ed2257d083c7a454a85cbf854f37a0966d8d483aff8c8a3ebcee" dependencies = [ "proc-macro2", "quote", @@ -1652,7 +1645,7 @@ checksum = "901704edd0dfe137f1987838ee4f259e4e063c31371bdb423f7ae38ec6f77f02" dependencies = [ "proc-macro2", "quote", - "syn 3.0.9", + "syn 3.0.6", ] [[package]] @@ -1685,7 +1678,7 @@ checksum = "fe5197923287db20a58125f0bc85c062f7f2c892de97b18c356f9efb14b28524" dependencies = [ "proc-macro2", "quote", - "syn 3.0.9", + "syn 3.0.6", ] [[package]] @@ -1715,7 +1708,7 @@ dependencies = [ "reqwest", "serde", "serde_json", - "sha2 0.11.1", + "sha2 0.11.0", "tempfile", "thiserror", "tinyagents-definition", @@ -1787,7 +1780,7 @@ dependencies = [ "reqwest", "serde", "serde_json", - "sha2 0.11.1", + "sha2 0.11.0", "tinystoragedrivers-secrets", "tracing", "url", @@ -1810,7 +1803,7 @@ dependencies = [ "regex", "serde", "serde_json", - "sha2 0.11.1", + "sha2 0.11.0", "thiserror", "tinyjuice-bus", "tinytools", @@ -1930,9 +1923,9 @@ checksum = "fd3ca314f692efd6c868f8408f53fe444634a845f96c028b97d35f6a1f79f0ee" [[package]] name = "tokio" -version = "1.54.0" +version = "1.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0c168a474b95bfecfe908a65d4bdffc523144b649a74c09c286afb35d53e0bc" +checksum = "202caea871b69668250d242070849eb495be178ed697a3e98aebce5bc81a0bed" dependencies = [ "bytes", "libc", @@ -1952,7 +1945,7 @@ checksum = "78773a2a397f451582ce068015985c33193cf6dea8b74d2a639fe457b2f07b0e" dependencies = [ "proc-macro2", "quote", - "syn 3.0.9", + "syn 3.0.6", ] [[package]] @@ -1967,9 +1960,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.20" +version = "0.7.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e464cf451ba96ebfc6f9b6542f17ee8b8956e33f1e40d9690624e59d7a7f8a4b" +checksum = "494815d09bf52b5548659851081238f0ca39ff638363907596da739561c62c52" dependencies = [ "bytes", "futures-core", @@ -2098,9 +2091,9 @@ dependencies = [ [[package]] name = "tree-sitter" -version = "0.27.1" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5129de2ccc97808c4583d48f1fb44576d015cf241e432800572bda11ef30c3b" +checksum = "2038684e0058edba0d17302619f62eabce4a8e11c6ac59506996a8d79848851d" dependencies = [ "cc", "regex", @@ -2111,9 +2104,9 @@ dependencies = [ [[package]] name = "tree-sitter-language" -version = "0.1.9" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0af592be68c579aa78a16846bd19422978c3c52e438523d45ff5d1bff1f9d4a" +checksum = "ca0d1bf6fdd806e43ae5198f82f527056d359def39e54e67a0f478ac09dac081" [[package]] name = "tree-sitter-python" @@ -2165,9 +2158,9 @@ checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" [[package]] name = "unicode-ident" -version = "1.0.27" +version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563" +checksum = "d245f478577f809a851594d02313b640fb437e0bb33866753cff937863096954" [[package]] name = "unicode-segmentation" @@ -2249,9 +2242,9 @@ dependencies = [ [[package]] name = "want" -version = "0.3.2" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec4cdd0dd910afe868b7ef477227d8d538b46b3075031afee8a9f2acb0a2ed0b" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" dependencies = [ "try-lock", ] @@ -2305,7 +2298,7 @@ dependencies = [ "bumpalo", "proc-macro2", "quote", - "syn 3.0.9", + "syn 3.0.6", "wasm-bindgen-shared", ] @@ -2353,9 +2346,9 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "1.0.10" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c1c8e20c8a38fc7d65abfe74eb7280e4aa667e8eec8bc84996d2874810748d9" +checksum = "7dcd9d09a39985f5344844e66b0c530a33843579125f23e21e9f0f220850f22a" dependencies = [ "rustls-pki-types", ] @@ -2469,15 +2462,6 @@ dependencies = [ "windows-targets", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets", -] - [[package]] name = "windows-sys" version = "0.61.2" @@ -2585,13 +2569,13 @@ dependencies = [ [[package]] name = "yoke-derive" -version = "0.8.4" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec8ebde2db3681e8c9980cc27822030e68752690ddfa9473e739aeb4dbde6d71" +checksum = "33811428bee40dbceb6d545e95754741d17a6aef9a4849f0fd62e2ba4f412a78" dependencies = [ "proc-macro2", "quote", - "syn 3.0.9", + "syn 3.0.6", "synstructure", ] @@ -2612,15 +2596,15 @@ checksum = "f75b4683f6c7f45248d4d64056a24298c6281e0993356d7d1b4a1a962ef10d4a" dependencies = [ "proc-macro2", "quote", - "syn 3.0.9", + "syn 3.0.6", "synstructure", ] [[package]] name = "zeroize" -version = "1.9.1" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e13084392c5e4bc371903e2935a5eaeed24905a7511356b883835e18a78f6879" +checksum = "e13c156562582aa81c60cb29407084cdb54c4164760106ab78e6c5b0858cf64e" [[package]] name = "zerotrie" @@ -2652,7 +2636,7 @@ checksum = "34df6fc39dbd26ddc9c10e6a2984476e13acce22e64e4487636ef494369225da" dependencies = [ "proc-macro2", "quote", - "syn 3.0.9", + "syn 3.0.6", ] [[package]] From cc2f15fce96fe51c5cba24e6a85a537a6a7a72cd Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 02:44:19 +0300 Subject: [PATCH 028/119] chore(deps): update windows-sys dependency version This updates the version of the windows-sys crate across various dependencies in the examples to 0.61.2 to align with current requirements. Auto-committed-on: dragonfly --- crates/tinyjuice-examples/Cargo.lock | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/tinyjuice-examples/Cargo.lock b/crates/tinyjuice-examples/Cargo.lock index 05de815e..9fe220b5 100644 --- a/crates/tinyjuice-examples/Cargo.lock +++ b/crates/tinyjuice-examples/Cargo.lock @@ -389,7 +389,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]] @@ -1224,7 +1224,7 @@ dependencies = [ "once_cell", "socket2", "tracing", - "windows-sys 0.52.0", + "windows-sys 0.61.2", ] [[package]] @@ -1407,7 +1407,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.12.1", - "windows-sys 0.52.0", + "windows-sys 0.61.2", ] [[package]] @@ -1658,7 +1658,7 @@ dependencies = [ "getrandom 0.4.3", "once_cell", "rustix 1.1.5", - "windows-sys 0.52.0", + "windows-sys 0.61.2", ] [[package]] @@ -2375,7 +2375,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]] From 40d2315f08ae89ce8f91637cd6508d4fd4215c5f Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 02:44:53 +0300 Subject: [PATCH 029/119] chore(deps): update submodule urls Updates the remote repository URLs for the vendor submodules to point to the new organization's repositories. This ensures all dependencies are tracked under the correct ownership. Auto-committed-on: dragonfly --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index e13b65db..e98360d6 100644 --- a/.gitmodules +++ b/.gitmodules @@ -3,7 +3,7 @@ url = https://github.com/tinyhumansai/tinyjuice.wiki.git [submodule "vendor/tinybus"] path = vendor/tinybus - url = https://github.com/senamakel/tinybus.git + url = https://github.com/tinyhumansai/tinybus.git [submodule "vendor/tinyagents"] path = vendor/tinyagents url = https://github.com/tinyhumansai/tinyagents From 65086aa1647e3e54f57e659d4e2f6a279c79c048 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 03:17:52 +0300 Subject: [PATCH 030/119] feat: move TinyJuice storage to host ports --- .gitmodules | 3 - Cargo.lock | 12 +- Cargo.toml | 5 +- crates/tinyjuice-bus/Cargo.toml | 2 +- crates/tinyjuice-cli/Cargo.toml | 2 +- crates/tinyjuice-cli/src/storage_tests.rs | 180 +++++++++++++++++- .../fixtures/legacy-ccr/v0.10.10/README.md | 7 +- crates/tinyjuice-drivers/Cargo.toml | 2 +- crates/tinyjuice-drivers/src/blocking.rs | 20 +- .../tinyjuice-drivers/src/blocking_tests.rs | 65 +++++++ crates/tinyjuice-examples/Cargo.toml | 2 +- crates/tinyjuice-module/Cargo.toml | 2 +- deny.toml | 2 + scripts/check-engine-deps.sh | 86 +++++++++ scripts/test-features.sh | 1 + 15 files changed, 365 insertions(+), 26 deletions(-) create mode 100644 crates/tinyjuice-drivers/src/blocking_tests.rs create mode 100755 scripts/check-engine-deps.sh diff --git a/.gitmodules b/.gitmodules index e98360d6..a895297f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,6 @@ [submodule "wiki"] path = wiki url = https://github.com/tinyhumansai/tinyjuice.wiki.git -[submodule "vendor/tinybus"] - path = vendor/tinybus - url = https://github.com/tinyhumansai/tinybus.git [submodule "vendor/tinyagents"] path = vendor/tinyagents url = https://github.com/tinyhumansai/tinyagents diff --git a/Cargo.lock b/Cargo.lock index 24d3ab63..a4bf7917 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1168,9 +1168,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.43" +version = "0.23.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0283386ce02abc0151e1761d08802dfe86c173b0b494af5cbc086574e453da06" +checksum = "48e13bd8c0e9365c43cfa5c9e8f9ad49d3c8444926c9aac819e0e4dc503c8fdf" dependencies = [ "log", "once_cell", @@ -1192,9 +1192,9 @@ dependencies = [ [[package]] name = "rustls-webpki" -version = "0.103.14" +version = "0.103.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0527518605e68109d875e248ea259b6758801cf165e4b2c2733ae3b51f12535a" +checksum = "4443b1b6d39d7c663139942cc4558262562d2c84123bb6282ef177009ca8b281" dependencies = [ "ring", "rustls-pki-types", @@ -2102,9 +2102,9 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "1.0.9" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dcd9d09a39985f5344844e66b0c530a33843579125f23e21e9f0f220850f22a" +checksum = "1c1c8e20c8a38fc7d65abfe74eb7280e4aa667e8eec8bc84996d2874810748d9" dependencies = [ "rustls-pki-types", ] diff --git a/Cargo.toml b/Cargo.toml index 46108263..9e908a7f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -rust-version = "1.88" +rust-version = "1.90" name = "tinyjuice" version = "0.11.0" edition = "2024" @@ -14,7 +14,6 @@ exclude = [ ".github/", ".gitmodules", "docs/", - "vendor/tinybus/", "vendor/tinyagents/", "crates/tinyjuice-examples/", "wiki/", @@ -23,7 +22,7 @@ exclude = [ [workspace] members = ["crates/tinyjuice-bus", "crates/tinyjuice-module", "crates/tinyjuice-drivers", "crates/tinyjuice-cli"] default-members = [".", "crates/tinyjuice-bus", "crates/tinyjuice-module", "crates/tinyjuice-drivers", "crates/tinyjuice-cli"] -exclude = ["vendor/tinybus", "vendor/tinyagents", "crates/tinyjuice-examples"] +exclude = ["vendor/tinyagents", "crates/tinyjuice-examples"] resolver = "3" [dependencies] diff --git a/crates/tinyjuice-bus/Cargo.toml b/crates/tinyjuice-bus/Cargo.toml index f5a4eec6..a1531ace 100644 --- a/crates/tinyjuice-bus/Cargo.toml +++ b/crates/tinyjuice-bus/Cargo.toml @@ -1,5 +1,5 @@ [package] -rust-version = "1.88" +rust-version = "1.90" name = "tinyjuice-bus" version = "0.11.0" edition = "2024" diff --git a/crates/tinyjuice-cli/Cargo.toml b/crates/tinyjuice-cli/Cargo.toml index 3d23cacf..40cd9c5b 100644 --- a/crates/tinyjuice-cli/Cargo.toml +++ b/crates/tinyjuice-cli/Cargo.toml @@ -2,7 +2,7 @@ name = "tinyjuice-cli" version = "0.11.0" edition = "2024" -rust-version = "1.88" +rust-version = "1.90" publish = false license = "GPL-3.0-only" description = "Standalone TinyJuice command-line tools." diff --git a/crates/tinyjuice-cli/src/storage_tests.rs b/crates/tinyjuice-cli/src/storage_tests.rs index 5ef3fa76..b968d134 100644 --- a/crates/tinyjuice-cli/src/storage_tests.rs +++ b/crates/tinyjuice-cli/src/storage_tests.rs @@ -1,5 +1,5 @@ use super::*; -use tinyjuice::cache::CcrStore; +use tinyjuice::cache::{CcrStore, RangeUnit}; use tinystoragedrivers_api::BlobStore; use tinystoragedrivers_testkit::FaultPlan; use tinystoragedrivers_types::{ @@ -79,6 +79,184 @@ fn collection_reports_bytes_removed_by_the_budget() { assert_eq!(collect(dir.path(), None, Some(0)).unwrap(), (2, 11, 0, 0)); } +#[test] +fn configure_and_inventory_report_invalid_storage_paths() { + let dir = tempfile::tempdir().unwrap(); + let missing = dir.path().join("missing"); + let inventory_error = match inventory(&missing, None) { + Err(error) => error, + Ok(_) => panic!("missing storage directory unexpectedly inventoried"), + }; + assert!(inventory_error.contains("does not exist")); + + let file_path = dir.path().join("not-a-directory"); + std::fs::write(&file_path, "file").unwrap(); + let configure_error = configure(&file_path, None, None).unwrap_err(); + assert!(configure_error.contains("cannot create CCR storage directory")); + let import_error = + import_legacy_files(&file_path, &open_file_blobs(dir.path()).unwrap(), None).unwrap_err(); + assert!(import_error.contains("failed to inspect legacy CCR directory")); +} + +#[test] +fn inventory_counts_ignored_entries_and_returns_imported_blobs() { + let dir = tempfile::tempdir().unwrap(); + std::fs::write(dir.path().join("not-a-token"), "ignored").unwrap(); + std::fs::create_dir(dir.path().join("nested")).unwrap(); + let content = "inventory imports the valid legacy entry"; + let token = tinyjuice::cache::short_hash(content); + std::fs::write(dir.path().join(&token), content).unwrap(); + + let result = inventory(dir.path(), None).unwrap(); + + assert_eq!(result.ignored_entries, 2); + assert_eq!(result.entries.len(), 1); + assert_eq!(result.entries[0].key, format!("{CCR_PREFIX}/{token}")); + assert_eq!( + BlobCcrStore::new(open_file_blobs(dir.path()).unwrap(), None) + .unwrap() + .get(&token) + .as_deref(), + Some(content) + ); +} + +#[test] +fn import_skips_directories_and_unrecognized_names_and_removes_expired_files() { + let dir = tempfile::tempdir().unwrap(); + let nested = dir.path().join("nested"); + std::fs::create_dir(&nested).unwrap(); + std::fs::write(nested.join("entry"), "not a top-level CCR").unwrap(); + let unrecognized = dir.path().join("not-a-token"); + std::fs::write(&unrecognized, "unrecognized").unwrap(); + + let content = "already expired legacy content"; + let token = tinyjuice::cache::short_hash(content); + let expired = dir.path().join(&token); + std::fs::write(&expired, content).unwrap(); + std::fs::File::open(&expired) + .unwrap() + .set_times(std::fs::FileTimes::new().set_modified(SystemTime::UNIX_EPOCH)) + .unwrap(); + let blobs = open_file_blobs(dir.path()).unwrap(); + + import_legacy_files(dir.path(), &blobs, Some(Duration::from_secs(1))).unwrap(); + + assert!(!expired.exists()); + assert!(unrecognized.exists()); + assert!(nested.join("entry").exists()); + assert!( + BlobCcrStore::new(blobs, None) + .unwrap() + .get(&token) + .is_none() + ); +} + +#[test] +fn import_uses_an_existing_backend_write_time_without_sidecars() { + let dir = tempfile::tempdir().unwrap(); + let content = "the already published backend body is newer"; + let token = tinyjuice::cache::short_hash(content); + let source = dir.path().join(&token); + std::fs::write(&source, content).unwrap(); + let source_time = SystemTime::now() - Duration::from_secs(60); + std::fs::File::open(&source) + .unwrap() + .set_times(std::fs::FileTimes::new().set_modified(source_time)) + .unwrap(); + let blobs = open_file_blobs(dir.path()).unwrap(); + let existing = BlobCcrStore::new(Arc::clone(&blobs), None).unwrap(); + assert!(existing.put(content).retained()); + let backend_time = backend_written_at(Arc::clone(&blobs), &format!("{CCR_PREFIX}/{token}")) + .unwrap() + .unwrap(); + + import_legacy_files(dir.path(), &blobs, None).unwrap(); + + assert!(!source.exists()); + assert_eq!( + read_semantic_time(blobs, &token).unwrap(), + Some(backend_time.max(unix_epoch_ms(source_time))) + ); +} + +#[test] +fn capped_store_delegates_byte_ranges_to_the_durable_store() { + let dir = tempfile::tempdir().unwrap(); + let blobs = open_file_blobs(dir.path()).unwrap(); + let store = CappedCcrStore { + store: BlobCcrStore::new(Arc::clone(&blobs), None).unwrap(), + blobs, + ttl: None, + max_bytes: None, + }; + let put = store.put("abcdefgh"); + + assert_eq!( + store + .get_range(put.token(), 2, 5, RangeUnit::Bytes) + .as_deref(), + Some("cde") + ); +} + +#[test] +fn timestamp_listing_ignores_non_tokens_and_rejects_malformed_values() { + let dir = tempfile::tempdir().unwrap(); + let blobs = open_file_blobs(dir.path()).unwrap(); + run_blob({ + let blobs = Arc::clone(&blobs); + async move { + blobs + .put( + &format!("{CCR_METADATA_PREFIX}not-a-token"), + b"not a timestamp".to_vec(), + None, + ) + .await + } + }) + .unwrap(); + assert!(list_semantic_times(Arc::clone(&blobs)).unwrap().is_empty()); + + let token = "0123456789abcdef0123456789abcdef"; + run_blob({ + let blobs = Arc::clone(&blobs); + async move { + blobs + .put(&format!("{CCR_METADATA_PREFIX}{token}"), vec![0xff], None) + .await + } + }) + .unwrap(); + assert!( + read_semantic_time(blobs, token) + .unwrap_err() + .contains("invalid CCR timestamp") + ); +} + +#[test] +fn deleting_a_non_ccr_blob_does_not_touch_ccr_metadata() { + let dir = tempfile::tempdir().unwrap(); + let blobs = open_file_blobs(dir.path()).unwrap(); + let key = "unrelated/object"; + run_blob({ + let blobs = Arc::clone(&blobs); + async move { blobs.put(key, b"data".to_vec(), None).await } + }) + .unwrap(); + + delete_blob_and_metadata(Arc::clone(&blobs), key).unwrap(); + + assert!( + run_blob(async move { blobs.get(key).await }) + .unwrap() + .is_none() + ); +} + #[test] fn durable_cli_writes_enforce_the_configured_byte_budget() { let dir = tempfile::tempdir().unwrap(); diff --git a/crates/tinyjuice-cli/tests/fixtures/legacy-ccr/v0.10.10/README.md b/crates/tinyjuice-cli/tests/fixtures/legacy-ccr/v0.10.10/README.md index 80501e63..7f63d2a3 100644 --- a/crates/tinyjuice-cli/tests/fixtures/legacy-ccr/v0.10.10/README.md +++ b/crates/tinyjuice-cli/tests/fixtures/legacy-ccr/v0.10.10/README.md @@ -18,8 +18,11 @@ lockfile was changed. Reproduce from the native repository root with: ```sh mkdir -p target/legacy-writer-v0.10.10 git archive --format=tar 4db24354d0e883f6a0aefe96e5cc0c76073fd76e | tar -x -C target/legacy-writer-v0.10.10 -mkdir -p target/legacy-writer-v0.10.10/vendor/tinybus target/legacy-writer-v0.10.10/vendor/tinyagents target/legacy-writer-v0.10.10/examples target/legacy-writer-v0.10.10/legacy-output -git -C vendor/tinybus archive 207a9a7df15e44fdba00a807d0f7eaf21904ba0e | tar -x -C target/legacy-writer-v0.10.10/vendor/tinybus +mkdir -p target/legacy-writer-v0.10.10/vendor/tinybus target/legacy-writer-v0.10.10/vendor/tinyagents target/legacy-writer-v0.10.10/examples target/legacy-writer-v0.10.10/legacy-output target/legacy-source-cache/tinybus +git -C target/legacy-source-cache/tinybus init +git -C target/legacy-source-cache/tinybus fetch --depth=1 https://github.com/tinyhumansai/tinybus.git 207a9a7df15e44fdba00a807d0f7eaf21904ba0e +git -C target/legacy-source-cache/tinybus checkout --detach FETCH_HEAD +git -C target/legacy-source-cache/tinybus archive 207a9a7df15e44fdba00a807d0f7eaf21904ba0e | tar -x -C target/legacy-writer-v0.10.10/vendor/tinybus git -C vendor/tinyagents archive aa5476fa48092d9bf051fbd2d1bf07f14cc9f331 | tar -x -C target/legacy-writer-v0.10.10/vendor/tinyagents cp crates/tinyjuice-cli/tests/fixtures/legacy-ccr/v0.10.10/write_ccr_fixture.rs target/legacy-writer-v0.10.10/examples/ cargo run --locked --manifest-path target/legacy-writer-v0.10.10/Cargo.toml -p tinyjuice --example write_ccr_fixture -- target/legacy-writer-v0.10.10/legacy-output "Fixture written by TinyJuice v0.10.10 public disk-tier API." diff --git a/crates/tinyjuice-drivers/Cargo.toml b/crates/tinyjuice-drivers/Cargo.toml index 9506b03b..7326aad6 100644 --- a/crates/tinyjuice-drivers/Cargo.toml +++ b/crates/tinyjuice-drivers/Cargo.toml @@ -1,5 +1,5 @@ [package] -rust-version = "1.88" +rust-version = "1.90" name = "tinyjuice-drivers" version = "0.9.0" edition = "2024" diff --git a/crates/tinyjuice-drivers/src/blocking.rs b/crates/tinyjuice-drivers/src/blocking.rs index 319debdd..9e832dbb 100644 --- a/crates/tinyjuice-drivers/src/blocking.rs +++ b/crates/tinyjuice-drivers/src/blocking.rs @@ -31,9 +31,7 @@ impl Blocking { let runtime = tokio::runtime::Builder::new_current_thread() .enable_all() .build() - .map_err(|error| { - StorageError::backend("cannot build the storage bridge runtime").with_source(error) - })?; + .map_err(runtime_build_error)?; thread::Builder::new() .name("tinyjuice-storage-bridge".into()) .spawn(move || { @@ -42,9 +40,7 @@ impl Blocking { job(&runtime); } }) - .map_err(|error| { - StorageError::backend("cannot start the storage bridge").with_source(error) - })?; + .map_err(thread_start_error)?; Ok(Self { jobs }) } @@ -66,3 +62,15 @@ impl Blocking { .map_err(|_| StorageError::backend("storage bridge dropped a call")) } } + +fn runtime_build_error(error: std::io::Error) -> StorageError { + StorageError::backend("cannot build the storage bridge runtime").with_source(error) +} + +fn thread_start_error(error: std::io::Error) -> StorageError { + StorageError::backend("cannot start the storage bridge").with_source(error) +} + +#[cfg(test)] +#[path = "blocking_tests.rs"] +mod tests; diff --git a/crates/tinyjuice-drivers/src/blocking_tests.rs b/crates/tinyjuice-drivers/src/blocking_tests.rs new file mode 100644 index 00000000..df642099 --- /dev/null +++ b/crates/tinyjuice-drivers/src/blocking_tests.rs @@ -0,0 +1,65 @@ +use super::*; + +#[test] +fn debug_output_hides_runtime_implementation() { + let bridge = Blocking::new().unwrap(); + let debug = format!("{bridge:?}"); + + assert_eq!(debug, "Blocking { .. }"); +} + +#[test] +fn bridge_rejects_reentrant_storage_calls() { + let bridge = Blocking::new().unwrap(); + let nested = bridge.clone(); + + let nested_result = bridge.run(async move { nested.run(async {}) }).unwrap(); + + assert!( + nested_result + .unwrap_err() + .to_string() + .contains("re-entered") + ); +} + +#[test] +fn bridge_reports_calls_when_its_worker_has_stopped() { + let (jobs, receiver) = mpsc::channel::(); + drop(receiver); + let bridge = Blocking { jobs }; + + let error = bridge.run(async {}).unwrap_err(); + + assert!(error.to_string().contains("storage bridge stopped")); +} + +#[test] +fn bridge_reports_a_worker_that_drops_a_call_without_replying() { + let (jobs, receiver) = mpsc::channel::(); + thread::spawn(move || drop(receiver.recv().unwrap())); + let bridge = Blocking { jobs }; + + let error = bridge.run(async {}).unwrap_err(); + + assert!(error.to_string().contains("storage bridge dropped a call")); +} + +#[test] +fn startup_errors_keep_their_source_and_backend_context() { + let runtime_error = runtime_build_error(std::io::Error::other("runtime resources unavailable")); + let thread_error = thread_start_error(std::io::Error::other("thread resources unavailable")); + + assert!( + runtime_error + .to_string() + .contains("cannot build the storage bridge runtime") + ); + assert!(std::error::Error::source(&runtime_error).is_some()); + assert!( + thread_error + .to_string() + .contains("cannot start the storage bridge") + ); + assert!(std::error::Error::source(&thread_error).is_some()); +} diff --git a/crates/tinyjuice-examples/Cargo.toml b/crates/tinyjuice-examples/Cargo.toml index 46edadde..7d1b8e0c 100644 --- a/crates/tinyjuice-examples/Cargo.toml +++ b/crates/tinyjuice-examples/Cargo.toml @@ -1,5 +1,5 @@ [package] -rust-version = "1.88" +rust-version = "1.90" name = "tinyjuice-examples" version = "0.0.0" edition = "2024" diff --git a/crates/tinyjuice-module/Cargo.toml b/crates/tinyjuice-module/Cargo.toml index 019c60d7..e34b43be 100644 --- a/crates/tinyjuice-module/Cargo.toml +++ b/crates/tinyjuice-module/Cargo.toml @@ -1,5 +1,5 @@ [package] -rust-version = "1.88" +rust-version = "1.90" name = "tinyjuice-module" version = "0.11.0" edition = "2024" diff --git a/deny.toml b/deny.toml index 501bb205..64f8d340 100644 --- a/deny.toml +++ b/deny.toml @@ -46,4 +46,6 @@ allow-registry = ["https://github.com/rust-lang/crates.io-index"] allow-git = [ "https://github.com/tinyhumansai/tinytools", "https://github.com/tinyhumansai/tinystoragedrivers", + "https://github.com/senamakel/tinystoragedrivers", + "https://github.com/senamakel/tinybus", ] diff --git a/scripts/check-engine-deps.sh b/scripts/check-engine-deps.sh new file mode 100755 index 00000000..967a738e --- /dev/null +++ b/scripts/check-engine-deps.sh @@ -0,0 +1,86 @@ +#!/usr/bin/env bash +set -euo pipefail +cd "$(dirname "${BASH_SOURCE[0]}")/.." + +engine_pattern='^(rusqlite|libsqlite3-sys|mongodb|bson|aws-sdk-s3|lapin|amq-protocol|sqlx|redb|sled|rocksdb|tinystoragedrivers-(document|kv|blob|queue|secrets|connect)|tinystoragedrivers)$' + +strip_carriage_return() { + printf '%s' "${1%$'\r'}" +} + +tree_names() { + printf '%s\n' "$1" | tr -d '\r' | awk '{print $1}' +} + +# Cargo metadata may be emitted with CRLF on Windows. Keep this parser +# self-test Bash 3 compatible, as used by the macOS runners. +crlf_packages=$'tinyjuice\r\ntinyjuice-module\r\n' +normalized_packages='' +while IFS= read -r package; do + [[ -n "$package" ]] || continue + package="$(strip_carriage_return "$package")" + normalized_packages="${normalized_packages:+${normalized_packages}$'\n'}${package}" +done <<< "$crlf_packages" +if [[ "$normalized_packages" != $'tinyjuice\ntinyjuice-module' ]]; then + echo "engine gate failed its CRLF package-list self-test" >&2 + exit 1 +fi +if [[ "$(tree_names $'tinyjuice\r\nrusqlite\r\n')" != $'tinyjuice\nrusqlite' ]]; then + echo "engine gate failed its CRLF cargo-tree self-test" >&2 + exit 1 +fi + +# Exact matching must detect backend engines, without rejecting the public +# ports or names that merely contain a forbidden package name. +for name in rusqlite libsqlite3-sys mongodb bson aws-sdk-s3 lapin amq-protocol sqlx redb sled rocksdb tinystoragedrivers-document tinystoragedrivers-kv tinystoragedrivers-blob tinystoragedrivers-queue tinystoragedrivers-secrets tinystoragedrivers-connect tinystoragedrivers; do + if ! printf '%s\n' "$name" | grep -xE "$engine_pattern" >/dev/null; then + echo "engine matcher missed package: $name" >&2 + exit 1 + fi +done +for name in tinyjuice tinyjuice-bus tinyjuice-drivers tinyjuice-module tinystoragedrivers-api tinystoragedrivers-busproxy tinystoragedrivers-testkit tinystoragedrivers-types not-tinystoragedrivers-document tinystoragedrivers-types-extra; do + if printf '%s\n' "$name" | grep -xE "$engine_pattern" >/dev/null; then + echo "engine matcher rejected allowed package name: $name" >&2 + exit 1 + fi +done + +libraries="$(cargo metadata --locked --format-version 1 --no-deps | python3 -c ' +import json, sys +metadata = json.load(sys.stdin) +members = set(metadata["workspace_members"]) +library_kinds = {"lib", "rlib", "cdylib", "dylib", "staticlib", "proc-macro"} +names = sorted({ + package["name"] + for package in metadata["packages"] + if package["id"] in members + and any(library_kinds.intersection(target["kind"]) for target in package["targets"]) +}) +print("\n".join(names)) +')" +if [[ -z "$libraries" ]]; then + echo "Cargo metadata found no workspace library targets" >&2 + exit 1 +fi + +while IFS= read -r package; do + package="$(strip_carriage_return "$package")" + [[ -n "$package" ]] || continue + for features in default all; do + args=(tree --locked -p "$package" -e normal,build --prefix none) + if [[ "$features" == all ]]; then + args+=(--all-features) + fi + tree="$(cargo "${args[@]}")" + names="$(tree_names "$tree")" + if ! printf '%s\n' "$names" | grep -Fx "$package" >/dev/null; then + echo "cargo tree for $package ($features) had no root package entry" >&2 + exit 1 + fi + forbidden="$(printf '%s\n' "$names" | grep -xE "$engine_pattern" || true)" + if [[ -n "$forbidden" ]]; then + printf 'engine dependencies found in %s (%s features):\n%s\n' "$package" "$features" "$forbidden" >&2 + exit 1 + fi + done +done <<< "$libraries" diff --git a/scripts/test-features.sh b/scripts/test-features.sh index 5b72f956..68dd6b02 100755 --- a/scripts/test-features.sh +++ b/scripts/test-features.sh @@ -4,6 +4,7 @@ cd "$(dirname "${BASH_SOURCE[0]}")/.." python3 scripts/test-e2e-version.py cargo test --locked --workspace cargo test --locked --workspace --all-features +scripts/check-engine-deps.sh case "${RUNNER_OS:-$(uname -s)}" in Windows|MINGW*|MSYS*|CYGWIN*) ;; *) python3 scripts/test-package-layout.py ;; From b8974e0308d845c3118ba3f293068bd5486bcf47 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 03:18:01 +0300 Subject: [PATCH 031/119] chore(deps): remove tinybus submodule This removes the tinybus submodule dependency from the project. This was done to simplify the repository structure and reduce external dependencies. Auto-committed-on: dragonfly --- vendor/tinybus | 1 - 1 file changed, 1 deletion(-) delete mode 160000 vendor/tinybus diff --git a/vendor/tinybus b/vendor/tinybus deleted file mode 160000 index 1f33d1be..00000000 --- a/vendor/tinybus +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 1f33d1be1901a2d44bfe674cd7cf294cf3848821 From f9395bcb3bb5576cdc885f5be5934ea9964ceb3e Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 03:21:49 +0300 Subject: [PATCH 032/119] chore(cli): add doc flag to tinyjuice binary This updates the Cargo configuration to explicitly set doc to false for the tinyjuice binary, which prevents unnecessary documentation generation during builds. Auto-committed-on: dragonfly --- crates/tinyjuice-cli/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/tinyjuice-cli/Cargo.toml b/crates/tinyjuice-cli/Cargo.toml index 40cd9c5b..434141ee 100644 --- a/crates/tinyjuice-cli/Cargo.toml +++ b/crates/tinyjuice-cli/Cargo.toml @@ -27,6 +27,7 @@ tinystoragedrivers-testkit = { version = "2.0.2", git = "https://github.com/sena [[bin]] name = "tinyjuice" path = "src/bin/tinyjuice.rs" +doc = false [[bin]] name = "tinyjuice-reduce" From 9bdb0a319ecb6cfe305abd5376fa3fe134af8fc4 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 03:22:56 +0300 Subject: [PATCH 033/119] docs: fix TinyJuice public rustdoc --- crates/tinyjuice-drivers/src/lib.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/crates/tinyjuice-drivers/src/lib.rs b/crates/tinyjuice-drivers/src/lib.rs index 46cc83d5..bc7ab067 100644 --- a/crates/tinyjuice-drivers/src/lib.rs +++ b/crates/tinyjuice-drivers/src/lib.rs @@ -7,12 +7,11 @@ //! host's choice, made when it builds the [`BlobStore`] handle. Nothing here //! names a database. //! -//! [`tinyjuice::cache::CcrStore`] is synchronous, so the store owns a -//! [`Blocking`] bridge that runs the port's futures on a dedicated runtime -//! thread. That works from inside or outside a tokio runtime. +//! [`tinyjuice::cache::CcrStore`] is synchronous, so the store uses a private +//! blocking bridge to run the port's futures on a dedicated runtime thread. +//! That works from inside or outside a tokio runtime. //! //! [`BlobStore`]: tinystoragedrivers_api::BlobStore -//! [`Blocking`]: crate::blocking::Blocking mod blob_store; mod blocking; From 1c643ce59add761bbce6871c25a416366a617faa Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 03:32:52 +0300 Subject: [PATCH 034/119] test: allow Windows mtime fixture updates --- crates/tinyjuice-cli/src/storage_tests.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/crates/tinyjuice-cli/src/storage_tests.rs b/crates/tinyjuice-cli/src/storage_tests.rs index b968d134..41b6fbcf 100644 --- a/crates/tinyjuice-cli/src/storage_tests.rs +++ b/crates/tinyjuice-cli/src/storage_tests.rs @@ -134,7 +134,9 @@ fn import_skips_directories_and_unrecognized_names_and_removes_expired_files() { let token = tinyjuice::cache::short_hash(content); let expired = dir.path().join(&token); std::fs::write(&expired, content).unwrap(); - std::fs::File::open(&expired) + std::fs::OpenOptions::new() + .write(true) + .open(&expired) .unwrap() .set_times(std::fs::FileTimes::new().set_modified(SystemTime::UNIX_EPOCH)) .unwrap(); @@ -161,7 +163,9 @@ fn import_uses_an_existing_backend_write_time_without_sidecars() { let source = dir.path().join(&token); std::fs::write(&source, content).unwrap(); let source_time = SystemTime::now() - Duration::from_secs(60); - std::fs::File::open(&source) + std::fs::OpenOptions::new() + .write(true) + .open(&source) .unwrap() .set_times(std::fs::FileTimes::new().set_modified(source_time)) .unwrap(); @@ -450,7 +454,9 @@ fn retry_after_timestamp_write_failure_preserves_the_source_file_age() { let source_path = dir.path().join(&token); std::fs::write(&source_path, content).unwrap(); let source_time = SystemTime::now() - Duration::from_secs(20); - std::fs::File::open(&source_path) + std::fs::OpenOptions::new() + .write(true) + .open(&source_path) .unwrap() .set_times(std::fs::FileTimes::new().set_modified(source_time)) .unwrap(); @@ -503,7 +509,9 @@ fn imports_released_v01010_disk_tier_file_and_preserves_its_age() { let source_path = dir.path().join(TOKEN); std::fs::write(&source_path, CONTENT).unwrap(); let source_time = SystemTime::now() - Duration::from_secs(5); - std::fs::File::open(&source_path) + std::fs::OpenOptions::new() + .write(true) + .open(&source_path) .unwrap() .set_times(std::fs::FileTimes::new().set_modified(source_time)) .unwrap(); From 7d0785828dc86a2f0724e33b8e6d00043e4ca7a1 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 14:35:59 +0300 Subject: [PATCH 035/119] test(savings_store): add test for import refusal leaving ledger unchanged Adds a new test case to verify that when a local import fails due to an unavailable error, the cached ledger state remains unmodified. This ensures data integrity even during storage write failures. Auto-committed-on: dragonfly --- .../src/savings_store_tests.rs | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/crates/tinyjuice-module/src/savings_store_tests.rs b/crates/tinyjuice-module/src/savings_store_tests.rs index 6d8156be..67581078 100644 --- a/crates/tinyjuice-module/src/savings_store_tests.rs +++ b/crates/tinyjuice-module/src/savings_store_tests.rs @@ -200,3 +200,56 @@ async fn an_import_whose_write_fails_is_an_error_leaves_totals_alone_and_can_ret let stored = flaky.get(SAVINGS_COLLECTION, SAVINGS_DOC_ID).await.unwrap(); assert_eq!(stored.unwrap().doc["total"]["events"], 3); } + +#[tokio::test] +async fn request_local_import_refusal_leaves_the_cached_ledger_unchanged() { + let backend = tinystoragedrivers_testkit::memory_backend(); + let ordinary = backend.for_scope(&Scope::new("ordinary").unwrap()).unwrap(); + let callback = backend.for_scope(&Scope::new("callback").unwrap()).unwrap(); + let faults = FaultPlan::new(); + faults.fail_operation_nth("documents.put", 1, ErrorKind::Unavailable); + let callback_docs = Arc::new(Failing::with_plan( + Arc::clone(callback.documents()), + faults, + )); + let callback_storage = tinystoragedrivers_api::Storage::new( + callback_docs.clone(), + Arc::clone(callback.streams()), + Arc::clone(callback.kv()), + Arc::clone(callback.blobs()), + Arc::clone(callback.queues()), + Arc::clone(callback.secrets()), + ); + let savings = Savings::new(); + { + let mut state = savings.state.lock().await; + state.docs = Some(Arc::clone(ordinary.documents())); + state.loaded = true; + } + let legacy = SavingsAggregate { + total: SavingsBucket { + events: 3, + original_tokens: 30, + compacted_tokens: 10, + tokens_saved: 20, + cost_saved_usd: 0.1, + }, + ..Default::default() + }; + + let failed = savings.import_at(&callback_storage, legacy).await; + assert!(failed.is_err()); + assert_eq!(savings.stats(None).await.total.events, 0); + assert!(ordinary + .documents() + .get(SAVINGS_COLLECTION, SAVINGS_DOC_ID) + .await + .unwrap() + .is_none()); + assert!(callback + .documents() + .get(SAVINGS_COLLECTION, SAVINGS_DOC_ID) + .await + .unwrap() + .is_none()); +} From 69766cb14544b6edbb13af02f866c3e35fbe7479 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 14:36:46 +0300 Subject: [PATCH 036/119] feat(savings_store): add import_at method for legacy snapshot adoption This introduces the `import_at` method to allow adopting a legacy savings snapshot via a temporary storage handle. This is useful for claim-bound imports where the storage handle is only valid for the duration of the call. Auto-committed-on: dragonfly --- crates/tinyjuice-module/src/savings_store.rs | 50 +++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/crates/tinyjuice-module/src/savings_store.rs b/crates/tinyjuice-module/src/savings_store.rs index 275b8586..6f1a49b8 100644 --- a/crates/tinyjuice-module/src/savings_store.rs +++ b/crates/tinyjuice-module/src/savings_store.rs @@ -13,7 +13,7 @@ use tinyjuice_bus::savings::{ RecordSavingsRequest, SAVINGS_DOC_ID, SavingsAggregate, StoredSavings, }; use tinyjuice_bus::storage::SAVINGS_COLLECTION; -use tinystoragedrivers_api::{DocumentStore, DocumentStoreExt}; +use tinystoragedrivers_api::{DocumentStore, DocumentStoreExt, Storage}; use tinystoragedrivers_types::Precondition; /// Working state behind one lock, so load, change and write never interleave. @@ -108,6 +108,54 @@ impl Savings { Ok(true) } + /// Adopt a legacy snapshot through a storage handle supplied for this one + /// call. This handle is deliberately not cached in `State`: hosts use it + /// for claim-bound imports, and its authority ends when the call returns. + pub(crate) async fn import_at( + &self, + storage: &Storage, + legacy: SavingsAggregate, + ) -> BusResult { + let mut state = self.state.lock().await; + let docs = storage.documents(); + let stored = docs + .get_as::(SAVINGS_COLLECTION, SAVINGS_DOC_ID) + .await + .map_err(|error| tinybus::Error::failed(format!("savings could not be read: {error}")))?; + if stored.is_some_and(|stored| stored.doc.total.events != 0) + || self.ledger.stats().total.events != 0 + { + log::debug!("[tinyjuice_module][savings] import skipped: totals exist"); + return Ok(false); + } + + let previous = self.ledger.stats(); + self.ledger.replace(legacy); + let body = StoredSavings::from_aggregate(&self.ledger.stats(), now_ms()); + if let Err(error) = docs + .put_as( + SAVINGS_COLLECTION, + SAVINGS_DOC_ID, + &body, + Precondition::None, + ) + .await + { + self.ledger.replace(previous); + return Err(tinybus::Error::failed(format!( + "savings could not be written: {error}" + ))); + } + + // The document is now authoritative, even if this module has not yet + // connected its ordinary long-lived storage port. Do not retain the + // invocation-scoped handle in `state.docs`. + state.loaded = true; + state.dirty = false; + state.reset_early = false; + Ok(true) + } + /// Reach the document port and reconcile the ledger with its document. /// /// Changes made before the document could be read are kept: they are From 033a61c436afec1c8aae244de1be4ac9fe636983 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 14:40:30 +0300 Subject: [PATCH 037/119] feat(bus): add import savings at method and contract v3.1 Introduces the `ImportSavingsAt` method to support importing legacy savings snapshots via a temporary callback storage. This change updates the contract version to 3.1 to reflect this new capability. Auto-committed-on: dragonfly --- crates/tinyjuice-bus/src/lib_tests.rs | 2 +- crates/tinyjuice-bus/src/names.rs | 4 ++ crates/tinyjuice-bus/src/savings.rs | 24 +++++++++ crates/tinyjuice-bus/src/version.rs | 8 +-- .../src/savings_store_tests.rs | 52 +++++++++++++++++++ 5 files changed, 86 insertions(+), 4 deletions(-) diff --git a/crates/tinyjuice-bus/src/lib_tests.rs b/crates/tinyjuice-bus/src/lib_tests.rs index 2940a342..109683bf 100644 --- a/crates/tinyjuice-bus/src/lib_tests.rs +++ b/crates/tinyjuice-bus/src/lib_tests.rs @@ -4,7 +4,7 @@ use super::*; #[test] fn the_contract_accepts_newer_minors_and_rejects_the_breaking_v2_contract() { - assert_eq!(CONTRACT_VERSION, (3, 0)); + assert_eq!(CONTRACT_VERSION, (3, 1)); assert!(is_compatible(CONTRACT_VERSION)); assert!(is_compatible((3, 1))); assert!( diff --git a/crates/tinyjuice-bus/src/names.rs b/crates/tinyjuice-bus/src/names.rs index 13de1295..e554f054 100644 --- a/crates/tinyjuice-bus/src/names.rs +++ b/crates/tinyjuice-bus/src/names.rs @@ -52,6 +52,9 @@ pub mod methods { /// when the module has recorded nothing yet; answers whether it took it. /// Added in contract 2.3. pub const IMPORT_SAVINGS: &str = "ImportSavings"; + /// Adopts legacy totals through an invocation-scoped host storage callback. + /// Added in contract 3.1. + pub const IMPORT_SAVINGS_AT: &str = "ImportSavingsAt"; /// Reports what the cache is holding. pub const CACHE_STATS: &str = "CacheStats"; } @@ -83,4 +86,5 @@ pub const METHODS: &[&str] = &[ methods::SAVINGS_STATS, methods::RESET_SAVINGS, methods::IMPORT_SAVINGS, + methods::IMPORT_SAVINGS_AT, ]; diff --git a/crates/tinyjuice-bus/src/savings.rs b/crates/tinyjuice-bus/src/savings.rs index 6b6dcb9e..4fee48cc 100644 --- a/crates/tinyjuice-bus/src/savings.rs +++ b/crates/tinyjuice-bus/src/savings.rs @@ -31,6 +31,30 @@ pub struct SavingsAggregate { pub by_compressor: HashMap, } +/// A callback storage endpoint that a host grants for one import invocation. +/// +/// The host name must be the unique name of the attested callback connection; +/// `object_root` must identify that invocation's isolated object subtree. The +/// address contains no storage policy or write condition. +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] +pub struct StorageCallbackAddress { + /// Unique TinyBus name serving this callback. + pub host: String, + /// Per-invocation TinyBus object root served by `host`. + pub object_root: String, +} + +/// A savings snapshot plus a temporary callback destination for adoption. +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] +pub struct ImportSavingsAtRequest { + /// The legacy savings snapshot to adopt if the destination has no totals. + pub aggregate: SavingsAggregate, + /// Host-created callback authority, valid only while the import call runs. + pub callback: StorageCallbackAddress, +} + /// One compaction attributed to the model that would consume its output. #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] diff --git a/crates/tinyjuice-bus/src/version.rs b/crates/tinyjuice-bus/src/version.rs index 6b63d954..f01cdad0 100644 --- a/crates/tinyjuice-bus/src/version.rs +++ b/crates/tinyjuice-bus/src/version.rs @@ -2,9 +2,11 @@ /// The wire contract version this crate defines. /// Version 3 removes the host-provided disk path and replaces it with an -/// explicit host-durability capability. Version 2 hosts must be rejected so -/// their old `diskTierRoot` request cannot silently lose its persistence. -pub const CONTRACT_VERSION: (u32, u32) = (3, 0); +/// explicit host-durability capability. Minor version 1 adds the +/// invocation-scoped savings-import callback while retaining the old import +/// method. Version 2 hosts must be rejected so their old `diskTierRoot` +/// request cannot silently lose its persistence. +pub const CONTRACT_VERSION: (u32, u32) = (3, 1); /// Returns whether a host using [`CONTRACT_VERSION`] can bind to `module`. /// diff --git a/crates/tinyjuice-module/src/savings_store_tests.rs b/crates/tinyjuice-module/src/savings_store_tests.rs index 67581078..2954a368 100644 --- a/crates/tinyjuice-module/src/savings_store_tests.rs +++ b/crates/tinyjuice-module/src/savings_store_tests.rs @@ -253,3 +253,55 @@ async fn request_local_import_refusal_leaves_the_cached_ledger_unchanged() { .unwrap() .is_none()); } + +#[tokio::test] +async fn request_local_import_uses_the_call_storage_without_caching_it() { + let backend = tinystoragedrivers_testkit::memory_backend(); + let ordinary = backend.for_scope(&Scope::new("local").unwrap()).unwrap(); + let ordinary_docs = Arc::clone(ordinary.documents()); + let callback_docs = Arc::new(Failing::with_plan( + Arc::clone(&ordinary_docs), + FaultPlan::new(), + )); + let callback_storage = tinystoragedrivers_api::Storage::new( + callback_docs, + Arc::clone(ordinary.streams()), + Arc::clone(ordinary.kv()), + Arc::clone(ordinary.blobs()), + Arc::clone(ordinary.queues()), + Arc::clone(ordinary.secrets()), + ); + let savings = Savings::new(); + { + let mut state = savings.state.lock().await; + state.docs = Some(Arc::clone(&ordinary_docs)); + state.loaded = true; + } + let legacy = SavingsAggregate { + total: SavingsBucket { + events: 2, + original_tokens: 18, + compacted_tokens: 8, + tokens_saved: 10, + cost_saved_usd: 0.25, + }, + ..Default::default() + }; + + assert!(savings.import_at(&callback_storage, legacy).await.unwrap()); + assert_eq!( + ordinary_docs + .get(SAVINGS_COLLECTION, SAVINGS_DOC_ID) + .await + .unwrap() + .unwrap() + .doc["total"]["tokens_saved"], + 10 + ); + assert_eq!(savings.stats(None).await.total.events, 2); + let state = savings.state.lock().await; + assert!(Arc::ptr_eq( + state.docs.as_ref().expect("ordinary port remains cached"), + &ordinary_docs, + )); +} From 7759ee6cadc782be3e9d99572d3b83c663d15dde Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 14:41:08 +0300 Subject: [PATCH 038/119] refactor(savings): remove PartialEq derive from ImportSavingsAtRequest The PartialEq derive was removed from ImportSavingsAtRequest as it was not strictly necessary for the current usage patterns. This change simplifies the struct definition without altering its core behavior. Auto-committed-on: dragonfly --- crates/tinyjuice-bus/src/savings.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/tinyjuice-bus/src/savings.rs b/crates/tinyjuice-bus/src/savings.rs index 4fee48cc..09c07674 100644 --- a/crates/tinyjuice-bus/src/savings.rs +++ b/crates/tinyjuice-bus/src/savings.rs @@ -46,7 +46,7 @@ pub struct StorageCallbackAddress { } /// A savings snapshot plus a temporary callback destination for adoption. -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize)] #[serde(deny_unknown_fields)] pub struct ImportSavingsAtRequest { /// The legacy savings snapshot to adopt if the destination has no totals. From 1bf35766b763972be992bee6aa1d551734b7bd62 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 14:42:11 +0300 Subject: [PATCH 039/119] fix(savings_store): improve savings import concurrency safety This change updates the savings import logic to use a version precondition when updating the savings document. This prevents a concurrent normal savings write from being overwritten by this legacy snapshot during the read-modify-write operation. Auto-committed-on: dragonfly --- crates/tinyjuice-module/src/savings_store.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/crates/tinyjuice-module/src/savings_store.rs b/crates/tinyjuice-module/src/savings_store.rs index 6f1a49b8..2f462fb4 100644 --- a/crates/tinyjuice-module/src/savings_store.rs +++ b/crates/tinyjuice-module/src/savings_store.rs @@ -122,13 +122,22 @@ impl Savings { .get_as::(SAVINGS_COLLECTION, SAVINGS_DOC_ID) .await .map_err(|error| tinybus::Error::failed(format!("savings could not be read: {error}")))?; - if stored.is_some_and(|stored| stored.doc.total.events != 0) + if stored + .as_ref() + .is_some_and(|stored| stored.doc.total.events != 0) || self.ledger.stats().total.events != 0 { log::debug!("[tinyjuice_module][savings] import skipped: totals exist"); return Ok(false); } + // Import is a read-modify-write operation. Preserve the observed + // document version (or absence) so a concurrent normal savings write + // cannot be overwritten by this legacy snapshot. + let precondition = stored.map_or(Precondition::Absent, |stored| { + Precondition::Version(stored.version) + }); + let previous = self.ledger.stats(); self.ledger.replace(legacy); let body = StoredSavings::from_aggregate(&self.ledger.stats(), now_ms()); @@ -137,7 +146,7 @@ impl Savings { SAVINGS_COLLECTION, SAVINGS_DOC_ID, &body, - Precondition::None, + precondition, ) .await { From 00333a2f863f9ebd085884a430e568c82685a48a Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 14:43:14 +0300 Subject: [PATCH 040/119] fix(savings_store): enforce storage readiness before import The import_at method now checks if the savings storage has been loaded and has documents before proceeding with the import. This prevents attempts to read storage that is not yet initialized, improving robustness. Auto-committed-on: dragonfly --- crates/tinyjuice-module/src/savings_store.rs | 12 +++++++++--- crates/tinyjuice-module/src/savings_store_tests.rs | 7 +++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/crates/tinyjuice-module/src/savings_store.rs b/crates/tinyjuice-module/src/savings_store.rs index 2f462fb4..04ffc313 100644 --- a/crates/tinyjuice-module/src/savings_store.rs +++ b/crates/tinyjuice-module/src/savings_store.rs @@ -113,10 +113,17 @@ impl Savings { /// for claim-bound imports, and its authority ends when the call returns. pub(crate) async fn import_at( &self, + connection: Option<&Connection>, storage: &Storage, legacy: SavingsAggregate, ) -> BusResult { let mut state = self.state.lock().await; + self.load(&mut state, connection).await; + if !state.loaded || state.docs.is_none() { + return Err(tinybus::Error::failed( + "savings storage is not readable yet", + )); + } let docs = storage.documents(); let stored = docs .get_as::(SAVINGS_COLLECTION, SAVINGS_DOC_ID) @@ -156,9 +163,8 @@ impl Savings { ))); } - // The document is now authoritative, even if this module has not yet - // connected its ordinary long-lived storage port. Do not retain the - // invocation-scoped handle in `state.docs`. + // The document is now authoritative through the ordinary port already + // held by this state. Never retain the invocation-scoped handle. state.loaded = true; state.dirty = false; state.reset_early = false; diff --git a/crates/tinyjuice-module/src/savings_store_tests.rs b/crates/tinyjuice-module/src/savings_store_tests.rs index 2954a368..53a4a40e 100644 --- a/crates/tinyjuice-module/src/savings_store_tests.rs +++ b/crates/tinyjuice-module/src/savings_store_tests.rs @@ -237,7 +237,7 @@ async fn request_local_import_refusal_leaves_the_cached_ledger_unchanged() { ..Default::default() }; - let failed = savings.import_at(&callback_storage, legacy).await; + let failed = savings.import_at(None, &callback_storage, legacy).await; assert!(failed.is_err()); assert_eq!(savings.stats(None).await.total.events, 0); assert!(ordinary @@ -288,7 +288,10 @@ async fn request_local_import_uses_the_call_storage_without_caching_it() { ..Default::default() }; - assert!(savings.import_at(&callback_storage, legacy).await.unwrap()); + assert!(savings + .import_at(None, &callback_storage, legacy) + .await + .unwrap()); assert_eq!( ordinary_docs .get(SAVINGS_COLLECTION, SAVINGS_DOC_ID) From 9927d80814a18dfeb0b4b35282feed7456f8bef8 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 14:43:23 +0300 Subject: [PATCH 041/119] refactor(savings_store): clean up savings store implementation This refactoring cleans up some boilerplate in the savings store logic, including simplifying error handling and removing unnecessary wrapping in `put_as`. Corresponding tests have been updated to reflect these changes. Auto-committed-on: dragonfly --- crates/tinyjuice-module/src/savings_store.rs | 11 ++--- .../src/savings_store_tests.rs | 43 ++++++++++--------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/crates/tinyjuice-module/src/savings_store.rs b/crates/tinyjuice-module/src/savings_store.rs index 04ffc313..e202561b 100644 --- a/crates/tinyjuice-module/src/savings_store.rs +++ b/crates/tinyjuice-module/src/savings_store.rs @@ -128,7 +128,9 @@ impl Savings { let stored = docs .get_as::(SAVINGS_COLLECTION, SAVINGS_DOC_ID) .await - .map_err(|error| tinybus::Error::failed(format!("savings could not be read: {error}")))?; + .map_err(|error| { + tinybus::Error::failed(format!("savings could not be read: {error}")) + })?; if stored .as_ref() .is_some_and(|stored| stored.doc.total.events != 0) @@ -149,12 +151,7 @@ impl Savings { self.ledger.replace(legacy); let body = StoredSavings::from_aggregate(&self.ledger.stats(), now_ms()); if let Err(error) = docs - .put_as( - SAVINGS_COLLECTION, - SAVINGS_DOC_ID, - &body, - precondition, - ) + .put_as(SAVINGS_COLLECTION, SAVINGS_DOC_ID, &body, precondition) .await { self.ledger.replace(previous); diff --git a/crates/tinyjuice-module/src/savings_store_tests.rs b/crates/tinyjuice-module/src/savings_store_tests.rs index 53a4a40e..628a4894 100644 --- a/crates/tinyjuice-module/src/savings_store_tests.rs +++ b/crates/tinyjuice-module/src/savings_store_tests.rs @@ -208,10 +208,7 @@ async fn request_local_import_refusal_leaves_the_cached_ledger_unchanged() { let callback = backend.for_scope(&Scope::new("callback").unwrap()).unwrap(); let faults = FaultPlan::new(); faults.fail_operation_nth("documents.put", 1, ErrorKind::Unavailable); - let callback_docs = Arc::new(Failing::with_plan( - Arc::clone(callback.documents()), - faults, - )); + let callback_docs = Arc::new(Failing::with_plan(Arc::clone(callback.documents()), faults)); let callback_storage = tinystoragedrivers_api::Storage::new( callback_docs.clone(), Arc::clone(callback.streams()), @@ -240,18 +237,22 @@ async fn request_local_import_refusal_leaves_the_cached_ledger_unchanged() { let failed = savings.import_at(None, &callback_storage, legacy).await; assert!(failed.is_err()); assert_eq!(savings.stats(None).await.total.events, 0); - assert!(ordinary - .documents() - .get(SAVINGS_COLLECTION, SAVINGS_DOC_ID) - .await - .unwrap() - .is_none()); - assert!(callback - .documents() - .get(SAVINGS_COLLECTION, SAVINGS_DOC_ID) - .await - .unwrap() - .is_none()); + assert!( + ordinary + .documents() + .get(SAVINGS_COLLECTION, SAVINGS_DOC_ID) + .await + .unwrap() + .is_none() + ); + assert!( + callback + .documents() + .get(SAVINGS_COLLECTION, SAVINGS_DOC_ID) + .await + .unwrap() + .is_none() + ); } #[tokio::test] @@ -288,10 +289,12 @@ async fn request_local_import_uses_the_call_storage_without_caching_it() { ..Default::default() }; - assert!(savings - .import_at(None, &callback_storage, legacy) - .await - .unwrap()); + assert!( + savings + .import_at(None, &callback_storage, legacy) + .await + .unwrap() + ); assert_eq!( ordinary_docs .get(SAVINGS_COLLECTION, SAVINGS_DOC_ID) From de3faa610a4ce5642efd40d41a74a007a6b0e072 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 14:44:28 +0300 Subject: [PATCH 042/119] test(lib): add test for request local savings import address descriptor Adds a new test case to verify that the request local savings import address correctly serializes and deserializes, ensuring the transport-only descriptor is maintained. Auto-committed-on: dragonfly --- crates/tinyjuice-bus/src/lib_tests.rs | 31 +++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/crates/tinyjuice-bus/src/lib_tests.rs b/crates/tinyjuice-bus/src/lib_tests.rs index 109683bf..55eb8df2 100644 --- a/crates/tinyjuice-bus/src/lib_tests.rs +++ b/crates/tinyjuice-bus/src/lib_tests.rs @@ -73,6 +73,37 @@ fn the_wire_envelopes_keep_their_json_contract() { ); } +#[test] +fn request_local_savings_import_address_is_a_transport_only_descriptor() { + use savings::{ImportSavingsAtRequest, SavingsAggregate, StorageCallbackAddress}; + + let request = ImportSavingsAtRequest { + aggregate: SavingsAggregate::default(), + callback: StorageCallbackAddress { + host: ":1.42".to_owned(), + object_root: "/ai/tinyhumans/tinystorage/Invocation/abc".to_owned(), + }, + }; + let encoded = serde_json::to_value(&request).unwrap(); + assert_eq!(encoded["callback"]["host"], ":1.42"); + assert_eq!( + encoded["callback"]["object_root"], + "/ai/tinyhumans/tinystorage/Invocation/abc" + ); + let decoded: ImportSavingsAtRequest = serde_json::from_value(encoded.clone()).unwrap(); + assert_eq!(decoded.callback.host, ":1.42"); + assert_eq!( + decoded.callback.object_root, + "/ai/tinyhumans/tinystorage/Invocation/abc" + ); + assert!(serde_json::from_value::({ + let mut value = encoded; + value["callback"]["write_condition"] = serde_json::json!("must-not-cross-the-bus"); + value + }) + .is_err()); +} + #[test] fn compress_options_round_trip_through_their_defaults() { // `CompressOptions` is `#[serde(default)]`, which is what lets a host send From d3c432b452854935ee2231abd39e634b79e26577 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 15:03:40 +0300 Subject: [PATCH 043/119] docs(specs): document ImportSavingsAt for contract 3.1 Adds the ImportSavingsAt member to the tinybus module spec, describing how a legacy savings snapshot is adopted through a temporary storage callback address and written with an absent/version precondition. The savings section heading is bumped to contract 3.1 to match. Auto-committed-on: dragonfly --- docs/specs/tinybus-module.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/specs/tinybus-module.md b/docs/specs/tinybus-module.md index 5e7b49ba..7e9b5237 100644 --- a/docs/specs/tinybus-module.md +++ b/docs/specs/tinybus-module.md @@ -111,7 +111,7 @@ narrow these values but cannot enlarge the module's stock ceilings. Grep keeps matching lines before allocating remaining context slots. An explicit summary `max_chars` also bounds a model-failure notice combined with its overview. -## Model-attributed savings (contract 2.1) +## Model-attributed savings (contract 3.1) The module owns aggregation and persistence. Since contract 2.3 the totals are one document, `juice.savings/totals` (snake_case body, `updated_ms`), in the @@ -124,6 +124,13 @@ link only `tinyjuice-bus::savings` and call these members: - `ImportSavings(SavingsAggregate) -> bool` (2.3) adopts a legacy camelCase snapshot the host read from its old file, only while nothing has been recorded; `false` means totals already existed and nothing changed. +- `ImportSavingsAt(ImportSavingsAtRequest) -> bool` (3.1) adopts that snapshot + through the request's temporary `StorageCallbackAddress` (`host` plus a + per-invocation `object_root`). The module opens the callback only for this + call and writes `juice.savings/totals` with an absent/version precondition; + an existing total or a concurrent writer wins. The normal module storage + provider and cached handles are unchanged. The host revokes the callback + after the call, so retries must create a new address. - `RecordSavings(RecordSavingsRequest) -> ()` records a positive token saving. The host supplies the attribution model, compressor identifier, pre/post token estimates, and its catalog lookup of the input price per million From 209bbdd435d3a3f631ac6972c4b57ad1e2f7e30a Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 16:37:04 +0300 Subject: [PATCH 044/119] feat(module): add request-scoped savings import Add an ImportSavingsAt method that adopts legacy savings totals through a host callback address supplied with the request, so the callback storage is used only for that invocation and never installed as the module's ordinary store. A test covers the new path and asserts the normal port is left untouched. Auto-committed-on: dragonfly --- crates/tinyjuice-module/src/service.rs | 27 +++++- crates/tinyjuice-module/src/service_tests.rs | 98 ++++++++++++++++++++ 2 files changed, 124 insertions(+), 1 deletion(-) diff --git a/crates/tinyjuice-module/src/service.rs b/crates/tinyjuice-module/src/service.rs index cfc6fd26..3f6f5187 100644 --- a/crates/tinyjuice-module/src/service.rs +++ b/crates/tinyjuice-module/src/service.rs @@ -10,6 +10,7 @@ use tinyjuice::types::{AgentTokenjuiceCompression, CompressedOutput, ContentHint // exists to remove. use tinyjuice::tool_integration::ToolOutputCall; use tinyjuice_bus::names::ml_host; +use tinyjuice_bus::savings::ImportSavingsAtRequest; pub use tinyjuice_bus::names::{BUS_NAME, ML_HOST_NAME, ML_HOST_PATH, OBJECT_PATH}; use tinyjuice_bus::wire::{ CacheStats, CompactRequest, CompactResponse, GenerateRequest, InstallRequest, @@ -220,6 +221,29 @@ impl Compression { ) -> BusResult { savings().import(self.connection.as_ref(), legacy).await } + + /// Adopt legacy totals through a host callback scoped to this invocation. + /// The callback handle is never installed as the module's ordinary store. + async fn import_savings_at(&self, request: ImportSavingsAtRequest) -> BusResult { + let connection = self.connection.as_ref().ok_or_else(|| { + tinybus::Error::failed("request-scoped savings storage is unavailable") + })?; + let host = tinybus::BusName::new(request.callback.host) + .map_err(|error| tinybus::Error::failed(error.to_string()))?; + let object_root = tinybus::ObjectPath::new(request.callback.object_root) + .map_err(|error| tinybus::Error::failed(error.to_string()))?; + let address = tinystoragedrivers_busproxy::StorageAddress::try_new(host, object_root) + .map_err(|error| tinybus::Error::failed(error.to_string()))?; + let storage = tinystoragedrivers_busproxy::connect_storage_at_address( + connection.clone(), + address, + ) + .await + .map_err(|error| tinybus::Error::failed(error.to_string()))?; + savings() + .import_at(Some(connection), &storage, request.aggregate) + .await + } } /// Requests may narrow a budget but never expand the module's stock ceilings. @@ -340,7 +364,8 @@ pub(crate) mod exports { "RecordSavings", "SavingsStats", "ResetSavings", - "ImportSavings" + "ImportSavings", + "ImportSavingsAt" ], signals = [], requires = [], diff --git a/crates/tinyjuice-module/src/service_tests.rs b/crates/tinyjuice-module/src/service_tests.rs index 230ea314..694721fb 100644 --- a/crates/tinyjuice-module/src/service_tests.rs +++ b/crates/tinyjuice-module/src/service_tests.rs @@ -363,3 +363,101 @@ async fn setup_serves_detection_and_forwards_model_calls_to_the_host() { tinyjuice::llm::configure_callback(None); broker_task.abort(); } + +#[tokio::test] +async fn import_savings_at_uses_only_its_request_scoped_storage_address() { + let _install = crate::storage::tests::INSTALL.lock().await; + use tinybus::broker::Broker; + use tinybus::transport::memory::MemoryBus; + use tinyjuice_bus::savings::{ImportSavingsAtRequest, SavingsAggregate, StorageCallbackAddress}; + use tinystoragedrivers_api::StorageBackend; + use tinystoragedrivers_busproxy::{ + INVOCATION_OBJECT_ROOT, PerCallerEndpoint, StorageAddress, StorageServer, + serve, serve_at_address, + }; + use tinystoragedrivers_testkit::MemoryBackend; + use tinystoragedrivers_types::Scope; + use tinyjuice_bus::storage::SAVINGS_COLLECTION; + use tinyjuice_bus::savings::SAVINGS_DOC_ID; + + let bus = MemoryBus::new(); + let broker_task = Broker::new().spawn(bus.clone()); + let host = Connection::connect(bus.connect().await.unwrap()) + .await + .unwrap(); + let backend = Arc::new(MemoryBackend::new()); + let ordinary_backend: Arc = backend.clone(); + let ordinary = ordinary_backend + .for_scope(&Scope::new("ordinary").unwrap()) + .unwrap(); + let ordinary_backend = Arc::clone(&ordinary_backend); + let ordinary_endpoint = PerCallerEndpoint::new(move |_| { + let storage = ordinary_backend + .for_scope(&Scope::new("ordinary").ok()?) + .ok()?; + Some(StorageServer::new(storage)) + }); + let _ordinary_server = serve(&host, Arc::new(ordinary_endpoint)).await.unwrap(); + + let callback_backend: Arc = backend; + let callback_scope = Scope::new("invocation").unwrap(); + let callback = callback_backend.for_scope(&callback_scope).unwrap(); + let callback_docs = Arc::clone(callback.documents()); + let address = StorageAddress::try_new( + host.unique_name().unwrap(), + tinybus::ObjectPath::new(format!("{INVOCATION_OBJECT_ROOT}/juice_test")).unwrap(), + ) + .unwrap(); + let _callback_server = serve_at_address( + &host, + address.clone(), + Arc::new(StorageServer::new(callback)), + ) + .await + .unwrap(); + + let module = Connection::connect(bus.connect().await.unwrap()) + .await + .unwrap(); + let module_for_setup = module.clone(); + setup(module_for_setup).await.unwrap(); + let proxy = host.proxy(BUS_NAME, OBJECT_PATH, BUS_NAME).unwrap(); + let _: SavingsAggregate = proxy.call("SavingsStats", ()).await.unwrap(); + let aggregate = SavingsAggregate { + total: tinyjuice_bus::savings::SavingsBucket { + events: 2, + original_tokens: 20, + compacted_tokens: 8, + tokens_saved: 12, + cost_saved_usd: 0.25, + }, + ..Default::default() + }; + let imported: bool = proxy + .call( + "ImportSavingsAt", + (ImportSavingsAtRequest { + aggregate, + callback: StorageCallbackAddress { + host: address.host().to_string(), + object_root: address.object_root().to_string(), + }, + },), + ) + .await + .unwrap(); + assert!(imported); + + let stored = ordinary + .documents() + .get(SAVINGS_COLLECTION, SAVINGS_DOC_ID) + .await + .unwrap(); + assert!(stored.is_none(), "the request port does not replace the normal port"); + assert!(callback_docs + .get(SAVINGS_COLLECTION, SAVINGS_DOC_ID) + .await + .unwrap() + .is_some()); + broker_task.abort(); +} From d995c8d1f0e7e1d7601133a14d7289a9f8111b40 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 16:38:33 +0300 Subject: [PATCH 045/119] refactor(module): extract request-scoped savings import into a helper The import_savings_at method now delegates to a free function that takes the savings store and connection explicitly, so the same logic can be exercised directly in tests without going through the bus proxy. The test was reworked to call that helper and to build its own savings store instead of installing a global one. Auto-committed-on: dragonfly --- crates/tinyjuice-module/src/service.rs | 44 ++++++----- crates/tinyjuice-module/src/service_tests.rs | 83 ++++++++++---------- 2 files changed, 68 insertions(+), 59 deletions(-) diff --git a/crates/tinyjuice-module/src/service.rs b/crates/tinyjuice-module/src/service.rs index 3f6f5187..d886b2f9 100644 --- a/crates/tinyjuice-module/src/service.rs +++ b/crates/tinyjuice-module/src/service.rs @@ -10,8 +10,8 @@ use tinyjuice::types::{AgentTokenjuiceCompression, CompressedOutput, ContentHint // exists to remove. use tinyjuice::tool_integration::ToolOutputCall; use tinyjuice_bus::names::ml_host; -use tinyjuice_bus::savings::ImportSavingsAtRequest; pub use tinyjuice_bus::names::{BUS_NAME, ML_HOST_NAME, ML_HOST_PATH, OBJECT_PATH}; +use tinyjuice_bus::savings::ImportSavingsAtRequest; use tinyjuice_bus::wire::{ CacheStats, CompactRequest, CompactResponse, GenerateRequest, InstallRequest, RangeUnit as WireRangeUnit, RetrieveRange, @@ -225,24 +225,7 @@ impl Compression { /// Adopt legacy totals through a host callback scoped to this invocation. /// The callback handle is never installed as the module's ordinary store. async fn import_savings_at(&self, request: ImportSavingsAtRequest) -> BusResult { - let connection = self.connection.as_ref().ok_or_else(|| { - tinybus::Error::failed("request-scoped savings storage is unavailable") - })?; - let host = tinybus::BusName::new(request.callback.host) - .map_err(|error| tinybus::Error::failed(error.to_string()))?; - let object_root = tinybus::ObjectPath::new(request.callback.object_root) - .map_err(|error| tinybus::Error::failed(error.to_string()))?; - let address = tinystoragedrivers_busproxy::StorageAddress::try_new(host, object_root) - .map_err(|error| tinybus::Error::failed(error.to_string()))?; - let storage = tinystoragedrivers_busproxy::connect_storage_at_address( - connection.clone(), - address, - ) - .await - .map_err(|error| tinybus::Error::failed(error.to_string()))?; - savings() - .import_at(Some(connection), &storage, request.aggregate) - .await + import_savings_at(savings(), self.connection.as_ref(), request).await } } @@ -383,3 +366,26 @@ fn savings() -> &'static crate::savings_store::Savings { static SAVINGS: std::sync::OnceLock = std::sync::OnceLock::new(); SAVINGS.get_or_init(crate::savings_store::Savings::new) } + +/// Perform an import through a callback port without caching that port. +async fn import_savings_at( + savings: &crate::savings_store::Savings, + connection: Option<&Connection>, + request: ImportSavingsAtRequest, +) -> BusResult { + let connection = connection + .ok_or_else(|| tinybus::Error::failed("request-scoped savings storage is unavailable"))?; + let host = tinybus::BusName::new(request.callback.host) + .map_err(|error| tinybus::Error::failed(error.to_string()))?; + let object_root = tinybus::ObjectPath::new(request.callback.object_root) + .map_err(|error| tinybus::Error::failed(error.to_string()))?; + let address = tinystoragedrivers_busproxy::StorageAddress::try_new(host, object_root) + .map_err(|error| tinybus::Error::failed(error.to_string()))?; + let storage = + tinystoragedrivers_busproxy::connect_storage_at_address(connection.clone(), address) + .await + .map_err(|error| tinybus::Error::failed(error.to_string()))?; + savings + .import_at(Some(connection), &storage, request.aggregate) + .await +} diff --git a/crates/tinyjuice-module/src/service_tests.rs b/crates/tinyjuice-module/src/service_tests.rs index 694721fb..b71e5888 100644 --- a/crates/tinyjuice-module/src/service_tests.rs +++ b/crates/tinyjuice-module/src/service_tests.rs @@ -366,19 +366,20 @@ async fn setup_serves_detection_and_forwards_model_calls_to_the_host() { #[tokio::test] async fn import_savings_at_uses_only_its_request_scoped_storage_address() { - let _install = crate::storage::tests::INSTALL.lock().await; use tinybus::broker::Broker; use tinybus::transport::memory::MemoryBus; - use tinyjuice_bus::savings::{ImportSavingsAtRequest, SavingsAggregate, StorageCallbackAddress}; + use tinyjuice_bus::savings::{ + ImportSavingsAtRequest, SAVINGS_DOC_ID, SavingsAggregate, SavingsBucket, + StorageCallbackAddress, + }; + use tinyjuice_bus::storage::SAVINGS_COLLECTION; use tinystoragedrivers_api::StorageBackend; use tinystoragedrivers_busproxy::{ - INVOCATION_OBJECT_ROOT, PerCallerEndpoint, StorageAddress, StorageServer, - serve, serve_at_address, + INVOCATION_OBJECT_ROOT, PerCallerEndpoint, StorageAddress, StorageServer, serve, + serve_at_address, }; use tinystoragedrivers_testkit::MemoryBackend; use tinystoragedrivers_types::Scope; - use tinyjuice_bus::storage::SAVINGS_COLLECTION; - use tinyjuice_bus::savings::SAVINGS_DOC_ID; let bus = MemoryBus::new(); let broker_task = Broker::new().spawn(bus.clone()); @@ -387,19 +388,16 @@ async fn import_savings_at_uses_only_its_request_scoped_storage_address() { .unwrap(); let backend = Arc::new(MemoryBackend::new()); let ordinary_backend: Arc = backend.clone(); - let ordinary = ordinary_backend - .for_scope(&Scope::new("ordinary").unwrap()) - .unwrap(); - let ordinary_backend = Arc::clone(&ordinary_backend); - let ordinary_endpoint = PerCallerEndpoint::new(move |_| { - let storage = ordinary_backend - .for_scope(&Scope::new("ordinary").ok()?) - .ok()?; - Some(StorageServer::new(storage)) + let ordinary_endpoint = PerCallerEndpoint::new({ + let backend = Arc::clone(&ordinary_backend); + move |_| { + let storage = backend.for_scope(&Scope::new("ordinary").ok()?).ok()?; + Some(StorageServer::new(storage)) + } }); let _ordinary_server = serve(&host, Arc::new(ordinary_endpoint)).await.unwrap(); - let callback_backend: Arc = backend; + let callback_backend: Arc = backend.clone(); let callback_scope = Scope::new("invocation").unwrap(); let callback = callback_backend.for_scope(&callback_scope).unwrap(); let callback_docs = Arc::clone(callback.documents()); @@ -419,12 +417,11 @@ async fn import_savings_at_uses_only_its_request_scoped_storage_address() { let module = Connection::connect(bus.connect().await.unwrap()) .await .unwrap(); - let module_for_setup = module.clone(); - setup(module_for_setup).await.unwrap(); - let proxy = host.proxy(BUS_NAME, OBJECT_PATH, BUS_NAME).unwrap(); - let _: SavingsAggregate = proxy.call("SavingsStats", ()).await.unwrap(); + let savings = crate::savings_store::Savings::new(); + let initial: SavingsAggregate = savings.stats(Some(&module)).await; + assert_eq!(initial.total.events, 0); let aggregate = SavingsAggregate { - total: tinyjuice_bus::savings::SavingsBucket { + total: SavingsBucket { events: 2, original_tokens: 20, compacted_tokens: 8, @@ -433,31 +430,37 @@ async fn import_savings_at_uses_only_its_request_scoped_storage_address() { }, ..Default::default() }; - let imported: bool = proxy - .call( - "ImportSavingsAt", - (ImportSavingsAtRequest { - aggregate, - callback: StorageCallbackAddress { - host: address.host().to_string(), - object_root: address.object_root().to_string(), - }, - },), - ) - .await - .unwrap(); + let imported = import_savings_at( + &savings, + Some(&module), + ImportSavingsAtRequest { + aggregate, + callback: StorageCallbackAddress { + host: address.host().to_string(), + object_root: address.object_root().to_string(), + }, + }, + ) + .await + .unwrap(); assert!(imported); + let ordinary = backend.for_scope(&Scope::new("ordinary").unwrap()).unwrap(); let stored = ordinary .documents() .get(SAVINGS_COLLECTION, SAVINGS_DOC_ID) .await .unwrap(); - assert!(stored.is_none(), "the request port does not replace the normal port"); - assert!(callback_docs - .get(SAVINGS_COLLECTION, SAVINGS_DOC_ID) - .await - .unwrap() - .is_some()); + assert!( + stored.is_none(), + "the request port does not replace the normal port" + ); + assert!( + callback_docs + .get(SAVINGS_COLLECTION, SAVINGS_DOC_ID) + .await + .unwrap() + .is_some() + ); broker_task.abort(); } From b304cca565bff8ec9e5cd76d5c3fae7d276c1549 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 16:39:23 +0300 Subject: [PATCH 046/119] chore(deps): record unused tinystoragedrivers patch entries Cargo.lock now lists the tinystoragedrivers crates as unused patch entries, reflecting the local patch overrides that are not currently selected by the dependency graph. Auto-committed-on: dragonfly --- Cargo.lock | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index a4bf7917..1e0f5a6a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2323,3 +2323,51 @@ dependencies = [ "cc", "pkg-config", ] + +[[patch.unused]] +name = "tinystoragedrivers" +version = "2.1.0" + +[[patch.unused]] +name = "tinystoragedrivers-api" +version = "2.1.0" + +[[patch.unused]] +name = "tinystoragedrivers-blob" +version = "2.1.0" + +[[patch.unused]] +name = "tinystoragedrivers-bus" +version = "2.1.0" + +[[patch.unused]] +name = "tinystoragedrivers-busproxy" +version = "2.1.0" + +[[patch.unused]] +name = "tinystoragedrivers-connect" +version = "2.1.0" + +[[patch.unused]] +name = "tinystoragedrivers-document" +version = "2.1.0" + +[[patch.unused]] +name = "tinystoragedrivers-kv" +version = "2.1.0" + +[[patch.unused]] +name = "tinystoragedrivers-queue" +version = "2.1.0" + +[[patch.unused]] +name = "tinystoragedrivers-secrets" +version = "2.1.0" + +[[patch.unused]] +name = "tinystoragedrivers-testkit" +version = "2.1.0" + +[[patch.unused]] +name = "tinystoragedrivers-types" +version = "2.1.0" From 91203d87cb48a20d4e344bb53e15faf2193eeee4 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 15:30:01 +0000 Subject: [PATCH 047/119] chore: files changed Cargo.lock Auto-committed-on: cuttlefish Co-authored-by: Medulla --- Cargo.lock | 48 ------------------------------------------------ 1 file changed, 48 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1e0f5a6a..a4bf7917 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2323,51 +2323,3 @@ dependencies = [ "cc", "pkg-config", ] - -[[patch.unused]] -name = "tinystoragedrivers" -version = "2.1.0" - -[[patch.unused]] -name = "tinystoragedrivers-api" -version = "2.1.0" - -[[patch.unused]] -name = "tinystoragedrivers-blob" -version = "2.1.0" - -[[patch.unused]] -name = "tinystoragedrivers-bus" -version = "2.1.0" - -[[patch.unused]] -name = "tinystoragedrivers-busproxy" -version = "2.1.0" - -[[patch.unused]] -name = "tinystoragedrivers-connect" -version = "2.1.0" - -[[patch.unused]] -name = "tinystoragedrivers-document" -version = "2.1.0" - -[[patch.unused]] -name = "tinystoragedrivers-kv" -version = "2.1.0" - -[[patch.unused]] -name = "tinystoragedrivers-queue" -version = "2.1.0" - -[[patch.unused]] -name = "tinystoragedrivers-secrets" -version = "2.1.0" - -[[patch.unused]] -name = "tinystoragedrivers-testkit" -version = "2.1.0" - -[[patch.unused]] -name = "tinystoragedrivers-types" -version = "2.1.0" From b7ff9b6d30f786878357df9c3475aa6f32bcb296 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 15:30:32 +0000 Subject: [PATCH 048/119] chore: files changed crates/tinyjuice-bus/Cargo.toml,crates/tinyjuice-cli/Cargo.toml,crates/tinyjuic Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-bus/Cargo.toml | 2 +- crates/tinyjuice-cli/Cargo.toml | 8 ++++---- crates/tinyjuice-drivers/Cargo.toml | 8 ++++---- crates/tinyjuice-module/Cargo.toml | 8 ++++---- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/crates/tinyjuice-bus/Cargo.toml b/crates/tinyjuice-bus/Cargo.toml index a1531ace..ff93e987 100644 --- a/crates/tinyjuice-bus/Cargo.toml +++ b/crates/tinyjuice-bus/Cargo.toml @@ -19,7 +19,7 @@ serde = { version = "1", features = ["derive"] } serde_json = "1" # Shared REPL error vocabulary; no execution dependencies. thiserror = "2" -tinystoragedrivers-types = { version = "2.0.2", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.2" } +tinystoragedrivers-types = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.1.0" } [features] default = [] diff --git a/crates/tinyjuice-cli/Cargo.toml b/crates/tinyjuice-cli/Cargo.toml index 434141ee..8e398309 100644 --- a/crates/tinyjuice-cli/Cargo.toml +++ b/crates/tinyjuice-cli/Cargo.toml @@ -11,9 +11,9 @@ repository = "https://github.com/tinyhumansai/tinyjuice" [dependencies] tinyjuice = { path = "../.." } tinyjuice-drivers = { path = "../tinyjuice-drivers" } -tinystoragedrivers = { version = "2.0.2", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.2", features = ["file"] } -tinystoragedrivers-api = { version = "2.0.2", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.2" } -tinystoragedrivers-types = { version = "2.0.2", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.2" } +tinystoragedrivers = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.1.0", features = ["file"] } +tinystoragedrivers-api = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.1.0" } +tinystoragedrivers-types = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.1.0" } dirs = "7" log = "0.4" serde_json = "1" @@ -22,7 +22,7 @@ tokio = { version = "1", features = ["rt-multi-thread"] } [dev-dependencies] async-trait = "0.1" tempfile = "3" -tinystoragedrivers-testkit = { version = "2.0.2", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.2" } +tinystoragedrivers-testkit = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.1.0" } [[bin]] name = "tinyjuice" diff --git a/crates/tinyjuice-drivers/Cargo.toml b/crates/tinyjuice-drivers/Cargo.toml index 7326aad6..7886e4eb 100644 --- a/crates/tinyjuice-drivers/Cargo.toml +++ b/crates/tinyjuice-drivers/Cargo.toml @@ -14,13 +14,13 @@ publish = false [dependencies] tinyjuice-bus = { path = "../tinyjuice-bus" } tinyjuice = { path = "../..", default-features = false } -tinystoragedrivers-api = { version = "2.0.2", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.2" } -tinystoragedrivers-types = { version = "2.0.2", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.2" } +tinystoragedrivers-api = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.1.0" } +tinystoragedrivers-types = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.1.0" } log = "0.4" tokio = { version = "1", features = ["rt"] } [dev-dependencies] tokio = { version = "1", features = ["macros", "rt-multi-thread", "time"] } async-trait = "0.1" -tinystoragedrivers-testkit = { version = "2.0.2", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.2" } -tinystoragedrivers-blob = { version = "2.0.2", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.2" } +tinystoragedrivers-testkit = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.1.0" } +tinystoragedrivers-blob = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.1.0" } diff --git a/crates/tinyjuice-module/Cargo.toml b/crates/tinyjuice-module/Cargo.toml index e34b43be..81a1071c 100644 --- a/crates/tinyjuice-module/Cargo.toml +++ b/crates/tinyjuice-module/Cargo.toml @@ -28,14 +28,14 @@ serde_json = "1" # The CCR store's durable tier is blobs on the host's storage ports, reached # over the storage bus. The module has no storage backend or file of its own. tinyjuice-drivers = { path = "../tinyjuice-drivers" } -tinystoragedrivers-api = { version = "2.0.2", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.2" } -tinystoragedrivers-types = { version = "2.0.2", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.2" } -tinystoragedrivers-busproxy = { version = "2.0.2", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.2" } +tinystoragedrivers-api = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.1.0" } +tinystoragedrivers-types = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.1.0" } +tinystoragedrivers-busproxy = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.1.0" } log = "0.4" [dev-dependencies] # Tests serve the storage objects on the in-memory broker the module connects to. -tinystoragedrivers-testkit = { version = "2.0.2", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.2" } +tinystoragedrivers-testkit = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.1.0" } tinybus = { version = "=0.1.6", git = "https://github.com/senamakel/tinybus", rev = "1d0aa34104c84f6817f398b0abe164df6c5e7b82", default-features = false, features = ["test-support"] } tempfile = "3" async-trait = "0.1" From a9d4cc25e1986643c2b877d53962c2667809a1f5 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 15:30:42 +0000 Subject: [PATCH 049/119] chore: files changed Cargo.lock Auto-committed-on: cuttlefish Co-authored-by: Medulla --- Cargo.lock | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a4bf7917..9183dcd4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1560,8 +1560,8 @@ dependencies = [ [[package]] name = "tinystoragedrivers" -version = "2.0.2" -source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.2#7acd22d8e8061edf7ef8cc4976c666b198a203c7" +version = "2.1.0" +source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.1.0#3332061434c01872b0161191268166c12563af87" dependencies = [ "tinystoragedrivers-api", "tinystoragedrivers-blob", @@ -1575,8 +1575,8 @@ dependencies = [ [[package]] name = "tinystoragedrivers-api" -version = "2.0.2" -source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.2#7acd22d8e8061edf7ef8cc4976c666b198a203c7" +version = "2.1.0" +source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.1.0#3332061434c01872b0161191268166c12563af87" dependencies = [ "async-trait", "bytes", @@ -1589,8 +1589,8 @@ dependencies = [ [[package]] name = "tinystoragedrivers-blob" -version = "2.0.2" -source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.2#7acd22d8e8061edf7ef8cc4976c666b198a203c7" +version = "2.1.0" +source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.1.0#3332061434c01872b0161191268166c12563af87" dependencies = [ "async-trait", "bytes", @@ -1604,8 +1604,8 @@ dependencies = [ [[package]] name = "tinystoragedrivers-bus" -version = "2.0.2" -source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.2#7acd22d8e8061edf7ef8cc4976c666b198a203c7" +version = "2.1.0" +source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.1.0#3332061434c01872b0161191268166c12563af87" dependencies = [ "serde", "serde_json", @@ -1615,8 +1615,8 @@ dependencies = [ [[package]] name = "tinystoragedrivers-busproxy" -version = "2.0.2" -source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.2#7acd22d8e8061edf7ef8cc4976c666b198a203c7" +version = "2.1.0" +source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.1.0#3332061434c01872b0161191268166c12563af87" dependencies = [ "async-trait", "bytes", @@ -1633,18 +1633,20 @@ dependencies = [ [[package]] name = "tinystoragedrivers-connect" -version = "2.0.2" -source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.2#7acd22d8e8061edf7ef8cc4976c666b198a203c7" +version = "2.1.0" +source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.1.0#3332061434c01872b0161191268166c12563af87" dependencies = [ "rusqlite", + "serde_json", "tinystoragedrivers-types", "tokio", + "zstd", ] [[package]] name = "tinystoragedrivers-document" -version = "2.0.2" -source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.2#7acd22d8e8061edf7ef8cc4976c666b198a203c7" +version = "2.1.0" +source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.1.0#3332061434c01872b0161191268166c12563af87" dependencies = [ "async-trait", "data-encoding", @@ -1662,8 +1664,8 @@ dependencies = [ [[package]] name = "tinystoragedrivers-kv" -version = "2.0.2" -source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.2#7acd22d8e8061edf7ef8cc4976c666b198a203c7" +version = "2.1.0" +source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.1.0#3332061434c01872b0161191268166c12563af87" dependencies = [ "async-trait", "libc", @@ -1676,8 +1678,8 @@ dependencies = [ [[package]] name = "tinystoragedrivers-queue" -version = "2.0.2" -source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.2#7acd22d8e8061edf7ef8cc4976c666b198a203c7" +version = "2.1.0" +source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.1.0#3332061434c01872b0161191268166c12563af87" dependencies = [ "async-trait", "data-encoding", @@ -1692,8 +1694,8 @@ dependencies = [ [[package]] name = "tinystoragedrivers-secrets" -version = "2.0.2" -source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.2#7acd22d8e8061edf7ef8cc4976c666b198a203c7" +version = "2.1.0" +source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.1.0#3332061434c01872b0161191268166c12563af87" dependencies = [ "async-trait", "tinystoragedrivers-api", @@ -1703,8 +1705,8 @@ dependencies = [ [[package]] name = "tinystoragedrivers-testkit" -version = "2.0.2" -source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.2#7acd22d8e8061edf7ef8cc4976c666b198a203c7" +version = "2.1.0" +source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.1.0#3332061434c01872b0161191268166c12563af87" dependencies = [ "async-trait", "bytes", @@ -1724,8 +1726,8 @@ dependencies = [ [[package]] name = "tinystoragedrivers-types" -version = "2.0.2" -source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.2#7acd22d8e8061edf7ef8cc4976c666b198a203c7" +version = "2.1.0" +source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.1.0#3332061434c01872b0161191268166c12563af87" dependencies = [ "serde", "serde_json", From 5008f79e2a8cc333f1ffd08e9132e1c810cca3a3 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 15:31:15 +0000 Subject: [PATCH 050/119] chore: files changed Cargo.lock,crates/tinyjuice-bus/Cargo.toml,crates/tinyjuice-cli/Cargo.toml,crat Auto-committed-on: cuttlefish Co-authored-by: Medulla --- Cargo.lock | 53 ++++++++++++++++++++--------- crates/tinyjuice-bus/Cargo.toml | 2 +- crates/tinyjuice-cli/Cargo.toml | 8 ++--- crates/tinyjuice-drivers/Cargo.toml | 8 ++--- crates/tinyjuice-module/Cargo.toml | 8 ++--- 5 files changed, 50 insertions(+), 29 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9183dcd4..207e6ed2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1439,6 +1439,27 @@ dependencies = [ "zip", ] +[[package]] +name = "tinybus" +version = "0.1.6" +source = "git+https://github.com/senamakel/tinybus?rev=24ec2ccafcc98fab35fa10ffcbcefa87eb32e3e8#24ec2ccafcc98fab35fa10ffcbcefa87eb32e3e8" +dependencies = [ + "async-trait", + "flate2", + "libc", + "serde", + "serde_json", + "sha2 0.10.9", + "tar", + "tempfile", + "thiserror", + "tokio", + "toml", + "tracing", + "ureq", + "zip", +] + [[package]] name = "tinybus-macros" version = "0.1.6" @@ -1457,7 +1478,7 @@ dependencies = [ "async-trait", "serde", "serde_json", - "tinybus", + "tinybus 0.1.6 (git+https://github.com/senamakel/tinybus?rev=1d0aa34104c84f6817f398b0abe164df6c5e7b82)", "tokio", "tracing", ] @@ -1546,7 +1567,7 @@ dependencies = [ "log", "serde_json", "tempfile", - "tinybus", + "tinybus 0.1.6 (git+https://github.com/senamakel/tinybus?rev=1d0aa34104c84f6817f398b0abe164df6c5e7b82)", "tinybus-module", "tinyjuice", "tinyjuice-bus", @@ -1561,7 +1582,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.1.0#3332061434c01872b0161191268166c12563af87" +source = "git+https://github.com/senamakel/tinystoragedrivers?rev=8a8bd701cc497a4ca099d98cae11aa684dd051aa#8a8bd701cc497a4ca099d98cae11aa684dd051aa" dependencies = [ "tinystoragedrivers-api", "tinystoragedrivers-blob", @@ -1576,7 +1597,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers-api" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.1.0#3332061434c01872b0161191268166c12563af87" +source = "git+https://github.com/senamakel/tinystoragedrivers?rev=8a8bd701cc497a4ca099d98cae11aa684dd051aa#8a8bd701cc497a4ca099d98cae11aa684dd051aa" dependencies = [ "async-trait", "bytes", @@ -1590,7 +1611,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers-blob" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.1.0#3332061434c01872b0161191268166c12563af87" +source = "git+https://github.com/senamakel/tinystoragedrivers?rev=8a8bd701cc497a4ca099d98cae11aa684dd051aa#8a8bd701cc497a4ca099d98cae11aa684dd051aa" dependencies = [ "async-trait", "bytes", @@ -1605,25 +1626,25 @@ dependencies = [ [[package]] name = "tinystoragedrivers-bus" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.1.0#3332061434c01872b0161191268166c12563af87" +source = "git+https://github.com/senamakel/tinystoragedrivers?rev=8a8bd701cc497a4ca099d98cae11aa684dd051aa#8a8bd701cc497a4ca099d98cae11aa684dd051aa" dependencies = [ "serde", "serde_json", - "tinybus", + "tinybus 0.1.6 (git+https://github.com/senamakel/tinybus?rev=24ec2ccafcc98fab35fa10ffcbcefa87eb32e3e8)", "tinystoragedrivers-types", ] [[package]] name = "tinystoragedrivers-busproxy" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.1.0#3332061434c01872b0161191268166c12563af87" +source = "git+https://github.com/senamakel/tinystoragedrivers?rev=8a8bd701cc497a4ca099d98cae11aa684dd051aa#8a8bd701cc497a4ca099d98cae11aa684dd051aa" dependencies = [ "async-trait", "bytes", "futures-core", "serde", "serde_json", - "tinybus", + "tinybus 0.1.6 (git+https://github.com/senamakel/tinybus?rev=24ec2ccafcc98fab35fa10ffcbcefa87eb32e3e8)", "tinystoragedrivers-api", "tinystoragedrivers-bus", "tinystoragedrivers-types", @@ -1634,7 +1655,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers-connect" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.1.0#3332061434c01872b0161191268166c12563af87" +source = "git+https://github.com/senamakel/tinystoragedrivers?rev=8a8bd701cc497a4ca099d98cae11aa684dd051aa#8a8bd701cc497a4ca099d98cae11aa684dd051aa" dependencies = [ "rusqlite", "serde_json", @@ -1646,7 +1667,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers-document" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.1.0#3332061434c01872b0161191268166c12563af87" +source = "git+https://github.com/senamakel/tinystoragedrivers?rev=8a8bd701cc497a4ca099d98cae11aa684dd051aa#8a8bd701cc497a4ca099d98cae11aa684dd051aa" dependencies = [ "async-trait", "data-encoding", @@ -1665,7 +1686,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers-kv" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.1.0#3332061434c01872b0161191268166c12563af87" +source = "git+https://github.com/senamakel/tinystoragedrivers?rev=8a8bd701cc497a4ca099d98cae11aa684dd051aa#8a8bd701cc497a4ca099d98cae11aa684dd051aa" dependencies = [ "async-trait", "libc", @@ -1679,7 +1700,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers-queue" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.1.0#3332061434c01872b0161191268166c12563af87" +source = "git+https://github.com/senamakel/tinystoragedrivers?rev=8a8bd701cc497a4ca099d98cae11aa684dd051aa#8a8bd701cc497a4ca099d98cae11aa684dd051aa" dependencies = [ "async-trait", "data-encoding", @@ -1695,7 +1716,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers-secrets" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.1.0#3332061434c01872b0161191268166c12563af87" +source = "git+https://github.com/senamakel/tinystoragedrivers?rev=8a8bd701cc497a4ca099d98cae11aa684dd051aa#8a8bd701cc497a4ca099d98cae11aa684dd051aa" dependencies = [ "async-trait", "tinystoragedrivers-api", @@ -1706,7 +1727,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers-testkit" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.1.0#3332061434c01872b0161191268166c12563af87" +source = "git+https://github.com/senamakel/tinystoragedrivers?rev=8a8bd701cc497a4ca099d98cae11aa684dd051aa#8a8bd701cc497a4ca099d98cae11aa684dd051aa" dependencies = [ "async-trait", "bytes", @@ -1727,7 +1748,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers-types" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.1.0#3332061434c01872b0161191268166c12563af87" +source = "git+https://github.com/senamakel/tinystoragedrivers?rev=8a8bd701cc497a4ca099d98cae11aa684dd051aa#8a8bd701cc497a4ca099d98cae11aa684dd051aa" dependencies = [ "serde", "serde_json", diff --git a/crates/tinyjuice-bus/Cargo.toml b/crates/tinyjuice-bus/Cargo.toml index ff93e987..fcbd3883 100644 --- a/crates/tinyjuice-bus/Cargo.toml +++ b/crates/tinyjuice-bus/Cargo.toml @@ -19,7 +19,7 @@ serde = { version = "1", features = ["derive"] } serde_json = "1" # Shared REPL error vocabulary; no execution dependencies. thiserror = "2" -tinystoragedrivers-types = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.1.0" } +tinystoragedrivers-types = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "8a8bd701cc497a4ca099d98cae11aa684dd051aa" } [features] default = [] diff --git a/crates/tinyjuice-cli/Cargo.toml b/crates/tinyjuice-cli/Cargo.toml index 8e398309..448bd509 100644 --- a/crates/tinyjuice-cli/Cargo.toml +++ b/crates/tinyjuice-cli/Cargo.toml @@ -11,9 +11,9 @@ repository = "https://github.com/tinyhumansai/tinyjuice" [dependencies] tinyjuice = { path = "../.." } tinyjuice-drivers = { path = "../tinyjuice-drivers" } -tinystoragedrivers = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.1.0", features = ["file"] } -tinystoragedrivers-api = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.1.0" } -tinystoragedrivers-types = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.1.0" } +tinystoragedrivers = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "8a8bd701cc497a4ca099d98cae11aa684dd051aa", features = ["file"] } +tinystoragedrivers-api = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "8a8bd701cc497a4ca099d98cae11aa684dd051aa" } +tinystoragedrivers-types = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "8a8bd701cc497a4ca099d98cae11aa684dd051aa" } dirs = "7" log = "0.4" serde_json = "1" @@ -22,7 +22,7 @@ tokio = { version = "1", features = ["rt-multi-thread"] } [dev-dependencies] async-trait = "0.1" tempfile = "3" -tinystoragedrivers-testkit = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.1.0" } +tinystoragedrivers-testkit = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "8a8bd701cc497a4ca099d98cae11aa684dd051aa" } [[bin]] name = "tinyjuice" diff --git a/crates/tinyjuice-drivers/Cargo.toml b/crates/tinyjuice-drivers/Cargo.toml index 7886e4eb..9dc0c88c 100644 --- a/crates/tinyjuice-drivers/Cargo.toml +++ b/crates/tinyjuice-drivers/Cargo.toml @@ -14,13 +14,13 @@ publish = false [dependencies] tinyjuice-bus = { path = "../tinyjuice-bus" } tinyjuice = { path = "../..", default-features = false } -tinystoragedrivers-api = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.1.0" } -tinystoragedrivers-types = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.1.0" } +tinystoragedrivers-api = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "8a8bd701cc497a4ca099d98cae11aa684dd051aa" } +tinystoragedrivers-types = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "8a8bd701cc497a4ca099d98cae11aa684dd051aa" } log = "0.4" tokio = { version = "1", features = ["rt"] } [dev-dependencies] tokio = { version = "1", features = ["macros", "rt-multi-thread", "time"] } async-trait = "0.1" -tinystoragedrivers-testkit = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.1.0" } -tinystoragedrivers-blob = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.1.0" } +tinystoragedrivers-testkit = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "8a8bd701cc497a4ca099d98cae11aa684dd051aa" } +tinystoragedrivers-blob = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "8a8bd701cc497a4ca099d98cae11aa684dd051aa" } diff --git a/crates/tinyjuice-module/Cargo.toml b/crates/tinyjuice-module/Cargo.toml index 81a1071c..5c713015 100644 --- a/crates/tinyjuice-module/Cargo.toml +++ b/crates/tinyjuice-module/Cargo.toml @@ -28,14 +28,14 @@ serde_json = "1" # The CCR store's durable tier is blobs on the host's storage ports, reached # over the storage bus. The module has no storage backend or file of its own. tinyjuice-drivers = { path = "../tinyjuice-drivers" } -tinystoragedrivers-api = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.1.0" } -tinystoragedrivers-types = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.1.0" } -tinystoragedrivers-busproxy = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.1.0" } +tinystoragedrivers-api = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "8a8bd701cc497a4ca099d98cae11aa684dd051aa" } +tinystoragedrivers-types = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "8a8bd701cc497a4ca099d98cae11aa684dd051aa" } +tinystoragedrivers-busproxy = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "8a8bd701cc497a4ca099d98cae11aa684dd051aa" } log = "0.4" [dev-dependencies] # Tests serve the storage objects on the in-memory broker the module connects to. -tinystoragedrivers-testkit = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.1.0" } +tinystoragedrivers-testkit = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "8a8bd701cc497a4ca099d98cae11aa684dd051aa" } tinybus = { version = "=0.1.6", git = "https://github.com/senamakel/tinybus", rev = "1d0aa34104c84f6817f398b0abe164df6c5e7b82", default-features = false, features = ["test-support"] } tempfile = "3" async-trait = "0.1" From b5216377ca256b45c0d4f1395229d3bb12eb080a Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 15:31:48 +0000 Subject: [PATCH 051/119] chore: files changed Cargo.lock,crates/tinyjuice-module/Cargo.toml,crates/tinyjuice-module/src/servi Auto-committed-on: cuttlefish Co-authored-by: Medulla --- Cargo.lock | 35 ++++---------------- crates/tinyjuice-module/Cargo.toml | 6 ++-- crates/tinyjuice-module/src/service_tests.rs | 4 ++- 3 files changed, 13 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 207e6ed2..e817c27c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1417,28 +1417,6 @@ dependencies = [ "syn 3.0.0", ] -[[package]] -name = "tinybus" -version = "0.1.6" -source = "git+https://github.com/senamakel/tinybus?rev=1d0aa34104c84f6817f398b0abe164df6c5e7b82#1d0aa34104c84f6817f398b0abe164df6c5e7b82" -dependencies = [ - "async-trait", - "flate2", - "libc", - "serde", - "serde_json", - "sha2 0.10.9", - "tar", - "tempfile", - "thiserror", - "tinybus-macros", - "tokio", - "toml", - "tracing", - "ureq", - "zip", -] - [[package]] name = "tinybus" version = "0.1.6" @@ -1453,6 +1431,7 @@ dependencies = [ "tar", "tempfile", "thiserror", + "tinybus-macros", "tokio", "toml", "tracing", @@ -1463,7 +1442,7 @@ dependencies = [ [[package]] name = "tinybus-macros" version = "0.1.6" -source = "git+https://github.com/senamakel/tinybus?rev=1d0aa34104c84f6817f398b0abe164df6c5e7b82#1d0aa34104c84f6817f398b0abe164df6c5e7b82" +source = "git+https://github.com/senamakel/tinybus?rev=24ec2ccafcc98fab35fa10ffcbcefa87eb32e3e8#24ec2ccafcc98fab35fa10ffcbcefa87eb32e3e8" dependencies = [ "proc-macro2", "quote", @@ -1473,12 +1452,12 @@ dependencies = [ [[package]] name = "tinybus-module" version = "0.1.6" -source = "git+https://github.com/senamakel/tinybus?rev=1d0aa34104c84f6817f398b0abe164df6c5e7b82#1d0aa34104c84f6817f398b0abe164df6c5e7b82" +source = "git+https://github.com/senamakel/tinybus?rev=24ec2ccafcc98fab35fa10ffcbcefa87eb32e3e8#24ec2ccafcc98fab35fa10ffcbcefa87eb32e3e8" dependencies = [ "async-trait", "serde", "serde_json", - "tinybus 0.1.6 (git+https://github.com/senamakel/tinybus?rev=1d0aa34104c84f6817f398b0abe164df6c5e7b82)", + "tinybus", "tokio", "tracing", ] @@ -1567,7 +1546,7 @@ dependencies = [ "log", "serde_json", "tempfile", - "tinybus 0.1.6 (git+https://github.com/senamakel/tinybus?rev=1d0aa34104c84f6817f398b0abe164df6c5e7b82)", + "tinybus", "tinybus-module", "tinyjuice", "tinyjuice-bus", @@ -1630,7 +1609,7 @@ source = "git+https://github.com/senamakel/tinystoragedrivers?rev=8a8bd701cc497a dependencies = [ "serde", "serde_json", - "tinybus 0.1.6 (git+https://github.com/senamakel/tinybus?rev=24ec2ccafcc98fab35fa10ffcbcefa87eb32e3e8)", + "tinybus", "tinystoragedrivers-types", ] @@ -1644,7 +1623,7 @@ dependencies = [ "futures-core", "serde", "serde_json", - "tinybus 0.1.6 (git+https://github.com/senamakel/tinybus?rev=24ec2ccafcc98fab35fa10ffcbcefa87eb32e3e8)", + "tinybus", "tinystoragedrivers-api", "tinystoragedrivers-bus", "tinystoragedrivers-types", diff --git a/crates/tinyjuice-module/Cargo.toml b/crates/tinyjuice-module/Cargo.toml index 5c713015..da73555a 100644 --- a/crates/tinyjuice-module/Cargo.toml +++ b/crates/tinyjuice-module/Cargo.toml @@ -21,8 +21,8 @@ tinyjuice = { path = "../..", default-features = false, features = ["jq"] } # The interface vocabulary. Shared with hosts, so this adapter cannot drift # from what a caller was compiled against. tinyjuice-bus = { path = "../tinyjuice-bus" } -tinybus = { version = "=0.1.6", git = "https://github.com/senamakel/tinybus", rev = "1d0aa34104c84f6817f398b0abe164df6c5e7b82", default-features = false, features = ["macros", "modules"] } -tinybus-module = { version = "=0.1.6", git = "https://github.com/senamakel/tinybus", rev = "1d0aa34104c84f6817f398b0abe164df6c5e7b82" } +tinybus = { version = "=0.1.6", git = "https://github.com/senamakel/tinybus", rev = "24ec2ccafcc98fab35fa10ffcbcefa87eb32e3e8", default-features = false, features = ["macros", "modules"] } +tinybus-module = { version = "=0.1.6", git = "https://github.com/senamakel/tinybus", rev = "24ec2ccafcc98fab35fa10ffcbcefa87eb32e3e8" } tokio = { version = "1", features = ["macros", "rt-multi-thread", "sync"] } serde_json = "1" # The CCR store's durable tier is blobs on the host's storage ports, reached @@ -36,7 +36,7 @@ log = "0.4" [dev-dependencies] # Tests serve the storage objects on the in-memory broker the module connects to. tinystoragedrivers-testkit = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "8a8bd701cc497a4ca099d98cae11aa684dd051aa" } -tinybus = { version = "=0.1.6", git = "https://github.com/senamakel/tinybus", rev = "1d0aa34104c84f6817f398b0abe164df6c5e7b82", default-features = false, features = ["test-support"] } +tinybus = { version = "=0.1.6", git = "https://github.com/senamakel/tinybus", rev = "24ec2ccafcc98fab35fa10ffcbcefa87eb32e3e8", default-features = false, features = ["test-support"] } tempfile = "3" async-trait = "0.1" tokio = { version = "1", features = ["macros", "rt-multi-thread", "time"] } diff --git a/crates/tinyjuice-module/src/service_tests.rs b/crates/tinyjuice-module/src/service_tests.rs index b71e5888..3041fa64 100644 --- a/crates/tinyjuice-module/src/service_tests.rs +++ b/crates/tinyjuice-module/src/service_tests.rs @@ -409,7 +409,9 @@ async fn import_savings_at_uses_only_its_request_scoped_storage_address() { let _callback_server = serve_at_address( &host, address.clone(), - Arc::new(StorageServer::new(callback)), + Arc::new(PerCallerEndpoint::new(move |_| { + Some(StorageServer::new(callback.clone())) + })), ) .await .unwrap(); From 50345686eaa535b39ba93561dbbd1e1afab8097c Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 15:32:13 +0000 Subject: [PATCH 052/119] chore: files changed crates/tinyjuice-module/src/service_tests.rs Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-module/src/service_tests.rs | 38 ++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/crates/tinyjuice-module/src/service_tests.rs b/crates/tinyjuice-module/src/service_tests.rs index 3041fa64..5a1b09d1 100644 --- a/crates/tinyjuice-module/src/service_tests.rs +++ b/crates/tinyjuice-module/src/service_tests.rs @@ -466,3 +466,41 @@ async fn import_savings_at_uses_only_its_request_scoped_storage_address() { ); broker_task.abort(); } + +#[tokio::test] +async fn import_savings_at_rejects_non_unique_hosts_and_non_invocation_roots() { + use tinybus::broker::Broker; + use tinybus::transport::memory::MemoryBus; + use tinyjuice_bus::savings::{ImportSavingsAtRequest, SavingsAggregate, StorageCallbackAddress}; + + let bus = MemoryBus::new(); + let broker_task = Broker::new().spawn(bus.clone()); + let module = Connection::connect(bus.connect().await.unwrap()) + .await + .unwrap(); + let savings = crate::savings_store::Savings::new(); + + let invalid_addresses = [ + StorageCallbackAddress { + host: "ai.example.Storage".into(), + object_root: "/ai/tinyhumans/tinystorage/Invocation/import-1".into(), + }, + StorageCallbackAddress { + host: ":1.7".into(), + object_root: "/ai/tinyhumans/tinystorage/Other/import-1".into(), + }, + ]; + for callback in invalid_addresses { + let result = import_savings_at( + &savings, + Some(&module), + ImportSavingsAtRequest { + aggregate: SavingsAggregate::default(), + callback, + }, + ) + .await; + assert!(result.is_err(), "invalid destination must be rejected"); + } + broker_task.abort(); +} From 53e786c76b279ce1d8944b86b160d55d704fa204 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 21 Oct 2026 15:32:59 +0000 Subject: [PATCH 053/119] chore: files changed crates/tinyjuice-bus/src/lib_tests.rs,crates/tinyjuice-module/src/service_tests Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-bus/src/lib_tests.rs | 14 ++++++++------ crates/tinyjuice-module/src/service_tests.rs | 4 +++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/crates/tinyjuice-bus/src/lib_tests.rs b/crates/tinyjuice-bus/src/lib_tests.rs index 55eb8df2..fa34535e 100644 --- a/crates/tinyjuice-bus/src/lib_tests.rs +++ b/crates/tinyjuice-bus/src/lib_tests.rs @@ -96,12 +96,14 @@ fn request_local_savings_import_address_is_a_transport_only_descriptor() { decoded.callback.object_root, "/ai/tinyhumans/tinystorage/Invocation/abc" ); - assert!(serde_json::from_value::({ - let mut value = encoded; - value["callback"]["write_condition"] = serde_json::json!("must-not-cross-the-bus"); - value - }) - .is_err()); + assert!( + serde_json::from_value::({ + let mut value = encoded; + value["callback"]["write_condition"] = serde_json::json!("must-not-cross-the-bus"); + value + }) + .is_err() + ); } #[test] diff --git a/crates/tinyjuice-module/src/service_tests.rs b/crates/tinyjuice-module/src/service_tests.rs index 5a1b09d1..78404d52 100644 --- a/crates/tinyjuice-module/src/service_tests.rs +++ b/crates/tinyjuice-module/src/service_tests.rs @@ -471,7 +471,9 @@ async fn import_savings_at_uses_only_its_request_scoped_storage_address() { async fn import_savings_at_rejects_non_unique_hosts_and_non_invocation_roots() { use tinybus::broker::Broker; use tinybus::transport::memory::MemoryBus; - use tinyjuice_bus::savings::{ImportSavingsAtRequest, SavingsAggregate, StorageCallbackAddress}; + use tinyjuice_bus::savings::{ + ImportSavingsAtRequest, SavingsAggregate, StorageCallbackAddress, + }; let bus = MemoryBus::new(); let broker_task = Broker::new().spawn(bus.clone()); From 3a6bb937b0efc3abfec51722663a10d04d553e41 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 05:11:19 +0000 Subject: [PATCH 054/119] test(cli): cover post-tool hook when cache storage cannot open Add a regression test asserting the post-tool-use hook still succeeds and emits its response when the persistent cache directory cannot be created, since cache setup failures must not fail the hook. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/tests/host_cli.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/crates/tinyjuice-cli/tests/host_cli.rs b/crates/tinyjuice-cli/tests/host_cli.rs index 154becdd..58c5842e 100644 --- a/crates/tinyjuice-cli/tests/host_cli.rs +++ b/crates/tinyjuice-cli/tests/host_cli.rs @@ -212,6 +212,32 @@ fn host_cli_reads_json_files_and_accepts_hooks_without_output() { } } +#[test] +fn post_tool_hook_still_runs_when_persistent_cache_storage_cannot_open() { + let dir = tempfile::tempdir().unwrap(); + std::fs::write(dir.path().join("ccr"), "not a directory").unwrap(); + let output = (0..200) + .map(|index| format!("\tmodified: src/file_{index}.rs")) + .collect::>() + .join("\n"); + let payload = serde_json::json!({ + "hook_event_name": "PostToolUse", + "tool_name": "Bash", + "tool_input": {"command": "git status"}, + "tool_response": {"output": output, "exitCode": 0} + }) + .to_string(); + + let out = invoke(dir.path(), &["codex-post-tool-use"], &payload); + + assert!(out.status.success(), "cache setup must not fail the hook: {out:?}"); + let response: serde_json::Value = serde_json::from_slice(&out.stdout).unwrap(); + assert_eq!( + response["hookSpecificOutput"]["hookEventName"], + "PostToolUse" + ); +} + #[test] fn host_cli_retrieves_original_from_disk_tier() { let dir = tempfile::tempdir().unwrap(); From 2f2c635aaf42fbbe0a60cde65934cec35e66b89e Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 05:15:53 +0000 Subject: [PATCH 055/119] test(storage): cover legacy import resilience and capped put in runtime Add tests verifying that legacy import skips corrupt entries while still importing valid files, and that a capped store put succeeds inside a current-thread Tokio runtime. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage_tests.rs | 49 +++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/crates/tinyjuice-cli/src/storage_tests.rs b/crates/tinyjuice-cli/src/storage_tests.rs index 41b6fbcf..a641e6ff 100644 --- a/crates/tinyjuice-cli/src/storage_tests.rs +++ b/crates/tinyjuice-cli/src/storage_tests.rs @@ -98,6 +98,35 @@ fn configure_and_inventory_report_invalid_storage_paths() { assert!(import_error.contains("failed to inspect legacy CCR directory")); } +#[test] +fn legacy_import_skips_corrupt_entries_and_continues_importing_valid_files() { + let dir = tempfile::tempdir().unwrap(); + let valid_content = "valid legacy entry still imports"; + let valid_token = tinyjuice::cache::short_hash(valid_content); + let mismatch_token = "0123456789abcdef0123456789abcdef"; + let unreadable_token = "fedcba9876543210fedcba9876543210"; + let valid_path = dir.path().join(&valid_token); + let mismatch_path = dir.path().join(mismatch_token); + let unreadable_path = dir.path().join(unreadable_token); + std::fs::write(&valid_path, valid_content).unwrap(); + std::fs::write(&mismatch_path, "content does not match its token").unwrap(); + std::fs::write(&unreadable_path, [0xff, 0xfe]).unwrap(); + let blobs = open_file_blobs(dir.path()).unwrap(); + + import_legacy_files(dir.path(), &blobs, None).unwrap(); + + assert!(!valid_path.exists(), "the valid legacy file is imported"); + assert!(mismatch_path.exists(), "the mismatched source is preserved"); + assert!(unreadable_path.exists(), "the unreadable source is preserved"); + assert_eq!( + BlobCcrStore::new(blobs, None) + .unwrap() + .get(&valid_token) + .as_deref(), + Some(valid_content) + ); +} + #[test] fn inventory_counts_ignored_entries_and_returns_imported_blobs() { let dir = tempfile::tempdir().unwrap(); @@ -414,6 +443,26 @@ fn failed_timestamp_refresh_does_not_leave_an_old_age_for_gc() { assert_eq!(original.get(&token).as_deref(), Some(content)); } +#[test] +fn capped_store_put_works_inside_a_current_thread_runtime() { + let dir = tempfile::tempdir().unwrap(); + let blobs = open_file_blobs(dir.path()).unwrap(); + let capped = CappedCcrStore { + store: BlobCcrStore::new(Arc::clone(&blobs), None).unwrap(), + blobs, + ttl: Some(Duration::from_secs(600)), + max_bytes: Some(1024), + }; + let runtime = tokio::runtime::Builder::new_current_thread() + .enable_all() + .build() + .unwrap(); + + let result = runtime.block_on(async { capped.put("retained from an active runtime") }); + + assert!(result.retained()); +} + #[test] fn import_refuses_to_replace_different_content_at_a_legacy_token() { let dir = tempfile::tempdir().unwrap(); From 2aee5cf63de3f45b4c72d2e7c5a2ec6e11995c7b Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 05:16:19 +0000 Subject: [PATCH 056/119] test(cli): rename and tighten post-tool hook cache failure test The test now asserts that the hook produces no output when persistent cache storage cannot be opened, matching the behaviour of skipping compression rather than emitting a PostToolUse response. The name was updated to describe that behaviour. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/tests/host_cli.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/crates/tinyjuice-cli/tests/host_cli.rs b/crates/tinyjuice-cli/tests/host_cli.rs index 58c5842e..8584cdff 100644 --- a/crates/tinyjuice-cli/tests/host_cli.rs +++ b/crates/tinyjuice-cli/tests/host_cli.rs @@ -213,7 +213,7 @@ fn host_cli_reads_json_files_and_accepts_hooks_without_output() { } #[test] -fn post_tool_hook_still_runs_when_persistent_cache_storage_cannot_open() { +fn post_tool_hook_skips_compression_when_persistent_cache_storage_cannot_open() { let dir = tempfile::tempdir().unwrap(); std::fs::write(dir.path().join("ccr"), "not a directory").unwrap(); let output = (0..200) @@ -231,10 +231,9 @@ fn post_tool_hook_still_runs_when_persistent_cache_storage_cannot_open() { let out = invoke(dir.path(), &["codex-post-tool-use"], &payload); assert!(out.status.success(), "cache setup must not fail the hook: {out:?}"); - let response: serde_json::Value = serde_json::from_slice(&out.stdout).unwrap(); - assert_eq!( - response["hookSpecificOutput"]["hookEventName"], - "PostToolUse" + assert!( + out.stdout.is_empty(), + "without durable recovery, the hook must leave host output unchanged" ); } From dccf0bed8d5f8e966582f26752af7b5eff0afa5c Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 05:19:02 +0000 Subject: [PATCH 057/119] fix(cli): make post-tool-use hook resilient to cache failures The hook now reads its input before configuring the cache and returns the original tool output when durable recovery is unavailable, since a short-lived hook process would lose in-memory CCR entries before the host could retrieve them. Legacy CCR imports skip unreadable entries and content hash mismatches instead of failing, and blob work runs on a dedicated thread so synchronous callers inside an active Tokio runtime no longer panic. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/bin/tinyjuice.rs | 7 +++++- crates/tinyjuice-cli/src/storage.rs | 27 ++++++++++++++++++----- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/crates/tinyjuice-cli/src/bin/tinyjuice.rs b/crates/tinyjuice-cli/src/bin/tinyjuice.rs index 0cf562c0..2602d5b3 100644 --- a/crates/tinyjuice-cli/src/bin/tinyjuice.rs +++ b/crates/tinyjuice-cli/src/bin/tinyjuice.rs @@ -131,8 +131,13 @@ fn reduce_json(args: Vec) -> Result<(), String> { } fn post_tool_use_hook(host: TinyJuiceHost) -> Result<(), String> { - configure_cli_cache()?; let input = read_input(None)?; + if configure_cli_cache().is_err() { + // A hook runs as a short-lived process, so its in-memory CCR entries + // would disappear before the host can retrieve them. Preserve the + // original tool output when durable recovery is unavailable. + return Ok(()); + } let runtime = tokio::runtime::Builder::new_current_thread() .enable_all() .build() diff --git a/crates/tinyjuice-cli/src/storage.rs b/crates/tinyjuice-cli/src/storage.rs index 220e55e0..953e8745 100644 --- a/crates/tinyjuice-cli/src/storage.rs +++ b/crates/tinyjuice-cli/src/storage.rs @@ -247,8 +247,17 @@ fn import_legacy_files( } let content = match std::fs::read_to_string(entry.path()) { Ok(content) => content, - Err(error) => return Err(format!("cannot import legacy CCR entry {token}: {error}")), + Err(error) => { + log::warn!("[tinyjuice_cli] skipping unreadable legacy CCR entry {token}: {error}"); + continue; + } }; + if tinyjuice::cache::short_hash(&content) != token { + log::warn!( + "[tinyjuice_cli] skipping legacy CCR entry {token}: content hash mismatch" + ); + continue; + } let modified = entry .metadata() .and_then(|metadata| metadata.modified()) @@ -560,11 +569,17 @@ fn run_blob( ) -> Result { // Each helper owns a separate current-thread runtime. Blob engines in this // CLI are self-contained and do not depend on work from another runtime. - let runtime = tokio::runtime::Builder::new_current_thread() - .enable_all() - .build() - .map_err(|error| format!("cannot start storage runtime: {error}"))?; - runtime.block_on(future).map_err(|error| error.to_string()) + // Run it on a dedicated thread because callers such as CcrStore::put can + // execute synchronously from inside an active Tokio runtime. + std::thread::spawn(move || { + let runtime = tokio::runtime::Builder::new_current_thread() + .enable_all() + .build() + .map_err(|error| format!("cannot start storage runtime: {error}"))?; + runtime.block_on(future).map_err(|error| error.to_string()) + }) + .join() + .map_err(|_| "storage worker thread panicked".to_owned())? } fn is_token(token: &str) -> bool { From 3d86ce24e82a48c3ad24cc2861ef75c0d9017c92 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 05:19:06 +0000 Subject: [PATCH 058/119] style: apply rustfmt formatting to storage and test assertions Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage.rs | 4 +--- crates/tinyjuice-cli/src/storage_tests.rs | 5 ++++- crates/tinyjuice-cli/tests/host_cli.rs | 5 ++++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/crates/tinyjuice-cli/src/storage.rs b/crates/tinyjuice-cli/src/storage.rs index 953e8745..8de55a83 100644 --- a/crates/tinyjuice-cli/src/storage.rs +++ b/crates/tinyjuice-cli/src/storage.rs @@ -253,9 +253,7 @@ fn import_legacy_files( } }; if tinyjuice::cache::short_hash(&content) != token { - log::warn!( - "[tinyjuice_cli] skipping legacy CCR entry {token}: content hash mismatch" - ); + log::warn!("[tinyjuice_cli] skipping legacy CCR entry {token}: content hash mismatch"); continue; } let modified = entry diff --git a/crates/tinyjuice-cli/src/storage_tests.rs b/crates/tinyjuice-cli/src/storage_tests.rs index a641e6ff..4e534157 100644 --- a/crates/tinyjuice-cli/src/storage_tests.rs +++ b/crates/tinyjuice-cli/src/storage_tests.rs @@ -117,7 +117,10 @@ fn legacy_import_skips_corrupt_entries_and_continues_importing_valid_files() { assert!(!valid_path.exists(), "the valid legacy file is imported"); assert!(mismatch_path.exists(), "the mismatched source is preserved"); - assert!(unreadable_path.exists(), "the unreadable source is preserved"); + assert!( + unreadable_path.exists(), + "the unreadable source is preserved" + ); assert_eq!( BlobCcrStore::new(blobs, None) .unwrap() diff --git a/crates/tinyjuice-cli/tests/host_cli.rs b/crates/tinyjuice-cli/tests/host_cli.rs index 8584cdff..7a877d08 100644 --- a/crates/tinyjuice-cli/tests/host_cli.rs +++ b/crates/tinyjuice-cli/tests/host_cli.rs @@ -230,7 +230,10 @@ fn post_tool_hook_skips_compression_when_persistent_cache_storage_cannot_open() let out = invoke(dir.path(), &["codex-post-tool-use"], &payload); - assert!(out.status.success(), "cache setup must not fail the hook: {out:?}"); + assert!( + out.status.success(), + "cache setup must not fail the hook: {out:?}" + ); assert!( out.stdout.is_empty(), "without durable recovery, the hook must leave host output unchanged" From f08feec1708d4c23a2a555f8e434a944c4dcde8f Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 05:57:50 +0000 Subject: [PATCH 059/119] chore(deps): point tinybus git dependencies at tinyhumansai org The tinybus git source moved from the senamakel org to tinyhumansai, so the dependency URLs in the module manifest, the lockfile, and the cargo-deny allow-list were updated to match. The pinned revision is unchanged, so no dependency code changes. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- Cargo.lock | 6 +++--- crates/tinyjuice-module/Cargo.toml | 6 +++--- deny.toml | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 43a563d2..b3696966 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1420,7 +1420,7 @@ dependencies = [ [[package]] name = "tinybus" version = "0.1.6" -source = "git+https://github.com/senamakel/tinybus?rev=24ec2ccafcc98fab35fa10ffcbcefa87eb32e3e8#24ec2ccafcc98fab35fa10ffcbcefa87eb32e3e8" +source = "git+https://github.com/tinyhumansai/tinybus?rev=24ec2ccafcc98fab35fa10ffcbcefa87eb32e3e8#24ec2ccafcc98fab35fa10ffcbcefa87eb32e3e8" dependencies = [ "async-trait", "flate2", @@ -1442,7 +1442,7 @@ dependencies = [ [[package]] name = "tinybus-macros" version = "0.1.6" -source = "git+https://github.com/senamakel/tinybus?rev=24ec2ccafcc98fab35fa10ffcbcefa87eb32e3e8#24ec2ccafcc98fab35fa10ffcbcefa87eb32e3e8" +source = "git+https://github.com/tinyhumansai/tinybus?rev=24ec2ccafcc98fab35fa10ffcbcefa87eb32e3e8#24ec2ccafcc98fab35fa10ffcbcefa87eb32e3e8" dependencies = [ "proc-macro2", "quote", @@ -1452,7 +1452,7 @@ dependencies = [ [[package]] name = "tinybus-module" version = "0.1.6" -source = "git+https://github.com/senamakel/tinybus?rev=24ec2ccafcc98fab35fa10ffcbcefa87eb32e3e8#24ec2ccafcc98fab35fa10ffcbcefa87eb32e3e8" +source = "git+https://github.com/tinyhumansai/tinybus?rev=24ec2ccafcc98fab35fa10ffcbcefa87eb32e3e8#24ec2ccafcc98fab35fa10ffcbcefa87eb32e3e8" dependencies = [ "async-trait", "serde", diff --git a/crates/tinyjuice-module/Cargo.toml b/crates/tinyjuice-module/Cargo.toml index da73555a..4d56b8a7 100644 --- a/crates/tinyjuice-module/Cargo.toml +++ b/crates/tinyjuice-module/Cargo.toml @@ -21,8 +21,8 @@ tinyjuice = { path = "../..", default-features = false, features = ["jq"] } # The interface vocabulary. Shared with hosts, so this adapter cannot drift # from what a caller was compiled against. tinyjuice-bus = { path = "../tinyjuice-bus" } -tinybus = { version = "=0.1.6", git = "https://github.com/senamakel/tinybus", rev = "24ec2ccafcc98fab35fa10ffcbcefa87eb32e3e8", default-features = false, features = ["macros", "modules"] } -tinybus-module = { version = "=0.1.6", git = "https://github.com/senamakel/tinybus", rev = "24ec2ccafcc98fab35fa10ffcbcefa87eb32e3e8" } +tinybus = { version = "=0.1.6", git = "https://github.com/tinyhumansai/tinybus", rev = "24ec2ccafcc98fab35fa10ffcbcefa87eb32e3e8", default-features = false, features = ["macros", "modules"] } +tinybus-module = { version = "=0.1.6", git = "https://github.com/tinyhumansai/tinybus", rev = "24ec2ccafcc98fab35fa10ffcbcefa87eb32e3e8" } tokio = { version = "1", features = ["macros", "rt-multi-thread", "sync"] } serde_json = "1" # The CCR store's durable tier is blobs on the host's storage ports, reached @@ -36,7 +36,7 @@ log = "0.4" [dev-dependencies] # Tests serve the storage objects on the in-memory broker the module connects to. tinystoragedrivers-testkit = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "8a8bd701cc497a4ca099d98cae11aa684dd051aa" } -tinybus = { version = "=0.1.6", git = "https://github.com/senamakel/tinybus", rev = "24ec2ccafcc98fab35fa10ffcbcefa87eb32e3e8", default-features = false, features = ["test-support"] } +tinybus = { version = "=0.1.6", git = "https://github.com/tinyhumansai/tinybus", rev = "24ec2ccafcc98fab35fa10ffcbcefa87eb32e3e8", default-features = false, features = ["test-support"] } tempfile = "3" async-trait = "0.1" tokio = { version = "1", features = ["macros", "rt-multi-thread", "time"] } diff --git a/deny.toml b/deny.toml index 64f8d340..ebcc3e7d 100644 --- a/deny.toml +++ b/deny.toml @@ -47,5 +47,5 @@ allow-git = [ "https://github.com/tinyhumansai/tinytools", "https://github.com/tinyhumansai/tinystoragedrivers", "https://github.com/senamakel/tinystoragedrivers", - "https://github.com/senamakel/tinybus", + "https://github.com/tinyhumansai/tinybus", ] From ac9a6a25e76461990523f97b2dcf83c9d37fc7b6 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 06:03:04 +0000 Subject: [PATCH 060/119] chore(deps): bump tinystoragedrivers to rev c1da1bf Update the pinned tinystoragedrivers git revision across the workspace crates and refresh Cargo.lock to match. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- Cargo.lock | 24 ++++++++++++------------ crates/tinyjuice-bus/Cargo.toml | 2 +- crates/tinyjuice-cli/Cargo.toml | 8 ++++---- crates/tinyjuice-drivers/Cargo.toml | 8 ++++---- crates/tinyjuice-module/Cargo.toml | 8 ++++---- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b3696966..870e8ebc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1561,7 +1561,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?rev=8a8bd701cc497a4ca099d98cae11aa684dd051aa#8a8bd701cc497a4ca099d98cae11aa684dd051aa" +source = "git+https://github.com/senamakel/tinystoragedrivers?rev=c1da1bf19bac8df675d36d48a7592e59ee7ff81c#c1da1bf19bac8df675d36d48a7592e59ee7ff81c" dependencies = [ "tinystoragedrivers-api", "tinystoragedrivers-blob", @@ -1576,7 +1576,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers-api" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?rev=8a8bd701cc497a4ca099d98cae11aa684dd051aa#8a8bd701cc497a4ca099d98cae11aa684dd051aa" +source = "git+https://github.com/senamakel/tinystoragedrivers?rev=c1da1bf19bac8df675d36d48a7592e59ee7ff81c#c1da1bf19bac8df675d36d48a7592e59ee7ff81c" dependencies = [ "async-trait", "bytes", @@ -1590,7 +1590,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers-blob" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?rev=8a8bd701cc497a4ca099d98cae11aa684dd051aa#8a8bd701cc497a4ca099d98cae11aa684dd051aa" +source = "git+https://github.com/senamakel/tinystoragedrivers?rev=c1da1bf19bac8df675d36d48a7592e59ee7ff81c#c1da1bf19bac8df675d36d48a7592e59ee7ff81c" dependencies = [ "async-trait", "bytes", @@ -1605,7 +1605,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers-bus" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?rev=8a8bd701cc497a4ca099d98cae11aa684dd051aa#8a8bd701cc497a4ca099d98cae11aa684dd051aa" +source = "git+https://github.com/senamakel/tinystoragedrivers?rev=c1da1bf19bac8df675d36d48a7592e59ee7ff81c#c1da1bf19bac8df675d36d48a7592e59ee7ff81c" dependencies = [ "serde", "serde_json", @@ -1616,7 +1616,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers-busproxy" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?rev=8a8bd701cc497a4ca099d98cae11aa684dd051aa#8a8bd701cc497a4ca099d98cae11aa684dd051aa" +source = "git+https://github.com/senamakel/tinystoragedrivers?rev=c1da1bf19bac8df675d36d48a7592e59ee7ff81c#c1da1bf19bac8df675d36d48a7592e59ee7ff81c" dependencies = [ "async-trait", "bytes", @@ -1634,7 +1634,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers-connect" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?rev=8a8bd701cc497a4ca099d98cae11aa684dd051aa#8a8bd701cc497a4ca099d98cae11aa684dd051aa" +source = "git+https://github.com/senamakel/tinystoragedrivers?rev=c1da1bf19bac8df675d36d48a7592e59ee7ff81c#c1da1bf19bac8df675d36d48a7592e59ee7ff81c" dependencies = [ "rusqlite", "serde_json", @@ -1646,7 +1646,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers-document" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?rev=8a8bd701cc497a4ca099d98cae11aa684dd051aa#8a8bd701cc497a4ca099d98cae11aa684dd051aa" +source = "git+https://github.com/senamakel/tinystoragedrivers?rev=c1da1bf19bac8df675d36d48a7592e59ee7ff81c#c1da1bf19bac8df675d36d48a7592e59ee7ff81c" dependencies = [ "async-trait", "data-encoding", @@ -1665,7 +1665,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers-kv" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?rev=8a8bd701cc497a4ca099d98cae11aa684dd051aa#8a8bd701cc497a4ca099d98cae11aa684dd051aa" +source = "git+https://github.com/senamakel/tinystoragedrivers?rev=c1da1bf19bac8df675d36d48a7592e59ee7ff81c#c1da1bf19bac8df675d36d48a7592e59ee7ff81c" dependencies = [ "async-trait", "libc", @@ -1679,7 +1679,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers-queue" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?rev=8a8bd701cc497a4ca099d98cae11aa684dd051aa#8a8bd701cc497a4ca099d98cae11aa684dd051aa" +source = "git+https://github.com/senamakel/tinystoragedrivers?rev=c1da1bf19bac8df675d36d48a7592e59ee7ff81c#c1da1bf19bac8df675d36d48a7592e59ee7ff81c" dependencies = [ "async-trait", "data-encoding", @@ -1695,7 +1695,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers-secrets" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?rev=8a8bd701cc497a4ca099d98cae11aa684dd051aa#8a8bd701cc497a4ca099d98cae11aa684dd051aa" +source = "git+https://github.com/senamakel/tinystoragedrivers?rev=c1da1bf19bac8df675d36d48a7592e59ee7ff81c#c1da1bf19bac8df675d36d48a7592e59ee7ff81c" dependencies = [ "async-trait", "tinystoragedrivers-api", @@ -1706,7 +1706,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers-testkit" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?rev=8a8bd701cc497a4ca099d98cae11aa684dd051aa#8a8bd701cc497a4ca099d98cae11aa684dd051aa" +source = "git+https://github.com/senamakel/tinystoragedrivers?rev=c1da1bf19bac8df675d36d48a7592e59ee7ff81c#c1da1bf19bac8df675d36d48a7592e59ee7ff81c" dependencies = [ "async-trait", "bytes", @@ -1727,7 +1727,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers-types" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?rev=8a8bd701cc497a4ca099d98cae11aa684dd051aa#8a8bd701cc497a4ca099d98cae11aa684dd051aa" +source = "git+https://github.com/senamakel/tinystoragedrivers?rev=c1da1bf19bac8df675d36d48a7592e59ee7ff81c#c1da1bf19bac8df675d36d48a7592e59ee7ff81c" dependencies = [ "serde", "serde_json", diff --git a/crates/tinyjuice-bus/Cargo.toml b/crates/tinyjuice-bus/Cargo.toml index fcbd3883..b7da87c1 100644 --- a/crates/tinyjuice-bus/Cargo.toml +++ b/crates/tinyjuice-bus/Cargo.toml @@ -19,7 +19,7 @@ serde = { version = "1", features = ["derive"] } serde_json = "1" # Shared REPL error vocabulary; no execution dependencies. thiserror = "2" -tinystoragedrivers-types = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "8a8bd701cc497a4ca099d98cae11aa684dd051aa" } +tinystoragedrivers-types = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "c1da1bf19bac8df675d36d48a7592e59ee7ff81c" } [features] default = [] diff --git a/crates/tinyjuice-cli/Cargo.toml b/crates/tinyjuice-cli/Cargo.toml index 448bd509..d62d56fe 100644 --- a/crates/tinyjuice-cli/Cargo.toml +++ b/crates/tinyjuice-cli/Cargo.toml @@ -11,9 +11,9 @@ repository = "https://github.com/tinyhumansai/tinyjuice" [dependencies] tinyjuice = { path = "../.." } tinyjuice-drivers = { path = "../tinyjuice-drivers" } -tinystoragedrivers = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "8a8bd701cc497a4ca099d98cae11aa684dd051aa", features = ["file"] } -tinystoragedrivers-api = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "8a8bd701cc497a4ca099d98cae11aa684dd051aa" } -tinystoragedrivers-types = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "8a8bd701cc497a4ca099d98cae11aa684dd051aa" } +tinystoragedrivers = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "c1da1bf19bac8df675d36d48a7592e59ee7ff81c", features = ["file"] } +tinystoragedrivers-api = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "c1da1bf19bac8df675d36d48a7592e59ee7ff81c" } +tinystoragedrivers-types = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "c1da1bf19bac8df675d36d48a7592e59ee7ff81c" } dirs = "7" log = "0.4" serde_json = "1" @@ -22,7 +22,7 @@ tokio = { version = "1", features = ["rt-multi-thread"] } [dev-dependencies] async-trait = "0.1" tempfile = "3" -tinystoragedrivers-testkit = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "8a8bd701cc497a4ca099d98cae11aa684dd051aa" } +tinystoragedrivers-testkit = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "c1da1bf19bac8df675d36d48a7592e59ee7ff81c" } [[bin]] name = "tinyjuice" diff --git a/crates/tinyjuice-drivers/Cargo.toml b/crates/tinyjuice-drivers/Cargo.toml index 9dc0c88c..024a95ce 100644 --- a/crates/tinyjuice-drivers/Cargo.toml +++ b/crates/tinyjuice-drivers/Cargo.toml @@ -14,13 +14,13 @@ publish = false [dependencies] tinyjuice-bus = { path = "../tinyjuice-bus" } tinyjuice = { path = "../..", default-features = false } -tinystoragedrivers-api = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "8a8bd701cc497a4ca099d98cae11aa684dd051aa" } -tinystoragedrivers-types = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "8a8bd701cc497a4ca099d98cae11aa684dd051aa" } +tinystoragedrivers-api = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "c1da1bf19bac8df675d36d48a7592e59ee7ff81c" } +tinystoragedrivers-types = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "c1da1bf19bac8df675d36d48a7592e59ee7ff81c" } log = "0.4" tokio = { version = "1", features = ["rt"] } [dev-dependencies] tokio = { version = "1", features = ["macros", "rt-multi-thread", "time"] } async-trait = "0.1" -tinystoragedrivers-testkit = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "8a8bd701cc497a4ca099d98cae11aa684dd051aa" } -tinystoragedrivers-blob = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "8a8bd701cc497a4ca099d98cae11aa684dd051aa" } +tinystoragedrivers-testkit = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "c1da1bf19bac8df675d36d48a7592e59ee7ff81c" } +tinystoragedrivers-blob = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "c1da1bf19bac8df675d36d48a7592e59ee7ff81c" } diff --git a/crates/tinyjuice-module/Cargo.toml b/crates/tinyjuice-module/Cargo.toml index 4d56b8a7..09218c05 100644 --- a/crates/tinyjuice-module/Cargo.toml +++ b/crates/tinyjuice-module/Cargo.toml @@ -28,14 +28,14 @@ serde_json = "1" # The CCR store's durable tier is blobs on the host's storage ports, reached # over the storage bus. The module has no storage backend or file of its own. tinyjuice-drivers = { path = "../tinyjuice-drivers" } -tinystoragedrivers-api = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "8a8bd701cc497a4ca099d98cae11aa684dd051aa" } -tinystoragedrivers-types = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "8a8bd701cc497a4ca099d98cae11aa684dd051aa" } -tinystoragedrivers-busproxy = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "8a8bd701cc497a4ca099d98cae11aa684dd051aa" } +tinystoragedrivers-api = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "c1da1bf19bac8df675d36d48a7592e59ee7ff81c" } +tinystoragedrivers-types = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "c1da1bf19bac8df675d36d48a7592e59ee7ff81c" } +tinystoragedrivers-busproxy = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "c1da1bf19bac8df675d36d48a7592e59ee7ff81c" } log = "0.4" [dev-dependencies] # Tests serve the storage objects on the in-memory broker the module connects to. -tinystoragedrivers-testkit = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "8a8bd701cc497a4ca099d98cae11aa684dd051aa" } +tinystoragedrivers-testkit = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "c1da1bf19bac8df675d36d48a7592e59ee7ff81c" } tinybus = { version = "=0.1.6", git = "https://github.com/tinyhumansai/tinybus", rev = "24ec2ccafcc98fab35fa10ffcbcefa87eb32e3e8", default-features = false, features = ["test-support"] } tempfile = "3" async-trait = "0.1" From d8215e409b98c784b157f6f8c1176769d6290d74 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 06:04:27 +0000 Subject: [PATCH 061/119] test(cli): cover reduce-json help and argument errors without cache Add a test asserting that reduce-json --help and an unknown flag both succeed or fail as expected without touching the cache directory, so early-exit paths are verified to avoid opening the cache. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/tests/host_cli.rs | 33 ++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/crates/tinyjuice-cli/tests/host_cli.rs b/crates/tinyjuice-cli/tests/host_cli.rs index 7a877d08..c36817a6 100644 --- a/crates/tinyjuice-cli/tests/host_cli.rs +++ b/crates/tinyjuice-cli/tests/host_cli.rs @@ -118,6 +118,39 @@ fn host_cli_help_templates_and_gc_are_usable() { } } +#[test] +fn reduce_json_help_and_argument_errors_do_not_open_cache() { + let dir = tempfile::tempdir().unwrap(); + let cache_path = dir.path().join("not-a-directory"); + std::fs::write(&cache_path, "not a directory").unwrap(); + + for (args, expected_success, expected_output) in [ + (&["reduce-json", "--help"][..], true, "Usage:"), + ( + &["reduce-json", "--unknown"][..], + false, + "unknown reduce-json flag", + ), + ] { + let out = Command::new(env!("CARGO_BIN_EXE_tinyjuice")) + .args(args) + .env("TINYJUICE_CCR_DIR", &cache_path) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .unwrap(); + assert_eq!(out.status.success(), expected_success, "{args:?}: {out:?}"); + let output = format!( + "{}{}", + String::from_utf8_lossy(&out.stdout), + String::from_utf8_lossy(&out.stderr) + ); + assert!(output.contains(expected_output), "{args:?}: {output}"); + assert!(!output.contains("not a directory"), "{args:?}: {output}"); + } +} + #[test] fn host_cli_install_update_and_uninstall_preserve_settings() { let dir = tempfile::tempdir().unwrap(); From eced684f296fa5ae0f0b79c2a9660b804150bbc9 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 06:07:04 +0000 Subject: [PATCH 062/119] chore(deps): bump tinybus and tinystoragedrivers git revisions Update the pinned git revisions for the tinybus and tinystoragedrivers dependencies across the workspace crates and refresh Cargo.lock to match. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- Cargo.lock | 30 ++++++++++++++--------------- crates/tinyjuice-bus/Cargo.toml | 2 +- crates/tinyjuice-cli/Cargo.toml | 8 ++++---- crates/tinyjuice-drivers/Cargo.toml | 8 ++++---- crates/tinyjuice-module/Cargo.toml | 14 +++++++------- 5 files changed, 31 insertions(+), 31 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 870e8ebc..ccfb125d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1420,7 +1420,7 @@ dependencies = [ [[package]] name = "tinybus" version = "0.1.6" -source = "git+https://github.com/tinyhumansai/tinybus?rev=24ec2ccafcc98fab35fa10ffcbcefa87eb32e3e8#24ec2ccafcc98fab35fa10ffcbcefa87eb32e3e8" +source = "git+https://github.com/tinyhumansai/tinybus?rev=0de2d283f35cbbff08efad6fbe05537ffb74611b#0de2d283f35cbbff08efad6fbe05537ffb74611b" dependencies = [ "async-trait", "flate2", @@ -1442,7 +1442,7 @@ dependencies = [ [[package]] name = "tinybus-macros" version = "0.1.6" -source = "git+https://github.com/tinyhumansai/tinybus?rev=24ec2ccafcc98fab35fa10ffcbcefa87eb32e3e8#24ec2ccafcc98fab35fa10ffcbcefa87eb32e3e8" +source = "git+https://github.com/tinyhumansai/tinybus?rev=0de2d283f35cbbff08efad6fbe05537ffb74611b#0de2d283f35cbbff08efad6fbe05537ffb74611b" dependencies = [ "proc-macro2", "quote", @@ -1452,7 +1452,7 @@ dependencies = [ [[package]] name = "tinybus-module" version = "0.1.6" -source = "git+https://github.com/tinyhumansai/tinybus?rev=24ec2ccafcc98fab35fa10ffcbcefa87eb32e3e8#24ec2ccafcc98fab35fa10ffcbcefa87eb32e3e8" +source = "git+https://github.com/tinyhumansai/tinybus?rev=0de2d283f35cbbff08efad6fbe05537ffb74611b#0de2d283f35cbbff08efad6fbe05537ffb74611b" dependencies = [ "async-trait", "serde", @@ -1561,7 +1561,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?rev=c1da1bf19bac8df675d36d48a7592e59ee7ff81c#c1da1bf19bac8df675d36d48a7592e59ee7ff81c" +source = "git+https://github.com/senamakel/tinystoragedrivers?rev=6bc73c82da12d0f6035f8d85b27293d197dcb312#6bc73c82da12d0f6035f8d85b27293d197dcb312" dependencies = [ "tinystoragedrivers-api", "tinystoragedrivers-blob", @@ -1576,7 +1576,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers-api" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?rev=c1da1bf19bac8df675d36d48a7592e59ee7ff81c#c1da1bf19bac8df675d36d48a7592e59ee7ff81c" +source = "git+https://github.com/senamakel/tinystoragedrivers?rev=6bc73c82da12d0f6035f8d85b27293d197dcb312#6bc73c82da12d0f6035f8d85b27293d197dcb312" dependencies = [ "async-trait", "bytes", @@ -1590,7 +1590,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers-blob" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?rev=c1da1bf19bac8df675d36d48a7592e59ee7ff81c#c1da1bf19bac8df675d36d48a7592e59ee7ff81c" +source = "git+https://github.com/senamakel/tinystoragedrivers?rev=6bc73c82da12d0f6035f8d85b27293d197dcb312#6bc73c82da12d0f6035f8d85b27293d197dcb312" dependencies = [ "async-trait", "bytes", @@ -1605,7 +1605,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers-bus" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?rev=c1da1bf19bac8df675d36d48a7592e59ee7ff81c#c1da1bf19bac8df675d36d48a7592e59ee7ff81c" +source = "git+https://github.com/senamakel/tinystoragedrivers?rev=6bc73c82da12d0f6035f8d85b27293d197dcb312#6bc73c82da12d0f6035f8d85b27293d197dcb312" dependencies = [ "serde", "serde_json", @@ -1616,7 +1616,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers-busproxy" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?rev=c1da1bf19bac8df675d36d48a7592e59ee7ff81c#c1da1bf19bac8df675d36d48a7592e59ee7ff81c" +source = "git+https://github.com/senamakel/tinystoragedrivers?rev=6bc73c82da12d0f6035f8d85b27293d197dcb312#6bc73c82da12d0f6035f8d85b27293d197dcb312" dependencies = [ "async-trait", "bytes", @@ -1634,7 +1634,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers-connect" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?rev=c1da1bf19bac8df675d36d48a7592e59ee7ff81c#c1da1bf19bac8df675d36d48a7592e59ee7ff81c" +source = "git+https://github.com/senamakel/tinystoragedrivers?rev=6bc73c82da12d0f6035f8d85b27293d197dcb312#6bc73c82da12d0f6035f8d85b27293d197dcb312" dependencies = [ "rusqlite", "serde_json", @@ -1646,7 +1646,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers-document" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?rev=c1da1bf19bac8df675d36d48a7592e59ee7ff81c#c1da1bf19bac8df675d36d48a7592e59ee7ff81c" +source = "git+https://github.com/senamakel/tinystoragedrivers?rev=6bc73c82da12d0f6035f8d85b27293d197dcb312#6bc73c82da12d0f6035f8d85b27293d197dcb312" dependencies = [ "async-trait", "data-encoding", @@ -1665,7 +1665,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers-kv" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?rev=c1da1bf19bac8df675d36d48a7592e59ee7ff81c#c1da1bf19bac8df675d36d48a7592e59ee7ff81c" +source = "git+https://github.com/senamakel/tinystoragedrivers?rev=6bc73c82da12d0f6035f8d85b27293d197dcb312#6bc73c82da12d0f6035f8d85b27293d197dcb312" dependencies = [ "async-trait", "libc", @@ -1679,7 +1679,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers-queue" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?rev=c1da1bf19bac8df675d36d48a7592e59ee7ff81c#c1da1bf19bac8df675d36d48a7592e59ee7ff81c" +source = "git+https://github.com/senamakel/tinystoragedrivers?rev=6bc73c82da12d0f6035f8d85b27293d197dcb312#6bc73c82da12d0f6035f8d85b27293d197dcb312" dependencies = [ "async-trait", "data-encoding", @@ -1695,7 +1695,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers-secrets" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?rev=c1da1bf19bac8df675d36d48a7592e59ee7ff81c#c1da1bf19bac8df675d36d48a7592e59ee7ff81c" +source = "git+https://github.com/senamakel/tinystoragedrivers?rev=6bc73c82da12d0f6035f8d85b27293d197dcb312#6bc73c82da12d0f6035f8d85b27293d197dcb312" dependencies = [ "async-trait", "tinystoragedrivers-api", @@ -1706,7 +1706,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers-testkit" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?rev=c1da1bf19bac8df675d36d48a7592e59ee7ff81c#c1da1bf19bac8df675d36d48a7592e59ee7ff81c" +source = "git+https://github.com/senamakel/tinystoragedrivers?rev=6bc73c82da12d0f6035f8d85b27293d197dcb312#6bc73c82da12d0f6035f8d85b27293d197dcb312" dependencies = [ "async-trait", "bytes", @@ -1727,7 +1727,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers-types" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?rev=c1da1bf19bac8df675d36d48a7592e59ee7ff81c#c1da1bf19bac8df675d36d48a7592e59ee7ff81c" +source = "git+https://github.com/senamakel/tinystoragedrivers?rev=6bc73c82da12d0f6035f8d85b27293d197dcb312#6bc73c82da12d0f6035f8d85b27293d197dcb312" dependencies = [ "serde", "serde_json", diff --git a/crates/tinyjuice-bus/Cargo.toml b/crates/tinyjuice-bus/Cargo.toml index b7da87c1..2d6fd873 100644 --- a/crates/tinyjuice-bus/Cargo.toml +++ b/crates/tinyjuice-bus/Cargo.toml @@ -19,7 +19,7 @@ serde = { version = "1", features = ["derive"] } serde_json = "1" # Shared REPL error vocabulary; no execution dependencies. thiserror = "2" -tinystoragedrivers-types = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "c1da1bf19bac8df675d36d48a7592e59ee7ff81c" } +tinystoragedrivers-types = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "6bc73c82da12d0f6035f8d85b27293d197dcb312" } [features] default = [] diff --git a/crates/tinyjuice-cli/Cargo.toml b/crates/tinyjuice-cli/Cargo.toml index d62d56fe..ad09c96a 100644 --- a/crates/tinyjuice-cli/Cargo.toml +++ b/crates/tinyjuice-cli/Cargo.toml @@ -11,9 +11,9 @@ repository = "https://github.com/tinyhumansai/tinyjuice" [dependencies] tinyjuice = { path = "../.." } tinyjuice-drivers = { path = "../tinyjuice-drivers" } -tinystoragedrivers = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "c1da1bf19bac8df675d36d48a7592e59ee7ff81c", features = ["file"] } -tinystoragedrivers-api = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "c1da1bf19bac8df675d36d48a7592e59ee7ff81c" } -tinystoragedrivers-types = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "c1da1bf19bac8df675d36d48a7592e59ee7ff81c" } +tinystoragedrivers = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "6bc73c82da12d0f6035f8d85b27293d197dcb312", features = ["file"] } +tinystoragedrivers-api = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "6bc73c82da12d0f6035f8d85b27293d197dcb312" } +tinystoragedrivers-types = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "6bc73c82da12d0f6035f8d85b27293d197dcb312" } dirs = "7" log = "0.4" serde_json = "1" @@ -22,7 +22,7 @@ tokio = { version = "1", features = ["rt-multi-thread"] } [dev-dependencies] async-trait = "0.1" tempfile = "3" -tinystoragedrivers-testkit = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "c1da1bf19bac8df675d36d48a7592e59ee7ff81c" } +tinystoragedrivers-testkit = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "6bc73c82da12d0f6035f8d85b27293d197dcb312" } [[bin]] name = "tinyjuice" diff --git a/crates/tinyjuice-drivers/Cargo.toml b/crates/tinyjuice-drivers/Cargo.toml index 024a95ce..cad6df1f 100644 --- a/crates/tinyjuice-drivers/Cargo.toml +++ b/crates/tinyjuice-drivers/Cargo.toml @@ -14,13 +14,13 @@ publish = false [dependencies] tinyjuice-bus = { path = "../tinyjuice-bus" } tinyjuice = { path = "../..", default-features = false } -tinystoragedrivers-api = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "c1da1bf19bac8df675d36d48a7592e59ee7ff81c" } -tinystoragedrivers-types = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "c1da1bf19bac8df675d36d48a7592e59ee7ff81c" } +tinystoragedrivers-api = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "6bc73c82da12d0f6035f8d85b27293d197dcb312" } +tinystoragedrivers-types = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "6bc73c82da12d0f6035f8d85b27293d197dcb312" } log = "0.4" tokio = { version = "1", features = ["rt"] } [dev-dependencies] tokio = { version = "1", features = ["macros", "rt-multi-thread", "time"] } async-trait = "0.1" -tinystoragedrivers-testkit = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "c1da1bf19bac8df675d36d48a7592e59ee7ff81c" } -tinystoragedrivers-blob = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "c1da1bf19bac8df675d36d48a7592e59ee7ff81c" } +tinystoragedrivers-testkit = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "6bc73c82da12d0f6035f8d85b27293d197dcb312" } +tinystoragedrivers-blob = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "6bc73c82da12d0f6035f8d85b27293d197dcb312" } diff --git a/crates/tinyjuice-module/Cargo.toml b/crates/tinyjuice-module/Cargo.toml index 09218c05..2b4d4ae5 100644 --- a/crates/tinyjuice-module/Cargo.toml +++ b/crates/tinyjuice-module/Cargo.toml @@ -21,22 +21,22 @@ tinyjuice = { path = "../..", default-features = false, features = ["jq"] } # The interface vocabulary. Shared with hosts, so this adapter cannot drift # from what a caller was compiled against. tinyjuice-bus = { path = "../tinyjuice-bus" } -tinybus = { version = "=0.1.6", git = "https://github.com/tinyhumansai/tinybus", rev = "24ec2ccafcc98fab35fa10ffcbcefa87eb32e3e8", default-features = false, features = ["macros", "modules"] } -tinybus-module = { version = "=0.1.6", git = "https://github.com/tinyhumansai/tinybus", rev = "24ec2ccafcc98fab35fa10ffcbcefa87eb32e3e8" } +tinybus = { version = "=0.1.6", git = "https://github.com/tinyhumansai/tinybus", rev = "0de2d283f35cbbff08efad6fbe05537ffb74611b", default-features = false, features = ["macros", "modules"] } +tinybus-module = { version = "=0.1.6", git = "https://github.com/tinyhumansai/tinybus", rev = "0de2d283f35cbbff08efad6fbe05537ffb74611b" } tokio = { version = "1", features = ["macros", "rt-multi-thread", "sync"] } serde_json = "1" # The CCR store's durable tier is blobs on the host's storage ports, reached # over the storage bus. The module has no storage backend or file of its own. tinyjuice-drivers = { path = "../tinyjuice-drivers" } -tinystoragedrivers-api = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "c1da1bf19bac8df675d36d48a7592e59ee7ff81c" } -tinystoragedrivers-types = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "c1da1bf19bac8df675d36d48a7592e59ee7ff81c" } -tinystoragedrivers-busproxy = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "c1da1bf19bac8df675d36d48a7592e59ee7ff81c" } +tinystoragedrivers-api = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "6bc73c82da12d0f6035f8d85b27293d197dcb312" } +tinystoragedrivers-types = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "6bc73c82da12d0f6035f8d85b27293d197dcb312" } +tinystoragedrivers-busproxy = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "6bc73c82da12d0f6035f8d85b27293d197dcb312" } log = "0.4" [dev-dependencies] # Tests serve the storage objects on the in-memory broker the module connects to. -tinystoragedrivers-testkit = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "c1da1bf19bac8df675d36d48a7592e59ee7ff81c" } -tinybus = { version = "=0.1.6", git = "https://github.com/tinyhumansai/tinybus", rev = "24ec2ccafcc98fab35fa10ffcbcefa87eb32e3e8", default-features = false, features = ["test-support"] } +tinystoragedrivers-testkit = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "6bc73c82da12d0f6035f8d85b27293d197dcb312" } +tinybus = { version = "=0.1.6", git = "https://github.com/tinyhumansai/tinybus", rev = "0de2d283f35cbbff08efad6fbe05537ffb74611b", default-features = false, features = ["test-support"] } tempfile = "3" async-trait = "0.1" tokio = { version = "1", features = ["macros", "rt-multi-thread", "time"] } From 4ef90b783ae419d507b8287d4fca77b2f9dd3548 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 06:09:41 +0000 Subject: [PATCH 063/119] test(module): assert request-scoped import leaves module stats untouched Extend the request-scoped import test to check that the module's own event count stays at zero after the import, guarding against request-scoped state leaking into ordinary module state. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-module/src/service_tests.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/tinyjuice-module/src/service_tests.rs b/crates/tinyjuice-module/src/service_tests.rs index 78404d52..a4720934 100644 --- a/crates/tinyjuice-module/src/service_tests.rs +++ b/crates/tinyjuice-module/src/service_tests.rs @@ -447,6 +447,12 @@ async fn import_savings_at_uses_only_its_request_scoped_storage_address() { .unwrap(); assert!(imported); + assert_eq!( + savings.stats(Some(&module)).await.total.events, + 0, + "request-scoped import state must not become ordinary module state" + ); + let ordinary = backend.for_scope(&Scope::new("ordinary").unwrap()).unwrap(); let stored = ordinary .documents() From 05210412a5bb73be0931911f377a6b60e3710119 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 06:25:01 +0000 Subject: [PATCH 064/119] fix: parse reduce-json arguments before cache setup Co-authored-by: Medulla --- crates/tinyjuice-cli/src/bin/tinyjuice.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/tinyjuice-cli/src/bin/tinyjuice.rs b/crates/tinyjuice-cli/src/bin/tinyjuice.rs index 2602d5b3..a737913b 100644 --- a/crates/tinyjuice-cli/src/bin/tinyjuice.rs +++ b/crates/tinyjuice-cli/src/bin/tinyjuice.rs @@ -78,7 +78,6 @@ fn run() -> Result<(), String> { } fn reduce_json(args: Vec) -> Result<(), String> { - configure_cli_cache()?; let mut host_override = None; let mut path = None; let mut index = 0; @@ -111,6 +110,7 @@ fn reduce_json(args: Vec) -> Result<(), String> { } } + configure_cli_cache()?; let input = read_input(path.as_deref())?; let value = serde_json::from_str(&input).map_err(|error| format!("invalid JSON: {error}"))?; let mut request = request_from_json_value(value).map_err(|error| error.to_string())?; From af11f50c4a80312fe8d8a77d52ced7fe4a21a789 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 06:25:01 +0000 Subject: [PATCH 065/119] fix: keep callback savings imports request scoped Co-authored-by: Medulla --- crates/tinyjuice-module/src/savings_store.rs | 24 +++++++------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/crates/tinyjuice-module/src/savings_store.rs b/crates/tinyjuice-module/src/savings_store.rs index e202561b..ba6e2305 100644 --- a/crates/tinyjuice-module/src/savings_store.rs +++ b/crates/tinyjuice-module/src/savings_store.rs @@ -147,24 +147,16 @@ impl Savings { Precondition::Version(stored.version) }); - let previous = self.ledger.stats(); - self.ledger.replace(legacy); - let body = StoredSavings::from_aggregate(&self.ledger.stats(), now_ms()); - if let Err(error) = docs - .put_as(SAVINGS_COLLECTION, SAVINGS_DOC_ID, &body, precondition) + let body = StoredSavings::from_aggregate(&legacy, now_ms()); + docs.put_as(SAVINGS_COLLECTION, SAVINGS_DOC_ID, &body, precondition) .await - { - self.ledger.replace(previous); - return Err(tinybus::Error::failed(format!( - "savings could not be written: {error}" - ))); - } + .map_err(|error| { + tinybus::Error::failed(format!("savings could not be written: {error}")) + })?; - // The document is now authoritative through the ordinary port already - // held by this state. Never retain the invocation-scoped handle. - state.loaded = true; - state.dirty = false; - state.reset_early = false; + // The callback port is invocation-scoped and may address a different + // document from the ordinary port. Keep its imported totals out of the + // ordinary in-memory ledger and leave the ordinary load state intact. Ok(true) } From 0ec44f3c5bc91fc6ca20ef3cf7a46dba4832064b Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 06:25:01 +0000 Subject: [PATCH 066/119] chore: normalize Cargo lock for pinned dependencies Co-authored-by: Medulla --- Cargo.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ccfb125d..5102d1eb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1391,7 +1391,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" dependencies = [ "fastrand", - "getrandom 0.4.3", + "getrandom 0.3.4", "once_cell", "rustix", "windows-sys 0.61.2", @@ -1654,7 +1654,7 @@ dependencies = [ "rusqlite", "serde", "serde_json", - "sha2 0.10.9", + "sha2 0.11.0", "tinystoragedrivers-api", "tinystoragedrivers-connect", "tinystoragedrivers-types", @@ -1685,7 +1685,7 @@ dependencies = [ "data-encoding", "serde", "serde_json", - "sha2 0.10.9", + "sha2 0.11.0", "tinystoragedrivers-api", "tinystoragedrivers-types", "tokio", From 43ca1143fad47179f1f02d124f4e79d13fe0d07b Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 06:27:39 +0000 Subject: [PATCH 067/119] test: cover retrieve argument errors before cache setup Co-authored-by: Medulla --- crates/tinyjuice-cli/tests/host_cli.rs | 28 ++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/crates/tinyjuice-cli/tests/host_cli.rs b/crates/tinyjuice-cli/tests/host_cli.rs index c36817a6..67f61d93 100644 --- a/crates/tinyjuice-cli/tests/host_cli.rs +++ b/crates/tinyjuice-cli/tests/host_cli.rs @@ -151,6 +151,34 @@ fn reduce_json_help_and_argument_errors_do_not_open_cache() { } } +#[test] +fn retrieve_argument_errors_do_not_open_cache() { + let dir = tempfile::tempdir().unwrap(); + let cache_path = dir.path().join("not-a-directory"); + std::fs::write(&cache_path, "not a directory").unwrap(); + + for (args, expected_error) in [ + (&["retrieve"][..], "retrieve requires a CCR token"), + ( + &["retrieve", "one", "two"][..], + "retrieve accepts exactly one CCR token", + ), + ] { + let out = Command::new(env!("CARGO_BIN_EXE_tinyjuice")) + .args(args) + .env("TINYJUICE_CCR_DIR", &cache_path) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .unwrap(); + assert!(!out.status.success(), "{args:?}: {out:?}"); + let stderr = String::from_utf8_lossy(&out.stderr); + assert!(stderr.contains(expected_error), "{args:?}: {stderr}"); + assert!(!stderr.contains("not a directory"), "{args:?}: {stderr}"); + } +} + #[test] fn host_cli_install_update_and_uninstall_preserve_settings() { let dir = tempfile::tempdir().unwrap(); From dcbb9620af25978549c62bba41577e189c81474c Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 06:27:39 +0000 Subject: [PATCH 068/119] fix: validate retrieve tokens before cache setup Co-authored-by: Medulla --- crates/tinyjuice-cli/src/bin/tinyjuice.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/tinyjuice-cli/src/bin/tinyjuice.rs b/crates/tinyjuice-cli/src/bin/tinyjuice.rs index a737913b..38fbcd59 100644 --- a/crates/tinyjuice-cli/src/bin/tinyjuice.rs +++ b/crates/tinyjuice-cli/src/bin/tinyjuice.rs @@ -532,13 +532,13 @@ fn finish_toml_lines(lines: Vec) -> String { } fn retrieve_command(args: Vec) -> Result<(), String> { - configure_cli_cache()?; let token = args .first() .ok_or_else(|| "retrieve requires a CCR token".to_string())?; if args.len() > 1 { return Err("retrieve accepts exactly one CCR token".to_string()); } + configure_cli_cache()?; let Some(original) = tinyjuice::cache::retrieve(token) else { return Err(format!("no original found for token {token}")); }; From 0f6dcbe39e15839a06ac220598d20d87ad614ffb Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 06:30:02 +0000 Subject: [PATCH 069/119] fix: reload ordinary savings after callback import Co-authored-by: Medulla --- crates/tinyjuice-module/src/savings_store.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/tinyjuice-module/src/savings_store.rs b/crates/tinyjuice-module/src/savings_store.rs index ba6e2305..3e883f64 100644 --- a/crates/tinyjuice-module/src/savings_store.rs +++ b/crates/tinyjuice-module/src/savings_store.rs @@ -155,8 +155,9 @@ impl Savings { })?; // The callback port is invocation-scoped and may address a different - // document from the ordinary port. Keep its imported totals out of the - // ordinary in-memory ledger and leave the ordinary load state intact. + // document from the ordinary port. Invalidate the cached ledger so the + // next ordinary operation reloads only through the ordinary port. + state.loaded = false; Ok(true) } From 007bed39a9998fd0828cfee5a48dab1a7b6fd76c Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 06:38:55 +0000 Subject: [PATCH 070/119] fix: reload cached savings through ordinary document port Co-authored-by: Medulla --- crates/tinyjuice-module/src/savings_store.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/tinyjuice-module/src/savings_store.rs b/crates/tinyjuice-module/src/savings_store.rs index 3e883f64..6ea7b3ce 100644 --- a/crates/tinyjuice-module/src/savings_store.rs +++ b/crates/tinyjuice-module/src/savings_store.rs @@ -170,11 +170,11 @@ impl Savings { if state.loaded { return; } - let Some(connection) = connection else { - state.loaded = true; - return; - }; if state.docs.is_none() { + let Some(connection) = connection else { + state.loaded = true; + return; + }; if state .last_connect_failure .is_some_and(|at| at.elapsed() < self.cooldown) From f2708264eb95079691737ca624ed05d5281dc2af Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 06:42:54 +0000 Subject: [PATCH 071/119] test(storage): cover corrupt legacy entries in collection Add a test asserting that garbage collection removes and reports corrupt legacy entries, and update the legacy import test to expect the mismatched source to be discarded rather than preserved. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage_tests.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/crates/tinyjuice-cli/src/storage_tests.rs b/crates/tinyjuice-cli/src/storage_tests.rs index 4e534157..fcea7fd3 100644 --- a/crates/tinyjuice-cli/src/storage_tests.rs +++ b/crates/tinyjuice-cli/src/storage_tests.rs @@ -79,6 +79,20 @@ fn collection_reports_bytes_removed_by_the_budget() { assert_eq!(collect(dir.path(), None, Some(0)).unwrap(), (2, 11, 0, 0)); } +#[test] +fn collection_removes_and_reports_corrupt_legacy_entries() { + let dir = tempfile::tempdir().unwrap(); + let token = "0123456789abcdef0123456789abcdef"; + let path = dir.path().join(token); + let corrupt_content = "content does not match its token"; + std::fs::write(&path, corrupt_content).unwrap(); + + let result = collect(dir.path(), None, Some(0)).unwrap(); + + assert_eq!(result, (1, corrupt_content.len() as u64, 0, 0)); + assert!(!path.exists(), "garbage collection removes the corrupt file"); +} + #[test] fn configure_and_inventory_report_invalid_storage_paths() { let dir = tempfile::tempdir().unwrap(); @@ -116,7 +130,10 @@ fn legacy_import_skips_corrupt_entries_and_continues_importing_valid_files() { import_legacy_files(dir.path(), &blobs, None).unwrap(); assert!(!valid_path.exists(), "the valid legacy file is imported"); - assert!(mismatch_path.exists(), "the mismatched source is preserved"); + assert!( + !mismatch_path.exists(), + "the corrupt source is discarded rather than retried forever" + ); assert!( unreadable_path.exists(), "the unreadable source is preserved" From 9a0f7c9cadabe2d326f5daa3dc67e5f580869dd2 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 06:43:43 +0000 Subject: [PATCH 072/119] fix(storage): count corrupt legacy entries in collection totals Corrupt legacy CCR entries were skipped during import and left on disk, so their bytes never appeared in the collection report. They are now removed and their count and size are folded into the totals returned by collect. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage.rs | 39 +++++++++++++++++++---- crates/tinyjuice-cli/src/storage_tests.rs | 5 ++- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/crates/tinyjuice-cli/src/storage.rs b/crates/tinyjuice-cli/src/storage.rs index 8de55a83..fa360a17 100644 --- a/crates/tinyjuice-cli/src/storage.rs +++ b/crates/tinyjuice-cli/src/storage.rs @@ -30,6 +30,14 @@ pub(crate) fn configure( ttl: Option, max_bytes: Option, ) -> Result<(), String> { + configure_with_report(root, ttl, max_bytes).map(|_| ()) +} + +fn configure_with_report( + root: &Path, + ttl: Option, + max_bytes: Option, +) -> Result<(usize, u64), String> { std::fs::create_dir_all(root).map_err(|error| { format!( "cannot create CCR storage directory {}: {error}", @@ -37,7 +45,7 @@ pub(crate) fn configure( ) })?; let blobs = open_file_blobs(root)?; - import_legacy_files(root, &blobs, ttl)?; + let discarded_legacy = import_legacy_files(root, &blobs, ttl)?; let store = BlobCcrStore::new(Arc::clone(&blobs), ttl).map_err(|error| error.to_string())?; let capped = CappedCcrStore { store, @@ -49,7 +57,7 @@ pub(crate) fn configure( prune(&blobs, ttl, max_bytes, None)?; } set_durable_tier(Some(Arc::new(capped))); - Ok(()) + Ok(discarded_legacy) } #[allow(dead_code)] // The reducer binary uses inventory; the hook binary shares this module. @@ -118,9 +126,15 @@ pub(crate) fn collect( ttl: Option, max_bytes: Option, ) -> Result<(usize, u64, usize, u64), String> { - configure(root, ttl, None)?; + let (legacy_removed, legacy_bytes) = configure_with_report(root, ttl, None)?; let blobs = open_file_blobs(root)?; - prune(&blobs, ttl, max_bytes, None) + let (removed, freed, kept, kept_bytes) = prune(&blobs, ttl, max_bytes, None)?; + Ok(( + legacy_removed.saturating_add(removed), + legacy_bytes.saturating_add(freed), + kept, + kept_bytes, + )) } fn prune( @@ -224,7 +238,9 @@ fn import_legacy_files( root: &Path, blobs: &Arc, ttl: Option, -) -> Result<(), String> { +) -> Result<(usize, u64), String> { + let mut discarded_corrupt = 0_usize; + let mut discarded_bytes = 0_u64; let entries = std::fs::read_dir(root).map_err(|error| { format!( "failed to inspect legacy CCR directory {}: {error}", @@ -254,6 +270,17 @@ fn import_legacy_files( }; if tinyjuice::cache::short_hash(&content) != token { log::warn!("[tinyjuice_cli] skipping legacy CCR entry {token}: content hash mismatch"); + let size = entry + .metadata() + .map_err(|error| { + format!("cannot inspect corrupt legacy CCR entry {token}: {error}") + })? + .len(); + std::fs::remove_file(entry.path()).map_err(|error| { + format!("cannot remove corrupt legacy CCR entry {token}: {error}") + })?; + discarded_corrupt = discarded_corrupt.saturating_add(1); + discarded_bytes = discarded_bytes.saturating_add(size); continue; } let modified = entry @@ -333,7 +360,7 @@ fn import_legacy_files( std::fs::remove_file(entry.path()) .map_err(|error| format!("cannot remove imported CCR entry {token}: {error}"))?; } - Ok(()) + Ok((discarded_corrupt, discarded_bytes)) } fn remaining_ttl(modified: SystemTime, now: SystemTime, ttl: Duration) -> Option { diff --git a/crates/tinyjuice-cli/src/storage_tests.rs b/crates/tinyjuice-cli/src/storage_tests.rs index fcea7fd3..9cc4ec32 100644 --- a/crates/tinyjuice-cli/src/storage_tests.rs +++ b/crates/tinyjuice-cli/src/storage_tests.rs @@ -90,7 +90,10 @@ fn collection_removes_and_reports_corrupt_legacy_entries() { let result = collect(dir.path(), None, Some(0)).unwrap(); assert_eq!(result, (1, corrupt_content.len() as u64, 0, 0)); - assert!(!path.exists(), "garbage collection removes the corrupt file"); + assert!( + !path.exists(), + "garbage collection removes the corrupt file" + ); } #[test] From 663198c938d5160eaec2e831057a562731ebec43 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 06:52:08 +0000 Subject: [PATCH 073/119] fix(storage): count expired legacy entries in collection stats Expired legacy CCR files were deleted during collection but not included in the removed count or byte total, so the reported figures understated what was actually cleaned up. The counters were renamed to reflect that they now cover both corrupt and expired entries, and a test covers the expired case. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage.rs | 18 +++++++++++++----- crates/tinyjuice-cli/src/storage_tests.rs | 17 +++++++++++++++++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/crates/tinyjuice-cli/src/storage.rs b/crates/tinyjuice-cli/src/storage.rs index fa360a17..7a6463c2 100644 --- a/crates/tinyjuice-cli/src/storage.rs +++ b/crates/tinyjuice-cli/src/storage.rs @@ -239,8 +239,8 @@ fn import_legacy_files( blobs: &Arc, ttl: Option, ) -> Result<(usize, u64), String> { - let mut discarded_corrupt = 0_usize; - let mut discarded_bytes = 0_u64; + let mut removed_legacy = 0_usize; + let mut removed_legacy_bytes = 0_u64; let entries = std::fs::read_dir(root).map_err(|error| { format!( "failed to inspect legacy CCR directory {}: {error}", @@ -279,8 +279,8 @@ fn import_legacy_files( std::fs::remove_file(entry.path()).map_err(|error| { format!("cannot remove corrupt legacy CCR entry {token}: {error}") })?; - discarded_corrupt = discarded_corrupt.saturating_add(1); - discarded_bytes = discarded_bytes.saturating_add(size); + removed_legacy = removed_legacy.saturating_add(1); + removed_legacy_bytes = removed_legacy_bytes.saturating_add(size); continue; } let modified = entry @@ -294,9 +294,17 @@ fn import_legacy_files( Some(ttl) => { let remaining = remaining_ttl(modified, SystemTime::now(), ttl); if remaining.is_none() { + let size = entry + .metadata() + .map_err(|error| { + format!("cannot inspect expired legacy CCR entry {token}: {error}") + })? + .len(); std::fs::remove_file(entry.path()).map_err(|error| { format!("cannot remove expired legacy CCR entry {token}: {error}") })?; + removed_legacy = removed_legacy.saturating_add(1); + removed_legacy_bytes = removed_legacy_bytes.saturating_add(size); continue; } remaining @@ -360,7 +368,7 @@ fn import_legacy_files( std::fs::remove_file(entry.path()) .map_err(|error| format!("cannot remove imported CCR entry {token}: {error}"))?; } - Ok((discarded_corrupt, discarded_bytes)) + Ok((removed_legacy, removed_legacy_bytes)) } fn remaining_ttl(modified: SystemTime, now: SystemTime, ttl: Duration) -> Option { diff --git a/crates/tinyjuice-cli/src/storage_tests.rs b/crates/tinyjuice-cli/src/storage_tests.rs index 9cc4ec32..7dae8b2a 100644 --- a/crates/tinyjuice-cli/src/storage_tests.rs +++ b/crates/tinyjuice-cli/src/storage_tests.rs @@ -96,6 +96,23 @@ fn collection_removes_and_reports_corrupt_legacy_entries() { ); } +#[test] +fn collection_reports_expired_legacy_entries() { + let dir = tempfile::tempdir().unwrap(); + let content = "valid but expired legacy entry"; + let token = tinyjuice::cache::short_hash(content); + let path = dir.path().join(token); + std::fs::write(&path, content).unwrap(); + + let result = collect(dir.path(), Some(Duration::ZERO), None).unwrap(); + + assert_eq!(result, (1, content.len() as u64, 0, 0)); + assert!( + !path.exists(), + "garbage collection removes expired legacy files" + ); +} + #[test] fn configure_and_inventory_report_invalid_storage_paths() { let dir = tempfile::tempdir().unwrap(); From f79d9bcaa9d3e39020dc31be42363aa85668b68b Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 06:53:28 +0000 Subject: [PATCH 074/119] test(storage): make expired legacy entry test deterministic The test now explicitly backdates the cache file's modification time to the Unix epoch instead of relying on the file being older than a zero-duration threshold, and the collection window is widened to one second so the entry is reliably reported as expired. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage_tests.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/tinyjuice-cli/src/storage_tests.rs b/crates/tinyjuice-cli/src/storage_tests.rs index 7dae8b2a..07ff9f69 100644 --- a/crates/tinyjuice-cli/src/storage_tests.rs +++ b/crates/tinyjuice-cli/src/storage_tests.rs @@ -103,8 +103,14 @@ fn collection_reports_expired_legacy_entries() { let token = tinyjuice::cache::short_hash(content); let path = dir.path().join(token); std::fs::write(&path, content).unwrap(); + std::fs::OpenOptions::new() + .write(true) + .open(&path) + .unwrap() + .set_times(std::fs::FileTimes::new().set_modified(SystemTime::UNIX_EPOCH)) + .unwrap(); - let result = collect(dir.path(), Some(Duration::ZERO), None).unwrap(); + let result = collect(dir.path(), Some(Duration::from_secs(1)), None).unwrap(); assert_eq!(result, (1, content.len() as u64, 0, 0)); assert!( From 2954e89adad7967594e8d7563e713395f4347323 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 06:59:24 +0000 Subject: [PATCH 075/119] refactor(storage): extract legacy entry removal into helper The duplicated metadata-and-remove logic for corrupt and expired legacy CCR entries now lives in a single remove_legacy_entry helper that takes the reason as a parameter, so the two call sites share one implementation and their error messages stay consistent. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage.rs | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/crates/tinyjuice-cli/src/storage.rs b/crates/tinyjuice-cli/src/storage.rs index 7a6463c2..82479aae 100644 --- a/crates/tinyjuice-cli/src/storage.rs +++ b/crates/tinyjuice-cli/src/storage.rs @@ -270,15 +270,7 @@ fn import_legacy_files( }; if tinyjuice::cache::short_hash(&content) != token { log::warn!("[tinyjuice_cli] skipping legacy CCR entry {token}: content hash mismatch"); - let size = entry - .metadata() - .map_err(|error| { - format!("cannot inspect corrupt legacy CCR entry {token}: {error}") - })? - .len(); - std::fs::remove_file(entry.path()).map_err(|error| { - format!("cannot remove corrupt legacy CCR entry {token}: {error}") - })?; + let size = remove_legacy_entry(&entry.path(), &token, "corrupt")?; removed_legacy = removed_legacy.saturating_add(1); removed_legacy_bytes = removed_legacy_bytes.saturating_add(size); continue; @@ -294,15 +286,7 @@ fn import_legacy_files( Some(ttl) => { let remaining = remaining_ttl(modified, SystemTime::now(), ttl); if remaining.is_none() { - let size = entry - .metadata() - .map_err(|error| { - format!("cannot inspect expired legacy CCR entry {token}: {error}") - })? - .len(); - std::fs::remove_file(entry.path()).map_err(|error| { - format!("cannot remove expired legacy CCR entry {token}: {error}") - })?; + let size = remove_legacy_entry(&entry.path(), &token, "expired")?; removed_legacy = removed_legacy.saturating_add(1); removed_legacy_bytes = removed_legacy_bytes.saturating_add(size); continue; @@ -371,6 +355,15 @@ fn import_legacy_files( Ok((removed_legacy, removed_legacy_bytes)) } +fn remove_legacy_entry(path: &Path, token: &str, reason: &str) -> Result { + let size = std::fs::metadata(path) + .map_err(|error| format!("cannot inspect {reason} legacy CCR entry {token}: {error}"))? + .len(); + std::fs::remove_file(path) + .map_err(|error| format!("cannot remove {reason} legacy CCR entry {token}: {error}"))?; + Ok(size) +} + fn remaining_ttl(modified: SystemTime, now: SystemTime, ttl: Duration) -> Option { let elapsed = now.duration_since(modified).unwrap_or_default(); let remaining = ttl.saturating_sub(elapsed); From 8105267fef0f28a9ecdd5f14b124a150ca8f5748 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 06:59:51 +0000 Subject: [PATCH 076/119] test(storage): cover legacy entry removal error paths Add a test asserting that removing a legacy CCR entry surfaces distinct errors when the path cannot be inspected and when removal fails, and that a failed removal leaves the directory in place. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage_tests.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/crates/tinyjuice-cli/src/storage_tests.rs b/crates/tinyjuice-cli/src/storage_tests.rs index 07ff9f69..5851f80b 100644 --- a/crates/tinyjuice-cli/src/storage_tests.rs +++ b/crates/tinyjuice-cli/src/storage_tests.rs @@ -119,6 +119,21 @@ fn collection_reports_expired_legacy_entries() { ); } +#[test] +fn removing_legacy_entries_reports_inspection_and_removal_errors() { + let dir = tempfile::tempdir().unwrap(); + let token = "0123456789abcdef0123456789abcdef"; + let missing_path = dir.path().join(token); + let inspect_error = remove_legacy_entry(&missing_path, token, "corrupt").unwrap_err(); + assert!(inspect_error.contains("cannot inspect corrupt legacy CCR entry")); + + let directory_path = dir.path().join(token); + std::fs::create_dir(&directory_path).unwrap(); + let remove_error = remove_legacy_entry(&directory_path, token, "expired").unwrap_err(); + assert!(remove_error.contains("cannot remove expired legacy CCR entry")); + assert!(directory_path.is_dir()); +} + #[test] fn configure_and_inventory_report_invalid_storage_paths() { let dir = tempfile::tempdir().unwrap(); From fa02ca7e138cadbcbfb9e672c2c33786b1401186 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 07:04:57 +0000 Subject: [PATCH 077/119] test(storage): cover removal of non-utf8 legacy entries Add a test asserting that garbage collection deletes non-UTF-8 legacy files and reports their bytes as reclaimed. Update the legacy import test to expect the non-UTF-8 source to be discarded rather than preserved, matching the new behaviour. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage_tests.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/crates/tinyjuice-cli/src/storage_tests.rs b/crates/tinyjuice-cli/src/storage_tests.rs index 5851f80b..31a60e13 100644 --- a/crates/tinyjuice-cli/src/storage_tests.rs +++ b/crates/tinyjuice-cli/src/storage_tests.rs @@ -119,6 +119,23 @@ fn collection_reports_expired_legacy_entries() { ); } +#[test] +fn collection_removes_and_reports_non_utf8_legacy_entries() { + let dir = tempfile::tempdir().unwrap(); + let token = "fedcba9876543210fedcba9876543210"; + let path = dir.path().join(token); + let corrupt_content = [0xff, 0xfe]; + std::fs::write(&path, corrupt_content).unwrap(); + + let result = collect(dir.path(), None, Some(0)).unwrap(); + + assert_eq!(result, (1, corrupt_content.len() as u64, 0, 0)); + assert!( + !path.exists(), + "garbage collection removes non-UTF-8 legacy files" + ); +} + #[test] fn removing_legacy_entries_reports_inspection_and_removal_errors() { let dir = tempfile::tempdir().unwrap(); @@ -176,8 +193,8 @@ fn legacy_import_skips_corrupt_entries_and_continues_importing_valid_files() { "the corrupt source is discarded rather than retried forever" ); assert!( - unreadable_path.exists(), - "the unreadable source is preserved" + !unreadable_path.exists(), + "the non-UTF-8 source is discarded" ); assert_eq!( BlobCcrStore::new(blobs, None) From b582a0d51f31e74c24a20a531dd549ba4490f758 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 07:05:14 +0000 Subject: [PATCH 078/119] fix(cli): discard non-utf-8 legacy ccr entries during import Legacy CCR files that are not valid UTF-8 previously aborted the import with an error. They are now treated like other unusable entries: the file is removed, counted toward the removed totals, and a warning is logged so the rest of the import can proceed. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/crates/tinyjuice-cli/src/storage.rs b/crates/tinyjuice-cli/src/storage.rs index 82479aae..604b8b50 100644 --- a/crates/tinyjuice-cli/src/storage.rs +++ b/crates/tinyjuice-cli/src/storage.rs @@ -263,6 +263,15 @@ fn import_legacy_files( } let content = match std::fs::read_to_string(entry.path()) { Ok(content) => content, + Err(error) if error.kind() == std::io::ErrorKind::InvalidData => { + log::warn!( + "[tinyjuice_cli] discarding non-UTF-8 legacy CCR entry {token}: {error}" + ); + let size = remove_legacy_entry(&entry.path(), &token, "non-UTF-8")?; + removed_legacy = removed_legacy.saturating_add(1); + removed_legacy_bytes = removed_legacy_bytes.saturating_add(size); + continue; + } Err(error) => { log::warn!("[tinyjuice_cli] skipping unreadable legacy CCR entry {token}: {error}"); continue; From d411f8f263a1bcbb86149a04b18930b8b1c2ec0b Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 07:09:26 +0000 Subject: [PATCH 079/119] fix(storage): discard malformed CCR timestamp sidecars Malformed timestamp metadata no longer aborts pruning or hides the backend write time; the bad sidecar is logged and deleted so the entry falls back to its backend timestamp. Added a read-faulting blob store double and tests covering the discard path. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage.rs | 35 ++++-- crates/tinyjuice-cli/src/storage_tests.rs | 132 +++++++++++++++++++++- 2 files changed, 154 insertions(+), 13 deletions(-) diff --git a/crates/tinyjuice-cli/src/storage.rs b/crates/tinyjuice-cli/src/storage.rs index 604b8b50..b7fa2c90 100644 --- a/crates/tinyjuice-cli/src/storage.rs +++ b/crates/tinyjuice-cli/src/storage.rs @@ -554,14 +554,33 @@ fn read_timestamp( token: &str, ) -> Result, String> { let key = format!("{prefix}{token}"); - run_blob(async move { blobs.get(&key).await })? - .map(|blob| { - std::str::from_utf8(&blob.bytes) - .map_err(|error| format!("invalid CCR timestamp metadata: {error}"))? - .parse::() - .map_err(|error| format!("invalid CCR timestamp metadata: {error}")) - }) - .transpose() + let lookup_key = key.clone(); + let Some(blob) = run_blob({ + let blobs = Arc::clone(&blobs); + async move { blobs.get(&lookup_key).await } + })? + else { + return Ok(None); + }; + match parse_timestamp(&blob.bytes) { + Ok(timestamp) => Ok(Some(timestamp)), + Err(error) => { + log::warn!("[tinyjuice_cli] discarding malformed CCR timestamp sidecar {key}: {error}"); + run_blob(async move { blobs.delete(&key).await }) + .map(|_| ()) + .map_err(|error| { + format!("cannot remove malformed CCR timestamp sidecar: {error}") + })?; + Ok(None) + } + } +} + +fn parse_timestamp(bytes: &[u8]) -> Result { + std::str::from_utf8(bytes) + .map_err(|error| format!("invalid CCR timestamp metadata: {error}"))? + .parse::() + .map_err(|error| format!("invalid CCR timestamp metadata: {error}")) } fn backend_written_at(blobs: Arc, key: &str) -> Result, String> { diff --git a/crates/tinyjuice-cli/src/storage_tests.rs b/crates/tinyjuice-cli/src/storage_tests.rs index 31a60e13..19c64bee 100644 --- a/crates/tinyjuice-cli/src/storage_tests.rs +++ b/crates/tinyjuice-cli/src/storage_tests.rs @@ -12,6 +12,12 @@ struct FailMetadataWrite { faults: FaultPlan, } +#[derive(Debug)] +struct FailMetadataRead { + inner: Arc, + faults: FaultPlan, +} + #[async_trait::async_trait] impl BlobStore for FailMetadataWrite { fn capabilities(&self) -> Capabilities { @@ -68,6 +74,62 @@ impl BlobStore for FailMetadataWrite { } } +#[async_trait::async_trait] +impl BlobStore for FailMetadataRead { + fn capabilities(&self) -> Capabilities { + self.inner.capabilities() + } + + fn max_key_len(&self) -> usize { + self.inner.max_key_len() + } + + async fn put( + &self, + key: &str, + bytes: Vec, + content_type: Option<&str>, + ) -> StorageResult { + self.inner.put(key, bytes, content_type).await + } + + async fn get(&self, key: &str) -> StorageResult> { + if key.starts_with(CCR_METADATA_PREFIX) || key.starts_with(CCR_IMPORT_PREFIX) { + self.faults.check("metadata_get")?; + } + self.inner.get(key).await + } + + async fn get_range( + &self, + key: &str, + range: std::ops::Range, + ) -> StorageResult>> { + self.inner.get_range(key, range).await + } + + async fn head(&self, key: &str) -> StorageResult> { + self.inner.head(key).await + } + + async fn delete(&self, key: &str) -> StorageResult { + self.inner.delete(key).await + } + + async fn list(&self, prefix: &str) -> StorageResult> { + self.inner.list(prefix).await + } + + async fn list_page( + &self, + prefix: &str, + after: Option<&str>, + limit: usize, + ) -> StorageResult { + self.inner.list_page(prefix, after, limit).await + } +} + #[test] fn collection_reports_bytes_removed_by_the_budget() { let dir = tempfile::tempdir().unwrap(); @@ -313,7 +375,7 @@ fn capped_store_delegates_byte_ranges_to_the_durable_store() { } #[test] -fn timestamp_listing_ignores_non_tokens_and_rejects_malformed_values() { +fn timestamp_listing_ignores_non_tokens_and_discards_malformed_values() { let dir = tempfile::tempdir().unwrap(); let blobs = open_file_blobs(dir.path()).unwrap(); run_blob({ @@ -341,11 +403,71 @@ fn timestamp_listing_ignores_non_tokens_and_rejects_malformed_values() { } }) .unwrap(); - assert!( - read_semantic_time(blobs, token) - .unwrap_err() - .contains("invalid CCR timestamp") + assert_eq!(read_semantic_time(blobs, token).unwrap(), None); +} + +#[test] +fn malformed_timestamp_sidecars_do_not_abort_pruning_or_hide_backend_write_time() { + let dir = tempfile::tempdir().unwrap(); + let blobs = open_file_blobs(dir.path()).unwrap(); + let store = BlobCcrStore::new(Arc::clone(&blobs), None).unwrap(); + let content = "recent content with malformed timestamp sidecars"; + let body_token = tinyjuice::cache::short_hash(content); + assert!(store.put(content).retained()); + let body_token_for_sidecar = body_token.clone(); + let intent_token = "0123456789abcdef0123456789abcdef"; + run_blob({ + let blobs = Arc::clone(&blobs); + async move { + blobs + .put( + &format!("{CCR_METADATA_PREFIX}{body_token_for_sidecar}"), + b"not-a-number".to_vec(), + None, + ) + .await?; + blobs + .put( + &format!("{CCR_IMPORT_PREFIX}{intent_token}"), + vec![0xff], + None, + ) + .await + } + }) + .unwrap(); + + assert_eq!( + prune(&blobs, Some(Duration::from_secs(3600)), None, None).unwrap(), + (0, 0, 1, content.len() as u64) ); + assert_eq!(store.get(&body_token).as_deref(), Some(content)); + assert_eq!( + read_semantic_time(Arc::clone(&blobs), &body_token).unwrap(), + None + ); + assert_eq!(read_import_intent(blobs, intent_token).unwrap(), None); +} + +#[test] +fn timestamp_backend_read_errors_still_abort_pruning() { + let dir = tempfile::tempdir().unwrap(); + let inner = open_file_blobs(dir.path()).unwrap(); + let token = "0123456789abcdef0123456789abcdef"; + write_semantic_time( + Arc::clone(&inner), + token, + unix_epoch_ms(SystemTime::now()), + None, + ) + .unwrap(); + let faults = FaultPlan::new(); + faults.fail_operation_nth("metadata_get", 1, ErrorKind::Backend); + let failing: Arc = Arc::new(FailMetadataRead { inner, faults }); + + let error = prune(&failing, None, None, None).unwrap_err(); + + assert!(error.contains("injected failure for metadata_get")); } #[test] From 9e2274429d363035013002f69d18bf289a8c0620 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 07:09:51 +0000 Subject: [PATCH 080/119] refactor(test): merge metadata fault wrappers into one type The two test-only BlobStore wrappers that injected metadata read and write faults were nearly identical, so they are now a single FailMetadataOperations type that handles both directions. This removes the duplicated delegation methods without changing what the tests exercise. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage_tests.rs | 69 ++--------------------- 1 file changed, 5 insertions(+), 64 deletions(-) diff --git a/crates/tinyjuice-cli/src/storage_tests.rs b/crates/tinyjuice-cli/src/storage_tests.rs index 19c64bee..d250f285 100644 --- a/crates/tinyjuice-cli/src/storage_tests.rs +++ b/crates/tinyjuice-cli/src/storage_tests.rs @@ -7,19 +7,13 @@ use tinystoragedrivers_types::{ }; #[derive(Debug)] -struct FailMetadataWrite { - inner: Arc, - faults: FaultPlan, -} - -#[derive(Debug)] -struct FailMetadataRead { +struct FailMetadataOperations { inner: Arc, faults: FaultPlan, } #[async_trait::async_trait] -impl BlobStore for FailMetadataWrite { +impl BlobStore for FailMetadataOperations { fn capabilities(&self) -> Capabilities { self.inner.capabilities() } @@ -40,59 +34,6 @@ impl BlobStore for FailMetadataWrite { self.inner.put(key, bytes, content_type).await } - async fn get(&self, key: &str) -> StorageResult> { - self.inner.get(key).await - } - - async fn get_range( - &self, - key: &str, - range: std::ops::Range, - ) -> StorageResult>> { - self.inner.get_range(key, range).await - } - - async fn head(&self, key: &str) -> StorageResult> { - self.inner.head(key).await - } - - async fn delete(&self, key: &str) -> StorageResult { - self.inner.delete(key).await - } - - async fn list(&self, prefix: &str) -> StorageResult> { - self.inner.list(prefix).await - } - - async fn list_page( - &self, - prefix: &str, - after: Option<&str>, - limit: usize, - ) -> StorageResult { - self.inner.list_page(prefix, after, limit).await - } -} - -#[async_trait::async_trait] -impl BlobStore for FailMetadataRead { - fn capabilities(&self) -> Capabilities { - self.inner.capabilities() - } - - fn max_key_len(&self) -> usize { - self.inner.max_key_len() - } - - async fn put( - &self, - key: &str, - bytes: Vec, - content_type: Option<&str>, - ) -> StorageResult { - self.inner.put(key, bytes, content_type).await - } - async fn get(&self, key: &str) -> StorageResult> { if key.starts_with(CCR_METADATA_PREFIX) || key.starts_with(CCR_IMPORT_PREFIX) { self.faults.check("metadata_get")?; @@ -463,7 +404,7 @@ fn timestamp_backend_read_errors_still_abort_pruning() { .unwrap(); let faults = FaultPlan::new(); faults.fail_operation_nth("metadata_get", 1, ErrorKind::Backend); - let failing: Arc = Arc::new(FailMetadataRead { inner, faults }); + let failing: Arc = Arc::new(FailMetadataOperations { inner, faults }); let error = prune(&failing, None, None, None).unwrap_err(); @@ -615,7 +556,7 @@ fn failed_timestamp_refresh_does_not_leave_an_old_age_for_gc() { let faults = FaultPlan::new(); faults.fail_operation_nth("metadata_put", 1, ErrorKind::Backend); - let failing: Arc = Arc::new(FailMetadataWrite { + let failing: Arc = Arc::new(FailMetadataOperations { inner: Arc::clone(&inner), faults, }); @@ -713,7 +654,7 @@ fn retry_after_timestamp_write_failure_preserves_the_source_file_age() { let inner = open_file_blobs(dir.path()).unwrap(); let faults = FaultPlan::new(); faults.fail_operation_nth("metadata_put", 1, ErrorKind::Backend); - let failing: Arc = Arc::new(FailMetadataWrite { + let failing: Arc = Arc::new(FailMetadataOperations { inner: Arc::clone(&inner), faults: faults.clone(), }); From 19f4a70892f6091fbdedc8bd055832025840d280 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 07:15:00 +0000 Subject: [PATCH 081/119] test(savings): cover local import without an ordinary storage port Add tests for request-local savings import when no ordinary storage port is configured, and when ordinary totals already exist but the callback destination should still receive the imported aggregate. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- .../src/savings_store_tests.rs | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/crates/tinyjuice-module/src/savings_store_tests.rs b/crates/tinyjuice-module/src/savings_store_tests.rs index 628a4894..8a5b8358 100644 --- a/crates/tinyjuice-module/src/savings_store_tests.rs +++ b/crates/tinyjuice-module/src/savings_store_tests.rs @@ -311,3 +311,94 @@ async fn request_local_import_uses_the_call_storage_without_caching_it() { &ordinary_docs, )); } + +#[tokio::test] +async fn request_local_import_works_without_an_ordinary_storage_port() { + let rig = rig(false).await?; + let callback = tinystoragedrivers_testkit::memory_backend(); + let callback_storage = Arc::clone( + callback + .for_scope(&Scope::new("callback")?)? + .storage(), + ); + let savings = Savings::new(); + let legacy = SavingsAggregate { + total: SavingsBucket { + events: 2, + original_tokens: 20, + compacted_tokens: 10, + tokens_saved: 10, + cost_saved_usd: 0.1, + }, + ..Default::default() + }; + + assert!(savings.import_at(None, &callback_storage, legacy).await?); + assert_eq!(savings.stats(Some(&rig.module)).await.total.events, 0); + assert_eq!( + callback_storage + .documents() + .get_as::(SAVINGS_COLLECTION, SAVINGS_DOC_ID) + .await? + .unwrap() + .doc + .total + .events, + 2 + ); + Ok(()) +} + +#[tokio::test] +async fn request_local_import_uses_callback_destination_when_ordinary_totals_exist() { + let backend = tinystoragedrivers_testkit::memory_backend(); + let ordinary = backend.for_scope(&Scope::new("ordinary")?)?; + let callback = backend.for_scope(&Scope::new("callback")?)?; + let savings = Savings::new(); + let ordinary_totals = SavingsAggregate { + total: SavingsBucket { + events: 1, + original_tokens: 9, + compacted_tokens: 4, + tokens_saved: 5, + cost_saved_usd: 0.1, + }, + ..Default::default() + }; + ordinary + .documents() + .put_as( + SAVINGS_COLLECTION, + SAVINGS_DOC_ID, + &StoredSavings::from_aggregate(&ordinary_totals, now_ms()), + Precondition::Absent, + ) + .await?; + assert_eq!(savings.stats(None).await.total.events, 1); + let callback_storage = Arc::clone(callback.storage()); + let legacy = SavingsAggregate { + total: SavingsBucket { + events: 2, + original_tokens: 20, + compacted_tokens: 10, + tokens_saved: 10, + cost_saved_usd: 0.1, + }, + ..Default::default() + }; + + assert!(savings.import_at(None, &callback_storage, legacy).await?); + assert_eq!( + callback_storage + .documents() + .get_as::(SAVINGS_COLLECTION, SAVINGS_DOC_ID) + .await? + .unwrap() + .doc + .total + .events, + 2 + ); + assert_eq!(savings.stats(None).await.total.events, 1); + Ok(()) +} From 501982e7c6d25bf9b6ebbc10f4e7d612b79ed90f Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 07:15:32 +0000 Subject: [PATCH 082/119] chore(deps): point tinystoragedrivers at tinyhumansai fork Repin the tinystoragedrivers git dependency from the senamakel repository to the tinyhumansai fork at a newer revision, updating the manifests and lockfile accordingly. The savings store and its tests were adjusted to match the fork's API, and the now-unneeded deny.toml exception was dropped. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- Cargo.lock | 24 +++++++++---------- crates/tinyjuice-bus/Cargo.toml | 2 +- crates/tinyjuice-cli/Cargo.toml | 8 +++---- crates/tinyjuice-drivers/Cargo.toml | 8 +++---- crates/tinyjuice-module/Cargo.toml | 8 +++---- crates/tinyjuice-module/src/savings_store.rs | 14 ++++------- .../src/savings_store_tests.rs | 23 +++++++++++++----- deny.toml | 1 - 8 files changed, 47 insertions(+), 41 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5102d1eb..ed9fa966 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1561,7 +1561,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?rev=6bc73c82da12d0f6035f8d85b27293d197dcb312#6bc73c82da12d0f6035f8d85b27293d197dcb312" +source = "git+https://github.com/tinyhumansai/tinystoragedrivers?rev=05eaada962decbab33bafa4763d2bd1a67f6b456#05eaada962decbab33bafa4763d2bd1a67f6b456" dependencies = [ "tinystoragedrivers-api", "tinystoragedrivers-blob", @@ -1576,7 +1576,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers-api" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?rev=6bc73c82da12d0f6035f8d85b27293d197dcb312#6bc73c82da12d0f6035f8d85b27293d197dcb312" +source = "git+https://github.com/tinyhumansai/tinystoragedrivers?rev=05eaada962decbab33bafa4763d2bd1a67f6b456#05eaada962decbab33bafa4763d2bd1a67f6b456" dependencies = [ "async-trait", "bytes", @@ -1590,7 +1590,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers-blob" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?rev=6bc73c82da12d0f6035f8d85b27293d197dcb312#6bc73c82da12d0f6035f8d85b27293d197dcb312" +source = "git+https://github.com/tinyhumansai/tinystoragedrivers?rev=05eaada962decbab33bafa4763d2bd1a67f6b456#05eaada962decbab33bafa4763d2bd1a67f6b456" dependencies = [ "async-trait", "bytes", @@ -1605,7 +1605,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers-bus" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?rev=6bc73c82da12d0f6035f8d85b27293d197dcb312#6bc73c82da12d0f6035f8d85b27293d197dcb312" +source = "git+https://github.com/tinyhumansai/tinystoragedrivers?rev=05eaada962decbab33bafa4763d2bd1a67f6b456#05eaada962decbab33bafa4763d2bd1a67f6b456" dependencies = [ "serde", "serde_json", @@ -1616,7 +1616,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers-busproxy" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?rev=6bc73c82da12d0f6035f8d85b27293d197dcb312#6bc73c82da12d0f6035f8d85b27293d197dcb312" +source = "git+https://github.com/tinyhumansai/tinystoragedrivers?rev=05eaada962decbab33bafa4763d2bd1a67f6b456#05eaada962decbab33bafa4763d2bd1a67f6b456" dependencies = [ "async-trait", "bytes", @@ -1634,7 +1634,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers-connect" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?rev=6bc73c82da12d0f6035f8d85b27293d197dcb312#6bc73c82da12d0f6035f8d85b27293d197dcb312" +source = "git+https://github.com/tinyhumansai/tinystoragedrivers?rev=05eaada962decbab33bafa4763d2bd1a67f6b456#05eaada962decbab33bafa4763d2bd1a67f6b456" dependencies = [ "rusqlite", "serde_json", @@ -1646,7 +1646,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers-document" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?rev=6bc73c82da12d0f6035f8d85b27293d197dcb312#6bc73c82da12d0f6035f8d85b27293d197dcb312" +source = "git+https://github.com/tinyhumansai/tinystoragedrivers?rev=05eaada962decbab33bafa4763d2bd1a67f6b456#05eaada962decbab33bafa4763d2bd1a67f6b456" dependencies = [ "async-trait", "data-encoding", @@ -1665,7 +1665,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers-kv" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?rev=6bc73c82da12d0f6035f8d85b27293d197dcb312#6bc73c82da12d0f6035f8d85b27293d197dcb312" +source = "git+https://github.com/tinyhumansai/tinystoragedrivers?rev=05eaada962decbab33bafa4763d2bd1a67f6b456#05eaada962decbab33bafa4763d2bd1a67f6b456" dependencies = [ "async-trait", "libc", @@ -1679,7 +1679,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers-queue" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?rev=6bc73c82da12d0f6035f8d85b27293d197dcb312#6bc73c82da12d0f6035f8d85b27293d197dcb312" +source = "git+https://github.com/tinyhumansai/tinystoragedrivers?rev=05eaada962decbab33bafa4763d2bd1a67f6b456#05eaada962decbab33bafa4763d2bd1a67f6b456" dependencies = [ "async-trait", "data-encoding", @@ -1695,7 +1695,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers-secrets" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?rev=6bc73c82da12d0f6035f8d85b27293d197dcb312#6bc73c82da12d0f6035f8d85b27293d197dcb312" +source = "git+https://github.com/tinyhumansai/tinystoragedrivers?rev=05eaada962decbab33bafa4763d2bd1a67f6b456#05eaada962decbab33bafa4763d2bd1a67f6b456" dependencies = [ "async-trait", "tinystoragedrivers-api", @@ -1706,7 +1706,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers-testkit" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?rev=6bc73c82da12d0f6035f8d85b27293d197dcb312#6bc73c82da12d0f6035f8d85b27293d197dcb312" +source = "git+https://github.com/tinyhumansai/tinystoragedrivers?rev=05eaada962decbab33bafa4763d2bd1a67f6b456#05eaada962decbab33bafa4763d2bd1a67f6b456" dependencies = [ "async-trait", "bytes", @@ -1727,7 +1727,7 @@ dependencies = [ [[package]] name = "tinystoragedrivers-types" version = "2.1.0" -source = "git+https://github.com/senamakel/tinystoragedrivers?rev=6bc73c82da12d0f6035f8d85b27293d197dcb312#6bc73c82da12d0f6035f8d85b27293d197dcb312" +source = "git+https://github.com/tinyhumansai/tinystoragedrivers?rev=05eaada962decbab33bafa4763d2bd1a67f6b456#05eaada962decbab33bafa4763d2bd1a67f6b456" dependencies = [ "serde", "serde_json", diff --git a/crates/tinyjuice-bus/Cargo.toml b/crates/tinyjuice-bus/Cargo.toml index 2d6fd873..d4ddea9d 100644 --- a/crates/tinyjuice-bus/Cargo.toml +++ b/crates/tinyjuice-bus/Cargo.toml @@ -19,7 +19,7 @@ serde = { version = "1", features = ["derive"] } serde_json = "1" # Shared REPL error vocabulary; no execution dependencies. thiserror = "2" -tinystoragedrivers-types = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "6bc73c82da12d0f6035f8d85b27293d197dcb312" } +tinystoragedrivers-types = { version = "2.1.0", git = "https://github.com/tinyhumansai/tinystoragedrivers", rev = "05eaada962decbab33bafa4763d2bd1a67f6b456" } [features] default = [] diff --git a/crates/tinyjuice-cli/Cargo.toml b/crates/tinyjuice-cli/Cargo.toml index ad09c96a..c6c00b22 100644 --- a/crates/tinyjuice-cli/Cargo.toml +++ b/crates/tinyjuice-cli/Cargo.toml @@ -11,9 +11,9 @@ repository = "https://github.com/tinyhumansai/tinyjuice" [dependencies] tinyjuice = { path = "../.." } tinyjuice-drivers = { path = "../tinyjuice-drivers" } -tinystoragedrivers = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "6bc73c82da12d0f6035f8d85b27293d197dcb312", features = ["file"] } -tinystoragedrivers-api = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "6bc73c82da12d0f6035f8d85b27293d197dcb312" } -tinystoragedrivers-types = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "6bc73c82da12d0f6035f8d85b27293d197dcb312" } +tinystoragedrivers = { version = "2.1.0", git = "https://github.com/tinyhumansai/tinystoragedrivers", rev = "05eaada962decbab33bafa4763d2bd1a67f6b456", features = ["file"] } +tinystoragedrivers-api = { version = "2.1.0", git = "https://github.com/tinyhumansai/tinystoragedrivers", rev = "05eaada962decbab33bafa4763d2bd1a67f6b456" } +tinystoragedrivers-types = { version = "2.1.0", git = "https://github.com/tinyhumansai/tinystoragedrivers", rev = "05eaada962decbab33bafa4763d2bd1a67f6b456" } dirs = "7" log = "0.4" serde_json = "1" @@ -22,7 +22,7 @@ tokio = { version = "1", features = ["rt-multi-thread"] } [dev-dependencies] async-trait = "0.1" tempfile = "3" -tinystoragedrivers-testkit = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "6bc73c82da12d0f6035f8d85b27293d197dcb312" } +tinystoragedrivers-testkit = { version = "2.1.0", git = "https://github.com/tinyhumansai/tinystoragedrivers", rev = "05eaada962decbab33bafa4763d2bd1a67f6b456" } [[bin]] name = "tinyjuice" diff --git a/crates/tinyjuice-drivers/Cargo.toml b/crates/tinyjuice-drivers/Cargo.toml index cad6df1f..cd82a0a4 100644 --- a/crates/tinyjuice-drivers/Cargo.toml +++ b/crates/tinyjuice-drivers/Cargo.toml @@ -14,13 +14,13 @@ publish = false [dependencies] tinyjuice-bus = { path = "../tinyjuice-bus" } tinyjuice = { path = "../..", default-features = false } -tinystoragedrivers-api = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "6bc73c82da12d0f6035f8d85b27293d197dcb312" } -tinystoragedrivers-types = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "6bc73c82da12d0f6035f8d85b27293d197dcb312" } +tinystoragedrivers-api = { version = "2.1.0", git = "https://github.com/tinyhumansai/tinystoragedrivers", rev = "05eaada962decbab33bafa4763d2bd1a67f6b456" } +tinystoragedrivers-types = { version = "2.1.0", git = "https://github.com/tinyhumansai/tinystoragedrivers", rev = "05eaada962decbab33bafa4763d2bd1a67f6b456" } log = "0.4" tokio = { version = "1", features = ["rt"] } [dev-dependencies] tokio = { version = "1", features = ["macros", "rt-multi-thread", "time"] } async-trait = "0.1" -tinystoragedrivers-testkit = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "6bc73c82da12d0f6035f8d85b27293d197dcb312" } -tinystoragedrivers-blob = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "6bc73c82da12d0f6035f8d85b27293d197dcb312" } +tinystoragedrivers-testkit = { version = "2.1.0", git = "https://github.com/tinyhumansai/tinystoragedrivers", rev = "05eaada962decbab33bafa4763d2bd1a67f6b456" } +tinystoragedrivers-blob = { version = "2.1.0", git = "https://github.com/tinyhumansai/tinystoragedrivers", rev = "05eaada962decbab33bafa4763d2bd1a67f6b456" } diff --git a/crates/tinyjuice-module/Cargo.toml b/crates/tinyjuice-module/Cargo.toml index 2b4d4ae5..7f4e55ec 100644 --- a/crates/tinyjuice-module/Cargo.toml +++ b/crates/tinyjuice-module/Cargo.toml @@ -28,14 +28,14 @@ serde_json = "1" # The CCR store's durable tier is blobs on the host's storage ports, reached # over the storage bus. The module has no storage backend or file of its own. tinyjuice-drivers = { path = "../tinyjuice-drivers" } -tinystoragedrivers-api = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "6bc73c82da12d0f6035f8d85b27293d197dcb312" } -tinystoragedrivers-types = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "6bc73c82da12d0f6035f8d85b27293d197dcb312" } -tinystoragedrivers-busproxy = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "6bc73c82da12d0f6035f8d85b27293d197dcb312" } +tinystoragedrivers-api = { version = "2.1.0", git = "https://github.com/tinyhumansai/tinystoragedrivers", rev = "05eaada962decbab33bafa4763d2bd1a67f6b456" } +tinystoragedrivers-types = { version = "2.1.0", git = "https://github.com/tinyhumansai/tinystoragedrivers", rev = "05eaada962decbab33bafa4763d2bd1a67f6b456" } +tinystoragedrivers-busproxy = { version = "2.1.0", git = "https://github.com/tinyhumansai/tinystoragedrivers", rev = "05eaada962decbab33bafa4763d2bd1a67f6b456" } log = "0.4" [dev-dependencies] # Tests serve the storage objects on the in-memory broker the module connects to. -tinystoragedrivers-testkit = { version = "2.1.0", git = "https://github.com/senamakel/tinystoragedrivers", rev = "6bc73c82da12d0f6035f8d85b27293d197dcb312" } +tinystoragedrivers-testkit = { version = "2.1.0", git = "https://github.com/tinyhumansai/tinystoragedrivers", rev = "05eaada962decbab33bafa4763d2bd1a67f6b456" } tinybus = { version = "=0.1.6", git = "https://github.com/tinyhumansai/tinybus", rev = "0de2d283f35cbbff08efad6fbe05537ffb74611b", default-features = false, features = ["test-support"] } tempfile = "3" async-trait = "0.1" diff --git a/crates/tinyjuice-module/src/savings_store.rs b/crates/tinyjuice-module/src/savings_store.rs index 6ea7b3ce..bc45c74d 100644 --- a/crates/tinyjuice-module/src/savings_store.rs +++ b/crates/tinyjuice-module/src/savings_store.rs @@ -113,17 +113,11 @@ impl Savings { /// for claim-bound imports, and its authority ends when the call returns. pub(crate) async fn import_at( &self, - connection: Option<&Connection>, + _connection: Option<&Connection>, storage: &Storage, legacy: SavingsAggregate, ) -> BusResult { let mut state = self.state.lock().await; - self.load(&mut state, connection).await; - if !state.loaded || state.docs.is_none() { - return Err(tinybus::Error::failed( - "savings storage is not readable yet", - )); - } let docs = storage.documents(); let stored = docs .get_as::(SAVINGS_COLLECTION, SAVINGS_DOC_ID) @@ -198,9 +192,11 @@ impl Savings { } }; if let Some(stored) = stored.filter(|_| !state.reset_early) { - let early = self.ledger.stats(); + let early = state.dirty.then(|| self.ledger.stats()); self.ledger.replace(stored); - self.ledger.absorb(&early); + if let Some(early) = early { + self.ledger.absorb(&early); + } } state.loaded = true; if state.dirty { diff --git a/crates/tinyjuice-module/src/savings_store_tests.rs b/crates/tinyjuice-module/src/savings_store_tests.rs index 8a5b8358..acf50294 100644 --- a/crates/tinyjuice-module/src/savings_store_tests.rs +++ b/crates/tinyjuice-module/src/savings_store_tests.rs @@ -1,7 +1,7 @@ use super::*; use crate::storage::tests::rig; use tinyjuice_bus::savings::SavingsBucket; -use tinystoragedrivers_api::{DocumentStore, StorageBackend}; +use tinystoragedrivers_api::{DocumentStore, Storage, StorageBackend}; use tinystoragedrivers_testkit::{Failing, FaultPlan}; use tinystoragedrivers_types::{ErrorKind, Scope}; @@ -316,10 +316,14 @@ async fn request_local_import_uses_the_call_storage_without_caching_it() { async fn request_local_import_works_without_an_ordinary_storage_port() { let rig = rig(false).await?; let callback = tinystoragedrivers_testkit::memory_backend(); - let callback_storage = Arc::clone( - callback - .for_scope(&Scope::new("callback")?)? - .storage(), + let callback = callback.for_scope(&Scope::new("callback")?)?; + let callback_storage = Storage::new( + Arc::clone(callback.documents()), + Arc::clone(callback.streams()), + Arc::clone(callback.kv()), + Arc::clone(callback.blobs()), + Arc::clone(callback.queues()), + Arc::clone(callback.secrets()), ); let savings = Savings::new(); let legacy = SavingsAggregate { @@ -375,7 +379,14 @@ async fn request_local_import_uses_callback_destination_when_ordinary_totals_exi ) .await?; assert_eq!(savings.stats(None).await.total.events, 1); - let callback_storage = Arc::clone(callback.storage()); + let callback_storage = Storage::new( + Arc::clone(callback.documents()), + Arc::clone(callback.streams()), + Arc::clone(callback.kv()), + Arc::clone(callback.blobs()), + Arc::clone(callback.queues()), + Arc::clone(callback.secrets()), + ); let legacy = SavingsAggregate { total: SavingsBucket { events: 2, diff --git a/deny.toml b/deny.toml index ebcc3e7d..fa1309b5 100644 --- a/deny.toml +++ b/deny.toml @@ -46,6 +46,5 @@ allow-registry = ["https://github.com/rust-lang/crates.io-index"] allow-git = [ "https://github.com/tinyhumansai/tinytools", "https://github.com/tinyhumansai/tinystoragedrivers", - "https://github.com/senamakel/tinystoragedrivers", "https://github.com/tinyhumansai/tinybus", ] From bf467fafca6debb2c68dac633e0247eb5b9d2314 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 07:17:49 +0000 Subject: [PATCH 083/119] fix(savings): skip import only when stored totals exist The import guard no longer treats the in-memory ledger's event count as a reason to skip, so a request-local import can still run when ordinary storage has totals but nothing has been persisted yet. The affected tests now return TestResult to propagate setup errors instead of unwrapping. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-module/src/savings_store.rs | 1 - crates/tinyjuice-module/src/savings_store_tests.rs | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/tinyjuice-module/src/savings_store.rs b/crates/tinyjuice-module/src/savings_store.rs index bc45c74d..3f93d81f 100644 --- a/crates/tinyjuice-module/src/savings_store.rs +++ b/crates/tinyjuice-module/src/savings_store.rs @@ -128,7 +128,6 @@ impl Savings { if stored .as_ref() .is_some_and(|stored| stored.doc.total.events != 0) - || self.ledger.stats().total.events != 0 { log::debug!("[tinyjuice_module][savings] import skipped: totals exist"); return Ok(false); diff --git a/crates/tinyjuice-module/src/savings_store_tests.rs b/crates/tinyjuice-module/src/savings_store_tests.rs index acf50294..b067a6c9 100644 --- a/crates/tinyjuice-module/src/savings_store_tests.rs +++ b/crates/tinyjuice-module/src/savings_store_tests.rs @@ -313,7 +313,7 @@ async fn request_local_import_uses_the_call_storage_without_caching_it() { } #[tokio::test] -async fn request_local_import_works_without_an_ordinary_storage_port() { +async fn request_local_import_works_without_an_ordinary_storage_port() -> TestResult { let rig = rig(false).await?; let callback = tinystoragedrivers_testkit::memory_backend(); let callback = callback.for_scope(&Scope::new("callback")?)?; @@ -354,7 +354,7 @@ async fn request_local_import_works_without_an_ordinary_storage_port() { } #[tokio::test] -async fn request_local_import_uses_callback_destination_when_ordinary_totals_exist() { +async fn request_local_import_uses_callback_destination_when_ordinary_totals_exist() -> TestResult { let backend = tinystoragedrivers_testkit::memory_backend(); let ordinary = backend.for_scope(&Scope::new("ordinary")?)?; let callback = backend.for_scope(&Scope::new("callback")?)?; From d4f1b5af326043a83977726c93251ba9b713e565 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 07:18:42 +0000 Subject: [PATCH 084/119] test(savings): seed ordinary totals before callback import The test now installs the ordinary documents and totals into the savings state before exercising the callback import path, so the assertion reflects the intended precondition instead of relying on an implicit initial state. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-module/src/savings_store_tests.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/tinyjuice-module/src/savings_store_tests.rs b/crates/tinyjuice-module/src/savings_store_tests.rs index b067a6c9..eb6a0fd1 100644 --- a/crates/tinyjuice-module/src/savings_store_tests.rs +++ b/crates/tinyjuice-module/src/savings_store_tests.rs @@ -378,7 +378,12 @@ async fn request_local_import_uses_callback_destination_when_ordinary_totals_exi Precondition::Absent, ) .await?; - assert_eq!(savings.stats(None).await.total.events, 1); + { + let mut state = savings.state.lock().await; + state.docs = Some(Arc::clone(ordinary.documents())); + state.loaded = true; + savings.ledger.replace(ordinary_totals.clone()); + } let callback_storage = Storage::new( Arc::clone(callback.documents()), Arc::clone(callback.streams()), From eaacc3e56821bf4206d67ebd1ad38186851d057c Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 07:21:57 +0000 Subject: [PATCH 085/119] fix(cli): tolerate already-removed legacy entries during import remove_legacy_entry now returns None instead of an error when the file is already gone, and callers only count a removal when one actually happened. This avoids aborting the legacy import when a stale entry disappears between the directory scan and the removal. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage.rs | 45 +++++++++++++++++++---------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/crates/tinyjuice-cli/src/storage.rs b/crates/tinyjuice-cli/src/storage.rs index b7fa2c90..d164e2d0 100644 --- a/crates/tinyjuice-cli/src/storage.rs +++ b/crates/tinyjuice-cli/src/storage.rs @@ -267,9 +267,10 @@ fn import_legacy_files( log::warn!( "[tinyjuice_cli] discarding non-UTF-8 legacy CCR entry {token}: {error}" ); - let size = remove_legacy_entry(&entry.path(), &token, "non-UTF-8")?; - removed_legacy = removed_legacy.saturating_add(1); - removed_legacy_bytes = removed_legacy_bytes.saturating_add(size); + if let Some(size) = remove_legacy_entry(&entry.path(), &token, "non-UTF-8")? { + removed_legacy = removed_legacy.saturating_add(1); + removed_legacy_bytes = removed_legacy_bytes.saturating_add(size); + } continue; } Err(error) => { @@ -279,9 +280,10 @@ fn import_legacy_files( }; if tinyjuice::cache::short_hash(&content) != token { log::warn!("[tinyjuice_cli] skipping legacy CCR entry {token}: content hash mismatch"); - let size = remove_legacy_entry(&entry.path(), &token, "corrupt")?; - removed_legacy = removed_legacy.saturating_add(1); - removed_legacy_bytes = removed_legacy_bytes.saturating_add(size); + if let Some(size) = remove_legacy_entry(&entry.path(), &token, "corrupt")? { + removed_legacy = removed_legacy.saturating_add(1); + removed_legacy_bytes = removed_legacy_bytes.saturating_add(size); + } continue; } let modified = entry @@ -295,9 +297,10 @@ fn import_legacy_files( Some(ttl) => { let remaining = remaining_ttl(modified, SystemTime::now(), ttl); if remaining.is_none() { - let size = remove_legacy_entry(&entry.path(), &token, "expired")?; - removed_legacy = removed_legacy.saturating_add(1); - removed_legacy_bytes = removed_legacy_bytes.saturating_add(size); + if let Some(size) = remove_legacy_entry(&entry.path(), &token, "expired")? { + removed_legacy = removed_legacy.saturating_add(1); + removed_legacy_bytes = removed_legacy_bytes.saturating_add(size); + } continue; } remaining @@ -364,13 +367,23 @@ fn import_legacy_files( Ok((removed_legacy, removed_legacy_bytes)) } -fn remove_legacy_entry(path: &Path, token: &str, reason: &str) -> Result { - let size = std::fs::metadata(path) - .map_err(|error| format!("cannot inspect {reason} legacy CCR entry {token}: {error}"))? - .len(); - std::fs::remove_file(path) - .map_err(|error| format!("cannot remove {reason} legacy CCR entry {token}: {error}"))?; - Ok(size) +fn remove_legacy_entry(path: &Path, token: &str, reason: &str) -> Result, String> { + let size = match std::fs::metadata(path) { + Ok(metadata) => metadata.len(), + Err(error) if error.kind() == std::io::ErrorKind::NotFound => return Ok(None), + Err(error) => { + return Err(format!( + "cannot inspect {reason} legacy CCR entry {token}: {error}" + )); + } + }; + match std::fs::remove_file(path) { + Ok(()) => Ok(Some(size)), + Err(error) if error.kind() == std::io::ErrorKind::NotFound => Ok(None), + Err(error) => Err(format!( + "cannot remove {reason} legacy CCR entry {token}: {error}" + )), + } } fn remaining_ttl(modified: SystemTime, now: SystemTime, ttl: Duration) -> Option { From d0fb8bffe0a56eaca9aa225db9c976dd41b6c632 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 07:22:30 +0000 Subject: [PATCH 086/119] refactor(storage): inject file removal into legacy entry cleanup The legacy entry removal helper now takes the file-removal operation as a parameter, with the existing behaviour preserved through a thin wrapper. This makes it possible to exercise the race where a file disappears between the metadata check and the removal, which the tests now cover. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage.rs | 11 ++++++++++- crates/tinyjuice-cli/src/storage_tests.rs | 13 +++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/crates/tinyjuice-cli/src/storage.rs b/crates/tinyjuice-cli/src/storage.rs index d164e2d0..d7f76189 100644 --- a/crates/tinyjuice-cli/src/storage.rs +++ b/crates/tinyjuice-cli/src/storage.rs @@ -368,6 +368,15 @@ fn import_legacy_files( } fn remove_legacy_entry(path: &Path, token: &str, reason: &str) -> Result, String> { + remove_legacy_entry_with(path, token, reason, std::fs::remove_file) +} + +fn remove_legacy_entry_with( + path: &Path, + token: &str, + reason: &str, + remove_file: impl FnOnce(&Path) -> std::io::Result<()>, +) -> Result, String> { let size = match std::fs::metadata(path) { Ok(metadata) => metadata.len(), Err(error) if error.kind() == std::io::ErrorKind::NotFound => return Ok(None), @@ -377,7 +386,7 @@ fn remove_legacy_entry(path: &Path, token: &str, reason: &str) -> Result Ok(Some(size)), Err(error) if error.kind() == std::io::ErrorKind::NotFound => Ok(None), Err(error) => Err(format!( diff --git a/crates/tinyjuice-cli/src/storage_tests.rs b/crates/tinyjuice-cli/src/storage_tests.rs index d250f285..5f8dd18b 100644 --- a/crates/tinyjuice-cli/src/storage_tests.rs +++ b/crates/tinyjuice-cli/src/storage_tests.rs @@ -144,8 +144,17 @@ fn removing_legacy_entries_reports_inspection_and_removal_errors() { let dir = tempfile::tempdir().unwrap(); let token = "0123456789abcdef0123456789abcdef"; let missing_path = dir.path().join(token); - let inspect_error = remove_legacy_entry(&missing_path, token, "corrupt").unwrap_err(); - assert!(inspect_error.contains("cannot inspect corrupt legacy CCR entry")); + assert_eq!(remove_legacy_entry(&missing_path, token, "corrupt").unwrap(), None); + + let raced_path = dir.path().join("raced"); + std::fs::write(&raced_path, "legacy").unwrap(); + let removed = remove_legacy_entry_with(&raced_path, token, "corrupt", |path| { + std::fs::remove_file(path)?; + Err(std::io::Error::from(std::io::ErrorKind::NotFound)) + }) + .unwrap(); + assert_eq!(removed, None); + assert!(!raced_path.exists()); let directory_path = dir.path().join(token); std::fs::create_dir(&directory_path).unwrap(); From a710c5b5cff318a662f42be9d63343fc17398211 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 07:22:48 +0000 Subject: [PATCH 087/119] chore(examples): update lockfile dependencies Refresh the examples lockfile to pick up tinystoragedrivers-types 2.1.0 from its new repository location and add tinytools 0.6.0 alongside the existing 0.5.0, disambiguating the two versions in dependent entries. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-examples/Cargo.lock | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/crates/tinyjuice-examples/Cargo.lock b/crates/tinyjuice-examples/Cargo.lock index 9fe220b5..7585b065 100644 --- a/crates/tinyjuice-examples/Cargo.lock +++ b/crates/tinyjuice-examples/Cargo.lock @@ -1689,7 +1689,7 @@ dependencies = [ "async-trait", "serde", "serde_json", - "tinytools", + "tinytools 0.5.0", "toml", "tracing", ] @@ -1716,7 +1716,7 @@ dependencies = [ "tinyinference-embeddings", "tinyinference-llm", "tinystoragedrivers-core", - "tinytools", + "tinytools 0.5.0", "tinytools-agent", "tokio", "tracing", @@ -1806,7 +1806,7 @@ dependencies = [ "sha2 0.11.0", "thiserror", "tinyjuice-bus", - "tinytools", + "tinytools 0.6.0", "tokio", "tree-sitter", "tree-sitter-python", @@ -1836,7 +1836,7 @@ dependencies = [ "tinyagents-harness", "tinyinference-llm", "tinyjuice", - "tinytools", + "tinytools 0.5.0", "tokio", ] @@ -1877,8 +1877,8 @@ dependencies = [ [[package]] name = "tinystoragedrivers-types" -version = "2.0.2" -source = "git+https://github.com/senamakel/tinystoragedrivers?tag=v2.0.2#7acd22d8e8061edf7ef8cc4976c666b198a203c7" +version = "2.1.0" +source = "git+https://github.com/tinyhumansai/tinystoragedrivers?rev=05eaada962decbab33bafa4763d2bd1a67f6b456#05eaada962decbab33bafa4763d2bd1a67f6b456" dependencies = [ "serde", "serde_json", @@ -1905,6 +1905,17 @@ dependencies = [ "serde_json", ] +[[package]] +name = "tinytools" +version = "0.6.0" +source = "git+https://github.com/tinyhumansai/tinytools?rev=3a01641f8ebd8a55656cd212f9a90638d958a447#3a01641f8ebd8a55656cd212f9a90638d958a447" +dependencies = [ + "anyhow", + "async-trait", + "serde", + "serde_json", +] + [[package]] name = "tinytools-agent" version = "0.5.0" @@ -1912,7 +1923,7 @@ dependencies = [ "regex", "serde", "serde_json", - "tinytools", + "tinytools 0.5.0", ] [[package]] From b740fe1a75ab4ce299047792c0a77fde3d449623 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 07:23:13 +0000 Subject: [PATCH 088/119] test(storage): reformat legacy entry removal assertion Wrap the assertion in removing_legacy_entries_reports_inspection_and_removal_errors across multiple lines so it matches the project's rustfmt output. No behaviour change. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage_tests.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/tinyjuice-cli/src/storage_tests.rs b/crates/tinyjuice-cli/src/storage_tests.rs index 5f8dd18b..fa8dc1fd 100644 --- a/crates/tinyjuice-cli/src/storage_tests.rs +++ b/crates/tinyjuice-cli/src/storage_tests.rs @@ -144,7 +144,10 @@ fn removing_legacy_entries_reports_inspection_and_removal_errors() { let dir = tempfile::tempdir().unwrap(); let token = "0123456789abcdef0123456789abcdef"; let missing_path = dir.path().join(token); - assert_eq!(remove_legacy_entry(&missing_path, token, "corrupt").unwrap(), None); + assert_eq!( + remove_legacy_entry(&missing_path, token, "corrupt").unwrap(), + None + ); let raced_path = dir.path().join("raced"); std::fs::write(&raced_path, "legacy").unwrap(); From 65d04b871b05390045f64b441d49d26f4339a998 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 07:23:29 +0000 Subject: [PATCH 089/119] fix(cli): wrap remove_file in closure for legacy entry removal The remove_legacy_entry helper now passes a closure around std::fs::remove_file instead of the function directly, so the call matches the expected signature of remove_legacy_entry_with. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/tinyjuice-cli/src/storage.rs b/crates/tinyjuice-cli/src/storage.rs index d7f76189..213af57d 100644 --- a/crates/tinyjuice-cli/src/storage.rs +++ b/crates/tinyjuice-cli/src/storage.rs @@ -368,7 +368,7 @@ fn import_legacy_files( } fn remove_legacy_entry(path: &Path, token: &str, reason: &str) -> Result, String> { - remove_legacy_entry_with(path, token, reason, std::fs::remove_file) + remove_legacy_entry_with(path, token, reason, |path| std::fs::remove_file(path)) } fn remove_legacy_entry_with( From 32ba15747f2112bdb5a8c6fd948963a3fd8ee3bd Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 07:29:34 +0000 Subject: [PATCH 090/119] test(storage): cover ttl-only startup pruning of expired blobs Add a test asserting that a startup sweep configured with a TTL but no byte cap removes previously stored content whose semantic time has expired. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage_tests.rs | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/crates/tinyjuice-cli/src/storage_tests.rs b/crates/tinyjuice-cli/src/storage_tests.rs index fa8dc1fd..4abc0468 100644 --- a/crates/tinyjuice-cli/src/storage_tests.rs +++ b/crates/tinyjuice-cli/src/storage_tests.rs @@ -139,6 +139,33 @@ fn collection_removes_and_reports_non_utf8_legacy_entries() { ); } +#[test] +fn startup_prunes_expired_blobs_with_ttl_without_a_byte_cap() { + let dir = tempfile::tempdir().unwrap(); + let blobs = open_file_blobs(dir.path()).unwrap(); + let content = "expired before a TTL-only restart"; + let store = BlobCcrStore::new(Arc::clone(&blobs), None).unwrap(); + let put = store.put(content); + assert!(put.retained()); + write_semantic_time( + Arc::clone(&blobs), + put.token(), + unix_epoch_ms(SystemTime::now() - Duration::from_secs(60)), + None, + ) + .unwrap(); + + configure_with_report(dir.path(), Some(Duration::from_secs(1)), None).unwrap(); + + assert!( + BlobCcrStore::new(open_file_blobs(dir.path()).unwrap(), None) + .unwrap() + .get(put.token()) + .is_none(), + "a TTL-only startup sweep removes previously stored expired content" + ); +} + #[test] fn removing_legacy_entries_reports_inspection_and_removal_errors() { let dir = tempfile::tempdir().unwrap(); From 519ee5f7c0a3fc0a3247888bbd38c95fdb365a55 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 07:30:14 +0000 Subject: [PATCH 091/119] fix(storage): prune when ttl is set without max_bytes The capped store only ran prune when max_bytes was configured, so a ttl-only configuration never evicted expired blobs. Pruning now also triggers when ttl is set, and a regression test covers a stale import intent not hiding a newer body write. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage.rs | 2 +- crates/tinyjuice-cli/src/storage_tests.rs | 60 ++++++++++++++++++++++- 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/crates/tinyjuice-cli/src/storage.rs b/crates/tinyjuice-cli/src/storage.rs index 213af57d..694b6317 100644 --- a/crates/tinyjuice-cli/src/storage.rs +++ b/crates/tinyjuice-cli/src/storage.rs @@ -53,7 +53,7 @@ fn configure_with_report( ttl, max_bytes, }; - if max_bytes.is_some() { + if ttl.is_some() || max_bytes.is_some() { prune(&blobs, ttl, max_bytes, None)?; } set_durable_tier(Some(Arc::new(capped))); diff --git a/crates/tinyjuice-cli/src/storage_tests.rs b/crates/tinyjuice-cli/src/storage_tests.rs index 4abc0468..9e3abb0c 100644 --- a/crates/tinyjuice-cli/src/storage_tests.rs +++ b/crates/tinyjuice-cli/src/storage_tests.rs @@ -3,7 +3,7 @@ use tinyjuice::cache::{CcrStore, RangeUnit}; use tinystoragedrivers_api::BlobStore; use tinystoragedrivers_testkit::FaultPlan; use tinystoragedrivers_types::{ - Blob, BlobListPage, BlobMeta, Capabilities, ErrorKind, Result as StorageResult, + Blob, BlobListPage, BlobMeta, Capabilities, ErrorKind, Result as StorageResult, StorageError, }; #[derive(Debug)] @@ -28,10 +28,20 @@ impl BlobStore for FailMetadataOperations { bytes: Vec, content_type: Option<&str>, ) -> StorageResult { + let fail_after_body_write = key.starts_with(&format!("{CCR_PREFIX}/")) + && self.faults.check("body_put_after_commit").is_err(); if key.starts_with(CCR_METADATA_PREFIX) { self.faults.check("metadata_put")?; } - self.inner.put(key, bytes, content_type).await + let metadata = self.inner.put(key, bytes, content_type).await?; + if fail_after_body_write { + Err(StorageError::new( + ErrorKind::Backend, + "simulated lost body-write acknowledgement", + )) + } else { + Ok(metadata) + } } async fn get(&self, key: &str) -> StorageResult> { @@ -623,6 +633,52 @@ fn failed_timestamp_refresh_does_not_leave_an_old_age_for_gc() { assert_eq!(original.get(&token).as_deref(), Some(content)); } +#[test] +fn stale_import_intent_does_not_hide_a_newer_body_write() { + let dir = tempfile::tempdir().unwrap(); + let content = "a later normal re-offload after an interrupted import"; + let token = tinyjuice::cache::short_hash(content); + let source_path = dir.path().join(&token); + std::fs::write(&source_path, content).unwrap(); + let old_time = SystemTime::now() - Duration::from_secs(60); + std::fs::OpenOptions::new() + .write(true) + .open(&source_path) + .unwrap() + .set_times(std::fs::FileTimes::new().set_modified(old_time)) + .unwrap(); + + let inner = open_file_blobs(dir.path()).unwrap(); + let initial = BlobCcrStore::new(Arc::clone(&inner), None).unwrap(); + assert!(initial.put(content).retained()); + write_import_intent(Arc::clone(&inner), &token, unix_epoch_ms(old_time), None).unwrap(); + + let faults = FaultPlan::new(); + faults.fail_operation_nth("body_put_after_commit", 1, ErrorKind::Backend); + let flaky: Arc = Arc::new(FailMetadataOperations { + inner: Arc::clone(&inner), + faults, + }); + let reoffloaded = CappedCcrStore { + store: BlobCcrStore::new(Arc::clone(&flaky), None).unwrap(), + blobs: flaky.clone(), + ttl: None, + max_bytes: None, + }; + assert!(!reoffloaded.put(content).retained()); + let backend_time = backend_written_at( + Arc::clone(&inner), + &format!("{CCR_PREFIX}/{token}"), + ) + .unwrap() + .unwrap(); + assert!(backend_time > unix_epoch_ms(old_time)); + + import_legacy_files(dir.path(), &flaky, None).unwrap(); + + assert_eq!(read_semantic_time(inner, &token).unwrap(), Some(backend_time)); +} + #[test] fn capped_store_put_works_inside_a_current_thread_runtime() { let dir = tempfile::tempdir().unwrap(); From 9d610cd40fb68b29eadf5be63e1e264b5a5d35b3 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 07:30:32 +0000 Subject: [PATCH 092/119] fix(storage): clear stale import intent before ccr writes The capped CCR store now deletes any leftover import intent for a token before writing a new body, and refuses the write if that cleanup fails. This prevents stale import chronology from overriding the backend write time of a newer body after an interrupted write. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage.rs | 9 +++++++++ crates/tinyjuice-cli/src/storage_tests.rs | 14 +++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/crates/tinyjuice-cli/src/storage.rs b/crates/tinyjuice-cli/src/storage.rs index 694b6317..5ca5c687 100644 --- a/crates/tinyjuice-cli/src/storage.rs +++ b/crates/tinyjuice-cli/src/storage.rs @@ -419,6 +419,15 @@ struct CappedCcrStore { impl CcrStore for CappedCcrStore { fn put(&self, content: &str) -> CcrPutResult { + let token = tinyjuice::cache::short_hash(content); + if let Err(error) = delete_import_intent(Arc::clone(&self.blobs), &token) { + log::debug!( + "[tinyjuice_cli] stale CCR import intent cleanup failed before write: {error}" + ); + // Do not publish a newer body while stale import chronology could + // still override its backend write time after an interrupted write. + return CcrPutResult::new(token, false); + } let result = self.store.put(content); if result.retained() { if let Err(error) = write_semantic_time( diff --git a/crates/tinyjuice-cli/src/storage_tests.rs b/crates/tinyjuice-cli/src/storage_tests.rs index 9e3abb0c..66819dd8 100644 --- a/crates/tinyjuice-cli/src/storage_tests.rs +++ b/crates/tinyjuice-cli/src/storage_tests.rs @@ -666,17 +666,17 @@ fn stale_import_intent_does_not_hide_a_newer_body_write() { max_bytes: None, }; assert!(!reoffloaded.put(content).retained()); - let backend_time = backend_written_at( - Arc::clone(&inner), - &format!("{CCR_PREFIX}/{token}"), - ) - .unwrap() - .unwrap(); + let backend_time = backend_written_at(Arc::clone(&inner), &format!("{CCR_PREFIX}/{token}")) + .unwrap() + .unwrap(); assert!(backend_time > unix_epoch_ms(old_time)); import_legacy_files(dir.path(), &flaky, None).unwrap(); - assert_eq!(read_semantic_time(inner, &token).unwrap(), Some(backend_time)); + assert_eq!( + read_semantic_time(inner, &token).unwrap(), + Some(backend_time) + ); } #[test] From 16a0b741a1b34b9014204705bc2f976053c79677 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 07:41:23 +0000 Subject: [PATCH 093/119] fix(storage): tolerate missing legacy entry during import Importing legacy CCR entries now treats a NotFound error when removing the source file as success, so a concurrent deletion no longer aborts the import. The removal is routed through a testable helper that mirrors the existing legacy-entry removal path. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage.rs | 21 +++++++++++++++++++-- crates/tinyjuice-cli/src/storage_tests.rs | 15 +++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/crates/tinyjuice-cli/src/storage.rs b/crates/tinyjuice-cli/src/storage.rs index 5ca5c687..61cf60cb 100644 --- a/crates/tinyjuice-cli/src/storage.rs +++ b/crates/tinyjuice-cli/src/storage.rs @@ -361,12 +361,29 @@ fn import_legacy_files( )); } delete_import_intent(Arc::clone(blobs), &token)?; - std::fs::remove_file(entry.path()) - .map_err(|error| format!("cannot remove imported CCR entry {token}: {error}"))?; + remove_imported_legacy_entry(&entry.path(), &token)?; } Ok((removed_legacy, removed_legacy_bytes)) } +fn remove_imported_legacy_entry(path: &Path, token: &str) -> Result<(), String> { + remove_imported_legacy_entry_with(path, token, |path| std::fs::remove_file(path)) +} + +fn remove_imported_legacy_entry_with( + path: &Path, + token: &str, + remove_file: impl FnOnce(&Path) -> std::io::Result<()>, +) -> Result<(), String> { + match remove_file(path) { + Ok(()) => Ok(()), + Err(error) if error.kind() == std::io::ErrorKind::NotFound => Ok(()), + Err(error) => Err(format!( + "cannot remove imported CCR entry {token}: {error}" + )), + } +} + fn remove_legacy_entry(path: &Path, token: &str, reason: &str) -> Result, String> { remove_legacy_entry_with(path, token, reason, |path| std::fs::remove_file(path)) } diff --git a/crates/tinyjuice-cli/src/storage_tests.rs b/crates/tinyjuice-cli/src/storage_tests.rs index 66819dd8..84bca7de 100644 --- a/crates/tinyjuice-cli/src/storage_tests.rs +++ b/crates/tinyjuice-cli/src/storage_tests.rs @@ -203,6 +203,21 @@ fn removing_legacy_entries_reports_inspection_and_removal_errors() { assert!(directory_path.is_dir()); } +#[test] +fn imported_legacy_removal_tolerates_a_concurrent_not_found() { + let dir = tempfile::tempdir().unwrap(); + let path = dir.path().join("imported"); + std::fs::write(&path, "legacy").unwrap(); + + remove_imported_legacy_entry_with(&path, "0123456789abcdef0123456789abcdef", |path| { + std::fs::remove_file(path)?; + Err(std::io::Error::from(std::io::ErrorKind::NotFound)) + }) + .unwrap(); + + assert!(!path.exists()); +} + #[test] fn configure_and_inventory_report_invalid_storage_paths() { let dir = tempfile::tempdir().unwrap(); From 24314e73a892cec1e9d8f462319ceff0ecccf773 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 07:41:40 +0000 Subject: [PATCH 094/119] refactor(storage): collapse multi-line format call Reformatted the error construction in remove_imported_legacy_entry_with onto a single line. No behaviour change. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/crates/tinyjuice-cli/src/storage.rs b/crates/tinyjuice-cli/src/storage.rs index 61cf60cb..a3ee66de 100644 --- a/crates/tinyjuice-cli/src/storage.rs +++ b/crates/tinyjuice-cli/src/storage.rs @@ -378,9 +378,7 @@ fn remove_imported_legacy_entry_with( match remove_file(path) { Ok(()) => Ok(()), Err(error) if error.kind() == std::io::ErrorKind::NotFound => Ok(()), - Err(error) => Err(format!( - "cannot remove imported CCR entry {token}: {error}" - )), + Err(error) => Err(format!("cannot remove imported CCR entry {token}: {error}")), } } From d4174e60fd3c913111ea93bb22105d0cebe92d63 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 07:50:47 +0000 Subject: [PATCH 095/119] test(storage): cover expired backend blobs pruned during configuration Add a test asserting that collection reports backend blobs whose semantic time has expired and that are swept while the store is being configured. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage_tests.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/crates/tinyjuice-cli/src/storage_tests.rs b/crates/tinyjuice-cli/src/storage_tests.rs index 84bca7de..6548bd80 100644 --- a/crates/tinyjuice-cli/src/storage_tests.rs +++ b/crates/tinyjuice-cli/src/storage_tests.rs @@ -132,6 +132,28 @@ fn collection_reports_expired_legacy_entries() { ); } +#[test] +fn collection_reports_expired_backend_blobs_pruned_during_configuration() { + let dir = tempfile::tempdir().unwrap(); + let blobs = open_file_blobs(dir.path()).unwrap(); + let content = "expired backend content swept during configuration"; + let store = BlobCcrStore::new(Arc::clone(&blobs), None).unwrap(); + let put = store.put(content); + assert!(put.retained()); + write_semantic_time( + Arc::clone(&blobs), + put.token(), + unix_epoch_ms(SystemTime::now() - Duration::from_secs(60)), + None, + ) + .unwrap(); + + assert_eq!( + collect(dir.path(), Some(Duration::from_secs(1)), None).unwrap(), + (1, content.len() as u64, 0, 0) + ); +} + #[test] fn collection_removes_and_reports_non_utf8_legacy_entries() { let dir = tempfile::tempdir().unwrap(); From 861d8b431d22e59e35f07bec21058937e53dcdae Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 07:51:15 +0000 Subject: [PATCH 096/119] fix(storage): report kept blob counts when no pruning limits are set configure_with_report now returns the prune report alongside the legacy cleanup totals, and collect reuses it instead of pruning a second time. When neither a TTL nor a max size is configured, collect lists the remaining blobs so the kept count and byte total are still reported. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage.rs | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/crates/tinyjuice-cli/src/storage.rs b/crates/tinyjuice-cli/src/storage.rs index a3ee66de..61960cb7 100644 --- a/crates/tinyjuice-cli/src/storage.rs +++ b/crates/tinyjuice-cli/src/storage.rs @@ -37,7 +37,7 @@ fn configure_with_report( root: &Path, ttl: Option, max_bytes: Option, -) -> Result<(usize, u64), String> { +) -> Result<((usize, u64), (usize, u64, usize, u64)), String> { std::fs::create_dir_all(root).map_err(|error| { format!( "cannot create CCR storage directory {}: {error}", @@ -53,11 +53,13 @@ fn configure_with_report( ttl, max_bytes, }; - if ttl.is_some() || max_bytes.is_some() { - prune(&blobs, ttl, max_bytes, None)?; - } + let prune_report = if ttl.is_some() || max_bytes.is_some() { + prune(&blobs, ttl, max_bytes, None)? + } else { + (0, 0, 0, 0) + }; set_durable_tier(Some(Arc::new(capped))); - Ok(discarded_legacy) + Ok((discarded_legacy, prune_report)) } #[allow(dead_code)] // The reducer binary uses inventory; the hook binary shares this module. @@ -126,9 +128,20 @@ pub(crate) fn collect( ttl: Option, max_bytes: Option, ) -> Result<(usize, u64, usize, u64), String> { - let (legacy_removed, legacy_bytes) = configure_with_report(root, ttl, None)?; - let blobs = open_file_blobs(root)?; - let (removed, freed, kept, kept_bytes) = prune(&blobs, ttl, max_bytes, None)?; + let ((legacy_removed, legacy_bytes), prune_report) = + configure_with_report(root, ttl, max_bytes)?; + let (removed, freed, kept, kept_bytes) = if ttl.is_some() || max_bytes.is_some() { + prune_report + } else { + let blobs = open_file_blobs(root)?; + let remaining = list_all(blobs)?; + ( + 0, + 0, + remaining.len(), + remaining.iter().map(|entry| entry.meta.len).sum(), + ) + }; Ok(( legacy_removed.saturating_add(removed), legacy_bytes.saturating_add(freed), From 7cc1bf0c29ca34dfd5ee8fde98e3e3ff7a6af150 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 07:58:06 +0000 Subject: [PATCH 097/119] refactor(storage): replace tuple reports with named structs The configure and collect helpers returned nested tuples that were hard to read at the call sites. They now return ConfigureReport and PruneReport structs with named fields, so the accounting of removed and kept entries is self-describing. No behaviour change. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage.rs | 65 ++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 19 deletions(-) diff --git a/crates/tinyjuice-cli/src/storage.rs b/crates/tinyjuice-cli/src/storage.rs index 61960cb7..13383965 100644 --- a/crates/tinyjuice-cli/src/storage.rs +++ b/crates/tinyjuice-cli/src/storage.rs @@ -25,6 +25,19 @@ pub(crate) struct Inventory { pub ignored_entries: usize, } +struct PruneReport { + removed: usize, + bytes_freed: u64, + kept: usize, + kept_bytes: u64, +} + +struct ConfigureReport { + legacy_removed: usize, + legacy_bytes: u64, + pruned: PruneReport, +} + pub(crate) fn configure( root: &Path, ttl: Option, @@ -37,7 +50,7 @@ fn configure_with_report( root: &Path, ttl: Option, max_bytes: Option, -) -> Result<((usize, u64), (usize, u64, usize, u64)), String> { +) -> Result { std::fs::create_dir_all(root).map_err(|error| { format!( "cannot create CCR storage directory {}: {error}", @@ -53,13 +66,28 @@ fn configure_with_report( ttl, max_bytes, }; - let prune_report = if ttl.is_some() || max_bytes.is_some() { - prune(&blobs, ttl, max_bytes, None)? + let pruned = if ttl.is_some() || max_bytes.is_some() { + let (removed, bytes_freed, kept, kept_bytes) = prune(&blobs, ttl, max_bytes, None)?; + PruneReport { + removed, + bytes_freed, + kept, + kept_bytes, + } } else { - (0, 0, 0, 0) + PruneReport { + removed: 0, + bytes_freed: 0, + kept: 0, + kept_bytes: 0, + } }; set_durable_tier(Some(Arc::new(capped))); - Ok((discarded_legacy, prune_report)) + Ok(ConfigureReport { + legacy_removed: discarded_legacy.0, + legacy_bytes: discarded_legacy.1, + pruned, + }) } #[allow(dead_code)] // The reducer binary uses inventory; the hook binary shares this module. @@ -128,25 +156,24 @@ pub(crate) fn collect( ttl: Option, max_bytes: Option, ) -> Result<(usize, u64, usize, u64), String> { - let ((legacy_removed, legacy_bytes), prune_report) = - configure_with_report(root, ttl, max_bytes)?; - let (removed, freed, kept, kept_bytes) = if ttl.is_some() || max_bytes.is_some() { - prune_report + let report = configure_with_report(root, ttl, max_bytes)?; + let pruned = if ttl.is_some() || max_bytes.is_some() { + report.pruned } else { let blobs = open_file_blobs(root)?; let remaining = list_all(blobs)?; - ( - 0, - 0, - remaining.len(), - remaining.iter().map(|entry| entry.meta.len).sum(), - ) + PruneReport { + removed: 0, + bytes_freed: 0, + kept: remaining.len(), + kept_bytes: remaining.iter().map(|entry| entry.meta.len).sum(), + } }; Ok(( - legacy_removed.saturating_add(removed), - legacy_bytes.saturating_add(freed), - kept, - kept_bytes, + report.legacy_removed.saturating_add(pruned.removed), + report.legacy_bytes.saturating_add(pruned.bytes_freed), + pruned.kept, + pruned.kept_bytes, )) } From e951b7552f9d6f1b95198b08b551ff22aa19ae38 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 07:59:41 +0000 Subject: [PATCH 098/119] test(storage): cover failed stale timestamp cleanup Add a test asserting that when clearing a stale semantic timestamp fails, the new body is neither advertised as retained nor pruned, and the old timestamp remains in place. The fault-injection store now also fails deletes of semantic metadata keys so the cleanup path can be exercised. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage_tests.rs | 36 +++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/crates/tinyjuice-cli/src/storage_tests.rs b/crates/tinyjuice-cli/src/storage_tests.rs index 6548bd80..55f22d7f 100644 --- a/crates/tinyjuice-cli/src/storage_tests.rs +++ b/crates/tinyjuice-cli/src/storage_tests.rs @@ -64,6 +64,9 @@ impl BlobStore for FailMetadataOperations { } async fn delete(&self, key: &str) -> StorageResult { + if key.starts_with(CCR_METADATA_PREFIX) { + self.faults.check("semantic_metadata_delete")?; + } self.inner.delete(key).await } @@ -670,6 +673,39 @@ fn failed_timestamp_refresh_does_not_leave_an_old_age_for_gc() { assert_eq!(original.get(&token).as_deref(), Some(content)); } +#[test] +fn failed_stale_timestamp_cleanup_does_not_advertise_or_prune_the_new_body() { + let dir = tempfile::tempdir().unwrap(); + let content = "fresh body whose stale semantic age cannot be cleared"; + let token = tinyjuice::cache::short_hash(content); + let inner = open_file_blobs(dir.path()).unwrap(); + let original = BlobCcrStore::new(Arc::clone(&inner), None).unwrap(); + assert!(original.put(content).retained()); + let old_time = unix_epoch_ms(SystemTime::now() - Duration::from_secs(86_400)); + write_semantic_time(Arc::clone(&inner), &token, old_time, None).unwrap(); + + let faults = FaultPlan::new(); + faults.fail_operation_nth("metadata_put", 1, ErrorKind::Backend); + faults.fail_operation_nth("semantic_metadata_delete", 1, ErrorKind::Backend); + let failing: Arc = Arc::new(FailMetadataOperations { + inner: Arc::clone(&inner), + faults, + }); + let capped = CappedCcrStore { + store: BlobCcrStore::new(Arc::clone(&failing), None).unwrap(), + blobs: failing, + ttl: Some(Duration::from_secs(3_600)), + max_bytes: None, + }; + + assert!(!capped.put(content).retained()); + assert_eq!( + read_semantic_time(Arc::clone(&inner), &token).unwrap(), + Some(old_time) + ); + assert_eq!(original.get(&token).as_deref(), Some(content)); +} + #[test] fn stale_import_intent_does_not_hide_a_newer_body_write() { let dir = tempfile::tempdir().unwrap(); From c6f02c23acba7f5dab2ccf816124a2b8a9a461f3 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 08:00:02 +0000 Subject: [PATCH 099/119] fix(tinyjuice-cli): report failed ccr put when stale cleanup fails When writing the CCR timestamp fails and the subsequent cleanup of stale metadata or import intent also fails, the store now returns an unsuccessful put result instead of silently reporting success. This surfaces the inconsistent state to callers so they can react to it. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/tinyjuice-cli/src/storage.rs b/crates/tinyjuice-cli/src/storage.rs index 13383965..d1234bcb 100644 --- a/crates/tinyjuice-cli/src/storage.rs +++ b/crates/tinyjuice-cli/src/storage.rs @@ -492,11 +492,17 @@ impl CcrStore for CappedCcrStore { self.ttl, ) { log::debug!("[tinyjuice_cli] CCR timestamp write failed: {error}"); + let mut stale_time_cleanup_failed = false; if let Err(error) = delete_metadata(Arc::clone(&self.blobs), result.token()) { log::debug!("[tinyjuice_cli] stale CCR timestamp cleanup failed: {error}"); + stale_time_cleanup_failed = true; } if let Err(error) = delete_import_intent(Arc::clone(&self.blobs), result.token()) { log::debug!("[tinyjuice_cli] stale CCR import intent cleanup failed: {error}"); + stale_time_cleanup_failed = true; + } + if stale_time_cleanup_failed { + return CcrPutResult::new(result.token().to_owned(), false); } } else if let Err(error) = delete_import_intent(Arc::clone(&self.blobs), result.token()) { From f8434c69debd836984a83b0952808725c20c0d3c Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 08:33:36 +0000 Subject: [PATCH 100/119] test(storage): cover concurrent capped writes and inventory counts Add a synchronizing blob store wrapper and two regression tests: one checks that inventory does not count backend storage after a blob write, and one checks that concurrent capped writes do not prune each other into an empty cache. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage_tests.rs | 114 ++++++++++++++++++++++ 1 file changed, 114 insertions(+) diff --git a/crates/tinyjuice-cli/src/storage_tests.rs b/crates/tinyjuice-cli/src/storage_tests.rs index 55f22d7f..57efaf95 100644 --- a/crates/tinyjuice-cli/src/storage_tests.rs +++ b/crates/tinyjuice-cli/src/storage_tests.rs @@ -84,6 +84,74 @@ impl BlobStore for FailMetadataOperations { } } +#[derive(Debug)] +struct SynchronizeConcurrentPuts { + inner: Arc, + body_writes: Arc, + prune_reads: Arc, +} + +#[async_trait::async_trait] +impl BlobStore for SynchronizeConcurrentPuts { + fn capabilities(&self) -> Capabilities { + self.inner.capabilities() + } + + fn max_key_len(&self) -> usize { + self.inner.max_key_len() + } + + async fn put( + &self, + key: &str, + bytes: Vec, + content_type: Option<&str>, + ) -> StorageResult { + let metadata = self.inner.put(key, bytes, content_type).await?; + if key.starts_with(&format!("{CCR_PREFIX}/")) { + let _ = tokio::time::timeout(Duration::from_millis(200), self.body_writes.wait()).await; + } + Ok(metadata) + } + + async fn get(&self, key: &str) -> StorageResult> { + self.inner.get(key).await + } + + async fn get_range( + &self, + key: &str, + range: std::ops::Range, + ) -> StorageResult>> { + self.inner.get_range(key, range).await + } + + async fn head(&self, key: &str) -> StorageResult> { + self.inner.head(key).await + } + + async fn delete(&self, key: &str) -> StorageResult { + self.inner.delete(key).await + } + + async fn list(&self, prefix: &str) -> StorageResult> { + self.inner.list(prefix).await + } + + async fn list_page( + &self, + prefix: &str, + after: Option<&str>, + limit: usize, + ) -> StorageResult { + let page = self.inner.list_page(prefix, after, limit).await?; + if prefix == format!("{CCR_PREFIX}/") { + let _ = tokio::time::timeout(Duration::from_millis(200), self.prune_reads.wait()).await; + } + Ok(page) + } +} + #[test] fn collection_reports_bytes_removed_by_the_budget() { let dir = tempfile::tempdir().unwrap(); @@ -320,6 +388,52 @@ fn inventory_counts_ignored_entries_and_returns_imported_blobs() { ); } +#[test] +fn inventory_does_not_count_backend_storage_after_a_blob_write() { + let dir = tempfile::tempdir().unwrap(); + let blobs = open_file_blobs(dir.path()).unwrap(); + let store = BlobCcrStore::new(blobs, None).unwrap(); + assert!(store.put("inventory backend entry").retained()); + + let first = inventory(dir.path(), None).unwrap(); + let second = inventory(dir.path(), None).unwrap(); + + assert_eq!(first.ignored_entries, second.ignored_entries); +} + +#[test] +fn concurrent_capped_writes_do_not_prune_each_other_into_an_empty_cache() { + let dir = tempfile::tempdir().unwrap(); + let inner = open_file_blobs(dir.path()).unwrap(); + let body_writes = Arc::new(tokio::sync::Barrier::new(2)); + let prune_reads = Arc::new(tokio::sync::Barrier::new(2)); + let blobs: Arc = Arc::new(SynchronizeConcurrentPuts { + inner: Arc::clone(&inner), + body_writes, + prune_reads, + }); + let lock_path = dir.path().join("scopes/tinyjuice-cli/.tinyjuice-ccr.lock"); + let make_store = || CappedCcrStore { + store: BlobCcrStore::new(Arc::clone(&blobs), None).unwrap(), + blobs: Arc::clone(&blobs), + lock_path: lock_path.clone(), + ttl: None, + max_bytes: Some(5), + }; + let first = make_store(); + let second = make_store(); + let first_put = std::thread::spawn(move || first.put("first")); + let second_put = std::thread::spawn(move || second.put("other")); + + let first_put = first_put.join().unwrap(); + let second_put = second_put.join().unwrap(); + assert!(first_put.retained()); + assert!(second_put.retained()); + let entries = run_blob(async move { inner.list(&format!("{CCR_PREFIX}/")).await }).unwrap(); + + assert_eq!(entries.len(), 1, "a capped concurrent write must retain one blob"); +} + #[test] fn import_skips_directories_and_unrecognized_names_and_removes_expired_files() { let dir = tempfile::tempdir().unwrap(); From d86c40b763a78e6f859fc578476c9983f12c9863 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 08:33:49 +0000 Subject: [PATCH 101/119] feat(storage): add process lock path to capped ccr store The capped CCR store now carries a lock path derived from the storage root, giving it a stable location to coordinate concurrent access. The path is computed once at construction so later operations can use it without recomputing the root. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/crates/tinyjuice-cli/src/storage.rs b/crates/tinyjuice-cli/src/storage.rs index d1234bcb..67be535e 100644 --- a/crates/tinyjuice-cli/src/storage.rs +++ b/crates/tinyjuice-cli/src/storage.rs @@ -2,6 +2,7 @@ use std::collections::{HashMap, HashSet}; use std::path::Path; +use std::path::PathBuf; use std::sync::Arc; use std::time::{Duration, SystemTime}; @@ -63,6 +64,7 @@ fn configure_with_report( let capped = CappedCcrStore { store, blobs: Arc::clone(&blobs), + lock_path: process_lock_path(root), ttl, max_bytes, }; @@ -468,10 +470,15 @@ fn remaining_ttl_from_epoch_ms( struct CappedCcrStore { store: BlobCcrStore, blobs: Arc, + lock_path: PathBuf, ttl: Option, max_bytes: Option, } +fn process_lock_path(root: &Path) -> PathBuf { + root.join("scopes/tinyjuice-cli/.tinyjuice-ccr.lock") +} + impl CcrStore for CappedCcrStore { fn put(&self, content: &str) -> CcrPutResult { let token = tinyjuice::cache::short_hash(content); From 276eb99f301efd2f3ac53301b78c5b94069b3174 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 08:34:03 +0000 Subject: [PATCH 102/119] test(storage): set lock path in capped store fixtures The CappedCcrStore test fixtures now supply a lock_path, matching the field the struct requires. Without it the fixtures would not compile against the current definition. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage_tests.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/tinyjuice-cli/src/storage_tests.rs b/crates/tinyjuice-cli/src/storage_tests.rs index 57efaf95..5a3f34bf 100644 --- a/crates/tinyjuice-cli/src/storage_tests.rs +++ b/crates/tinyjuice-cli/src/storage_tests.rs @@ -505,6 +505,7 @@ fn capped_store_delegates_byte_ranges_to_the_durable_store() { let store = CappedCcrStore { store: BlobCcrStore::new(Arc::clone(&blobs), None).unwrap(), blobs, + lock_path: process_lock_path(dir.path()), ttl: None, max_bytes: None, }; @@ -641,6 +642,7 @@ fn durable_cli_writes_enforce_the_configured_byte_budget() { let store = CappedCcrStore { store: BlobCcrStore::new(Arc::clone(&blobs), None).unwrap(), blobs: Arc::clone(&blobs), + lock_path: process_lock_path(dir.path()), ttl: None, max_bytes: Some(9), }; @@ -766,6 +768,7 @@ fn failed_timestamp_refresh_does_not_leave_an_old_age_for_gc() { let refreshed = CappedCcrStore { store: BlobCcrStore::new(Arc::clone(&failing), None).unwrap(), blobs: failing, + lock_path: process_lock_path(dir.path()), ttl: None, max_bytes: None, }; @@ -808,6 +811,7 @@ fn failed_stale_timestamp_cleanup_does_not_advertise_or_prune_the_new_body() { let capped = CappedCcrStore { store: BlobCcrStore::new(Arc::clone(&failing), None).unwrap(), blobs: failing, + lock_path: process_lock_path(dir.path()), ttl: Some(Duration::from_secs(3_600)), max_bytes: None, }; @@ -849,6 +853,7 @@ fn stale_import_intent_does_not_hide_a_newer_body_write() { let reoffloaded = CappedCcrStore { store: BlobCcrStore::new(Arc::clone(&flaky), None).unwrap(), blobs: flaky.clone(), + lock_path: process_lock_path(dir.path()), ttl: None, max_bytes: None, }; @@ -873,6 +878,7 @@ fn capped_store_put_works_inside_a_current_thread_runtime() { let capped = CappedCcrStore { store: BlobCcrStore::new(Arc::clone(&blobs), None).unwrap(), blobs, + lock_path: process_lock_path(dir.path()), ttl: Some(Duration::from_secs(600)), max_bytes: Some(1024), }; From 540554f5b55d752670f1ddb6babde8de53c5ed44 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 08:35:25 +0000 Subject: [PATCH 103/119] fix(storage): serialize CCR writes with a process lock The CLI now takes an exclusive file lock around CCR configuration and writes so concurrent processes cannot interleave pruning and puts. Prune was also moved onto the async blob APIs and the scopes directory is skipped during inventory. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage.rs | 182 +++++++++++++++++++++++++--- 1 file changed, 167 insertions(+), 15 deletions(-) diff --git a/crates/tinyjuice-cli/src/storage.rs b/crates/tinyjuice-cli/src/storage.rs index 67be535e..d630913b 100644 --- a/crates/tinyjuice-cli/src/storage.rs +++ b/crates/tinyjuice-cli/src/storage.rs @@ -1,6 +1,7 @@ //! CLI-owned composition of CCR over Tiny Storage Drivers' file backend. use std::collections::{HashMap, HashSet}; +use std::fs::{File, OpenOptions}; use std::path::Path; use std::path::PathBuf; use std::sync::Arc; @@ -59,6 +60,7 @@ fn configure_with_report( ) })?; let blobs = open_file_blobs(root)?; + let _lock = acquire_process_lock(&process_lock_path(root))?; let discarded_legacy = import_legacy_files(root, &blobs, ttl)?; let store = BlobCcrStore::new(Arc::clone(&blobs), ttl).map_err(|error| error.to_string())?; let capped = CappedCcrStore { @@ -108,6 +110,9 @@ pub(crate) fn inventory(root: &Path, ttl: Option) -> Result, protect: Option<&str>, ) -> Result<(usize, u64, usize, u64), String> { - let mut entries = list_all(Arc::clone(blobs))?; - let semantic_times = list_semantic_times(Arc::clone(blobs))?; + run_blob({ + let blobs = Arc::clone(blobs); + let protect = protect.map(str::to_owned); + async move { prune_async(blobs, ttl, max_bytes, protect.as_deref()).await } + }) +} + +async fn prune_async( + blobs: Arc, + ttl: Option, + max_bytes: Option, + protect: Option<&str>, +) -> Result<(usize, u64, usize, u64), String> { + let mut entries = list_all_prefix_async(Arc::clone(&blobs), &format!("{CCR_PREFIX}/")).await?; + let semantic_times = list_timestamps_async(Arc::clone(&blobs), CCR_METADATA_PREFIX).await?; for entry in &mut entries { if let Some(token) = entry.meta.key.strip_prefix(&format!("{CCR_PREFIX}/")) && let Some(written_at_ms) = semantic_times.get(token) @@ -214,7 +232,7 @@ fn prune( if let Some(entry) = entries.iter().find(|entry| &entry.meta.key == key) { removed_bytes = removed_bytes.saturating_add(entry.meta.len); } - delete_blob_and_metadata(Arc::clone(blobs), key)?; + delete_blob_and_metadata_async(Arc::clone(&blobs), key).await?; } entries.retain(|entry| !remove.contains(&entry.meta.key)); let mut total = entries.iter().map(|entry| entry.meta.len).sum::(); @@ -227,13 +245,13 @@ fn prune( if protect.is_some_and(|token| entry.meta.key == format!("{CCR_PREFIX}/{token}")) { continue; } - delete_blob_and_metadata(Arc::clone(blobs), &entry.meta.key)?; + delete_blob_and_metadata_async(Arc::clone(&blobs), &entry.meta.key).await?; removed_bytes = removed_bytes.saturating_add(entry.meta.len); total = total.saturating_sub(entry.meta.len); remove.push(entry.meta.key); } } - let remaining = list_all(Arc::clone(blobs))?; + let remaining = list_all_prefix_async(Arc::clone(&blobs), &format!("{CCR_PREFIX}/")).await?; let remaining_bytes = remaining.iter().map(|entry| entry.meta.len).sum(); let remaining_tokens = remaining .iter() @@ -241,12 +259,15 @@ fn prune( .collect::>(); for token in semantic_times.keys() { if !remaining_tokens.contains(token.as_str()) { - delete_metadata(Arc::clone(blobs), token)?; + delete_metadata_async(Arc::clone(&blobs), token).await?; } } - for token in list_timestamps(Arc::clone(blobs), CCR_IMPORT_PREFIX)?.keys() { + for token in list_timestamps_async(Arc::clone(&blobs), CCR_IMPORT_PREFIX) + .await? + .keys() + { if !remaining_tokens.contains(token.as_str()) { - delete_import_intent(Arc::clone(blobs), token)?; + delete_import_intent_async(Arc::clone(&blobs), token).await?; } } Ok(( @@ -479,9 +500,34 @@ fn process_lock_path(root: &Path) -> PathBuf { root.join("scopes/tinyjuice-cli/.tinyjuice-ccr.lock") } +fn acquire_process_lock(path: &Path) -> Result { + let parent = path + .parent() + .ok_or_else(|| "CCR process lock has no parent directory".to_owned())?; + std::fs::create_dir_all(parent) + .map_err(|error| format!("cannot create CCR process-lock directory: {error}"))?; + let lock = OpenOptions::new() + .create(true) + .truncate(false) + .read(true) + .write(true) + .open(path) + .map_err(|error| format!("cannot open CCR process lock: {error}"))?; + lock.lock() + .map_err(|error| format!("cannot acquire CCR process lock: {error}"))?; + Ok(lock) +} + impl CcrStore for CappedCcrStore { fn put(&self, content: &str) -> CcrPutResult { let token = tinyjuice::cache::short_hash(content); + let _lock = match acquire_process_lock(&self.lock_path) { + Ok(lock) => lock, + Err(error) => { + log::debug!("[tinyjuice_cli] CCR process lock failed: {error}"); + return CcrPutResult::new(token, false); + } + }; if let Err(error) = delete_import_intent(Arc::clone(&self.blobs), &token) { log::debug!( "[tinyjuice_cli] stale CCR import intent cleanup failed before write: {error}" @@ -567,6 +613,25 @@ fn list_all_prefix( } } +async fn list_all_prefix_async( + blobs: Arc, + prefix: &str, +) -> Result, String> { + let mut entries = Vec::new(); + let mut after = None; + loop { + let page = blobs + .list_page(prefix, after.as_deref(), PAGE_SIZE) + .await + .map_err(|error| error.to_string())?; + entries.extend(page.items); + after = page.next_after; + if after.is_none() { + return Ok(entries); + } + } +} + fn delete_blob(blobs: Arc, key: &str) -> Result<(), String> { let key = key.to_owned(); let handle = Arc::clone(&blobs); @@ -581,12 +646,35 @@ fn delete_blob_and_metadata(blobs: Arc, key: &str) -> Result<(), delete_metadata(blobs, token) } +async fn delete_blob_and_metadata_async( + blobs: Arc, + key: &str, +) -> Result<(), String> { + blobs + .delete(key) + .await + .map_err(|error| error.to_string())?; + let Some(token) = key.strip_prefix(&format!("{CCR_PREFIX}/")) else { + return Ok(()); + }; + delete_metadata_async(blobs, token).await +} + fn delete_metadata(blobs: Arc, token: &str) -> Result<(), String> { let key = format!("{CCR_METADATA_PREFIX}{token}"); let handle = Arc::clone(&blobs); run_blob(async move { handle.delete(&key).await }).map(|_| ()) } +async fn delete_metadata_async(blobs: Arc, token: &str) -> Result<(), String> { + let key = format!("{CCR_METADATA_PREFIX}{token}"); + blobs + .delete(&key) + .await + .map(|_| ()) + .map_err(|error| error.to_string()) +} + fn write_semantic_time( blobs: Arc, token: &str, @@ -614,6 +702,18 @@ fn delete_import_intent(blobs: Arc, token: &str) -> Result<(), St run_blob(async move { blobs.delete(&key).await }).map(|_| ()) } +async fn delete_import_intent_async( + blobs: Arc, + token: &str, +) -> Result<(), String> { + let key = format!("{CCR_IMPORT_PREFIX}{token}"); + blobs + .delete(&key) + .await + .map(|_| ()) + .map_err(|error| error.to_string()) +} + fn write_timestamp( blobs: Arc, prefix: &str, @@ -675,6 +775,35 @@ fn read_timestamp( } } +async fn read_timestamp_async( + blobs: Arc, + prefix: &str, + token: &str, +) -> Result, String> { + let key = format!("{prefix}{token}"); + let Some(blob) = blobs + .get(&key) + .await + .map_err(|error| error.to_string())? + else { + return Ok(None); + }; + match parse_timestamp(&blob.bytes) { + Ok(timestamp) => Ok(Some(timestamp)), + Err(error) => { + log::warn!("[tinyjuice_cli] discarding malformed CCR timestamp sidecar {key}: {error}"); + blobs + .delete(&key) + .await + .map(|_| ()) + .map_err(|error| { + format!("cannot remove malformed CCR timestamp sidecar: {error}") + })?; + Ok(None) + } + } +} + fn parse_timestamp(bytes: &[u8]) -> Result { std::str::from_utf8(bytes) .map_err(|error| format!("invalid CCR timestamp metadata: {error}"))? @@ -717,13 +846,36 @@ fn list_timestamps( Ok(times) } -fn run_blob( - future: impl std::future::Future> + Send + 'static, -) -> Result { - // Each helper owns a separate current-thread runtime. Blob engines in this - // CLI are self-contained and do not depend on work from another runtime. - // Run it on a dedicated thread because callers such as CcrStore::put can - // execute synchronously from inside an active Tokio runtime. +async fn list_timestamps_async( + blobs: Arc, + prefix: &str, +) -> Result, String> { + let entries = list_all_prefix_async(Arc::clone(&blobs), prefix).await?; + let mut times = HashMap::new(); + for entry in entries { + let Some(token) = entry.meta.key.strip_prefix(prefix) else { + continue; + }; + if !is_token(token) { + continue; + } + if let Some(timestamp) = read_timestamp_async(Arc::clone(&blobs), prefix, token).await? { + times.insert(token.to_owned(), timestamp); + } + } + Ok(times) +} + +fn run_blob( + future: impl std::future::Future> + Send + 'static, +) -> Result +where + T: Send + 'static, + E: std::fmt::Display + Send + 'static, +{ + // Blob engines in this CLI are self-contained and do not depend on work + // from another runtime. Run the synchronous entry point on one dedicated + // thread so it remains safe inside a current-thread Tokio runtime. std::thread::spawn(move || { let runtime = tokio::runtime::Builder::new_current_thread() .enable_all() From 2c24b4d07206a957c1b62ec9d4dd3f99f2af6416 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 08:35:34 +0000 Subject: [PATCH 104/119] style(tinyjuice-cli): reformat storage code to satisfy rustfmt Collapsed several multi-line expressions in the storage module onto single lines and reflowed an assertion in the storage tests. No behaviour changed; this only brings the files in line with the formatter. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage.rs | 26 ++++++----------------- crates/tinyjuice-cli/src/storage_tests.rs | 6 +++++- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/crates/tinyjuice-cli/src/storage.rs b/crates/tinyjuice-cli/src/storage.rs index d630913b..d69d0bff 100644 --- a/crates/tinyjuice-cli/src/storage.rs +++ b/crates/tinyjuice-cli/src/storage.rs @@ -650,10 +650,7 @@ async fn delete_blob_and_metadata_async( blobs: Arc, key: &str, ) -> Result<(), String> { - blobs - .delete(key) - .await - .map_err(|error| error.to_string())?; + blobs.delete(key).await.map_err(|error| error.to_string())?; let Some(token) = key.strip_prefix(&format!("{CCR_PREFIX}/")) else { return Ok(()); }; @@ -702,10 +699,7 @@ fn delete_import_intent(blobs: Arc, token: &str) -> Result<(), St run_blob(async move { blobs.delete(&key).await }).map(|_| ()) } -async fn delete_import_intent_async( - blobs: Arc, - token: &str, -) -> Result<(), String> { +async fn delete_import_intent_async(blobs: Arc, token: &str) -> Result<(), String> { let key = format!("{CCR_IMPORT_PREFIX}{token}"); blobs .delete(&key) @@ -781,24 +775,16 @@ async fn read_timestamp_async( token: &str, ) -> Result, String> { let key = format!("{prefix}{token}"); - let Some(blob) = blobs - .get(&key) - .await - .map_err(|error| error.to_string())? - else { + let Some(blob) = blobs.get(&key).await.map_err(|error| error.to_string())? else { return Ok(None); }; match parse_timestamp(&blob.bytes) { Ok(timestamp) => Ok(Some(timestamp)), Err(error) => { log::warn!("[tinyjuice_cli] discarding malformed CCR timestamp sidecar {key}: {error}"); - blobs - .delete(&key) - .await - .map(|_| ()) - .map_err(|error| { - format!("cannot remove malformed CCR timestamp sidecar: {error}") - })?; + blobs.delete(&key).await.map(|_| ()).map_err(|error| { + format!("cannot remove malformed CCR timestamp sidecar: {error}") + })?; Ok(None) } } diff --git a/crates/tinyjuice-cli/src/storage_tests.rs b/crates/tinyjuice-cli/src/storage_tests.rs index 5a3f34bf..0ef021d3 100644 --- a/crates/tinyjuice-cli/src/storage_tests.rs +++ b/crates/tinyjuice-cli/src/storage_tests.rs @@ -431,7 +431,11 @@ fn concurrent_capped_writes_do_not_prune_each_other_into_an_empty_cache() { assert!(second_put.retained()); let entries = run_blob(async move { inner.list(&format!("{CCR_PREFIX}/")).await }).unwrap(); - assert_eq!(entries.len(), 1, "a capped concurrent write must retain one blob"); + assert_eq!( + entries.len(), + 1, + "a capped concurrent write must retain one blob" + ); } #[test] From 7c5b253e4c71cf46468a5520609441656dc9ac8b Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 08:41:23 +0000 Subject: [PATCH 105/119] test(storage): raise concurrency sync timeouts to 500ms The two synchronization points in the concurrent put test helper now wait up to 500ms instead of 200ms, reducing flakiness when the awaited body writes or prune reads are slow to arrive. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage_tests.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/tinyjuice-cli/src/storage_tests.rs b/crates/tinyjuice-cli/src/storage_tests.rs index 0ef021d3..cec23ea0 100644 --- a/crates/tinyjuice-cli/src/storage_tests.rs +++ b/crates/tinyjuice-cli/src/storage_tests.rs @@ -109,7 +109,7 @@ impl BlobStore for SynchronizeConcurrentPuts { ) -> StorageResult { let metadata = self.inner.put(key, bytes, content_type).await?; if key.starts_with(&format!("{CCR_PREFIX}/")) { - let _ = tokio::time::timeout(Duration::from_millis(200), self.body_writes.wait()).await; + let _ = tokio::time::timeout(Duration::from_millis(500), self.body_writes.wait()).await; } Ok(metadata) } @@ -146,7 +146,7 @@ impl BlobStore for SynchronizeConcurrentPuts { ) -> StorageResult { let page = self.inner.list_page(prefix, after, limit).await?; if prefix == format!("{CCR_PREFIX}/") { - let _ = tokio::time::timeout(Duration::from_millis(200), self.prune_reads.wait()).await; + let _ = tokio::time::timeout(Duration::from_millis(500), self.prune_reads.wait()).await; } Ok(page) } From 47eabbb7309e6709eb85194ee53b99b99d6c1c52 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 08:45:06 +0000 Subject: [PATCH 106/119] refactor(storage): remove process lock from ccr put The CappedCcrStore put path no longer acquires the process lock before writing, replacing the lock acquisition with a no-op. This drops the serialization the lock provided, so concurrent puts are no longer guarded against each other. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/crates/tinyjuice-cli/src/storage.rs b/crates/tinyjuice-cli/src/storage.rs index d69d0bff..89bb1077 100644 --- a/crates/tinyjuice-cli/src/storage.rs +++ b/crates/tinyjuice-cli/src/storage.rs @@ -521,13 +521,7 @@ fn acquire_process_lock(path: &Path) -> Result { impl CcrStore for CappedCcrStore { fn put(&self, content: &str) -> CcrPutResult { let token = tinyjuice::cache::short_hash(content); - let _lock = match acquire_process_lock(&self.lock_path) { - Ok(lock) => lock, - Err(error) => { - log::debug!("[tinyjuice_cli] CCR process lock failed: {error}"); - return CcrPutResult::new(token, false); - } - }; + let _lock = (); if let Err(error) = delete_import_intent(Arc::clone(&self.blobs), &token) { log::debug!( "[tinyjuice_cli] stale CCR import intent cleanup failed before write: {error}" From 8022b4e257778275b15477beace5ce8a4a31cfa5 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 08:45:30 +0000 Subject: [PATCH 107/119] fix(cli): acquire process lock before ccr store writes The capped CCR store previously used a placeholder instead of taking the process lock, so concurrent writers could race on the same token. It now acquires the lock and skips the write with a debug log if acquisition fails. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/tinyjuice-cli/src/storage.rs b/crates/tinyjuice-cli/src/storage.rs index 89bb1077..d69d0bff 100644 --- a/crates/tinyjuice-cli/src/storage.rs +++ b/crates/tinyjuice-cli/src/storage.rs @@ -521,7 +521,13 @@ fn acquire_process_lock(path: &Path) -> Result { impl CcrStore for CappedCcrStore { fn put(&self, content: &str) -> CcrPutResult { let token = tinyjuice::cache::short_hash(content); - let _lock = (); + let _lock = match acquire_process_lock(&self.lock_path) { + Ok(lock) => lock, + Err(error) => { + log::debug!("[tinyjuice_cli] CCR process lock failed: {error}"); + return CcrPutResult::new(token, false); + } + }; if let Err(error) = delete_import_intent(Arc::clone(&self.blobs), &token) { log::debug!( "[tinyjuice_cli] stale CCR import intent cleanup failed before write: {error}" From 735bb11aefe35f514a59fed2685d16e74a980fd5 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 08:46:46 +0000 Subject: [PATCH 108/119] chore(storage): gate test-only helpers behind cfg(test) Mark delete_blob, delete_blob_and_metadata, list_semantic_times and list_timestamps as test-only so they are not compiled into release builds. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/tinyjuice-cli/src/storage.rs b/crates/tinyjuice-cli/src/storage.rs index d69d0bff..72b3c577 100644 --- a/crates/tinyjuice-cli/src/storage.rs +++ b/crates/tinyjuice-cli/src/storage.rs @@ -632,12 +632,14 @@ async fn list_all_prefix_async( } } +#[cfg(test)] fn delete_blob(blobs: Arc, key: &str) -> Result<(), String> { let key = key.to_owned(); let handle = Arc::clone(&blobs); run_blob(async move { handle.delete(&key).await }).map(|_| ()) } +#[cfg(test)] fn delete_blob_and_metadata(blobs: Arc, key: &str) -> Result<(), String> { delete_blob(Arc::clone(&blobs), key)?; let Some(token) = key.strip_prefix(&format!("{CCR_PREFIX}/")) else { @@ -808,10 +810,12 @@ fn backend_written_at(blobs: Arc, key: &str) -> Result) -> Result, String> { list_timestamps(blobs, CCR_METADATA_PREFIX) } +#[cfg(test)] fn list_timestamps( blobs: Arc, prefix: &str, From e05d4ad81c5bb07b445b34c5f9dd31aa7f014da3 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 08:59:14 +0000 Subject: [PATCH 109/119] test(storage): cover lock and cleanup failure paths Add tests asserting that a capped write fails closed when the process lock directory cannot be created, and that pruning aborts when a malformed timestamp sidecar cannot be removed. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage_tests.rs | 63 +++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/crates/tinyjuice-cli/src/storage_tests.rs b/crates/tinyjuice-cli/src/storage_tests.rs index cec23ea0..ac6f02fc 100644 --- a/crates/tinyjuice-cli/src/storage_tests.rs +++ b/crates/tinyjuice-cli/src/storage_tests.rs @@ -438,6 +438,31 @@ fn concurrent_capped_writes_do_not_prune_each_other_into_an_empty_cache() { ); } +#[test] +fn capped_write_fails_closed_when_process_lock_directory_cannot_be_created() { + let dir = tempfile::tempdir().unwrap(); + let blobs = open_file_blobs(dir.path()).unwrap(); + let blocker = dir.path().join("not-a-directory"); + std::fs::write(&blocker, b"file blocks lock directory creation").unwrap(); + let store = CappedCcrStore { + store: BlobCcrStore::new(Arc::clone(&blobs), None).unwrap(), + blobs: Arc::clone(&blobs), + lock_path: blocker.join(".tinyjuice-ccr.lock"), + ttl: None, + max_bytes: Some(1024), + }; + + let result = store.put("must not be written without the process lock"); + + assert!(!result.retained()); + assert!( + run_blob(async move { blobs.list(&format!("{CCR_PREFIX}/")).await }) + .unwrap() + .is_empty(), + "the write must not proceed after process-lock acquisition fails" + ); +} + #[test] fn import_skips_directories_and_unrecognized_names_and_removes_expired_files() { let dir = tempfile::tempdir().unwrap(); @@ -598,6 +623,44 @@ fn malformed_timestamp_sidecars_do_not_abort_pruning_or_hide_backend_write_time( assert_eq!(read_import_intent(blobs, intent_token).unwrap(), None); } +#[test] +fn malformed_timestamp_cleanup_failure_aborts_pruning() { + let dir = tempfile::tempdir().unwrap(); + let inner = open_file_blobs(dir.path()).unwrap(); + let content = "body with an unreadable timestamp sidecar"; + let token = tinyjuice::cache::short_hash(content); + assert!(BlobCcrStore::new(Arc::clone(&inner), None) + .unwrap() + .put(content) + .retained()); + run_blob({ + let inner = Arc::clone(&inner); + async move { + inner + .put( + &format!("{CCR_METADATA_PREFIX}{token}"), + b"not-a-number".to_vec(), + None, + ) + .await + } + }) + .unwrap(); + let faults = FaultPlan::new(); + faults.fail_operation_nth("semantic_metadata_delete", 1, ErrorKind::Backend); + let failing: Arc = Arc::new(FailMetadataOperations { + inner: Arc::clone(&inner), + faults, + }); + + let error = prune(&failing, None, None, None).unwrap_err(); + + assert!(error.contains("cannot remove malformed CCR timestamp sidecar")); + assert!(run_blob(async move { inner.get(&format!("{CCR_METADATA_PREFIX}{token}")).await }) + .unwrap() + .is_some()); +} + #[test] fn timestamp_backend_read_errors_still_abort_pruning() { let dir = tempfile::tempdir().unwrap(); From 597754f512f9e59fc2382fd753d0f3c5512d594f Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 08:59:24 +0000 Subject: [PATCH 110/119] test(storage): reformat assertions to satisfy rustfmt Reformatted two multi-line assertions in the malformed timestamp cleanup test so they match rustfmt's expected layout. No behaviour change. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage_tests.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/crates/tinyjuice-cli/src/storage_tests.rs b/crates/tinyjuice-cli/src/storage_tests.rs index ac6f02fc..5db6c9c3 100644 --- a/crates/tinyjuice-cli/src/storage_tests.rs +++ b/crates/tinyjuice-cli/src/storage_tests.rs @@ -629,10 +629,12 @@ fn malformed_timestamp_cleanup_failure_aborts_pruning() { let inner = open_file_blobs(dir.path()).unwrap(); let content = "body with an unreadable timestamp sidecar"; let token = tinyjuice::cache::short_hash(content); - assert!(BlobCcrStore::new(Arc::clone(&inner), None) - .unwrap() - .put(content) - .retained()); + assert!( + BlobCcrStore::new(Arc::clone(&inner), None) + .unwrap() + .put(content) + .retained() + ); run_blob({ let inner = Arc::clone(&inner); async move { @@ -656,9 +658,11 @@ fn malformed_timestamp_cleanup_failure_aborts_pruning() { let error = prune(&failing, None, None, None).unwrap_err(); assert!(error.contains("cannot remove malformed CCR timestamp sidecar")); - assert!(run_blob(async move { inner.get(&format!("{CCR_METADATA_PREFIX}{token}")).await }) - .unwrap() - .is_some()); + assert!( + run_blob(async move { inner.get(&format!("{CCR_METADATA_PREFIX}{token}")).await }) + .unwrap() + .is_some() + ); } #[test] From e11a157188b1dfbf45253fcb27f1f37b8c58799e Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 08:59:54 +0000 Subject: [PATCH 111/119] test(storage): clone token before moving into async block The malformed timestamp cleanup test moved the token into the async block before it was needed for the sidecar key, so the token is now cloned and the clone is captured instead. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage_tests.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/tinyjuice-cli/src/storage_tests.rs b/crates/tinyjuice-cli/src/storage_tests.rs index 5db6c9c3..89830ee9 100644 --- a/crates/tinyjuice-cli/src/storage_tests.rs +++ b/crates/tinyjuice-cli/src/storage_tests.rs @@ -635,12 +635,13 @@ fn malformed_timestamp_cleanup_failure_aborts_pruning() { .put(content) .retained() ); + let token_for_sidecar = token.clone(); run_blob({ let inner = Arc::clone(&inner); async move { inner .put( - &format!("{CCR_METADATA_PREFIX}{token}"), + &format!("{CCR_METADATA_PREFIX}{token_for_sidecar}"), b"not-a-number".to_vec(), None, ) From e415879429690a5aed116996110bd406cf0fdb8d Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 09:03:16 +0000 Subject: [PATCH 112/119] test(storage): cover ttl reapplication to existing blobs Add a test asserting that changing the configured TTL rewrites the physical expiry of already stored blobs, extending it when the TTL grows and clearing it when the TTL is removed while the entry stays readable. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage_tests.rs | 48 +++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/crates/tinyjuice-cli/src/storage_tests.rs b/crates/tinyjuice-cli/src/storage_tests.rs index 89830ee9..40d30053 100644 --- a/crates/tinyjuice-cli/src/storage_tests.rs +++ b/crates/tinyjuice-cli/src/storage_tests.rs @@ -269,6 +269,54 @@ fn startup_prunes_expired_blobs_with_ttl_without_a_byte_cap() { ); } +#[test] +fn configuration_reapplies_changed_ttl_to_existing_blobs() { + let dir = tempfile::tempdir().unwrap(); + let root = dir.path(); + let blobs = open_file_blobs(root).unwrap(); + let content = "an existing cache entry whose configured TTL changes"; + let token = tinyjuice::cache::short_hash(content); + assert!( + BlobCcrStore::new(Arc::clone(&blobs), Some(Duration::from_secs(3_600))) + .unwrap() + .put(content) + .retained() + ); + + let body_sidecar = || { + std::fs::read_dir(root.join("scopes/tinyjuice-cli/blobs")) + .unwrap() + .map(|entry| std::fs::read(entry.unwrap().path()).unwrap()) + .filter_map(|bytes| serde_json::from_slice::(&bytes).ok()) + .find(|sidecar| sidecar["key"] == format!("{CCR_PREFIX}/{token}")) + .expect("CCR body metadata sidecar exists") + }; + let original_expiry = body_sidecar()["expires_at_ms"] + .as_u64() + .expect("the initial TTL is recorded in the backend sidecar"); + + configure(root, Some(Duration::from_secs(7_200)), None).unwrap(); + + let extended_expiry = body_sidecar()["expires_at_ms"] + .as_u64() + .expect("the updated TTL is recorded in the backend sidecar"); + assert!( + extended_expiry > original_expiry, + "a longer configured TTL must replace the old physical expiry" + ); + + configure(root, None, None).unwrap(); + + assert!(body_sidecar()["expires_at_ms"].is_null()); + assert_eq!( + BlobCcrStore::new(open_file_blobs(root).unwrap(), None) + .unwrap() + .get(&token) + .as_deref(), + Some(content) + ); +} + #[test] fn removing_legacy_entries_reports_inspection_and_removal_errors() { let dir = tempfile::tempdir().unwrap(); From 728c6a26f2cf2a7231c7028d9e02414d236313c5 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 09:04:01 +0000 Subject: [PATCH 113/119] fix(storage): reapply ttl to existing blobs on configure Existing blobs kept whatever expiry they were written with, so changing the configured ttl had no effect on data already in the store. On configure, walk the body, metadata and import prefixes and rewrite each entry with an expiry derived from its original write time, leaving entries whose ttl has already elapsed untouched. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage.rs | 105 ++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) diff --git a/crates/tinyjuice-cli/src/storage.rs b/crates/tinyjuice-cli/src/storage.rs index 72b3c577..51d52338 100644 --- a/crates/tinyjuice-cli/src/storage.rs +++ b/crates/tinyjuice-cli/src/storage.rs @@ -63,6 +63,7 @@ fn configure_with_report( let _lock = acquire_process_lock(&process_lock_path(root))?; let discarded_legacy = import_legacy_files(root, &blobs, ttl)?; let store = BlobCcrStore::new(Arc::clone(&blobs), ttl).map_err(|error| error.to_string())?; + reapply_existing_blob_ttl(&blobs, ttl)?; let capped = CappedCcrStore { store, blobs: Arc::clone(&blobs), @@ -197,6 +198,110 @@ fn prune( }) } +fn reapply_existing_blob_ttl( + blobs: &Arc, + ttl: Option, +) -> Result<(), String> { + run_blob({ + let blobs = Arc::clone(blobs); + async move { + let body_prefix = format!("{CCR_PREFIX}/"); + let bodies = list_all_prefix_async(Arc::clone(&blobs), &body_prefix).await?; + let semantic_times = + list_timestamps_async(Arc::clone(&blobs), CCR_METADATA_PREFIX).await?; + let now_ms = unix_epoch_ms(SystemTime::now()); + + for entry in bodies { + let Some(token) = entry.meta.key.strip_prefix(&body_prefix) else { + continue; + }; + let Some(body) = blobs + .get(&entry.meta.key) + .await + .map_err(|error| error.to_string())? + else { + continue; + }; + let written_at_ms = semantic_times.get(token).copied().or(entry.written_at_ms); + refresh_blob_expiry_async( + Arc::clone(&blobs), + &entry.meta.key, + body.bytes, + body.meta.content_type.as_deref(), + written_at_ms, + ttl, + now_ms, + ) + .await?; + } + + for prefix in [CCR_METADATA_PREFIX, CCR_IMPORT_PREFIX] { + let entries = list_all_prefix_async(Arc::clone(&blobs), prefix).await?; + for entry in entries { + let Some(token) = entry.meta.key.strip_prefix(prefix) else { + continue; + }; + if !is_token(token) { + continue; + } + let Some(sidecar) = blobs + .get(&entry.meta.key) + .await + .map_err(|error| error.to_string())? + else { + continue; + }; + let Ok(written_at_ms) = parse_timestamp(&sidecar.bytes) else { + continue; + }; + refresh_blob_expiry_async( + Arc::clone(&blobs), + &entry.meta.key, + sidecar.bytes, + sidecar.meta.content_type.as_deref(), + Some(written_at_ms), + ttl, + now_ms, + ) + .await?; + } + } + Ok(()) + } + }) +} + +async fn refresh_blob_expiry_async( + blobs: Arc, + key: &str, + bytes: Vec, + content_type: Option<&str>, + written_at_ms: Option, + ttl: Option, + now_ms: u64, +) -> Result<(), String> { + match ttl { + None => blobs + .put(key, bytes, content_type) + .await + .map(|_| ()) + .map_err(|error| error.to_string()), + Some(ttl) => { + let remaining = written_at_ms + .and_then(|written| remaining_ttl_from_epoch_ms(written, now_ms, ttl)) + .unwrap_or(ttl); + if remaining.is_zero() { + return Ok(()); + } + blobs + .put_expiring(key, bytes, content_type, remaining) + .await + .map(|_| ()) + .map_err(|error| error.to_string()) + } + } +} + async fn prune_async( blobs: Arc, ttl: Option, From 6bf1c6546f6b52f8622fd93d497e2279ba5528fb Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 09:04:20 +0000 Subject: [PATCH 114/119] refactor(storage): pass SystemTime instead of epoch millis The TTL reapply path now captures SystemTime::now() once and threads the SystemTime value through refresh_blob_expiry_async, converting to epoch milliseconds only where remaining_ttl_from_epoch_ms needs it. This keeps the clock reading in one place and avoids converting back and forth. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/tinyjuice-cli/src/storage.rs b/crates/tinyjuice-cli/src/storage.rs index 51d52338..15e044dc 100644 --- a/crates/tinyjuice-cli/src/storage.rs +++ b/crates/tinyjuice-cli/src/storage.rs @@ -209,7 +209,7 @@ fn reapply_existing_blob_ttl( let bodies = list_all_prefix_async(Arc::clone(&blobs), &body_prefix).await?; let semantic_times = list_timestamps_async(Arc::clone(&blobs), CCR_METADATA_PREFIX).await?; - let now_ms = unix_epoch_ms(SystemTime::now()); + let now = SystemTime::now(); for entry in bodies { let Some(token) = entry.meta.key.strip_prefix(&body_prefix) else { @@ -230,7 +230,7 @@ fn reapply_existing_blob_ttl( body.meta.content_type.as_deref(), written_at_ms, ttl, - now_ms, + now, ) .await?; } @@ -261,12 +261,12 @@ fn reapply_existing_blob_ttl( sidecar.meta.content_type.as_deref(), Some(written_at_ms), ttl, - now_ms, + now, ) .await?; } } - Ok(()) + Ok::<(), String>(()) } }) } @@ -278,7 +278,7 @@ async fn refresh_blob_expiry_async( content_type: Option<&str>, written_at_ms: Option, ttl: Option, - now_ms: u64, + now: SystemTime, ) -> Result<(), String> { match ttl { None => blobs @@ -288,7 +288,7 @@ async fn refresh_blob_expiry_async( .map_err(|error| error.to_string()), Some(ttl) => { let remaining = written_at_ms - .and_then(|written| remaining_ttl_from_epoch_ms(written, now_ms, ttl)) + .and_then(|written| remaining_ttl_from_epoch_ms(written, now, ttl)) .unwrap_or(ttl); if remaining.is_zero() { return Ok(()); From f67f0a88ac0a6f6d0f99344e4537d89285f6eb8b Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 09:05:00 +0000 Subject: [PATCH 115/119] fix(storage): skip blob expiry refresh when ttl already elapsed The remaining TTL calculation now distinguishes a missing write timestamp from an expired one, so a blob whose TTL has fully elapsed is left alone instead of being refreshed with a zero duration. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/tinyjuice-cli/src/storage.rs b/crates/tinyjuice-cli/src/storage.rs index 15e044dc..68673f78 100644 --- a/crates/tinyjuice-cli/src/storage.rs +++ b/crates/tinyjuice-cli/src/storage.rs @@ -287,9 +287,13 @@ async fn refresh_blob_expiry_async( .map(|_| ()) .map_err(|error| error.to_string()), Some(ttl) => { - let remaining = written_at_ms - .and_then(|written| remaining_ttl_from_epoch_ms(written, now, ttl)) - .unwrap_or(ttl); + let remaining = match written_at_ms { + Some(written) => remaining_ttl_from_epoch_ms(written, now, ttl), + None => Some(ttl), + }; + let Some(remaining) = remaining else { + return Ok(()); + }; if remaining.is_zero() { return Ok(()); } From 45ad727de02a487eb3eeada2f196ace839df6a2a Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 09:15:08 +0000 Subject: [PATCH 116/119] test(storage): cover ttl reconfiguration edge cases Add tests verifying that reapplying expiry preserves the original write time when a blob has no semantic timestamp, and that an unchanged TTL leaves cached body metadata untouched. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage_tests.rs | 73 +++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/crates/tinyjuice-cli/src/storage_tests.rs b/crates/tinyjuice-cli/src/storage_tests.rs index 40d30053..740988e7 100644 --- a/crates/tinyjuice-cli/src/storage_tests.rs +++ b/crates/tinyjuice-cli/src/storage_tests.rs @@ -317,6 +317,79 @@ fn configuration_reapplies_changed_ttl_to_existing_blobs() { ); } +#[test] +fn configuration_preserves_backend_write_time_when_semantic_time_is_missing() { + let dir = tempfile::tempdir().unwrap(); + let root = dir.path(); + let blobs = open_file_blobs(root).unwrap(); + let content = "existing body without a semantic timestamp"; + let token = tinyjuice::cache::short_hash(content); + assert!( + BlobCcrStore::new(Arc::clone(&blobs), Some(Duration::from_secs(3_600))) + .unwrap() + .put(content) + .retained() + ); + let written_at_ms = list_all(Arc::clone(&blobs)) + .unwrap() + .into_iter() + .find(|entry| entry.meta.key == format!("{CCR_PREFIX}/{token}")) + .and_then(|entry| entry.written_at_ms) + .expect("file backend records the original body write time"); + + configure(root, Some(Duration::from_secs(7_200)), None).unwrap(); + + assert_eq!( + read_semantic_time(open_file_blobs(root).unwrap(), &token).unwrap(), + Some(written_at_ms), + "reapplying expiry must preserve the original age for later pruning" + ); +} + +#[test] +fn configuration_does_not_rewrite_cache_when_ttl_is_unchanged() { + let dir = tempfile::tempdir().unwrap(); + let root = dir.path(); + let blobs = open_file_blobs(root).unwrap(); + let content = "cache body used to check unchanged TTL configuration"; + let token = tinyjuice::cache::short_hash(content); + let ttl = Some(Duration::from_secs(3_600)); + assert!( + BlobCcrStore::new(Arc::clone(&blobs), ttl) + .unwrap() + .put(content) + .retained() + ); + configure(root, ttl, None).unwrap(); + + let body_sidecar = std::fs::read_dir(root.join("scopes/tinyjuice-cli/blobs")) + .unwrap() + .map(|entry| entry.unwrap().path()) + .find(|path| { + path.extension() + .is_some_and(|extension| extension == "json") + && std::fs::read(path) + .ok() + .and_then(|bytes| serde_json::from_slice::(&bytes).ok()) + .is_some_and(|sidecar| sidecar["key"] == format!("{CCR_PREFIX}/{token}")) + }) + .expect("CCR body metadata sidecar exists"); + std::fs::OpenOptions::new() + .write(true) + .open(&body_sidecar) + .unwrap() + .set_times(std::fs::FileTimes::new().set_modified(SystemTime::UNIX_EPOCH)) + .unwrap(); + + configure(root, ttl, None).unwrap(); + + assert_eq!( + std::fs::metadata(body_sidecar).unwrap().modified().unwrap(), + SystemTime::UNIX_EPOCH, + "an unchanged TTL must not rewrite each cached body's metadata" + ); +} + #[test] fn removing_legacy_entries_reports_inspection_and_removal_errors() { let dir = tempfile::tempdir().unwrap(); From 35f72fdb0077cf1540366177c14e8345980919b3 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 09:15:56 +0000 Subject: [PATCH 117/119] perf(storage): skip ttl reapply when configuration is unchanged Configuration now records a signature of the applied TTL and skips reapplying expiry to existing blobs when it matches, avoiding redundant work on every configure call. Blobs missing semantic timestamps now fall back to the current time and have their metadata refreshed so their expiry stays consistent. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage.rs | 57 +++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 3 deletions(-) diff --git a/crates/tinyjuice-cli/src/storage.rs b/crates/tinyjuice-cli/src/storage.rs index 68673f78..1c61c191 100644 --- a/crates/tinyjuice-cli/src/storage.rs +++ b/crates/tinyjuice-cli/src/storage.rs @@ -20,6 +20,7 @@ const DEFAULT_CLI_CCR_TTL_SECS: u64 = 7 * 24 * 60 * 60; const CCR_METADATA_PREFIX: &str = "tinyjuice/ccr-metadata/"; const CCR_METADATA_CONTENT_TYPE: &str = "application/vnd.tinyjuice.ccr-metadata"; const CCR_IMPORT_PREFIX: &str = "tinyjuice/ccr-import-intent/"; +const CCR_TTL_CONFIGURATION_KEY: &str = "tinyjuice/ccr-config/applied-ttl"; #[allow(dead_code)] // The reducer binary uses inventory; the hook binary shares this module. pub(crate) struct Inventory { @@ -63,7 +64,7 @@ fn configure_with_report( let _lock = acquire_process_lock(&process_lock_path(root))?; let discarded_legacy = import_legacy_files(root, &blobs, ttl)?; let store = BlobCcrStore::new(Arc::clone(&blobs), ttl).map_err(|error| error.to_string())?; - reapply_existing_blob_ttl(&blobs, ttl)?; + reapply_existing_blob_ttl_if_changed(&blobs, ttl)?; let capped = CappedCcrStore { store, blobs: Arc::clone(&blobs), @@ -198,6 +199,40 @@ fn prune( }) } +fn reapply_existing_blob_ttl_if_changed( + blobs: &Arc, + ttl: Option, +) -> Result<(), String> { + let signature = ttl_signature(ttl); + let key = CCR_TTL_CONFIGURATION_KEY.to_owned(); + let existing = run_blob({ + let blobs = Arc::clone(blobs); + let key = key.clone(); + async move { blobs.get(&key).await } + })?; + if existing.is_some_and(|blob| blob.bytes == signature.as_bytes()) { + return Ok(()); + } + + reapply_existing_blob_ttl(blobs, ttl)?; + run_blob({ + let blobs = Arc::clone(blobs); + async move { + blobs + .put(&key, signature.into_bytes(), None) + .await + .map(|_| ()) + } + }) +} + +fn ttl_signature(ttl: Option) -> String { + match ttl { + Some(ttl) => format!("{}.{:09}", ttl.as_secs(), ttl.subsec_nanos()), + None => "disabled".to_owned(), + } +} + fn reapply_existing_blob_ttl( blobs: &Arc, ttl: Option, @@ -222,13 +257,29 @@ fn reapply_existing_blob_ttl( else { continue; }; - let written_at_ms = semantic_times.get(token).copied().or(entry.written_at_ms); + let written_at_ms = semantic_times + .get(token) + .copied() + .or(entry.written_at_ms) + .unwrap_or_else(|| unix_epoch_ms(now)); + if !semantic_times.contains_key(token) { + refresh_blob_expiry_async( + Arc::clone(&blobs), + &format!("{CCR_METADATA_PREFIX}{token}"), + written_at_ms.to_string().into_bytes(), + Some(CCR_METADATA_CONTENT_TYPE), + Some(written_at_ms), + ttl, + now, + ) + .await?; + } refresh_blob_expiry_async( Arc::clone(&blobs), &entry.meta.key, body.bytes, body.meta.content_type.as_deref(), - written_at_ms, + Some(written_at_ms), ttl, now, ) From ca503b1686bd20612e55a5e20e5fc7350c48d60e Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 09:24:37 +0000 Subject: [PATCH 118/119] test(storage): cover stale capped store after configuration change Add a test asserting that a capped store holding a superseded TTL does not publish a body once the on-disk configuration has changed. This guards the case where a long-lived process keeps writing with stale settings. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage_tests.rs | 28 +++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/crates/tinyjuice-cli/src/storage_tests.rs b/crates/tinyjuice-cli/src/storage_tests.rs index 740988e7..b74665c0 100644 --- a/crates/tinyjuice-cli/src/storage_tests.rs +++ b/crates/tinyjuice-cli/src/storage_tests.rs @@ -390,6 +390,34 @@ fn configuration_does_not_rewrite_cache_when_ttl_is_unchanged() { ); } +#[test] +fn stale_capped_store_does_not_write_after_configuration_changes() { + let dir = tempfile::tempdir().unwrap(); + let root = dir.path(); + let blobs = open_file_blobs(root).unwrap(); + let old_ttl = Some(Duration::from_secs(3_600)); + let new_ttl = Some(Duration::from_secs(7_200)); + configure(root, old_ttl, None).unwrap(); + let stale = CappedCcrStore { + store: BlobCcrStore::new(Arc::clone(&blobs), old_ttl).unwrap(), + blobs: Arc::clone(&blobs), + lock_path: process_lock_path(root), + ttl: old_ttl, + max_bytes: None, + }; + configure(root, new_ttl, None).unwrap(); + + let result = stale.put("stale process must not write with an old TTL"); + + assert!(!result.retained()); + assert!( + run_blob(async move { blobs.list(&format!("{CCR_PREFIX}/")).await }) + .unwrap() + .is_empty(), + "a store configured with a superseded TTL must not publish a body" + ); +} + #[test] fn removing_legacy_entries_reports_inspection_and_removal_errors() { let dir = tempfile::tempdir().unwrap(); From e2a57d6ac2e3147793b4be366739e5e13415d2b0 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 09:25:46 +0000 Subject: [PATCH 119/119] fix(storage): track storage configuration alongside ttl The applied-configuration marker now records the byte cap as well as the ttl, so a change to either setting triggers reapplication to existing blobs. Writes are skipped while the stored configuration is stale, which prevents new entries from being admitted under limits that have not yet been applied. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinyjuice-cli/src/storage.rs | 54 +++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 7 deletions(-) diff --git a/crates/tinyjuice-cli/src/storage.rs b/crates/tinyjuice-cli/src/storage.rs index 1c61c191..585baf7a 100644 --- a/crates/tinyjuice-cli/src/storage.rs +++ b/crates/tinyjuice-cli/src/storage.rs @@ -20,7 +20,7 @@ const DEFAULT_CLI_CCR_TTL_SECS: u64 = 7 * 24 * 60 * 60; const CCR_METADATA_PREFIX: &str = "tinyjuice/ccr-metadata/"; const CCR_METADATA_CONTENT_TYPE: &str = "application/vnd.tinyjuice.ccr-metadata"; const CCR_IMPORT_PREFIX: &str = "tinyjuice/ccr-import-intent/"; -const CCR_TTL_CONFIGURATION_KEY: &str = "tinyjuice/ccr-config/applied-ttl"; +const CCR_STORAGE_CONFIGURATION_KEY: &str = "tinyjuice/ccr-config/applied-storage"; #[allow(dead_code)] // The reducer binary uses inventory; the hook binary shares this module. pub(crate) struct Inventory { @@ -64,7 +64,7 @@ fn configure_with_report( let _lock = acquire_process_lock(&process_lock_path(root))?; let discarded_legacy = import_legacy_files(root, &blobs, ttl)?; let store = BlobCcrStore::new(Arc::clone(&blobs), ttl).map_err(|error| error.to_string())?; - reapply_existing_blob_ttl_if_changed(&blobs, ttl)?; + reapply_existing_blob_ttl_if_changed(&blobs, ttl, max_bytes)?; let capped = CappedCcrStore { store, blobs: Arc::clone(&blobs), @@ -202,19 +202,27 @@ fn prune( fn reapply_existing_blob_ttl_if_changed( blobs: &Arc, ttl: Option, + max_bytes: Option, ) -> Result<(), String> { - let signature = ttl_signature(ttl); - let key = CCR_TTL_CONFIGURATION_KEY.to_owned(); + let ttl_signature = ttl_signature(ttl); + let signature = storage_configuration_signature(ttl, max_bytes); + let key = CCR_STORAGE_CONFIGURATION_KEY.to_owned(); let existing = run_blob({ let blobs = Arc::clone(blobs); let key = key.clone(); async move { blobs.get(&key).await } })?; - if existing.is_some_and(|blob| blob.bytes == signature.as_bytes()) { - return Ok(()); + let existing_signature = existing.map(|blob| String::from_utf8_lossy(&blob.bytes).into_owned()); + let existing_ttl_signature = existing_signature + .as_deref() + .map(|value| value.split('|').next().unwrap_or(value)); + if existing_ttl_signature != Some(ttl_signature.as_str()) { + reapply_existing_blob_ttl(blobs, ttl)?; } - reapply_existing_blob_ttl(blobs, ttl)?; + if existing_signature.as_deref() == Some(signature.as_str()) { + return Ok(()); + } run_blob({ let blobs = Arc::clone(blobs); async move { @@ -233,6 +241,25 @@ fn ttl_signature(ttl: Option) -> String { } } +fn storage_configuration_signature(ttl: Option, max_bytes: Option) -> String { + let max_bytes = max_bytes.map_or_else(|| "unlimited".to_owned(), |value| value.to_string()); + format!("{}|{max_bytes}", ttl_signature(ttl)) +} + +fn stored_configuration_matches( + blobs: &Arc, + ttl: Option, + max_bytes: Option, +) -> Result { + let key = CCR_STORAGE_CONFIGURATION_KEY.to_owned(); + let signature = storage_configuration_signature(ttl, max_bytes); + let existing = run_blob({ + let blobs = Arc::clone(blobs); + async move { blobs.get(&key).await } + })?; + Ok(existing.is_none_or(|blob| blob.bytes == signature.as_bytes())) +} + fn reapply_existing_blob_ttl( blobs: &Arc, ttl: Option, @@ -688,6 +715,19 @@ impl CcrStore for CappedCcrStore { return CcrPutResult::new(token, false); } }; + match stored_configuration_matches(&self.blobs, self.ttl, self.max_bytes) { + Ok(true) => {} + Ok(false) => { + log::debug!( + "[tinyjuice_cli] CCR write skipped because store configuration is stale" + ); + return CcrPutResult::new(token, false); + } + Err(error) => { + log::debug!("[tinyjuice_cli] CCR configuration check failed: {error}"); + return CcrPutResult::new(token, false); + } + } if let Err(error) = delete_import_intent(Arc::clone(&self.blobs), &token) { log::debug!( "[tinyjuice_cli] stale CCR import intent cleanup failed before write: {error}"