-
Notifications
You must be signed in to change notification settings - Fork 0
feat(sessionledger): project graph-native metadata #549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
19e08b1
3cedeec
4e0276d
d314baf
dff0187
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,8 @@ use std::sync::RwLock; | |
| use serde::{Deserialize, Serialize}; | ||
| use tracing::info; | ||
|
|
||
| use crate::export::BundleMeta; | ||
|
|
||
| /// Prometheus histogram bucket upper bounds in seconds. | ||
| pub const HTTP_DURATION_BUCKETS: &[f64] = | ||
| &[0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1.0, 2.5, 5.0, 10.0]; | ||
|
|
@@ -240,6 +242,8 @@ fn linux_open_fds() -> Option<u64> { | |
| pub struct MetricsSummary { | ||
| pub total_bundles: u64, | ||
| pub total_tokens: u64, | ||
| #[serde(default)] | ||
| pub total_user_turns: u64, | ||
|
KooshaPari marked this conversation as resolved.
|
||
| pub avg_tokens: u64, | ||
| pub model_counts: HashMap<String, u64>, | ||
| pub daily_counts: HashMap<String, u64>, | ||
|
|
@@ -257,6 +261,7 @@ pub fn compute_metrics(out_dir: &Path) -> MetricsSummary { | |
| let Ok(content) = std::fs::read_to_string(&path) else { continue }; | ||
| let Ok(val) = serde_json::from_str::<serde_json::Value>(&content) else { continue }; | ||
| s.total_bundles += 1; | ||
| s.total_user_turns = s.total_user_turns.saturating_add(BundleMeta::from_value(&val).user_turn_count); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SUGGESTION: Reply with |
||
| if let Some(t) = val.get("total_tokens").and_then(|v| v.as_u64()) { | ||
| s.total_tokens += t; | ||
| } | ||
|
|
@@ -358,6 +363,29 @@ mod tests { | |
| assert_eq!(m.total_tokens, 0); | ||
| } | ||
|
|
||
| #[test] | ||
| fn graph_okf_contributes_user_turns_without_fabricating_tokens() { | ||
| let d = tempfile::TempDir::new().unwrap(); | ||
| std::fs::write( | ||
| d.path().join("graph.okf.json"), | ||
| r#"{"okf":"1.0","source_id":"graph-1","entities":[{"id":"intent-0","type":"intent","label":"ship it","properties":{"user_turn_count":4}}],"relations":[],"provenance":{"corpus":"codex","source_id":"graph-1"}}"#, | ||
| ) | ||
| .unwrap(); | ||
|
|
||
| let m = compute_metrics(d.path()); | ||
| assert_eq!(m.total_bundles, 1); | ||
| assert_eq!(m.total_user_turns, 4); | ||
| assert_eq!(m.total_tokens, 0); | ||
| } | ||
|
|
||
| #[test] | ||
| fn metrics_deserializes_legacy_payload_without_user_turns() { | ||
| let legacy = r#"{"total_bundles":1,"total_tokens":42,"avg_tokens":42,"model_counts":{},"daily_counts":{}}"#; | ||
|
|
||
| let metrics: MetricsSummary = serde_json::from_str(legacy).expect("legacy metrics payload"); | ||
| assert_eq!(metrics.total_user_turns, 0); | ||
| } | ||
|
|
||
| #[test] | ||
| fn normalize_http_route_collapses_replay_paths() { | ||
| assert_eq!(normalize_http_route("/healthz"), "healthz"); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,8 @@ pub struct SearchResult { | |
| #[serde(default)] | ||
| pub message_count: u64, | ||
| #[serde(default)] | ||
| pub user_turn_count: u64, | ||
| #[serde(default)] | ||
| pub duration_ms: u64, | ||
| #[serde(default)] | ||
| pub tags: Vec<String>, | ||
|
|
@@ -86,6 +88,14 @@ fn urlencoding(s: &str) -> String { | |
| .collect() | ||
| } | ||
|
|
||
| fn user_turn_label(user_turn_count: u64) -> &'static str { | ||
| if user_turn_count == 1 { | ||
| "user turn" | ||
| } else { | ||
| "user turns" | ||
| } | ||
| } | ||
|
|
||
| /// Stable id for search fetch errors — paired with `aria-errormessage` on fields. | ||
| const SEARCH_ERROR_ID: &str = "search-error-message"; | ||
|
|
||
|
|
@@ -459,6 +469,7 @@ pub fn SearchView() -> Element { | |
| let cls = if is_selected { "session-item selected" } else { "session-item" }; | ||
| let r = result.clone(); | ||
| let tags_display = r.tags.join(", "); | ||
| let user_turn_label = user_turn_label(r.user_turn_count); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SUGGESTION: The local Reply with |
||
| rsx! { | ||
| div { | ||
| key: "{r.session_id}-{idx}", | ||
|
|
@@ -468,6 +479,9 @@ pub fn SearchView() -> Element { | |
| div { class: "session-goal", "model: {r.model}" } | ||
| div { class: "session-meta", | ||
| span { class: "meta-bundles", "{r.token_count} tokens" } | ||
| if r.user_turn_count > 0 { | ||
| span { class: "session-meta-muted", "{r.user_turn_count} {user_turn_label}" } | ||
| } | ||
| span { class: "session-meta-muted", "{r.created_at}" } | ||
| if !tags_display.is_empty() { | ||
| span { class: "badge badge-ok", "{tags_display}" } | ||
|
|
@@ -609,4 +623,10 @@ mod tests { | |
| assert_eq!(advanced_filter_active_count("", "rust", "50"), 1); | ||
| assert_eq!(advanced_filter_active_count(" ", " ", "50"), 0); | ||
| } | ||
|
|
||
| #[test] | ||
| fn user_turn_label_handles_singular_and_plural() { | ||
| assert_eq!(user_turn_label(1), "user turn"); | ||
| assert_eq!(user_turn_label(2), "user turns"); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.