The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
refactor(tokenjuice): remove dead turn model scope
Steven Enamakelf95dd18fb597
diff --git a/crates/openhuman-core/src/inference/tokenjuice/savings.rs b/crates/openhuman-core/src/inference/tokenjuice/savings.rsindex b8858e46b9..fcc1451633 100644--- a/crates/openhuman-core/src/inference/tokenjuice/savings.rs+++ b/crates/openhuman-core/src/inference/tokenjuice/savings.rs@@ -8,8 +8,8 @@//!//! Aggregates are kept process-global and snapshotted to//! `workspace_dir/state/tokenjuice_savings.json` so the dashboard survives-//! restarts. Attribution model + snapshot path are installed once at startup-//! via [`configure`].+//! restarts. The configured default model and snapshot path are installed via+//! [`configure`].use std::collections::HashMap;use std::path::PathBuf;@@ -93,41 +93,8 @@ fn state() -> &'static Mutex<State> {STATE.get_or_init(|| Mutex::new(State::default()))}-tokio::task_local! {- /// The model actually running the current turn/sub-agent, scoped around- /// the tinyagents turn (`run_turn_via_tinyagents_shared`) — the same- /// task-local pattern as- /// [`crate::agent::harness::turn_attachments_context`]. When set,- /// compaction savings are priced against *this* model instead of the- /// process-global configured default (issue #4122). Unset ⇒ fall back to- /// the configured default, so non-harness callers and tests are unaffected- /// — strictly additive.- pub static TURN_MODEL: String;-}--/// Run `future` with `model` installed as the per-turn attribution model used-/// to price compaction savings. Intended call site is around each turn's-/// `run_turn_via_tinyagents_shared` invocation, alongside the other per-turn-/// `*_context` scopes (issue #4122).-pub async fn with_turn_model<F, R>(model: String, future: F) -> R-where- F: std::future::Future<Output = R>,-{- TURN_MODEL.scope(model, future).await-}--/// The model to attribute savings to: the per-turn [`TURN_MODEL`] when scoped-/// and non-empty, otherwise the process-global configured `default`.-fn resolve_attribution_model(default: &str) -> String {- TURN_MODEL- .try_with(|m| m.clone())- .ok()- .filter(|m| !m.trim().is_empty())- .unwrap_or_else(|| default.to_string())-}--/// Install the attribution model and snapshot location, loading a prior-/// snapshot once per workspace.+/// Install the configured-default attribution model and snapshot location,+/// loading a prior snapshot once per workspace.pub fn configure(attribution_model: String, workspace_dir: &std::path::Path) {let path = workspace_dir.join("state").join("tokenjuice_savings.json");let mut st = state().lock().unwrap_or_else(|p| p.into_inner());@@ -163,12 +130,8 @@ pub fn record(return;}let mut st = state().lock().unwrap_or_else(|p| p.into_inner());- // Attribute the saving to the per-turn model the agent loop scoped via- // `with_turn_model` (issue #4122); fall back to the configured default when- // unscoped (non-harness callers, tests).- let model = resolve_attribution_model(&st.attribution_model);st.aggregate.record_saving(- &model,+ &st.attribution_model,compressor.as_str(),original_tokens,compacted_tokens,diff --git a/crates/openhuman-core/src/inference/tokenjuice/savings_tests.rs b/crates/openhuman-core/src/inference/tokenjuice/savings_tests.rsindex 83525c7ab3..3220879d7b 100644--- a/crates/openhuman-core/src/inference/tokenjuice/savings_tests.rs+++ b/crates/openhuman-core/src/inference/tokenjuice/savings_tests.rs@@ -43,29 +43,3 @@ fn record_saving_attributes_to_given_model() {);assert!(agg.by_model["turn-model-x"].cost_saved_usd > 0.0);}--#[tokio::test]-async fn attribution_model_falls_back_to_default_when_unscoped() {- assert_eq!(resolve_attribution_model("default-model"), "default-model");-}--#[tokio::test]-async fn attribution_model_prefers_scoped_turn_model() {- let got = with_turn_model("turn-model".to_string(), async {- resolve_attribution_model("default-model")- })- .await;- assert_eq!(- got, "turn-model",- "scoped per-turn model wins (issue #4122)"- );-}--#[tokio::test]-async fn blank_turn_model_falls_back_to_default() {- let got = with_turn_model(" ".to_string(), async {- resolve_attribution_model("default-model")- })- .await;- assert_eq!(got, "default-model", "blank scoped model is ignored");-}diff --git a/gitbooks/features/token-compression.md b/gitbooks/features/token-compression.mdindex d7a05d23bf..27b88046db 100644--- a/gitbooks/features/token-compression.md+++ b/gitbooks/features/token-compression.md@@ -103,7 +103,7 @@ So the agent gets the cheap compacted view by default, and can transparently "zo## Savings tracking-Every compression is metered by an OpenHuman savings callback (`crates/openhuman-core/src/inference/tokenjuice/savings.rs`). TokenJuice reports events and token deltas; OpenHuman applies per-model input pricing, aggregates `total`, `by_model`, and `by_compressor`, and persists stats to `<workspace>/state/tokenjuice_savings.json`.+Every compression is metered by an OpenHuman savings callback (`crates/openhuman-core/src/inference/tokenjuice/savings.rs`). TokenJuice reports events and token deltas; OpenHuman applies the configured default model's input pricing, aggregates `total`, `by_model`, and `by_compressor`, and persists stats to `<workspace>/state/tokenjuice_savings.json`.Read them over RPC with `openhuman.tokenjuice_savings_stats`; clear them with `openhuman.tokenjuice_savings_reset`.