BlueGit

ict rusty-teams

fix(forwards): retry a failed heal, give up channel forwards without content

- a failed Graph read no longer leaves a forward on Loading until restart
- channel forwards without content show Original message not available

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-10-17 · 6 weeks ago

Hash
d65bd8a676ca6077cbbde727620919a53f3e2463
Parent
19f7f89d
1 file changed +29 −3
crates/core/src/forward_sync.rs +29 −3
@@ -20,16 +20,21 @@ fn is_gone(error: &Error) -> bool {
20 20 }
21 21
22 22 impl<R: Remote> SyncEngine<R> {
23 /// Once per chat and session, for cached forwards stored before their original message was kept.
23 /// Once per conversation and session (again after a failed Graph read), for cached forwards stored before their original message was kept.
24 24 pub(crate) async fn heal_forwards(&self, conversation_id: &str) -> bool {
25 25 let first = self
26 26 .forwards_healed
27 27 .lock()
28 28 .unwrap_or_else(|poisoned| poisoned.into_inner())
29 29 .insert(conversation_id.to_owned());
30 if !first || !matches!(self.resolve_stored(conversation_id), Ok(Conversation::Chat)) {
30 if !first {
31 31 return false;
32 32 }
33 let in_chat = match self.resolve_stored(conversation_id) {
34 Ok(Conversation::Chat) => true,
35 Ok(Conversation::Channel { .. }) => false,
36 Err(_) => return false,
37 };
33 38 let Ok(cached) = self
34 39 .store
35 40 .messages_with_attachment_type(conversation_id, FORWARDED_CONTENT_TYPE)
@@ -44,32 +49,53 @@ impl<R: Remote> SyncEngine<R> {
44 49 if stale_ids.is_empty() {
45 50 return false;
46 51 }
52 if !in_chat {
53 let given_up = self.given_up_forwards(conversation_id, &stale_ids);
54 return self
55 .ingest(conversation_id, given_up)
56 .is_ok_and(|delta| !delta.is_empty());
57 }
47 58 let Ok(answers) = self
48 59 .remote
49 60 .chat_messages_by_id(conversation_id, &stale_ids)
50 61 .await
51 62 else {
63 self.retry_forward_heal(conversation_id);
52 64 return false;
53 65 };
54 66 let mut healed = Vec::new();
55 67 let mut given_up_ids = Vec::new();
68 let mut retry = false;
56 69 for (message_id, answer) in stale_ids.iter().zip(answers) {
57 70 let fresh = match answer {
58 71 Ok(message) => message_record(conversation_id, &message),
59 72 Err(error) if is_gone(&error) => None,
60 Err(_) => continue,
73 Err(_) => {
74 retry = true;
75 continue;
76 }
61 77 };
62 78 match fresh {
63 79 Some(record) if !lacks_forward_content(&record) => healed.push(record),
64 80 _ => given_up_ids.push(message_id.clone()),
65 81 }
66 82 }
83 if retry {
84 self.retry_forward_heal(conversation_id);
85 }
67 86 self.apply_chat_emotions(conversation_id, &mut healed).await;
68 87 healed.extend(self.given_up_forwards(conversation_id, &given_up_ids));
69 88 self.ingest(conversation_id, healed)
70 89 .is_ok_and(|delta| !delta.is_empty())
71 90 }
72 91
92 fn retry_forward_heal(&self, conversation_id: &str) {
93 self.forwards_healed
94 .lock()
95 .unwrap_or_else(|poisoned| poisoned.into_inner())
96 .remove(conversation_id);
97 }
98
73 99 /// Read again, as the delta fetch running alongside may have stored a newer version meanwhile.
74 100 fn given_up_forwards(
75 101 &self,
@@ -20,16 +20,21 @@ fn is_gone(error: &Error) -> bool {
20}
20}
21
21
22impl<R: Remote> SyncEngine<R> {
22impl<R: Remote> SyncEngine<R> {
23 /// Once per chat and session, for cached forwards stored before their original message was kept.
23 /// Once per conversation and session (again after a failed Graph read), for cached forwards stored before their original message was kept.
24 pub(crate) async fn heal_forwards(&self, conversation_id: &str) -> bool {
24 pub(crate) async fn heal_forwards(&self, conversation_id: &str) -> bool {
25 let first = self
25 let first = self
26 .forwards_healed
26 .forwards_healed
27 .lock()
27 .lock()
28 .unwrap_or_else(|poisoned| poisoned.into_inner())
28 .unwrap_or_else(|poisoned| poisoned.into_inner())
29 .insert(conversation_id.to_owned());
29 .insert(conversation_id.to_owned());
30 if !first || !matches!(self.resolve_stored(conversation_id), Ok(Conversation::Chat)) {
30 if !first {
31 return false;
31 return false;
32 }
32 }
33 let in_chat = match self.resolve_stored(conversation_id) {
34 Ok(Conversation::Chat) => true,
35 Ok(Conversation::Channel { .. }) => false,
36 Err(_) => return false,
37 };
33 let Ok(cached) = self
38 let Ok(cached) = self
34 .store
39 .store
35 .messages_with_attachment_type(conversation_id, FORWARDED_CONTENT_TYPE)
40 .messages_with_attachment_type(conversation_id, FORWARDED_CONTENT_TYPE)
@@ -44,32 +49,53 @@ impl<R: Remote> SyncEngine<R> {
44 if stale_ids.is_empty() {
49 if stale_ids.is_empty() {
45 return false;
50 return false;
46 }
51 }
52 if !in_chat {
53 let given_up = self.given_up_forwards(conversation_id, &stale_ids);
54 return self
55 .ingest(conversation_id, given_up)
56 .is_ok_and(|delta| !delta.is_empty());
57 }
47 let Ok(answers) = self
58 let Ok(answers) = self
48 .remote
59 .remote
49 .chat_messages_by_id(conversation_id, &stale_ids)
60 .chat_messages_by_id(conversation_id, &stale_ids)
50 .await
61 .await
51 else {
62 else {
63 self.retry_forward_heal(conversation_id);
52 return false;
64 return false;
53 };
65 };
54 let mut healed = Vec::new();
66 let mut healed = Vec::new();
55 let mut given_up_ids = Vec::new();
67 let mut given_up_ids = Vec::new();
68 let mut retry = false;
56 for (message_id, answer) in stale_ids.iter().zip(answers) {
69 for (message_id, answer) in stale_ids.iter().zip(answers) {
57 let fresh = match answer {
70 let fresh = match answer {
58 Ok(message) => message_record(conversation_id, &message),
71 Ok(message) => message_record(conversation_id, &message),
59 Err(error) if is_gone(&error) => None,
72 Err(error) if is_gone(&error) => None,
60 Err(_) => continue,
73 Err(_) => {
74 retry = true;
75 continue;
76 }
61 };
77 };
62 match fresh {
78 match fresh {
63 Some(record) if !lacks_forward_content(&record) => healed.push(record),
79 Some(record) if !lacks_forward_content(&record) => healed.push(record),
64 _ => given_up_ids.push(message_id.clone()),
80 _ => given_up_ids.push(message_id.clone()),
65 }
81 }
66 }
82 }
83 if retry {
84 self.retry_forward_heal(conversation_id);
85 }
67 self.apply_chat_emotions(conversation_id, &mut healed).await;
86 self.apply_chat_emotions(conversation_id, &mut healed).await;
68 healed.extend(self.given_up_forwards(conversation_id, &given_up_ids));
87 healed.extend(self.given_up_forwards(conversation_id, &given_up_ids));
69 self.ingest(conversation_id, healed)
88 self.ingest(conversation_id, healed)
70 .is_ok_and(|delta| !delta.is_empty())
89 .is_ok_and(|delta| !delta.is_empty())
71 }
90 }
72
91
92 fn retry_forward_heal(&self, conversation_id: &str) {
93 self.forwards_healed
94 .lock()
95 .unwrap_or_else(|poisoned| poisoned.into_inner())
96 .remove(conversation_id);
97 }
98
73 /// Read again, as the delta fetch running alongside may have stored a newer version meanwhile.
99 /// Read again, as the delta fetch running alongside may have stored a newer version meanwhile.
74 fn given_up_forwards(
100 fn given_up_forwards(
75 &self,
101 &self,