diff --git a/poc-memory/src/transcript.rs b/poc-memory/src/transcript.rs index 3fe3679..3855768 100644 --- a/poc-memory/src/transcript.rs +++ b/poc-memory/src/transcript.rs @@ -158,20 +158,11 @@ pub fn tail_messages(path: &str, max_tokens: usize) -> Vec<(String, String, Stri for obj_bytes in JsonlBackwardIter::new(&mmap) { if token_count >= max_tokens { break; } - // Stop at compaction boundary - if contains_bytes(obj_bytes, compaction_marker) { - let obj: Value = match serde_json::from_slice(obj_bytes) { - Ok(v) => v, - Err(_) => continue, - }; - if obj.get("type").and_then(|v| v.as_str()) == Some("user") { - if let Some(c) = obj.get("message") - .and_then(|m| m.get("content")) - .and_then(|c| c.as_str()) - && c.starts_with("This session is being continued") { - break; - } - } + // Quick byte check: skip objects that aren't user/assistant + // (avoids parsing large tool_result / system objects) + if !contains_bytes(obj_bytes, b"\"user\"") + && !contains_bytes(obj_bytes, b"\"assistant\"") { + continue; } let obj: Value = match serde_json::from_slice(obj_bytes) { @@ -196,6 +187,11 @@ pub fn tail_messages(path: &str, max_tokens: usize) -> Vec<(String, String, Stri }; if text.is_empty() { continue; } + // Stop at compaction boundary + if msg_type == "user" && text.starts_with("This session is being continued") { + break; + } + let timestamp = obj.get("timestamp") .and_then(|v| v.as_str()) .unwrap_or("")