fix(channels): use platform message IDs to prevent duplicate memories

Fixes #430 - Prevents duplicate memories after restart by using platform message IDs instead of random UUIDs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Argenis 2026-02-16 19:04:37 -05:00 committed by GitHub
parent c3cc835346
commit e8553a800a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 217 additions and 82 deletions

View file

@ -160,8 +160,8 @@ impl Channel for SlackChannel {
last_ts = ts.to_string();
let channel_msg = ChannelMessage {
id: Uuid::new_v4().to_string(),
sender: channel_id.clone(),
id: format!("slack_{channel_id}_{ts}"),
sender: user.to_string(),
content: text.to_string(),
channel: "slack".to_string(),
timestamp: std::time::SystemTime::now()
@ -252,4 +252,53 @@ mod tests {
assert!(ch.is_user_allowed("U111"));
assert!(ch.is_user_allowed("anyone"));
}
// ── Message ID edge cases ─────────────────────────────────────
#[test]
fn slack_message_id_format_includes_channel_and_ts() {
// Verify that message IDs follow the format: slack_{channel_id}_{ts}
let ts = "1234567890.123456";
let channel_id = "C12345";
let expected_id = format!("slack_{channel_id}_{ts}");
assert_eq!(expected_id, "slack_C12345_1234567890.123456");
}
#[test]
fn slack_message_id_is_deterministic() {
// Same channel_id + same ts = same ID (prevents duplicates after restart)
let ts = "1234567890.123456";
let channel_id = "C12345";
let id1 = format!("slack_{channel_id}_{ts}");
let id2 = format!("slack_{channel_id}_{ts}");
assert_eq!(id1, id2);
}
#[test]
fn slack_message_id_different_ts_different_id() {
// Different timestamps produce different IDs
let channel_id = "C12345";
let id1 = format!("slack_{channel_id}_1234567890.123456");
let id2 = format!("slack_{channel_id}_1234567890.123457");
assert_ne!(id1, id2);
}
#[test]
fn slack_message_id_different_channel_different_id() {
// Different channels produce different IDs even with same ts
let ts = "1234567890.123456";
let id1 = format!("slack_C12345_{ts}");
let id2 = format!("slack_C67890_{ts}");
assert_ne!(id1, id2);
}
#[test]
fn slack_message_id_no_uuid_randomness() {
// Verify format doesn't contain random UUID components
let ts = "1234567890.123456";
let channel_id = "C12345";
let id = format!("slack_{channel_id}_{ts}");
assert!(!id.contains('-')); // No UUID dashes
assert!(id.starts_with("slack_"));
}
}