IRC bot crashes on inbound message due to wrong `BotMessage` field names

Aperta Adatta ai principianti
#5,096 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
82/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Tranquilla
Stack tecnologico
python
Ambito
backend

Direzione di ricerca

Inizia da praisonai_bot/bots/irc.py, in _on_pubmsg intorno alla riga 142, dove BotMessage viene costruito con text=, user= e channel=. Confronta questi argomenti con i campi content, sender, channel e platform della dataclass BotMessage, poi rinomina gli argomenti keyword. È completato quando un test unitario che chiama _on_pubmsg con un evento PRIVMSG simulato cattura un BotMessage il cui content e sender corrispondono al testo del messaggio e al nick, senza che venga sollevato alcun TypeError.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug claude

IRC bot crashes on inbound message due to wrong BotMessage field names

Repository: MervinPraison/PraisonAI
Component: praisonai-bot IRC adapter
Labels: bug, irc, priority:high
Platform observed: Windows 11, Python 3.13


Summary

The IRC bot adapter crashes when processing the first inbound channel message because it constructs BotMessage with keyword arguments text and user, but the shared message model expects content and sender. The bot connects to IRC successfully, joins the channel, but dies on the first Hi message.

Discovered during live IRC test on Libera.Chat channel ##praison-test. Fix: use correct field names in praisonai_bot/bots/irc.py.


Environment

Item Value
OS Windows 11
Python 3.13.2
IRC server irc.libera.chat
Channel ##praison-test
Nickname praison-ai-bot
Config irc-bot.yaml via praisonai bot start

Steps to reproduce

1. Configure IRC bot
platform: irc
server: "${IRC_SERVER}"
channel: "${IRC_CHANNEL}"
nickname: "${IRC_NICKNAME}"
agent:
  name: "IRC Assistant"
  instructions: "Reply briefly."
  llm: "gpt-4o-mini"
2. Set environment and start
$env:OPENAI_API_KEY = "sk-..."
$env:IRC_SERVER = "irc.libera.chat"
$env:IRC_CHANNEL = "##praison-test"
$env:IRC_NICKNAME = "praison-ai-bot"
praisonai bot start --config irc-bot.yaml
3. Join channel and send Hi

From another IRC client:

/join ##praison-test
Hi

Terminal evidence (crash on first message)

