Merge commit 'refs/c35/943' into integ/content-batch

This commit is contained in:
Michael Sitarzewski
2026-09-30 21:38:26 -05:00
@@ -128,7 +128,16 @@ def reconstruct_thread(messages):
- Quoted replies duplicate content (20-msg thread = ~4-5x token bloat)
- Thread forks when people reply to different messages in the chain
"""
# Build reply graph from In-Reply-To and References headers
# Reject ambiguous identities before building or mutating the graph.
# Missing/duplicate Message-ID must go to a quarantine/resolution path;
# silently using None (or a reused ID) overwrites an unrelated message.
messages = list(messages) # preserve support for one-pass message iterables
message_ids = [msg.get("message_id") for msg in messages]
if any(not isinstance(mid, str) or not mid.strip() for mid in message_ids):
raise ValueError("Every message needs a nonempty Message-ID")
if len(set(message_ids)) != len(message_ids):
raise ValueError("Duplicate Message-ID: resolve identity before reconstruction")
graph = {}
for msg in messages:
parent_id = msg["in_reply_to"]