Skip to content

fix: thread title leaks @(role) placeholder from resolve_mentions() #372

@thepagent

Description

@thepagent

Problem

When a user triggers the bot via role mention, the thread title shows @(role) prefix instead of a clean title.

Discord message: "@AgentBroker HIHI intro yourself"
Raw content:     "<@&123456> HIHI intro yourself"
                      │
                      ▼
              resolve_mentions()
              ┌─────────────────────────────────┐
              │ Role mentions → "@(role)"        │ ◄── replaces <@&ID> with literal "@(role)"
              └─────────────────────────────────┘
                      │
                      ▼
              prompt = "@(role) HIHI intro yourself"
                      │
          ┌───────────┴───────────┐
          ▼                       ▼
   sent to agent            shorten_thread_name()
   (fine for LLM)           ┌──────────────────┐
                             │ ❌ Does NOT strip │
                             │ "@(role)" prefix  │
                             └──────────────────┘
                                      │
                                      ▼
                      thread title = "@(role) HIHI intro yourself"
                                      ❌

Fix

Strip placeholders in shorten_thread_name():

fn shorten_thread_name(prompt: &str) -> String {
    let cleaned = prompt.replace("@(role)", "").replace("@(user)", "");
    let re = regex::Regex::new(r"https?://github\.com/([^/]+/[^/]+)/(issues|pull)/(\d+)").unwrap();
    let shortened = re.replace_all(cleaned.trim(), "$1#$3");
    let name: String = shortened.chars().take(40).collect();
    if name.len() < shortened.len() {
        format!("{name}...")
    } else {
        name
    }
}
              AFTER FIX
              ─────────
              prompt = "@(role) HIHI intro yourself"
                      │
                      ▼
              shorten_thread_name()
              ┌──────────────────────────┐
              │ .replace("@(role)", "")  │ ◄── NEW
              │ .replace("@(user)", "")  │ ◄── NEW
              └──────────────────────────┘
                      │
                      ▼
              thread title = "HIHI intro yourself"
                              ✅

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions