Lightweight coding agent that runs in your terminal
Rust
Add timestamped SQLite /feedback logs without schema changes (#13645)
Charley Cunningham9f91c7f90f27
diff --git a/codex-rs/state/src/log_db.rs b/codex-rs/state/src/log_db.rsindex e646828bda..387dc9f4b5 100644--- a/codex-rs/state/src/log_db.rs+++ b/codex-rs/state/src/log_db.rs@@ -420,11 +420,23 @@ mod tests {drop(guard);- // TODO(ccunningham): Store enough span metadata in SQLite to reproduce span- // prefixes like `feedback-thread{thread_id="thread-1"}:` in feedback exports.+ // SQLite exports now include timestamps, while this test writer has+ // `.without_time()`. Compare bodies after stripping the SQLite prefix.let feedback_logs = writer.snapshot().replace("feedback-thread{thread_id=\"thread-1\"}: ", "");+ let strip_sqlite_timestamp = |logs: &str| {+ logs.lines()+ .map(|line| {+ line.split_once(' ')+ .map_or_else(|| line.to_string(), |(_, rest)| rest.to_string())+ })+ .collect::<Vec<_>>()+ };+ let feedback_lines = feedback_logs+ .lines()+ .map(ToString::to_string)+ .collect::<Vec<_>>();let deadline = Instant::now() + Duration::from_secs(2);loop {let sqlite_logs = String::from_utf8(@@ -434,7 +446,7 @@ mod tests {.expect("query feedback logs"),).expect("valid utf-8");- if sqlite_logs == feedback_logs {+ if strip_sqlite_timestamp(&sqlite_logs) == feedback_lines {break;}assert!(diff --git a/codex-rs/state/src/runtime/logs.rs b/codex-rs/state/src/runtime/logs.rsindex 2ee8940afd..0a6798f11f 100644--- a/codex-rs/state/src/runtime/logs.rs+++ b/codex-rs/state/src/runtime/logs.rs@@ -288,6 +288,8 @@ WHERE id IN (/// Query per-thread feedback logs, capped to the per-thread SQLite retention budget.pub async fn query_feedback_logs(&self, thread_id: &str) -> anyhow::Result<Vec<u8>> {let max_bytes = LOG_PARTITION_SIZE_LIMIT_BYTES;+ // TODO(ccunningham): Store rendered span/event fields in SQLite so this+ // export can match feedback formatting beyond timestamp + level + message.let lines = sqlx::query_scalar::<_, String>(r#"WITH latest_process AS (@@ -299,12 +301,24 @@ WITH latest_process AS (),feedback_logs AS (SELECT- printf('%5s %s', level, message) || CASE+ printf(+ '%s.%06dZ %5s %s',+ strftime('%Y-%m-%dT%H:%M:%S', ts, 'unixepoch'),+ ts_nanos / 1000,+ level,+ message+ ) || CASEWHEN substr(message, -1, 1) = char(10) THEN ''ELSE char(10)END AS line,length(CAST(- printf('%5s %s', level, message) || CASE+ printf(+ '%s.%06dZ %5s %s',+ strftime('%Y-%m-%dT%H:%M:%S', ts, 'unixepoch'),+ ts_nanos / 1000,+ level,+ message+ ) || CASEWHEN substr(message, -1, 1) = char(10) THEN ''ELSE char(10)END AS BLOB@@ -830,7 +844,7 @@ mod tests {assert_eq!(String::from_utf8(bytes).expect("valid utf-8"),- " INFO alpha\n INFO bravo\n INFO charlie\n"+ "1970-01-01T00:00:01.000000Z INFO alpha\n1970-01-01T00:00:02.000000Z INFO bravo\n1970-01-01T00:00:03.000000Z INFO charlie\n");let _ = tokio::fs::remove_dir_all(codex_home).await;@@ -952,7 +966,7 @@ mod tests {assert_eq!(String::from_utf8(bytes).expect("valid utf-8"),- " INFO threadless-before\n INFO thread-scoped\n INFO threadless-after\n"+ "1970-01-01T00:00:01.000000Z INFO threadless-before\n1970-01-01T00:00:02.000000Z INFO thread-scoped\n1970-01-01T00:00:03.000000Z INFO threadless-after\n");let _ = tokio::fs::remove_dir_all(codex_home).await;@@ -1026,7 +1040,7 @@ mod tests {assert_eq!(String::from_utf8(bytes).expect("valid utf-8"),- " INFO old-process-thread\n INFO new-process-thread\n INFO new-process-threadless\n"+ "1970-01-01T00:00:02.000000Z INFO old-process-thread\n1970-01-01T00:00:03.000000Z INFO new-process-thread\n1970-01-01T00:00:04.000000Z INFO new-process-threadless\n");let _ = tokio::fs::remove_dir_all(codex_home).await;