Skip to content

Emitter: compiled regex matchers only match from the start of the event path (should match anywhere) #1556

Description

@Osamaali313

Summary

A compiled-regex event listener only fires when the pattern matches from the start of the event path, so patterns meant to match a path segment never match.

Details

Emitter._create_matcher (python/beeai_framework/emitter/emitter.py) handles the re.Pattern case with:

matchers.append(lambda event: matcher.match(event.path) is not None)

re.Pattern.match is anchored at the start of the string. The TypeScript sibling uses matcher.test() (search anywhere), and the shipped example does:

emitter.on(re.compile(r"watsonx"), ...)   # examples/emitter/matchers.py

which is intended to match an event path like backend.watsonx.chat.start. With .match() it never fires.

Reproduction

import asyncio, re
from beeai_framework.emitter import Emitter, EmitterOptions

async def main():
    root = Emitter.root(); hits = []
    root.on(re.compile(r"watsonx"), lambda _, e: hits.append(e.path), EmitterOptions(match_nested=True))
    await root.child(namespace=["backend", "watsonx", "chat"]).emit("start", 1)
    print(hits)   # [] — expected ["backend.watsonx.chat.start"]

asyncio.run(main())

Expected

A compiled regex matches anywhere in the event path (like the TS .test()), so the listener fires.

Fix

Use matcher.search() instead of matcher.match() (.search is a superset of .match, so anchored patterns still match). PR to follow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions