Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix: ui_events timestamp format — write RFC 3339, read both formats

Louis Beaumont8446dff1467d
diff --git a/Cargo.lock b/Cargo.lock
index 0a7d42221..5cb4633d0 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -6692,7 +6692,7 @@ dependencies = [
[[package]]
name = "screenpipe-audio"
-version = "0.3.235"
+version = "0.3.236"
dependencies = [
"anyhow",
"audiopipe",
@@ -6752,7 +6752,7 @@ dependencies = [
[[package]]
name = "screenpipe-config"
-version = "0.3.235"
+version = "0.3.236"
dependencies = [
"dirs 6.0.0",
"serde",
@@ -6765,7 +6765,7 @@ dependencies = [
[[package]]
name = "screenpipe-connect"
-version = "0.3.235"
+version = "0.3.236"
dependencies = [
"anyhow",
"async-trait",
@@ -6791,7 +6791,7 @@ dependencies = [
[[package]]
name = "screenpipe-core"
-version = "0.3.235"
+version = "0.3.236"
dependencies = [
"accessibility",
"accessibility-sys",
@@ -6836,7 +6836,7 @@ dependencies = [
[[package]]
name = "screenpipe-db"
-version = "0.3.235"
+version = "0.3.236"
dependencies = [
"anyhow",
"chrono",
@@ -6862,7 +6862,7 @@ dependencies = [
[[package]]
name = "screenpipe-engine"
-version = "0.3.235"
+version = "0.3.236"
dependencies = [
"anyhow",
"async-trait",
@@ -6932,7 +6932,7 @@ dependencies = [
[[package]]
name = "screenpipe-events"
-version = "0.3.235"
+version = "0.3.236"
dependencies = [
"anyhow",
"chrono",
@@ -6950,7 +6950,7 @@ dependencies = [
[[package]]
name = "screenpipe-screen"
-version = "0.3.235"
+version = "0.3.236"
dependencies = [
"accessibility-sys",
"anyhow",
@@ -6990,7 +6990,7 @@ dependencies = [
[[package]]
name = "screenpipe-vault"
-version = "0.3.235"
+version = "0.3.236"
dependencies = [
"argon2",
"chacha20poly1305",
diff --git a/crates/screenpipe-db/src/db.rs b/crates/screenpipe-db/src/db.rs
index a4bbeb050..22c8aef09 100644
--- a/crates/screenpipe-db/src/db.rs
+++ b/crates/screenpipe-db/src/db.rs
@@ -6334,7 +6334,7 @@ LIMIT ? OFFSET ?
let result = self
.write_queue
.submit(WriteOp::InsertUiEvent {
- timestamp: event.timestamp.to_string(),
+ timestamp: event.timestamp.to_rfc3339(),
session_id: event.session_id.clone(),
relative_ms: event.relative_ms,
event_type: event.event_type.to_string(),
diff --git a/crates/screenpipe-db/src/types.rs b/crates/screenpipe-db/src/types.rs
index 04bfddc62..187a58702 100644
--- a/crates/screenpipe-db/src/types.rs
+++ b/crates/screenpipe-db/src/types.rs
@@ -1,10 +1,35 @@
-use chrono::{DateTime, Utc};
+use chrono::{DateTime, NaiveDateTime, Utc};
use oasgen::OaSchema;
use serde::{Deserialize, Serialize};
use sqlx::FromRow;
use std::error::Error as StdError;
use std::fmt::{self, Display};
+/// Parse a timestamp string that may be in RFC 3339 ("2026-03-26T21:07:37+00:00"),
+/// chrono Display ("2026-03-26 21:07:37.993675 UTC"), or naive ("2026-03-26 21:07:37")
+/// format. Returns epoch (1970-01-01) if all parsing fails rather than panicking.
+fn parse_flexible_timestamp(s: &str) -> DateTime<Utc> {
+ // RFC 3339 / ISO 8601 (correct format from to_rfc3339())
+ if let Ok(dt) = DateTime::parse_from_rfc3339(s) {
+ return dt.with_timezone(&Utc);
+ }
+ // chrono Display format: "2026-03-26 21:07:37.993675 UTC"
+ if let Some(trimmed) = s.strip_suffix(" UTC") {
+ if let Ok(naive) = NaiveDateTime::parse_from_str(trimmed, "%Y-%m-%d %H:%M:%S%.f") {
+ return naive.and_utc();
+ }
+ }
+ // Naive without timezone: "2026-03-26 21:07:37" or with fractional
+ if let Ok(naive) = NaiveDateTime::parse_from_str(s, "%Y-%m-%d %H:%M:%S%.f") {
+ return naive.and_utc();
+ }
+ if let Ok(naive) = NaiveDateTime::parse_from_str(s, "%Y-%m-%d %H:%M:%S") {
+ return naive.and_utc();
+ }
+ // Last resort: epoch
+ DateTime::UNIX_EPOCH
+}
+
/// Audio chunk that has no corresponding transcription row.
/// Used by the reconciliation sweep to detect and retry orphaned chunks.
#[derive(Debug, Clone, FromRow)]
@@ -537,11 +562,13 @@ pub struct UiEventRecord {
pub frame_id: Option<i64>,
}
-/// Raw row from ui_events table
+/// Raw row from ui_events table.
+/// `timestamp` is read as String to handle both legacy format ("2026-03-26 21:07:37 UTC")
+/// and RFC 3339 format ("2026-03-26T21:07:37+00:00") from existing databases.
#[derive(Debug, FromRow)]
pub struct UiEventRow {
pub id: i64,
- pub timestamp: DateTime<Utc>,
+ pub timestamp: String,
pub session_id: Option<String>,
pub relative_ms: i64,
pub event_type: String,
@@ -588,7 +615,7 @@ impl From<UiEventRow> for UiEventRecord {
UiEventRecord {
id: row.id,
- timestamp: row.timestamp,
+ timestamp: parse_flexible_timestamp(&row.timestamp),
session_id: row.session_id,
relative_ms: row.relative_ms,
event_type: row.event_type.parse().unwrap_or(UiEventType::Click),
@@ -784,4 +811,24 @@ mod tests {
serde_json::from_str(r#""memory""#).unwrap()
);
}
+
+ #[test]
+ fn parse_flexible_timestamp_all_formats_agree() {
+ let rfc = super::parse_flexible_timestamp("2026-03-26T21:07:37.993675+00:00");
+ let display = super::parse_flexible_timestamp("2026-03-26 21:07:37.993675 UTC");
+ let naive = super::parse_flexible_timestamp("2026-03-26 21:07:37");
+ // All three should parse to the same date (naive loses sub-second)
+ assert_eq!(rfc.date_naive(), display.date_naive());
+ assert_eq!(rfc.date_naive(), naive.date_naive());
+ assert_eq!(rfc, display);
+ assert_eq!(naive.format("%Y-%m-%d %H:%M:%S").to_string(), "2026-03-26 21:07:37");
+ // None should be epoch
+ assert_ne!(rfc, chrono::DateTime::UNIX_EPOCH);
+ }
+
+ #[test]
+ fn parse_flexible_timestamp_garbage_returns_epoch() {
+ let ts = super::parse_flexible_timestamp("not-a-date");
+ assert_eq!(ts, chrono::DateTime::UNIX_EPOCH);
+ }
}