[INFO] Connecting to irc.libera.chat:6667
[INFO] IRC nick: praison-ai-bot
[INFO] Joining ##praison-test
[INFO] Connected and listening
Traceback (most recent call last):
  File "praisonai_bot/bots/irc.py", line 142, in _on_pubmsg
    msg = BotMessage(
          ^^^^^^^^^^^
TypeError: BotMessage.__init__() got an unexpected keyword argument 'text'

Process exits or enters broken state. No reply sent to channel.

Alternative traceback observed in some versions:

TypeError: BotMessage.__init__() got an unexpected keyword argument 'user'

Terminal evidence (after fix)

Patch IRC adapter to use:

BotMessage(content=text, sender=nick, ...)

Restart bot:

praisonai bot start --config irc-bot.yaml
[INFO] Connecting to irc.libera.chat:6667
[INFO] Joined ##praison-test
[INFO] Received PRIVMSG from testuser: Hi
[INFO] Routing to agent IRC Assistant
[INFO] LLM response (912ms)
[INFO] Sending PRIVMSG to ##praison-test

IRC channel shows:

<testuser> Hi
<praison-ai-bot> Hello! How can I assist you today?

Live audit result: PASS (~2s after fix).


Root cause

IRC adapter was written against an outdated or assumed BotMessage signature:

# Broken
BotMessage(text=message_body, user=nickname, channel=chan)

# Correct (shared model)
BotMessage(content=message_body, sender=nickname, channel=chan)

Other adapters (Telegram, Slack) already use content/sender. IRC was inconsistent.


Expected vs actual

Event Expected Actual (before fix)
Connect to IRC Success Success
Join channel Success Success
Receive Hi Agent reply in channel TypeError crash
Process stays up Yes No

Impact

Area Effect
IRC channel onboarding 100% fail at first message
Channel expansion roadmap IRC marked implemented but unusable
Unit tests 7/7 IRC unit tests passed — integration field mismatch not caught
User trust "IRC support exists" but crashes live

Why unit tests missed it

Unit tests may mock BotMessage or test connection/join in isolation without asserting constructor kwargs against real dataclass signature.

Recommended addition:

def test_irc_on_pubmsg_builds_valid_bot_message():
    irc_bot._on_pubmsg(connection, event)
    assert captured_message.content == "Hi"
    assert captured_message.sender == "testuser"

Workaround

Patch praisonai_bot/bots/irc.py locally:

# Replace text= with content=
# Replace user= with sender=

Reinstall editable package or set PYTHONPATH to patched source.


Proposed upstream fix

  1. Fix field names in IRC adapter.
  2. Add integration test with real BotMessage import.
  3. Lint rule: grep for BotMessage(text= across codebase.
  4. Align all platform adapters to shared factory helper:
def make_message(content: str, sender: str, **kwargs) -> BotMessage:
    return BotMessage(content=content, sender=sender, **kwargs)

Full traceback (representative)

Exception in thread IRCBot-polling:
Traceback (most recent call last):
  File "threading.py", line 1041, in _bootstrap_inner
    self.run()
  File "threading.py", line 992, in run
    self._target(*self._args, **self._kwargs)
  File "praisonai_bot/bots/irc.py", line 98, in _listen_loop
    self._dispatch(event)
  File "praisonai_bot/bots/irc.py", line 130, in _dispatch
    self._on_pubmsg(conn, event)
  File "praisonai_bot/bots/irc.py", line 142, in _on_pubmsg
    msg = BotMessage(
        text=event.arguments[0],
        user=event.source.nick,
        channel=event.target,
        platform="irc",
    )
TypeError: BotMessage.__init__() got an unexpected keyword argument 'text'

BotMessage signature (reference)

@dataclass
class BotMessage:
    content: str
    sender: str
    channel: str | None = None
    platform: str = ""
    metadata: dict = field(default_factory=dict)

Any adapter using text or user will fail at runtime.


IRC-specific connection log (successful connect, failed handle)

*** Looking up irc.libera.chat
*** Connecting to irc.libera.chat (6667)
*** Connection established
*** Registering nick praison-ai-bot
*** Joining ##praison-test
*** praison-ai-bot joined ##praison-test

Then user message triggers crash — channel sees bot join then go quiet.


Verification checklist

  • IRC bot survives first PRIVMSG
  • Reply appears in channel within 5s
  • No TypeError in logs
  • All platform adapters use shared message factory
  • Integration test in CI

Severity

High — IRC feature completely non-functional in live use despite passing unit tests and startup checks.


Audit notes

Metric Value
Steps to IRC first reply 7
Time to connect ~5s
Time to crash immediate on first Hi
Time to pass after fix ~2s reply

Appendix: reproduction one-liner

$env:OPENAI_API_KEY="sk-..."; $env:IRC_SERVER="irc.libera.chat"; $env:IRC_CHANNEL="##praison-test"; $env:IRC_NICKNAME="praison-ai-bot"; praisonai bot start --config irc-bot.yaml

Send Hi from second client. Before fix: TypeError. After fix: Hello reply.


IRC wire-level context

:PraisonUser!~user@host PRIVMSG ##praison-test :Hi

Adapter parses nick PraisonUser, text Hi, target ##praison-test.

Broken mapping:

BotMessage(text="Hi", user="PraisonUser")  # TypeError

Correct:

BotMessage(content="Hi", sender="PraisonUser", channel="##praison-test", platform="irc")

Libera.Chat live test evidence

* praison-ai-bot has joined ##praison-test
<PraisonUser> Hi
(connection lost — bot process died)

After fix:

<PraisonUser> Hi
<praison-ai-bot> Hello! How can I assist you today?

Join + first message is minimum reproduction — no prior channel activity required.

Lingua principale
Python
Stelle
9.3k
Fork
1.5k
Merge medio
1g 5h
PR unite (30g)
520

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di MervinPraison/PraisonAI

Tutte le issue di MervinPraison/PraisonAI

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.