Skip to content

bug: Proactive message fails with NoneType error when owner email is NULL #372

Closed

Description

@vybe

Summary

Proactive messaging via Telegram fails with HTTP 500 when the agent owner's email is NULL in the database. The can_agent_message_email function calls .lower() on a None value, causing an AttributeError. This blocks all proactive messaging for agents whose owners have NULL email fields.

Component

Backend / Database / Agent Sharing

Priority

P1

Error

AttributeError: 'NoneType' object has no attribute 'lower'

File "/app/routers/messages.py", line 98, in send_proactive_message
    result = await proactive_message_service.send_message(
File "/app/services/proactive_message_service.py", line 186, in send_message
    if not db.can_agent_message_email(agent_name, recipient_email):
File "/app/database.py", line 397, in can_agent_message_email
    return self._agent_ops.can_agent_message_email(agent_name, email)
File "/app/db/agent_settings/sharing.py", line 206, in can_agent_message_email
    if owner_user and owner_user.get("email", "").lower() == email.lower():
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'lower'

Location

  • File: src/backend/db/agent_settings/sharing.py
  • Line: 206
  • Function/Class: can_agent_message_email

Root Cause

The code uses owner_user.get("email", "") expecting an empty string as default when email is missing. However, .get() only returns the default when the key is absent - when the key exists but the value is NULL/None, it returns None. Calling .lower() on None raises AttributeError.

Reproduction Steps

  1. Have an agent whose owner has a NULL email field in the users table
  2. Agent attempts to send a proactive message (e.g., via Telegram)
  3. Backend returns HTTP 500
  4. Check logs: AttributeError on .lower() call

Suggested Fix

Use or "" pattern to handle both missing keys and NULL values:

# In db/agent_settings/sharing.py line 206
# BEFORE:
if owner_user and owner_user.get("email", "").lower() == email.lower():

# AFTER:
owner_email = owner_user.get("email") or ""
if owner_user and owner_email.lower() == email.lower():

Or inline:

if owner_user and (owner_user.get("email") or "").lower() == email.lower():

Environment

  • Trinity version: 4bde5d5
  • Docker version: 24.x
  • OS: Ubuntu 22.04

Related

  • src/backend/db/agent_settings/sharing.py
  • src/backend/services/proactive_message_service.py
  • src/backend/routers/messages.py

Activity

  1. added
    priority-p1
    type-bug
    status-in-progress
    on Apr 17, 2026
  2. added a commit that references this issue on Apr 17, 2026
    d961621
  3. added
    complexity-low
    on Jun 3, 2026
  4. removed
    status-in-progress
    on Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    complexity-lowpriority-p1type-bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions