Skip to content

Bug: app.state.orchestrator never set in lifespan.py — POST /workflow/execute always returns 422 #2235

@mrveiss

Description

@mrveiss

Problem

app.state.orchestrator is never assigned in initialization/lifespan.py, but api/workflow.py reads it via getattr(request.app.state, "orchestrator", None). Since it's always None, the _validate_orchestrator() helper raises HTTP 422 on every request to POST /workflow/execute.

Similarly, api/agent.py accesses request.app.state.orchestrator directly (lines 787, 838, 890) — these will raise AttributeError at runtime.

Evidence

# No assignment of app.state.orchestrator anywhere in lifespan.py
grep -n "app.state.orchestrator" autobot-backend/initialization/lifespan.py
# (no output)

# But it's read in workflow.py and agent.py
grep -rn "app.state.orchestrator" autobot-backend/api/
# api/workflow.py:245:    orchestrator = getattr(request.app.state, "orchestrator", None)
# api/agent.py:787:    orchestrator = request.app.state.orchestrator
# api/agent.py:838:    orchestrator = request.app.state.orchestrator
# api/agent.py:890:    orchestrator = request.app.state.orchestrator

Discovered During

Working on #2181 (orchestrator consolidation). The LightweightOrchestrator had the same problem (never set on app.state) and was removed. The main orchestrator has the same gap.

Expected Fix

In initialization/lifespan.py, during startup:

from orchestrator import get_orchestrator
app.state.orchestrator = await get_orchestrator()

Also audit api/agent.py to use safe getattr() access.

Impact

HighPOST /workflow/execute and agent orchestration endpoints are non-functional.

Files

  • autobot-backend/initialization/lifespan.py — missing assignment
  • autobot-backend/api/workflow.py — reads app.state.orchestrator
  • autobot-backend/api/agent.py — reads request.app.state.orchestrator (3 locations)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions