Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(email): skip missing labels on message insert instead of erroring (#4622)

Evan Hutnikcaf5b5339e3e
diff --git a/rust/cloud-storage/.sqlx/query-6f84ce5949c02518f69930a6a30b78c285f0440e2c5157d1ef2ee614cc2105f3.json b/rust/cloud-storage/.sqlx/query-6f84ce5949c02518f69930a6a30b78c285f0440e2c5157d1ef2ee614cc2105f3.json
deleted file mode 100644
index 030f8c2f2f..0000000000
--- a/rust/cloud-storage/.sqlx/query-6f84ce5949c02518f69930a6a30b78c285f0440e2c5157d1ef2ee614cc2105f3.json
+++ /dev/null
@@ -1,23 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n SELECT id\n FROM email_labels\n WHERE link_id = $1 AND provider_label_id = ANY($2)\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "id",
- "type_info": "Uuid"
- }
- ],
- "parameters": {
- "Left": [
- "Uuid",
- "TextArray"
- ]
- },
- "nullable": [
- false
- ]
- },
- "hash": "6f84ce5949c02518f69930a6a30b78c285f0440e2c5157d1ef2ee614cc2105f3"
-}
diff --git a/rust/cloud-storage/.sqlx/query-ae83e71bca66496aa73ef46a875f60a2fed05e3d27e6e1b12c35f6cebae2c534.json b/rust/cloud-storage/.sqlx/query-ae83e71bca66496aa73ef46a875f60a2fed05e3d27e6e1b12c35f6cebae2c534.json
new file mode 100644
index 0000000000..0d6f5acf15
--- /dev/null
+++ b/rust/cloud-storage/.sqlx/query-ae83e71bca66496aa73ef46a875f60a2fed05e3d27e6e1b12c35f6cebae2c534.json
@@ -0,0 +1,29 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT id, provider_label_id\n FROM email_labels\n WHERE link_id = $1 AND provider_label_id = ANY($2)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "provider_label_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false,
+ false
+ ]
+ },
+ "hash": "ae83e71bca66496aa73ef46a875f60a2fed05e3d27e6e1b12c35f6cebae2c534"
+}
diff --git a/rust/cloud-storage/email_db_client/src/labels/insert.rs b/rust/cloud-storage/email_db_client/src/labels/insert.rs
index 2c2c49f7f6..056a45c178 100644
--- a/rust/cloud-storage/email_db_client/src/labels/insert.rs
+++ b/rust/cloud-storage/email_db_client/src/labels/insert.rs
@@ -273,14 +273,15 @@ pub async fn insert_message_labels(
// get back label ids to use in junction table insert
#[derive(Debug)]
- struct LabelId {
+ struct LabelMapping {
id: Uuid,
+ provider_label_id: String,
}
- let label_mappings: Vec<LabelId> = sqlx::query_as!(
- LabelId,
+ let label_mappings: Vec<LabelMapping> = sqlx::query_as!(
+ LabelMapping,
r#"
- SELECT id
+ SELECT id, provider_label_id
FROM email_labels
WHERE link_id = $1 AND provider_label_id = ANY($2)
"#,
@@ -290,11 +291,21 @@ pub async fn insert_message_labels(
.fetch_all(&mut *tx)
.await?;
+ // labels can be missing if they were created after the last label sync; skip them
if label_mappings.len() != provider_label_ids.len() {
- anyhow::bail!(
- "Could not find all expected labels in database after upsert. link_id: {}, provider_label_ids: {:?}",
- link_id,
- provider_label_ids
+ let found: std::collections::HashSet<&str> = label_mappings
+ .iter()
+ .map(|m| m.provider_label_id.as_str())
+ .collect();
+ let missing: Vec<&String> = provider_label_ids
+ .iter()
+ .filter(|id| !found.contains(id.as_str()))
+ .collect();
+ tracing::warn!(
+ link_id = %link_id,
+ message_id = %message_id,
+ missing_provider_label_ids = ?missing,
+ "Some message labels not found in database, skipping them"
);
}