Skip to content

armgit / kwant

Public Imported from GitHub
0

Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.

Insights: cost per verified outcome counts only verified tasks that reported a cost

Lin (kwant bot)7f71df5f998b
diff --git a/docs/mission-control.md b/docs/mission-control.md
index 20ca6427..25ae28cc 100644
--- a/docs/mission-control.md
+++ b/docs/mission-control.md
@@ -246,7 +246,7 @@ changes routing, budgets or who gets work.
{"verified_weekly": [{"start": "…", "end": "…", "verified": 0, "active": false}, …], // 8, oldest first
"active_weeks": 0, "verified_per_active_week": null,
"cost_7d_usd": null, "cost_per_verified_7d_usd": null,
- "verified_observed_7d": 0, "settled_7d": 0, "unpriced_7d": 0}
+ "verified_observed_7d": 0, "verified_priced_7d": 0, "settled_7d": 0, "unpriced_7d": 0}
```
- `verified_weekly` is 8 rolling weeks ending now. A task counts once in each week it reached
@@ -255,11 +255,13 @@ changes routing, budgets or who gets work.
the active weeks, one decimal, or null with none: verified tasks per active space per week.
- Cost comes from the Performance Market observations (§17) of tasks that settled in the last 7 days:
the owner's reported model cost inside its claims. `cost_7d_usd` sums every settled task, verified,
- failed or cancelled-after-running, and `cost_per_verified_7d_usd` divides it by the verified ones
- (`verified_observed_7d`), so failures are part of what an outcome costs. Both are null when nothing
- reported a cost; `cost_per_verified_7d_usd` is also null with no verified task. `unpriced_7d` counts
- settled tasks whose engine reported no cost: when it is above 0 the cost undercounts, and the panel
- should say so. Costs are rounded to 6 decimals.
+ failed or cancelled-after-running, and `cost_per_verified_7d_usd` divides it by the verified tasks
+ that reported a cost (`verified_priced_7d`, at most `verified_observed_7d`), so failures are part of
+ what an outcome costs and a verified task with no reported cost doesn't pull the figure down.
+ `cost_7d_usd` is null when nothing reported a cost; `cost_per_verified_7d_usd` is null when no
+ verified task reported one. `unpriced_7d` counts settled tasks (any result) whose engine reported no
+ cost: when it is above 0 the figures are an estimate from the priced tasks (an unpriced failure
+ isn't in the total), and the panel should say so. Costs are rounded to 6 decimals.
## 7. Live events (SSE `/api/events`)
diff --git a/frontend/src/missions.ts b/frontend/src/missions.ts
index 157db270..bdf235a0 100644
--- a/frontend/src/missions.ts
+++ b/frontend/src/missions.ts
@@ -420,8 +420,11 @@ export interface Insights {
verified_per_active_week?: number | null;
/** Reported model cost of tasks settled in the last 7 days; null when none reported one. */
cost_7d_usd?: number | null;
+ /** `cost_7d_usd` over `verified_priced_7d`; null when no verified task reported a cost. */
cost_per_verified_7d_usd?: number | null;
verified_observed_7d?: number;
+ /** Verified tasks that reported a cost: the divisor of `cost_per_verified_7d_usd`. */
+ verified_priced_7d?: number;
settled_7d?: number;
/** Settled tasks with no reported cost: above 0, the cost undercounts. */
unpriced_7d?: number;
diff --git a/src/server/missions/routes.rs b/src/server/missions/routes.rs
index 236a80a4..3aeabeec 100644
--- a/src/server/missions/routes.rs
+++ b/src/server/missions/routes.rs
@@ -361,6 +361,7 @@ pub async fn insights(State(state): State<AppState>, Scope(space): Scope) -> Res
"cost_7d_usd": cost.total,
"cost_per_verified_7d_usd": cost.per_verified,
"verified_observed_7d": cost.verified,
+ "verified_priced_7d": cost.verified_priced,
"settled_7d": cost.settled,
"unpriced_7d": cost.unpriced,
}))
@@ -407,9 +408,13 @@ pub struct OutcomeCost {
/// Reported model cost of every task that settled in the window, verified or not; null when
/// none reported a cost.
pub total: Value,
- /// `total` over the verified ones: what one verified outcome cost, failures included.
+ /// `total` over the verified tasks that reported a cost: what one verified outcome cost,
+ /// failures included. A verified task with no reported cost is left out of the divisor, so it
+ /// can't pull the figure down.
pub per_verified: Value,
pub verified: usize,
+ /// Verified tasks that reported a cost: the divisor of `per_verified`.
+ pub verified_priced: usize,
pub settled: usize,
/// Settled tasks whose model calls reported no cost (so `total` undercounts them).
pub unpriced: usize,
@@ -419,12 +424,14 @@ pub struct OutcomeCost {
pub fn outcome_cost(observed: &[crate::db::performance::Observation]) -> OutcomeCost {
let priced: Vec<f64> = observed.iter().filter_map(|o| o.cost_usd).collect();
let verified = observed.iter().filter(|o| o.result == "verified").count();
+ let verified_priced = observed.iter().filter(|o| o.result == "verified" && o.cost_usd.is_some()).count();
let sum: f64 = priced.iter().sum();
let round = |x: f64| json!((x * 1_000_000.0).round() / 1_000_000.0);
OutcomeCost {
total: if priced.is_empty() { Value::Null } else { round(sum) },
- per_verified: if priced.is_empty() || verified == 0 { Value::Null } else { round(sum / verified as f64) },
+ per_verified: if verified_priced == 0 { Value::Null } else { round(sum / verified_priced as f64) },
verified,
+ verified_priced,
settled: observed.len(),
unpriced: observed.len() - priced.len(),
}
@@ -1016,8 +1023,12 @@ mod tests {
source: "live".into(),
created_at: Utc::now(),
};
+ // The unpriced verified task isn't in the divisor: 0.6 over the 2 priced verified, not 3
let c = outcome_cost(&[o("verified", Some(0.1)), o("verified", Some(0.2)), o("failed", Some(0.3)), o("verified", None)]);
- assert_eq!((c.total, c.per_verified, c.verified, c.settled, c.unpriced), (json!(0.6), json!(0.2), 3, 4, 1));
+ assert_eq!((c.total, c.per_verified, c.verified, c.verified_priced, c.settled, c.unpriced), (json!(0.6), json!(0.3), 3, 2, 4, 1));
+ // Priced failures but no priced verified task: no per-outcome figure, never a made-up one
+ let c = outcome_cost(&[o("failed", Some(0.3)), o("verified", None)]);
+ assert_eq!((c.total, c.per_verified, c.verified, c.verified_priced), (json!(0.3), Value::Null, 1, 0));
let c = outcome_cost(&[o("failed", Some(0.3))]);
assert_eq!((c.total, c.per_verified), (json!(0.3), Value::Null), "no verified outcome: no per-outcome cost");
let c = outcome_cost(&[o("verified", None)]);
diff --git a/tests/performance_test.rs b/tests/performance_test.rs
index 3f3ac049..80961b95 100644
--- a/tests/performance_test.rs
+++ b/tests/performance_test.rs
@@ -334,6 +334,8 @@ async fn insights_counts_verified_tasks_per_week_and_cost_per_verified_outcome()
// an observation from 10 days ago is outside the window
db.store_observation(&NewObservation { cost_usd: Some(0.15), ..obs(1, "general", &e.bot.id, "m1", "failed", 1) }, "live").await.unwrap();
db.store_observation(&obs(2, "general", &e.bot.id, "m1", "unverified", 2), "live").await.unwrap();
+ // A verified task whose engine reported no cost: counted, but not in the per-outcome divisor
+ db.store_observation(&obs(4, "general", &e.bot.id, "m1", "verified", 3), "live").await.unwrap();
db.store_observation(&NewObservation { cost_usd: Some(9.0), ..obs(3, "general", &e.bot.id, "m1", "verified", 10) }, "live").await.unwrap();
let v = person(&e, "GET", "/api/missions/insights", None).await;
@@ -342,9 +344,14 @@ async fn insights_counts_verified_tasks_per_week_and_cost_per_verified_outcome()
assert_eq!(weeks[7], (2, true), "{v}");
assert_eq!(v["verified_weekly"][7]["verified"], v["verified_7d"], "the last week is the verified_7d window");
assert_eq!((v["active_weeks"].as_u64(), v["verified_per_active_week"].as_f64()), (Some(1), Some(2.0)), "{v}");
- // $0.25 + $0.25 verified + $0.15 failed, over the two verified outcomes
+ // $0.25 + $0.25 verified + $0.15 failed, over the two verified outcomes that reported a cost
+ // (over all three it would read $0.216667)
assert_eq!((v["cost_7d_usd"].as_f64(), v["cost_per_verified_7d_usd"].as_f64()), (Some(0.65), Some(0.325)), "{v}");
- assert_eq!((v["verified_observed_7d"].as_u64(), v["settled_7d"].as_u64(), v["unpriced_7d"].as_u64()), (Some(2), Some(4), Some(1)), "{v}");
+ assert_eq!(
+ (v["verified_observed_7d"].as_u64(), v["verified_priced_7d"].as_u64(), v["settled_7d"].as_u64(), v["unpriced_7d"].as_u64()),
+ (Some(3), Some(2), Some(5), Some(2)),
+ "{v}"
+ );
// The old fields are unchanged
assert_eq!(v["verified_7d"], 2);
}