Skip to content

Technical debt: Multiple EnhancedOrchestrator instances — no shared singleton #2207

@mrveiss

Description

@mrveiss

Problem

`EnhancedOrchestrator()` is instantiated independently in 5+ locations, each creating its own agent registry, knowledge base, and LLM interface. There is no shared singleton or dependency injection pattern.

Evidence

grep -rn "EnhancedOrchestrator()" autobot-backend/ --include="*.py" | grep -v test | grep -v e2e

Instances created in:

  1. `initialization/lifespan.py:856` — scheduler executor wiring (PR fix(orchestration): wire WorkflowExecutor into scheduler startup (#2166) #2201)
  2. `services/advanced_workflow/orchestrator.py:42` — AdvancedWorkflowOrchestrator
  3. `services/advanced_workflow/step_generator.py:43` — StepGenerator
  4. `services/workflow_automation/manager.py:54` — WorkflowAutomationManager
  5. `utils/resource_factory.py:99` — ResourceFactory (attempts to cache in app state)

Impact

Medium — Each instance has its own:

  • Agent registry: Agent health/availability not shared — one instance marks an agent degraded, others don't see it
  • Knowledge base: Separate connections, no shared cache
  • LLM interface: Separate rate limit tracking

The scheduler's orchestrator (from #2166 fix) is particularly isolated — it doesn't share agent health state with the workflow automation manager's orchestrator.

Expected Fix

Use `resource_factory.py`'s caching pattern everywhere, or introduce a proper singleton:

# Option A: Use resource_factory everywhere
from utils.resource_factory import get_enhanced_orchestrator
orchestrator = get_enhanced_orchestrator()

# Option B: Module-level singleton
# enhanced_orchestrator.py
_instance = None
def get_instance():
    global _instance
    if _instance is None:
        _instance = EnhancedOrchestrator()
    return _instance

Files

All files listed above that call `EnhancedOrchestrator()`.

Discovered During

Implementation of #2166 (scheduler wiring added yet another instance).

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions