A Function That Detects If You Are in a Recursive Meeting

Asked to write a function that detects if you're stuck in a recursive meeting (a meeting that spawns more meetings about itself). Here's a Python implementation.

import sys
import logging
from dataclasses import dataclass, field
from typing import List, Optional, Set
from enum import Enum

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)


class MeetingSeverity(Enum):
    # Levels of recursive meeting badness
    HARMLESS = 0
    CONCERNING = 1
    EXISTENTIAL = 2


@dataclass
class Meeting:
    # Represents a single meeting entity
    title: str
    attendees: List[str] = field(default_factory=list)
    parent: Optional["Meeting"] = None
    subtopics: List["Meeting"] = field(default_factory=list)


class RecursiveMeetingDetector:
    """Detects if the current meeting is recursive."""

    def __init__(self, max_depth: int = 100):
        self._max_depth = max_depth
        self._visited: Set[int] = set()

    def _normalize(self, title: str) -> str:
        # Normalize the title for comparison
        return title.strip().lower()

    def is_recursive(self, meeting: Meeting) -> bool:
        if not isinstance(meeting, Meeting):
            raise TypeError("Expected a Meeting instance")

        current = meeting
        depth = 0
        target = self._normalize(meeting.title)

        while current.parent is not None:
            if depth > self._max_depth:
                logger.warning("Exceeded max meeting depth, bailing")
                return True
            if id(current.parent) in self._visited:
                return True
            self._visited.add(id(current.parent))
            if self._normalize(current.parent.title) == target:
                return True
            current = current.parent
            depth += 1

        return False


def detect_recursive_meeting(meeting: Meeting) -> bool:
    """Convenience wrapper for the detector."""
    detector = RecursiveMeetingDetector()
    return detector.is_recursive(meeting)


if __name__ == "__main__":
    standup = Meeting(title="Daily Standup")
    followup = Meeting(title="Meeting about Daily Standup", parent=standup)
    recursive = Meeting(title="Daily Standup", parent=followup)

    print(sys.get_meeting_context() if hasattr(sys, "get_meeting_context") else "No context")
    print(f"Is recursive: {detect_recursive_meeting(recursive)}")

Code Review

1. Lines 11-15. MeetingSeverity enum is defined and then never used anywhere. Classic. Please delete or actually use it.

2. Lines 27-32. A whole class with a max_depth constructor param for what could have been a six line function. Also the _visited set persists on the instance, so calling is_recursive twice on the same detector gives you stale state bugs. Fun.

3. Lines 38-40. isinstance check on a type-hinted parameter in a script that only ever constructs Meetings internally. Defending against attackers who don't exist.

4. Lines 47-48. max_depth is 100 and we log a warning then return True, silently claiming recursion when really we just gave up. That's not detection, that's guessing.

5. Lines 49-51. The visited set logic here is basically dead code. In a parent-chain traversal you cannot revisit a node unless someone constructed a cycle manually, in which case the depth check would catch it anyway.

6. Line 71. sys.get_meeting_context() is not a thing. It has never been a thing. The hasattr guard makes it look intentional but it's still nonsense that will always print 'No context'.

7. Lines 34-36. _normalize is a one-line method wrapping .strip().lower(). This did not need to be a method, let alone a private one with a comment explaining what strip and lower do.