From c65f7fe962ea8a1590aa8c71d70b484c6259d31d Mon Sep 17 00:00:00 2001 From: kosmos Date: Sun, 22 Nov 2026 00:01:01 +0000 Subject: [PATCH] fix(forge): read a GitHub notification id as a string or a number The notifications feed sends `id` as a JSON string (`"27210544329"`), unlike every other row this adapter decodes, so `WireNotification`'s `Option` refused one real row and failed the whole page. The account watch has been stuck on 'error decoding response body' since the first notification arrived (82 consecutive failures at the time of writing). `lenient_id` accepts either shape; a non-numeric string is still a loud parse error rather than a dropped row. The regression test is the row captured live. --- .../rhema-forge-integration/src/github.rs | 87 ++++++++++++++++++- 1 file changed, 86 insertions(+), 1 deletion(-) diff --git a/integrations/rhema-forge-integration/src/github.rs b/integrations/rhema-forge-integration/src/github.rs index 335d455..9b33bd1 100644 --- a/integrations/rhema-forge-integration/src/github.rs +++ b/integrations/rhema-forge-integration/src/github.rs @@ -287,7 +287,9 @@ struct WireComment { /// One row of the account notifications feed. #[derive(Debug, Clone, Deserialize)] struct WireNotification { - #[serde(default)] + /// GitHub sends this one as a JSON string, unlike every other id in + /// this adapter; see [`lenient_id`]. + #[serde(default, deserialize_with = "lenient_id")] id: Option, #[serde(default)] reason: Option, @@ -452,6 +454,32 @@ fn parent_number(url: &str) -> Option { url.trim_end_matches('/').rsplit('/').next()?.parse().ok() } +/// An id that arrives as either a JSON number or a JSON string. +/// +/// GitHub's notifications feed is the odd one out: `id` there is a +/// string (`"27210544329"`), while issues, comments and reviews send +/// numbers. One row that refuses to decode fails the whole page, so the +/// notification id is read leniently. +fn lenient_id<'de, D>(deserializer: D) -> Result, D::Error> +where + D: serde::Deserializer<'de>, +{ + #[derive(Deserialize)] + #[serde(untagged)] + enum IdWire { + Number(i64), + Text(String), + } + + match Option::::deserialize(deserializer)? { + None => Ok(None), + Some(IdWire::Number(n)) => Ok(Some(n)), + Some(IdWire::Text(text)) => text.trim().parse().map(Some).map_err(|_| { + serde::de::Error::custom(format!("notification id is not a number: {text}")) + }), + } +} + /// The notification a notifications row carries. GitHub's `reason` field /// is the row's whole why; the subject's API URL yields the thread. fn notification_event(row: &WireNotification) -> Result, ForgeError> { @@ -870,4 +898,61 @@ mod tests { assert_eq!(event.raw["node_id"], "MDU6SXNzdWUxMDA3"); assert!(event.raw.get("title").is_none()); } + fn notification(json: &str) -> WireNotification { + serde_json::from_str(json).expect("notification fixture parses") + } + + // Captured from the live feed on 2026-11-21: `id` there is a string, + // and one such row used to fail the whole page's decode. + #[test] + fn a_notification_id_sent_as_a_string_decodes() { + let row = notification( + r#"{"id": "27210544329", "unread": true, "reason": "mention", + "updated_at": "2026-11-21T22:33:00Z", "last_read_at": null, + "subject": {"title": "Snap build failed for v2.5.1", + "url": "https://api.github.com/repos/acme/widgets/issues/10", + "latest_comment_url": "https://api.github.com/repos/acme/widgets/issues/comments/7070", + "type": "Issue"}, + "repository": {"id": 1239653662, "full_name": "acme/widgets"}, + "url": "https://api.github.com/notifications/threads/27210544329"}"#, + ); + let notification = notification_event(&row) + .expect("maps") + .expect("carries a notification"); + assert_eq!(notification.number, 10); + assert_eq!(notification.repo, RepoRef::new("acme", "widgets")); + assert_eq!(notification.reason, NotificationReason::Mention); + assert!(!notification.is_pr); + assert_eq!( + notification.id, + "github:notification:27210544329@2026-11-21T22:33:00Z" + ); + } + + #[test] + fn a_notification_id_sent_as_a_number_still_decodes() { + let row = notification( + r#"{"id": 42188, "reason": "review_requested", + "updated_at": "2026-10-08T12:00:00Z", + "subject": {"title": "tidy the parser", "type": "PullRequest", + "url": "https://api.github.com/repos/acme/widgets/pulls/8"}, + "repository": {"full_name": "acme/widgets"}}"#, + ); + let notification = notification_event(&row) + .expect("maps") + .expect("carries a notification"); + assert_eq!(notification.number, 8); + assert!(notification.is_pr); + assert_eq!( + notification.id, + "github:notification:42188@2026-10-08T12:00:00Z" + ); + } + + #[test] + fn a_notification_id_that_is_not_a_number_is_a_parse_error() { + let err = serde_json::from_str::(r#"{"id": "not-a-number"}"#) + .expect_err("a junk id is loud, not silently dropped"); + assert!(err.to_string().contains("not-a-number"), "got: {err}"); + } } -- 2.54.0