Skip to content

Bug: In-memory prompt sessions lost in multi-worker deployments #5

Description

@AdityaPatil22

Description

In Backend/app/routes/fix.py, the prompt session cache (_prompt_sessions) is stored in a plain Python dictionary:

_prompt_sessions: dict[str, dict] = {}

This is used by the browser-local LLM flow:

  1. POST /generate-prompt → stores context in _prompt_sessions and returns a session_id
  2. POST /build-patches → retrieves context using the session_id

Impact

In a production deployment with multiple workers (gunicorn, uvicorn with --workers > 1), step 1 might hit Worker A and step 2 might hit Worker B. Since the dict is per-process, Worker B won't find the session and returns a 404 error: "Prompt session expired or not found."

This also means sessions are lost entirely on server restart (e.g., during Railway deployments).

Steps to Reproduce

  1. Deploy with uvicorn main:app --workers 4
  2. Call POST /api/generate-prompt → receive session_id
  3. Call POST /api/build-patches with that session_id
  4. Observe intermittent 404 errors (~75% of the time with 4 workers)

Expected Behavior

Use a shared session store (Redis, database, or a shared-memory approach) that persists across workers. Alternatively, return all necessary context in the /generate-prompt response and pass it back in /build-patches (stateless design).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions