Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves email reply threading in the gateway’s Email platform adapter by carrying forward inbound References headers into outbound replies and extending the References chain with the message being replied to, with new focused tests to validate the behavior.
Changes:
- Capture inbound
Referencesin_fetch_new_messages()and persist it into_thread_contextduring dispatch. - Build outbound
Referencesby combining stored inboundReferenceswith the currentMessage-IDbeing replied to (for plain and attachment sends). - Add focused tests asserting
In-Reply-ToandReferencesbehavior for replies with/without priorReferences.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| plugins/platforms/email/adapter.py | Stores inbound References and uses it to build outbound reply threading headers. |
| tests/test_email_threading_headers.py | Adds targeted tests validating outbound In-Reply-To/References header construction. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| references = " ".join( | ||
| part for part in [ctx.get("references", ""), original_msg_id] if part | ||
| ) | ||
| msg["References"] = references |
| references = " ".join( | ||
| part for part in [ctx.get("references", ""), original_msg_id] if part | ||
| ) | ||
| msg["References"] = references |
| references = " ".join( | ||
| part for part in [ctx.get("references", ""), original_msg_id] if part | ||
| ) | ||
| msg["References"] = references |
Email-threading cluster: this PR is the narrow outbound |
6eddd51 to
aded28b
Compare
|
Addressed the review feedback about re-emitting inbound Update:
Verification:
|
teknium1
left a comment
There was a problem hiding this comment.
Thank you for addressing the folded-header and duplicate-ID feedback; the new helper in plugins/platforms/email/adapter.py:71-108 is a clear improvement over re-emitting inbound header text.
Problems
plugins/platforms/email/adapter.py:881addsreferencesto context that is still keyed only bysender_addr. Current main reads that context by recipient address in all three send paths (:933,:1047,:1127). If one sender has two active email threads, the later inbound message overwrites the earlier thread'sReferenceschain. The gateway passes the individual reply anchor (gateway/platforms/base.py:5028-5033), but_send_emailcombines it with that overwritten context.
Suggested changes
- Carry a stable email-thread key through dispatch and reply delivery, then key context by that value; add a two-threads/same-sender regression test.
- Add attachment-path coverage for the two additional changed send methods.
Automated hermes-sweeper review.
| self._thread_context[sender_addr] = { | ||
| "subject": subject, | ||
| "message_id": msg_data["message_id"], | ||
| "references": msg_data.get("references", ""), |
There was a problem hiding this comment.
This value is still stored under sender_addr, while every send path later retrieves context by recipient address. A second, unrelated thread from the same sender overwrites this References chain before the first thread's response is sent. Please key/route the context by a stable email-thread identity and add a same-sender/two-threads regression.
Summary
Referenceswhen sending gateway repliesMessage-IDto the outboundReferenceschainTest
uv run --with pytest pytest -q tests/test_email_threading_headers.pypython -m py_compile plugins/platforms/email/adapter.py tests/test_email_threading_headers.py