Skip to content

fix(channels): resolve outbound email recipients from metadata and reply_to - #601

Closed
s97472091-pixel wants to merge 1 commit into
use-agent-os:mainfrom
s97472091-pixel:fix/email-resolve-target-598
Closed

fix(channels): resolve outbound email recipients from metadata and reply_to#601
s97472091-pixel wants to merge 1 commit into
use-agent-os:mainfrom
s97472091-pixel:fix/email-resolve-target-598

Conversation

@s97472091-pixel

Copy link
Copy Markdown
Contributor

Summary

Fixes outbound email sends failing with ValueError: email.send has no recipient for reply_to.

EmailChannel._resolve_target() only consulted metadata["to"] and the inbound thread cache, so every outbound send initiated by the agent failed:

  • Message tool sends (agentos.tools.builtin.messaging) set metadata["recipient"] — never checked.
  • Scheduler/heartbeat delivery pass the recipient as reply_to (e.g. alerts@example.com) — never checked.

Change

Resolve the recipient in priority order:

  1. metadata["to"] (existing reply flow)
  2. metadata["recipient"] (message tool)
  3. thread cache lookup (existing — kept before the email-shaped reply_to so thread keys that look like addresses still resolve to the thread)
  4. reply_to when it parses as an email address (scheduler/heartbeat)

Tests

  • test_send_resolves_recipient_from_metadata_recipient — message tool path
  • test_send_resolves_recipient_from_reply_to_email_address — scheduler/heartbeat path
  • Existing thread-cache and refusal tests still pass (42 tests total in test_email_channel.py)

Fixes #598

…ply_to

EmailChannel._resolve_target only consulted metadata["to"] and the
inbound thread cache, so every outbound send failed with
"email.send has no recipient for reply_to":

- message tool sends set metadata["recipient"] (agentos.tools.builtin.messaging)
- scheduler/heartbeat delivery pass reply_to as the recipient address

Resolve the recipient from metadata["recipient"] and fall back to an
email-shaped reply_to after the thread lookup (which stays first so
thread keys that look like addresses still resolve to the thread).

Adds regression tests for both outbound paths; existing thread-cache and
refusal tests still pass.

Fixes use-agent-os#598
@s97472091-pixel

Copy link
Copy Markdown
Contributor Author

Hi @andreapn — gentle nudge whenever you have a moment: this PR is ready for review, CI green and mergeable. It is one of a small batch of focused fixes I opened today (#602, #606, #615, #626). Happy to adjust anything that does not fit. Thanks!

@andreapn

andreapn commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Thanks for the fix — three PRs landed on #598 with essentially the same resolution order (torecipient → thread cache → reply_to when it parses as an address), so I picked one and I'm closing the rest at review time rather than leaving them open.

I went with #695: same core change, plus it also fixes the adjacent subject bug (a brand-new outbound mail was getting Re: (no subject)), covers the full precedence chain in one test, and ships a CHANGELOG entry. Nothing wrong with your version — it was a timing call, not a quality one.

Sorry for the duplicated effort. Please pick up another open issue; happy to review.

@andreapn andreapn closed this Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: EmailChannel._resolve_target fails on outbound sends from message tool and scheduler delivery

2 participants