enrich: set created_at from event timestamp, not mining time

Experience-mined journal entries were all getting created_at = now(),
causing them to sort by mining time instead of when the event actually
happened. Parse the conversation timestamp and set created_at to the
event time so journal-tail shows correct chronological order.
This commit is contained in:
ProofOfConcept 2026-03-06 22:09:44 -05:00
parent 80bdaab8ee
commit 36cb3b641f

View file

@ -19,6 +19,21 @@ use std::hash::{Hash, Hasher};
use crate::store::StoreView; use crate::store::StoreView;
/// Parse a timestamp string like "2026-03-05T19:56" to unix epoch seconds.
fn parse_timestamp_to_epoch(ts: &str) -> Option<i64> {
use chrono::{Local, NaiveDateTime, TimeZone};
// Try common formats
let formats = ["%Y-%m-%dT%H:%M:%S", "%Y-%m-%dT%H:%M", "%Y-%m-%d %H:%M:%S", "%Y-%m-%d %H:%M"];
for fmt in &formats {
if let Ok(ndt) = NaiveDateTime::parse_from_str(ts, fmt) {
if let Some(dt) = Local.from_local_datetime(&ndt).earliest() {
return Some(dt.timestamp());
}
}
}
None
}
/// Compute the store dedup key for a transcript file. /// Compute the store dedup key for a transcript file.
/// This is the same key experience_mine uses to mark a transcript as mined. /// This is the same key experience_mine uses to mark a transcript as mined.
pub fn transcript_dedup_key(path: &str) -> Result<String, String> { pub fn transcript_dedup_key(path: &str) -> Result<String, String> {
@ -353,11 +368,16 @@ pub fn experience_mine(
continue; continue;
} }
// Write to store // Write to store — use event timestamp, not mining time
let mut node = new_node(&key, &full_content); let mut node = new_node(&key, &full_content);
node.node_type = store::NodeType::EpisodicSession; node.node_type = store::NodeType::EpisodicSession;
node.category = store::Category::Observation; node.category = store::Category::Observation;
node.provenance = store::Provenance::AgentExperienceMine; node.provenance = store::Provenance::AgentExperienceMine;
if !ts.is_empty() {
if let Some(epoch) = parse_timestamp_to_epoch(ts) {
node.created_at = epoch;
}
}
let _ = store.upsert_node(node); let _ = store.upsert_node(node);
count += 1; count += 1;