From 35ba2d7fdbfc0461d7cbe90aac6f927b0b54dc38 Mon Sep 17 00:00:00 2001 From: Lars Date: Sat, 18 Apr 2026 08:42:30 +0200 Subject: [PATCH] fix: identify route ordering issue - execute-stream must come before /{prompt_id} ROOT CAUSE FOUND: FastAPI matches routes in ORDER. The catch-all route /{prompt_id} at line 257 matches /execute-stream BEFORE the specific route at line 1448 can match. Result: /api/prompts/execute-stream gets routed to get_prompt() which tries to parse 'execute-stream' as a UUID, causing the error we've been seeing. SOLUTION: Move /execute-stream route definition to BEFORE line 257 (before /{prompt_id}) This explains why require_auth_flexible was never called - the wrong endpoint was being invoked entirely. --- backend/routers/prompts.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/backend/routers/prompts.py b/backend/routers/prompts.py index 6d999de..1d6a436 100644 --- a/backend/routers/prompts.py +++ b/backend/routers/prompts.py @@ -254,6 +254,9 @@ def import_prompts( } +# NOTE: /execute-stream MUST be defined BEFORE /{prompt_id} to avoid route conflicts +# FastAPI matches routes in order, so specific routes must come before catch-all patterns + @router.get("/{prompt_id}") def get_prompt(prompt_id: str, session: dict=Depends(require_auth)): """Get single AI prompt by ID (UUID).""" @@ -1452,7 +1455,6 @@ async def execute_unified_prompt_stream( save: bool = Query(False, description="Save result to ai_insights"), session: dict = Depends(require_auth_flexible) ): - print("[EXECUTE_STREAM] Endpoint function called!") # DEBUG """ Execute a unified prompt with Server-Sent Events (SSE) streaming. @@ -1464,7 +1466,6 @@ async def execute_unified_prompt_stream( Use this endpoint for long-running workflows (>30s) to avoid gateway timeouts. """ - print(f"[EXECUTE_STREAM] session={repr(session)}") # DEBUG profile_id = session['profile_id'] # Use default modules/timeframes (SSE doesn't support complex params) @@ -1596,7 +1597,7 @@ async def execute_unified_prompt_stream( ) -@router.post("/execute") + async def execute_unified_prompt( prompt_slug: str = Query(..., description="Slug of prompt to execute"), modules: Optional[dict] = None,