* [PATCH b4 0/2] correctly walk a series when a message is missing from the lore archive
@ 2026-11-17 16:44 Brian Masney
2026-11-17 16:44 ` [PATCH b4 1/2] " Brian Masney
2026-11-17 16:44 ` [PATCH b4 2/2] review: tui: " Brian Masney
0 siblings, 2 replies; 3+ messages in thread
From: Brian Masney @ 2026-11-17 16:44 UTC (permalink / raw)
To: Kernel.org Tools; +Cc: Konstantin Ryabitsev, Jerome Brunet, Brian Masney
Here's some fixes for the 'b4 am' and 'b4 review tui' that can cause a
trailer from someone to not show up when there is a message missing in
the lore archive.
I ran into this with the series linked below. The message from Brian
with ID avXhA9mJL0EIcm_0@x1g10 is missing from the lore archive. This
causes the Reviewed-by from Jerome that is in the archive to not be
picked up when 'git am' is used. With this change, the trailer is
picked up as expected, and the messages show up in the review TUI,
along with the trailer.
Link: https://lore.kernel.org/linux-clk/20261112-upstream-clk-divider-large-rates-v2-0-18f3bb888b0c@baylibre.com/
Signed-off-by: Brian Masney <masneyb@kernel.org>
---
Brian Masney (2):
correctly walk a series when a message is missing from the lore archive
review: tui: correctly walk a series when a message is missing from the lore archive
src/b4/__init__.py | 15 +++++++++++
src/b4/review/tracking.py | 38 +++++++++++++++++++++++++---
src/b4/review_tui/_common.py | 46 +++++++++++++++++++++++++++++++---
src/b4/review_tui/_review_app.py | 6 ++---
src/tests/test___init__.py | 31 +++++++++++++++++++++++
src/tests/test_tui_review.py | 54 +++++++++++++++++++++++++++++++++++++++-
6 files changed, 179 insertions(+), 11 deletions(-)
---
base-commit: cad0be6e2c6eddd41ebe13a729464dd406cc4c53
change-id: 20261117-lore-missing-msg-id-fix-c83c6c3c67c6
Best regards,
--
Brian Masney <masneyb@kernel.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH b4 1/2] correctly walk a series when a message is missing from the lore archive
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 ` Brian Masney
2026-11-17 16:44 ` [PATCH b4 2/2] review: tui: " Brian Masney
1 sibling, 0 replies; 3+ messages in thread
From: Brian Masney @ 2026-11-17 16:44 UTC (permalink / raw)
To: Kernel.org Tools; +Cc: Konstantin Ryabitsev, Jerome Brunet, Brian Masney
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 and it shows the message from Brian with ID
avXhA9mJL0EIcm_0@x1g10 is missing from the lore archive. This causes
the Reviewed-by from Jerome that is in the archive to not be picked
up when 'git am' is used. With this change, the trailer is picked up
as expected.
Let's also add a test case for this scenario.
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/__init__.py | 15 +++++++++++++++
src/tests/test___init__.py | 31 +++++++++++++++++++++++++++++++
2 files changed, 46 insertions(+)
diff --git a/src/b4/__init__.py b/src/b4/__init__.py
index 1ea899c35fa9..e2c1b617a609 100644
--- a/src/b4/__init__.py
+++ b/src/b4/__init__.py
@@ -643,6 +643,21 @@ class LoreMailbox:
break
elif (pmsg := self.msgid_map.get(fmsg.in_reply_to)) is not None:
logger.debug('Found in-reply-to %s in msgid_map', fmsg.in_reply_to)
+ else:
+ # The parent never made it into the thread (e.g. it is
+ # missing from the archive), so use the closest ancestor
+ # from References that we do have
+ for refid in reversed(fmsg.references):
+ if (
+ refid not in (fmsg.msgid, fmsg.in_reply_to)
+ and (pmsg := self.msgid_map.get(refid)) is not None
+ ):
+ logger.debug(
+ 'Missing in-reply-to %s, using references entry %s',
+ fmsg.in_reply_to,
+ refid,
+ )
+ break
if pmsg is None:
# Can't find the message we're replying to here
continue
diff --git a/src/tests/test___init__.py b/src/tests/test___init__.py
index 8b041340e9e5..50ba2928e64e 100644
--- a/src/tests/test___init__.py
+++ b/src/tests/test___init__.py
@@ -539,6 +539,37 @@ def test_get_series_twice_adds_no_duplicate_trailers(
assert _followup_trailer_keys(again) == before
+def test_followup_with_missing_parent_uses_references(sampledir: str) -> None:
+ """A reply whose In-Reply-To parent is absent from the thread still
+ has its trailers attached via the closest known References entry."""
+ lmbx = b4.LoreMailbox()
+ for msg in b4.get_msgs_from_mailbox_or_maildir(
+ f'{sampledir}/trailers-followup-with-cover.mbox'
+ ):
+ lmbx.add_message(msg)
+ reply = email.message.EmailMessage()
+ reply['From'] = 'Missing Parent <missing.parent@example.com>'
+ reply['Subject'] = 'Re: [PATCH v2 2/2] Simple test 2'
+ reply['Date'] = 'Tue, 30 Aug 2022 11:19:07 -0400'
+ reply['Message-Id'] = '<late-reply@example.com>'
+ reply['In-Reply-To'] = '<not-in-archive@example.com>'
+ reply['References'] = (
+ '<cover-message@example.com> <patch-2-message@example.com> '
+ '<not-in-archive@example.com>'
+ )
+ reply.set_content(
+ 'Agreed.\n\nReviewed-by: Missing Parent <missing.parent@example.com>\n'
+ )
+ lmbx.add_message(reply)
+ lser = lmbx.get_series()
+ assert lser is not None
+ patch2 = lser.patches[2]
+ assert patch2 is not None
+ assert ('Reviewed-by', 'Missing Parent <missing.parent@example.com>') in [
+ (t.name, t.value) for t in patch2.followup_trailers
+ ]
+
+
def test_same_trailer_in_two_replies_is_kept_twice(sampledir: str) -> None:
"""Only a repeat from the same message is a duplicate, not a second reply."""
msgs = b4.get_msgs_from_mailbox_or_maildir(
--
2.56.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH b4 2/2] review: tui: correctly walk a series when a message is missing from the lore archive
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
1 sibling, 0 replies; 3+ messages in thread
From: Brian Masney @ 2026-11-17 16:44 UTC (permalink / raw)
To: Kernel.org Tools; +Cc: Konstantin Ryabitsev, Jerome Brunet, Brian Masney
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-17 16:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH b4 2/2] review: tui: " Brian Masney
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.