Skip to content

fix: #457 llm will add rfp compliant id when replying#560

Open
hindmakarem-qa wants to merge 3 commits intotaylorwilsdon:mainfrom
hindmakarem-qa:fix/email-threading-headers
Open

fix: #457 llm will add rfp compliant id when replying#560
hindmakarem-qa wants to merge 3 commits intotaylorwilsdon:mainfrom
hindmakarem-qa:fix/email-threading-headers

Conversation

@hindmakarem-qa
Copy link

@hindmakarem-qa hindmakarem-qa commented Mar 12, 2026

Description

Fix email reply threading by ensuring reply headers use RFC-compliant values.
Updates Gmail metadata header fetching to include In-Reply-To and References.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Testing

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have tested this change manually

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have enabled "Allow edits from maintainers" for this pull request

Additional Notes

  • Root cause: reply threading depends on RFC headers (Message-ID, In-Reply-To, References). When these are missing, replies may not thread correctly across clients.
  • Change summary:
    • Expanded GMAIL_METADATA_HEADERS to include In-Reply-To and References.
    • Updated tool parameter docs to clarify that in_reply_to should be an RFC Message-ID (e.g., <...@gmail.com>), not Gmail’s internal message id.
  • Expected impact: when reply-related headers are available, the client/tooling can build correct threading chains and produce more reliable reply grouping.

Summary by CodeRabbit

  • Improvements
    • Gmail metadata extraction now captures In-Reply-To and References headers to improve threading and conversation context.
  • Documentation
    • Updated message field descriptions to clarify RFC-style Message-ID formatting and threading examples for send and draft operations.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 12, 2026

📝 Walkthrough

Walkthrough

Adds "In-Reply-To" and "References" to Gmail metadata extraction and output alongside Subject, From, To, Cc, Message-ID, and Date; updates in_reply_to and references field descriptions to reference RFC-style Message-ID examples; minor formatting/spacing adjustments.

Changes

Cohort / File(s) Summary
Gmail metadata & message formatting
gmail/gmail_tools.py
Added "In-Reply-To" and "References" to GMAIL_METADATA_HEADERS; included these headers in message fetch, formatting, batch output, and in get_gmail_message_content; updated in_reply_to and references field descriptions to show RFC Message-ID examples; minor spacing/format tweaks.

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 I nibble headers, tidy and neat,
In-Reply-To joins the thread so sweet,
References hop along in line,
Message-IDs wrapped up fine. 🥕✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title references issue #457 and describes the core change: adding RFC-compliant IDs for email replies, which aligns with the PR's objective of fixing email reply threading.
Description check ✅ Passed The description follows the template structure with all required sections completed: Description, Type of Change, Testing, Checklist, and Additional Notes with clear explanation of root cause and impact.
Docstring Coverage ✅ Passed Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
gmail/gmail_tools.py (1)

1162-1172: ⚠️ Potential issue | 🟠 Major

Validate reply-header inputs instead of relying on doc text.

These updates improve the hints, but both tools still pass in_reply_to and references straight into _prepare_gmail_message() without checking that they are RFC-style Message-IDs. A Gmail internal id or malformed reference chain will still be emitted verbatim, so the threading bug can persist in both send and draft flows.

🛠️ Suggested direction
+def _normalize_rfc_message_id(value: str, field_name: str) -> str:
+    candidate = value.strip()
+    if not (candidate.startswith("<") and candidate.endswith(">")):
+        raise UserInputError(
+            f"{field_name} must be an RFC Message-ID like '<message123@gmail.com>'."
+        )
+    return candidate
+
+def _normalize_references(value: str) -> str:
+    refs = [_normalize_rfc_message_id(ref, "references") for ref in value.split()]
+    if not refs:
+        raise UserInputError(
+            "references must contain one or more RFC Message-IDs separated by spaces."
+        )
+    return " ".join(refs)

Then normalize before assigning message["In-Reply-To"] and message["References"].

