From: Brian Masney <masneyb@kernel.org>
To: "Kernel.org Tools" <tools@kernel.org>
Cc: Konstantin Ryabitsev <konstantin@linuxfoundation.org>,
Jerome Brunet <jbrunet@baylibre.com>,
Brian Masney <masneyb@kernel.org>
Subject: [PATCH b4 2/2] review: tui: correctly walk a series when a message is missing from the lore archive
Date: Tue, 17 Nov 2026 11:44:41 -0500 [thread overview]
Message-ID: <20261117-lore-missing-msg-id-fix-v1-2-a5d13a11eb10@kernel.org> (raw)
In-Reply-To: <20261117-lore-missing-msg-id-fix-v1-0-a5d13a11eb10@kernel.org>
When a parent message does not make it's way into the lore archive, walk
the references to look for the closet ancestor that is available to
allow parsing what all is available.
A practical effect of this bug is that it can cause a trailer that
someone left will not be picked up. For example, look at the thread
linked below in the review TUI and the message from Jerome, along with
his Reviewed-by, does not show up in the TUI. With this change, the
message from Jerome shows up, along with his Reviewed-by tag.
Link: https://lore.kernel.org/linux-clk/20261112-upstream-clk-divider-large-rates-v2-0-18f3bb888b0c@baylibre.com/
Assisted-by: LLM
Signed-off-by: Brian Masney <masneyb@kernel.org>
---
src/b4/review/tracking.py | 38 +++++++++++++++++++++++++---
src/b4/review_tui/_common.py | 46 +++++++++++++++++++++++++++++++---
src/b4/review_tui/_review_app.py | 6 ++---
src/tests/test_tui_review.py | 54 +++++++++++++++++++++++++++++++++++++++-
4 files changed, 133 insertions(+), 11 deletions(-)
diff --git a/src/b4/review/tracking.py b/src/b4/review/tracking.py
index 5a1a91fb3737..048a8c357c2b 100644
--- a/src/b4/review/tracking.py
+++ b/src/b4/review/tracking.py
@@ -2756,10 +2756,33 @@ def get_thread_mbox(topdir: str, blob_sha: str) -> Optional[bytes]:
return out
+def _next_known_from_references_local(
+ missing: str,
+ references: Optional[List[str]],
+ patch_msgids: Dict[str, int],
+ msgid_map: Dict[str, Any],
+) -> Optional[str]:
+ """Find the closest known ancestor of *missing* using References.
+
+ Duplicated from review_tui._common to avoid a cross-layer import.
+ """
+ if not references:
+ return None
+ try:
+ candidates = references[: references.index(missing)]
+ except ValueError:
+ candidates = references
+ for refid in reversed(candidates):
+ if refid in patch_msgids or refid in msgid_map:
+ return refid
+ return None
+
+
def _resolve_patch_for_followup_local(
in_reply_to: Optional[str],
patch_msgids: Dict[str, int],
msgid_map: Dict[str, Any],
+ references: Optional[List[str]] = None,
) -> Optional[int]:
"""Walk the in_reply_to chain to find which patch a follow-up belongs to.
@@ -2774,7 +2797,10 @@ def _resolve_patch_for_followup_local(
seen.add(current)
lmsg = msgid_map.get(current)
if lmsg is None:
- break
+ current = _next_known_from_references_local(
+ current, references, patch_msgids, msgid_map
+ )
+ continue
current = lmsg.in_reply_to
return None
@@ -2783,6 +2809,7 @@ def _get_followup_depth_local(
in_reply_to: Optional[str],
patch_msgids: Dict[str, int],
msgid_map: Dict[str, Any],
+ references: Optional[List[str]] = None,
max_depth: int = 5,
) -> int:
"""Return the threading depth of a follow-up relative to its patch.
@@ -2800,7 +2827,10 @@ def _get_followup_depth_local(
seen.add(current)
lmsg = msgid_map.get(current)
if lmsg is None:
- break
+ current = _next_known_from_references_local(
+ current, references, patch_msgids, msgid_map
+ )
+ continue
depth += 1
current = lmsg.in_reply_to
return min(depth, max_depth)
@@ -2843,7 +2873,7 @@ def _parse_msgs_to_followup_comments(
followup_comments: Dict[int, List[Dict[str, Any]]] = {}
for lmsg in sorted(lmbx.followups, key=lambda m: m.date):
display_idx = _resolve_patch_for_followup_local(
- lmsg.in_reply_to, patch_msgids, lmbx.msgid_map
+ lmsg.in_reply_to, patch_msgids, lmbx.msgid_map, lmsg.references
)
if display_idx is None:
continue
@@ -2865,7 +2895,7 @@ def _parse_msgs_to_followup_comments(
'msgid': lmsg.msgid,
'subject': lmsg.subject,
'depth': _get_followup_depth_local(
- lmsg.in_reply_to, patch_msgids, lmbx.msgid_map
+ lmsg.in_reply_to, patch_msgids, lmbx.msgid_map, lmsg.references
),
}
followup_comments.setdefault(display_idx, []).append(entry)
diff --git a/src/b4/review_tui/_common.py b/src/b4/review_tui/_common.py
index 41aab1ac87e2..81d46597c124 100644
--- a/src/b4/review_tui/_common.py
+++ b/src/b4/review_tui/_common.py
@@ -712,15 +712,42 @@ def _write_followup_comments(
_FOLLOWUP_MAX_DEPTH = 5
+def _next_known_from_references(
+ missing: str,
+ references: Optional[List[str]],
+ patch_msgids: Dict[str, int],
+ msgid_map: Dict[str, 'b4.LoreMessage'],
+) -> Optional[str]:
+ """Find the closest known ancestor of *missing* using References.
+
+ When a message in the in_reply_to chain is not in the thread (e.g. it
+ never made it to the archive), the References header of the follow-up
+ still lists the rest of the ancestry. Return the nearest entry before
+ *missing* that is either a series patch or a message we have.
+ """
+ if not references:
+ return None
+ try:
+ candidates = references[: references.index(missing)]
+ except ValueError:
+ candidates = references
+ for refid in reversed(candidates):
+ if refid in patch_msgids or refid in msgid_map:
+ return refid
+ return None
+
+
def _get_followup_depth(
in_reply_to: Optional[str],
patch_msgids: Dict[str, int],
msgid_map: Dict[str, 'b4.LoreMessage'],
+ references: Optional[List[str]] = None,
) -> int:
"""Return the threading depth of a follow-up relative to its patch.
Depth 0 = direct reply to a patch; depth N = N hops through follow-up
replies. Capped at _FOLLOWUP_MAX_DEPTH to prevent runaway indentation.
+ Missing messages in the chain are skipped using *references*.
"""
depth = 0
seen: Set[str] = set()
@@ -731,7 +758,10 @@ def _get_followup_depth(
seen.add(current)
lmsg = msgid_map.get(current)
if lmsg is None:
- break
+ current = _next_known_from_references(
+ current, references, patch_msgids, msgid_map
+ )
+ continue
depth += 1
current = lmsg.in_reply_to
return min(depth, _FOLLOWUP_MAX_DEPTH)
@@ -741,9 +771,12 @@ def _resolve_patch_for_followup(
in_reply_to: Optional[str],
patch_msgids: Dict[str, int],
msgid_map: Dict[str, 'b4.LoreMessage'],
+ references: Optional[List[str]] = None,
) -> Optional[int]:
"""Walk the in_reply_to chain to find which patch a follow-up belongs to.
+ If a message in the chain is missing from the thread, fall back to
+ *references* (the follow-up's References header) to keep walking.
Returns the display index (0=cover, 1..N=patches) or None.
"""
seen: Set[str] = set()
@@ -754,7 +787,10 @@ def _resolve_patch_for_followup(
seen.add(current)
lmsg = msgid_map.get(current)
if lmsg is None:
- break
+ current = _next_known_from_references(
+ current, references, patch_msgids, msgid_map
+ )
+ continue
current = lmsg.in_reply_to
return None
@@ -763,6 +799,7 @@ def _chain_has_additional_patch(
in_reply_to: Optional[str],
patch_msgids: Dict[str, int],
msgid_map: Dict[str, 'b4.LoreMessage'],
+ references: Optional[List[str]] = None,
) -> bool:
"""Check whether the in-reply-to chain passes through a message that
contains its own diff before reaching a known series patch.
@@ -779,7 +816,10 @@ def _chain_has_additional_patch(
seen.add(current)
lmsg = msgid_map.get(current)
if lmsg is None:
- break
+ current = _next_known_from_references(
+ current, references, patch_msgids, msgid_map
+ )
+ continue
if lmsg.has_diff:
return True
current = lmsg.in_reply_to
diff --git a/src/b4/review_tui/_review_app.py b/src/b4/review_tui/_review_app.py
index 97cc3e778db6..fa38143688cd 100644
--- a/src/b4/review_tui/_review_app.py
+++ b/src/b4/review_tui/_review_app.py
@@ -1934,7 +1934,7 @@ class ReviewApp(LoreNodeShutdownMixin, CheckRunnerMixin, App[None]):
all_followups = lmbx.followups + lmbx.unknowns
for lmsg in sorted(all_followups, key=lambda m: m.date):
display_idx = _resolve_patch_for_followup(
- lmsg.in_reply_to, patch_msgids, lmbx.msgid_map
+ lmsg.in_reply_to, patch_msgids, lmbx.msgid_map, lmsg.references
)
if display_idx is None:
continue
@@ -1966,11 +1966,11 @@ class ReviewApp(LoreNodeShutdownMixin, CheckRunnerMixin, App[None]):
'subject': lmsg.full_subject,
'reply': lmsg.reply,
'depth': _get_followup_depth(
- lmsg.in_reply_to, patch_msgids, lmbx.msgid_map
+ lmsg.in_reply_to, patch_msgids, lmbx.msgid_map, lmsg.references
),
'lmsg': lmsg,
'replies-to-diff': _chain_has_additional_patch(
- lmsg.in_reply_to, patch_msgids, lmbx.msgid_map
+ lmsg.in_reply_to, patch_msgids, lmbx.msgid_map, lmsg.references
),
}
self._followup_comments.setdefault(display_idx, []).append(entry)
diff --git a/src/tests/test_tui_review.py b/src/tests/test_tui_review.py
index e164bf646154..b212e7f7aa85 100644
--- a/src/tests/test_tui_review.py
+++ b/src/tests/test_tui_review.py
@@ -26,7 +26,11 @@ from textual.widgets import ListView
import b4
import b4.review
import b4.review.tracking
-from b4.review_tui._common import filter_range_diff_for_commit
+from b4.review_tui._common import (
+ _get_followup_depth,
+ _resolve_patch_for_followup,
+ filter_range_diff_for_commit,
+)
from b4.review_tui._review_app import FollowupItem, PatchListItem, ReviewApp
from .helpers.tracking import create_review_branch
@@ -1029,3 +1033,51 @@ class TestPatchListItemPreMountStyling:
"""The held reference must be what compose() yields, not a copy."""
item = PatchListItem('a patch', 1, 'done')
assert list(item.compose()) == [item._label]
+
+
+class TestFollowupThreadingMissingParent:
+ """A follow-up whose In-Reply-To parent never reached the archive must
+ still be attached to its patch by walking its References header."""
+
+ # cover <- patch1 <- review <- reply <- (missing) <- late-reply
+ PATCH_MSGIDS = {'cover@x': 0, 'patch1@x': 1}
+ REFERENCES = ['cover@x', 'patch1@x', 'review@x', 'reply@x', 'missing@x']
+
+ @staticmethod
+ def _msgid_map() -> Dict[str, Any]:
+ return {
+ 'review@x': mock.Mock(in_reply_to='patch1@x', has_diff=False),
+ 'reply@x': mock.Mock(in_reply_to='review@x', has_diff=False),
+ }
+
+ def test_resolves_patch_through_references(self) -> None:
+ assert (
+ _resolve_patch_for_followup(
+ 'missing@x', self.PATCH_MSGIDS, self._msgid_map(), self.REFERENCES
+ )
+ == 1
+ )
+
+ def test_depth_skips_missing_parent(self) -> None:
+ assert (
+ _get_followup_depth(
+ 'missing@x', self.PATCH_MSGIDS, self._msgid_map(), self.REFERENCES
+ )
+ == 2
+ )
+
+ def test_without_references_is_unresolved(self) -> None:
+ assert (
+ _resolve_patch_for_followup(
+ 'missing@x', self.PATCH_MSGIDS, self._msgid_map()
+ )
+ is None
+ )
+
+ def test_tracking_copy_resolves_patch_through_references(self) -> None:
+ assert (
+ b4.review.tracking._resolve_patch_for_followup_local(
+ 'missing@x', self.PATCH_MSGIDS, self._msgid_map(), self.REFERENCES
+ )
+ == 1
+ )
--
2.56.1
prev parent reply other threads:[~2026-11-17 16:44 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 16:44 [PATCH b4 0/2] correctly walk a series when a message is missing from the lore archive Brian Masney
2026-11-17 16:44 ` [PATCH b4 1/2] " Brian Masney
2026-11-17 16:44 ` Brian Masney [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261117-lore-missing-msg-id-fix-v1-2-a5d13a11eb10@kernel.org \
--to=masneyb@kernel.org \
--cc=jbrunet@baylibre.com \
--cc=konstantin@linuxfoundation.org \
--cc=tools@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.