Skip to content

[BUG] Nasty side effect in hook before_cat_sends_message #1043

Open
@pieroit

Description

@pieroit

If you call cat.llm from within the before_cat_sends_message hook, model interactions are not saved in the final CatMessage.why.model_interactions. Example:

@hook
def before_cat_sends_message(mex, cat):

    joke = cat.llm("Tell me a joke about da police")
    mex.text += joke

    return mex

The LLM is actually used and the joke added to the reply, but since MadHatter.execute_hook stores the original CatMessage and passes to each hook a deepcopy of it, when the second is returned and overwritten on the first, some info gets lost.

This only happens in hooks having side effects on the same data structure passed by argument to the hook.
The example above does not incur in the same bug with other hooks.

A possible solution is to avoid deepcopying the hook argument?
It was there to avoid side effects in the first place XD.

Also, this kind of stuff should be heavily tested, at the MadHatter class level tests.

Nasty one

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghooksMake the cat extensible via plugins hooksmad hatterRelated to the plugin system

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions