Hmbown/CodeWhale · error

Agent Mail source and destination threads must differ

Error message

Agent Mail source and destination threads must differ

What it means

Self-mail guard in the Agent Mail send path: source_thread_id and destination_thread_id must differ, checked after request.validate(). A message a thread addresses to itself is rejected before any ownership or persistence work.

Solutions

  1. Set destination_thread_id to a different thread.
  2. Route self-directed notes through a different mechanism; Agent Mail is inter-thread by design.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/tui/src/runtime_threads.rs:6366 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/f317d9231fb6a95f. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/runtime_threads.rs:6366

        if agent_mail_looks_like_raw_transcript(&request.summary) {
            bail!("Agent Mail accepts a bounded handoff summary, not a raw transcript");
        }
        request.summary = sanitize_agent_mail_text(&request.summary, MAX_AGENT_MAIL_SUMMARY_BYTES);
        request.sender.display_label = sanitize_agent_mail_text(
            &request.sender.display_label,
            codewhale_protocol::agent_mail::MAX_AGENT_MAIL_DISPLAY_LABEL_BYTES,
        );
        for evidence in &mut request.evidence {
            if let Some(label) = evidence.label.as_mut() {
                *label = sanitize_agent_mail_text(
                    label,
                    codewhale_protocol::agent_mail::MAX_AGENT_MAIL_EVIDENCE_LABEL_BYTES,
                );
            }
        }
        request.validate().map_err(|error| anyhow!(error))?;
        if request.source_thread_id == request.destination_thread_id {
            bail!("Agent Mail source and destination threads must differ");
        }

        let source_thread = self.get_thread(&request.source_thread_id).await?;
        let destination_thread = self.get_thread(&request.destination_thread_id).await?;
        let source = agent_mail_address(&self.store.owner_id, &source_thread)?;
        let destination = agent_mail_address(&self.store.owner_id, &destination_thread)?;
        if source.owner_id != destination.owner_id
            || source.workspace_id != destination.workspace_id
        {
            bail!(
                "Agent Mail ownership denied: source and destination must belong to the same runtime owner and workspace"
            );
        }
        let expected_sender = agent_mail_sender_identity(&source_thread)?;
        if request.sender.identity != expected_sender {
            bail!(
                "Agent Mail ownership denied: sender identity does not own the source task/session"
            );

View on GitHub (pinned to 73e0f67d83)