Skip to content

[Bug]: /ask Q&A endpoint returns null due to duplicate ask_question function declaration #586

Description

@Sandeep6135

Summary

Summary

The endpoint handler for the /ask route in main.py is declared twice consecutively under the function name ask_question.
The first declaration (lines 3388-3389) is decorated with @app.post("/ask") but only performs session cleanup and returns nothing. The second declaration (starting at line 3392) contains the actual Q&A/inference implementation but has no route decorator.
In Python, redeclaring a function in the same scope overrides the previous name in the namespace. However, FastAPI registers the first decorated function during application startup. When a client calls /ask, FastAPI routes the request to the first (empty) implementation, which returns None/null to the client. The actual Q&A logic is unreachable and behaves as dead code.

Steps to reproduce

Steps to Reproduce

  1. Start the backend RAG service and the Express gateway.
  2. Upload a PDF and submit a question using the chat input.
  3. Observe that the API returns 200 OK but a body of null (or empty JSON).
  4. Inspect the RAG service logs: the Q&A pipeline and model inference never execute.

Expected behavior

Expected Behavior

The /ask endpoint should parse the question, verify the session secret, invoke the LLM model, and return a JSON response containing answer, sources, and mode.

Actual behavior

Actual Behavior

The endpoint returns null with a 200 OK status code, completely bypassing the question-answering logic.

Additional context

Additional Context

The duplicate function declaration in main.py:

@app.post("/ask")
def ask_question(data: Question, _ready: None = Depends(require_models_ready)):
    cleanup_expired_sessions()
def ask_question(data: Question):
    question = (data.question or "").strip()

Metadata

Metadata

Assignees

Labels

backendExpress or API gateway workbugSomething isn't workingduplicateThis issue or pull request already existsenhancementNew feature or requestfeatureA new feature or improvementfixA targeted fix or cleanupfrontendFrontend-related workquestionFurther information is requestedrag-serviceFastAPI / model service work

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions