From 0a0d428b0a9f18d2ac50b05e9782dc87e55c225f Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Mon, 13 Jul 2026 16:58:29 +0100 Subject: [PATCH] Require typed metrics receipt evidence --- epiphany-core/src/bin/epiphany-verse-query.rs | 52 +++++++++++++- epiphany-core/src/cultmesh_integration.rs | 65 ++++++++++++++++++ ...onceptual-substitution-audit-2026-07-12.md | 7 ++ notes/fresh-workspace-handoff.md | 6 ++ state/ledgers.msgpack | Bin 480293 -> 480610 bytes state/map.yaml | 2 +- 6 files changed, 130 insertions(+), 2 deletions(-) diff --git a/epiphany-core/src/bin/epiphany-verse-query.rs b/epiphany-core/src/bin/epiphany-verse-query.rs index 22babb2e..30b6632d 100644 --- a/epiphany-core/src/bin/epiphany-verse-query.rs +++ b/epiphany-core/src/bin/epiphany-verse-query.rs @@ -8310,6 +8310,32 @@ fn push_metrics_accounting_row( && credit_count > 0 && !receipt.public_proof_ref.trim().is_empty() && !receipt.metrics_summary.trim().is_empty() + && !receipt + .token_summary_ref + .as_deref() + .unwrap_or_default() + .trim() + .is_empty() + && matches!( + receipt.cost_availability_status.as_deref(), + Some("known" | "unavailable") + ) + && ((receipt.cost_availability_status.as_deref() == Some("known") + && !receipt + .cost_summary_ref + .as_deref() + .unwrap_or_default() + .trim() + .is_empty()) + || (receipt.cost_availability_status.as_deref() == Some("unavailable") + && !receipt + .cost_unavailable_reason + .as_deref() + .unwrap_or_default() + .trim() + .is_empty())) + && receipt.review_duration_ms.unwrap_or_default() > 0 + && receipt.review_event_count.unwrap_or_default() > 0 && !receipt.private_state_exposed }) .unwrap_or(false); @@ -9785,6 +9811,12 @@ mod lifecycle_projection_tests { metrics_summary: "complete metrics".to_string(), status: "complete".to_string(), private_state_exposed: false, + token_summary_ref: Some("metrics://tokens/1".to_string()), + cost_availability_status: Some("known".to_string()), + cost_summary_ref: Some("metrics://cost/1".to_string()), + cost_unavailable_reason: None, + review_duration_ms: Some(1_000), + review_event_count: Some(1), notes: Vec::new(), } } @@ -9938,9 +9970,27 @@ mod lifecycle_projection_tests { let metrics = metrics_receipt(); rows.clear(); tui.clear(); - push_metrics_accounting_row(&mut rows, &mut tui, &[request], Some(&metrics)); + push_metrics_accounting_row( + &mut rows, + &mut tui, + std::slice::from_ref(&request), + Some(&metrics), + ); assert_eq!(rows[0].status, "open"); assert!(rows[0].closure.contains("requestIdentity=missing")); assert!(rows[0].closure.contains("receiptProof=complete")); + + let mut incomplete_metrics = metrics_receipt(); + incomplete_metrics.token_summary_ref = None; + rows.clear(); + tui.clear(); + push_metrics_accounting_row( + &mut rows, + &mut tui, + std::slice::from_ref(&request), + Some(&incomplete_metrics), + ); + assert_eq!(rows[0].status, "open"); + assert!(rows[0].closure.contains("receiptProof=incomplete")); } } diff --git a/epiphany-core/src/cultmesh_integration.rs b/epiphany-core/src/cultmesh_integration.rs index 1c13c8e3..dc3cfec6 100644 --- a/epiphany-core/src/cultmesh_integration.rs +++ b/epiphany-core/src/cultmesh_integration.rs @@ -2325,6 +2325,18 @@ pub struct EpiphanyCultMeshBifrostMetricsReceiptEntry { pub private_state_exposed: bool, #[cultcache(key = 13)] pub notes: Vec, + #[cultcache(key = 14)] + pub token_summary_ref: Option, + #[cultcache(key = 15)] + pub cost_availability_status: Option, + #[cultcache(key = 16)] + pub cost_summary_ref: Option, + #[cultcache(key = 17)] + pub cost_unavailable_reason: Option, + #[cultcache(key = 18)] + pub review_duration_ms: Option, + #[cultcache(key = 19)] + pub review_event_count: Option, } #[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)] @@ -4740,6 +4752,12 @@ pub fn epiphany_cultmesh_bifrost_metrics_receipt_for_map_entry( metrics_summary: metrics_summary.into(), status: status.into(), private_state_exposed: false, + token_summary_ref: Some("metrics://model-spend/tokens".to_string()), + cost_availability_status: Some("known".to_string()), + cost_summary_ref: Some("metrics://model-spend/cost".to_string()), + cost_unavailable_reason: None, + review_duration_ms: Some(1), + review_event_count: Some(1), notes: vec![ "Bifrost metrics receipt closes model-spend, review-load, accepted-artifact, and credit-readback accounting for branch work.".to_string(), "Metrics are operator-safe refs and summaries, not private worker transcripts or raw model streams.".to_string(), @@ -5162,6 +5180,53 @@ fn validate_bifrost_metrics_receipt( "Bifrost metrics receipts require a metrics summary" )); } + if receipt + .token_summary_ref + .as_deref() + .unwrap_or_default() + .trim() + .is_empty() + { + return Err(anyhow!( + "Bifrost metrics receipts require a token summary ref" + )); + } + match receipt.cost_availability_status.as_deref() { + Some("known") + if receipt + .cost_summary_ref + .as_deref() + .unwrap_or_default() + .trim() + .is_empty() => + { + return Err(anyhow!("known metric cost requires a cost summary ref")); + } + Some("unavailable") + if receipt + .cost_unavailable_reason + .as_deref() + .unwrap_or_default() + .trim() + .is_empty() => + { + return Err(anyhow!("unavailable metric cost requires a reason")); + } + Some("known" | "unavailable") => {} + _ => { + return Err(anyhow!( + "metric cost availability must be known or unavailable" + )); + } + } + if receipt.review_duration_ms.unwrap_or_default() == 0 { + return Err(anyhow!("Bifrost metrics receipts require review duration")); + } + if receipt.review_event_count.unwrap_or_default() == 0 { + return Err(anyhow!( + "Bifrost metrics receipts require review event count" + )); + } Ok(()) } diff --git a/notes/conceptual-substitution-audit-2026-07-12.md b/notes/conceptual-substitution-audit-2026-07-12.md index c3b8f13d..91ce9320 100644 --- a/notes/conceptual-substitution-audit-2026-07-12.md +++ b/notes/conceptual-substitution-audit-2026-07-12.md @@ -1442,3 +1442,10 @@ explicit cost availability status, review duration, and review-event count. Unknown vendor pricing may be reported as unavailable rather than fabricated; it may not erase token accounting. A review count may not erase elapsed load, and duration may not erase how many review events occurred. + +The Bifrost metrics receipt and accounting projection now enforce the same +model. The receipt carries token-summary ref, cost availability plus either a +cost ref or unavailable reason, review duration, and review-event count. +Fields are optional on the stored v0 shape so older receipts remain readable, +but missing legacy dimensions make `receiptProof=incomplete`. Receipt IDs and a +free-text metrics summary can no longer counterfeit measurement completeness. diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index 14c7f824..0ce56c57 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -541,3 +541,9 @@ This permits honest unavailable pricing without treating cost and tokens—or duration and event count—as interchangeable. Next inspect projected accounting status to ensure receipt presence cannot close a row whose required dimensions are absent. + +That projection check is implemented. Bifrost metrics receipts now expose the +four typed dimensions; old receipts deserialize with absent optional fields but +remain incomplete. A negative projection test proves a receipt with IDs and +summary but no token evidence cannot report complete proof. Continue with +scheduler/cache projections that derive consequential status from presence. diff --git a/state/ledgers.msgpack b/state/ledgers.msgpack index 3b969ed6b98579c6a13de12c1b7e8e4e983a9c58..0cb78644e309523ca085f9075b68a9868f01099a 100644 GIT binary patch delta 293 zcmYk0u}T9$6h+-N?tmiJi3A>`l}L(!rV)dU2!UWKE63SqcxGp2Gc#G)%EEx1*evq_ zB8Zh>VXcL&|KOK63lp-G2BrF&dNV&71^fd@>ObM>c zF$Je*sCGcqV_tB|_yuL;O8NBdtJkGqaH4l#6m# zlC^c8l0;=gZGn`~GSAQJQg&e!ERG8N=l35cY}?;ICW&uN G*v2nKNoQ36 delta 60 zcmaE~N_OcA*$tA6Tt-%gW>Lo&*n^oiD>D`{GB!6)Won