Also applies to: 1206-1208, 1369-1379, 1410-1412

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@gmail/gmail_tools.py` around lines 1162 - 1172, The in_reply_to and
references parameters are passed into _prepare_gmail_message without validation;
add validation and normalization before passing them or before assigning to
message["In-Reply-To"] / message["References"] in _prepare_gmail_message: ensure
each token is a valid RFC‑2822 Message-ID (match/extract tokens like <...@...>
via regex), wrap single IDs with angle brackets if missing, and for references
normalize a space-separated chain of Message-IDs (extract valid IDs and join
with single spaces); apply this logic where in_reply_to and references are
accepted (functions/params named in_reply_to, references) and where
_prepare_gmail_message sets message["In-Reply-To"] and message["References"] so
malformed gmail internal ids or raw strings are not emitted verbatim.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@gmail/gmail_tools.py`:
- Around line 40-44: The GMAIL_METADATA_HEADERS list was updated but the
functions still omit the new reply headers from their outputs; update
get_gmail_message_content() and get_gmail_messages_content_batch() to include
the "In-Reply-To" and "References" metadata when composing the returned message
string (i.e., when iterating/formatting headers or metadata for the returned
content, include those two header keys from GMAIL_METADATA_HEADERS), ensuring
callers receive those headers so reply chains can be reconstructed for
RFC-compliant follow-ups.

---

Outside diff comments:
In `@gmail/gmail_tools.py`:
- Around line 1162-1172: The in_reply_to and references parameters are passed
into _prepare_gmail_message without validation; add validation and normalization
before passing them or before assigning to message["In-Reply-To"] /
message["References"] in _prepare_gmail_message: ensure each token is a valid
RFC‑2822 Message-ID (match/extract tokens like <...@...> via regex), wrap single
IDs with angle brackets if missing, and for references normalize a
space-separated chain of Message-IDs (extract valid IDs and join with single
spaces); apply this logic where in_reply_to and references are accepted
(functions/params named in_reply_to, references) and where
_prepare_gmail_message sets message["In-Reply-To"] and message["References"] so
malformed gmail internal ids or raw strings are not emitted verbatim.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3f1d88b6-ef9e-4f4b-a530-7b5b6762a486

📥 Commits

Reviewing files that changed from the base of the PR and between 5a2e1f3 and 4d79bf2.

📒 Files selected for processing (1)
  • gmail/gmail_tools.py

@taylorwilsdon taylorwilsdon self-assigned this Mar 15, 2026
@taylorwilsdon taylorwilsdon added the enhancement New feature or request label Mar 15, 2026
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
gmail/gmail_tools.py (1)

724-730: Add regression tests for header rendering across all modified output branches.

Given changes in three formatting paths, add focused tests for present/absent In-Reply-To and References in: single message, batch metadata, and batch full outputs.

Also applies to: 896-909, 934-947

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@gmail/gmail_tools.py` around lines 724 - 730, Add regression tests that
exercise header rendering for the in_reply_to and references logic around the
in_reply_to, references, and content_lines handling in gmail/gmail_tools.py:
create unit tests for the three output branches that were modified (single
message output, batch metadata output, and batch full output) verifying both
presence and absence of "In-Reply-To" and "References" headers. For each branch,
add cases for (1) neither header present, (2) only In-Reply-To present, (3) only
References present, and (4) both present, asserting the generated content
includes the correct header lines when present and omits them when absent.
Ensure tests call the exact functions/pathways that build content_lines (the
single message renderer and the two batch renderers) and compare the rendered
string or list to expected outputs to prevent regressions.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@gmail/gmail_tools.py`:
- Around line 724-730: Add regression tests that exercise header rendering for
the in_reply_to and references logic around the in_reply_to, references, and
content_lines handling in gmail/gmail_tools.py: create unit tests for the three
output branches that were modified (single message output, batch metadata
output, and batch full output) verifying both presence and absence of
"In-Reply-To" and "References" headers. For each branch, add cases for (1)
neither header present, (2) only In-Reply-To present, (3) only References
present, and (4) both present, asserting the generated content includes the
correct header lines when present and omits them when absent. Ensure tests call
the exact functions/pathways that build content_lines (the single message
renderer and the two batch renderers) and compare the rendered string or list to
expected outputs to prevent regressions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cfaf890f-2357-441b-ac55-2f8411e9244a

📥 Commits

Reviewing files that changed from the base of the PR and between 4d79bf2 and ee6fd7c.

📒 Files selected for processing (1)
  • gmail/gmail_tools.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants