Databricks environment variables not recognized when running 'make dev' with parallel execution #1614

Closed
opened 2026-02-16 17:31:45 -05:00 by yindo · 1 comment
Owner

Originally created by @simondmorias on GitHub (Sep 5, 2025).

Problem Description

When running make dev to start both the Next.js frontend and FastAPI backend in parallel, the FastAPI application fails to recognize Databricks environment variables that are correctly set in the shell. This results in a 503 error for the /api/analytics/sql/run endpoint.

Error Messages

Databricks configuration is required but not found. Please set DATABRICKS_SERVER_HOSTNAME, DATABRICKS_HTTP_PATH, and DATABRICKS_ACCESS_TOKEN environment variables to connect to your Databricks warehouse.
Failed to initialize graph runner: Databricks configuration is required but not found...
Analytics SQL service not available: SQL graph initialization failed...

Note: The error message incorrectly refers to DATABRICKS_SERVER_HOSTNAME, DATABRICKS_HTTP_PATH, and DATABRICKS_ACCESS_TOKEN when the actual environment variables are DATABRICKS_HOST, DATABRICKS_TOKEN, and DATABRICKS_SQL_WAREHOUSE_HTTP_PATH.

Environment

  • Repository: gain
  • Location: /Users/simon/repos/green/gain
  • Python: 3.12 with shared .venv at repo root
  • Servers: Next.js on port 3000, FastAPI on port 8000

Root Cause Analysis

The issue appears to be related to how make -j2 dev-web dev-api runs both servers in parallel. The FastAPI application creates a settings singleton at module import time (line 228 in components/ui/api/app/main.py):

# Get configuration settings
settings = get_api_settings()  # Creates singleton on first import

When both servers start simultaneously via parallel make, there may be a race condition or timing issue where the environment variables aren't fully available when the Python module is first imported and the singleton is created.

Verification

The environment variables ARE correctly set and work in these scenarios:

  • Running make dev-api alone (without parallel execution)
  • Running the servers in separate terminals
  • Starting uvicorn directly without the --reload flag
  • Testing the settings module directly with Python

Current Workarounds

  1. Run servers separately (recommended):

    # Terminal 1
    make dev-api
    
    # Terminal 2
    make dev-web
    
  2. Run only the API for testing:

    make dev-api
    curl http://localhost:8000/health  # Should show analytics_sql as healthy
    
  3. Export variables explicitly before make:

    export DATABRICKS_HOST=<your-host>
    export DATABRICKS_TOKEN=<your-token>
    export DATABRICKS_SQL_WAREHOUSE_HTTP_PATH=<your-path>
    make dev
    

Proposed Solutions

  1. Lazy initialization: Move the settings singleton creation from module-level to inside the lifespan function or make it lazy-loaded
  2. Fix error message: Update the error message to show the correct environment variable names
  3. Sequential startup: Modify the Makefile to start servers sequentially instead of in parallel
  4. Environment check: Add a pre-flight check in the Makefile to verify required env vars before starting

Additional Notes

  • The Pydantic settings correctly use validation_alias to map the environment variables
  • The health endpoint shows the service as healthy when started correctly
  • This issue only occurs with parallel make execution (make -j2)
Originally created by @simondmorias on GitHub (Sep 5, 2025). ## Problem Description When running `make dev` to start both the Next.js frontend and FastAPI backend in parallel, the FastAPI application fails to recognize Databricks environment variables that are correctly set in the shell. This results in a 503 error for the `/api/analytics/sql/run` endpoint. ## Error Messages ``` Databricks configuration is required but not found. Please set DATABRICKS_SERVER_HOSTNAME, DATABRICKS_HTTP_PATH, and DATABRICKS_ACCESS_TOKEN environment variables to connect to your Databricks warehouse. Failed to initialize graph runner: Databricks configuration is required but not found... Analytics SQL service not available: SQL graph initialization failed... ``` Note: The error message incorrectly refers to `DATABRICKS_SERVER_HOSTNAME`, `DATABRICKS_HTTP_PATH`, and `DATABRICKS_ACCESS_TOKEN` when the actual environment variables are `DATABRICKS_HOST`, `DATABRICKS_TOKEN`, and `DATABRICKS_SQL_WAREHOUSE_HTTP_PATH`. ## Environment - **Repository**: gain - **Location**: /Users/simon/repos/green/gain - **Python**: 3.12 with shared .venv at repo root - **Servers**: Next.js on port 3000, FastAPI on port 8000 ## Root Cause Analysis The issue appears to be related to how `make -j2 dev-web dev-api` runs both servers in parallel. The FastAPI application creates a settings singleton at module import time (line 228 in `components/ui/api/app/main.py`): ```python # Get configuration settings settings = get_api_settings() # Creates singleton on first import ``` When both servers start simultaneously via parallel make, there may be a race condition or timing issue where the environment variables aren't fully available when the Python module is first imported and the singleton is created. ## Verification The environment variables ARE correctly set and work in these scenarios: - Running `make dev-api` alone (without parallel execution) - Running the servers in separate terminals - Starting uvicorn directly without the `--reload` flag - Testing the settings module directly with Python ## Current Workarounds 1. **Run servers separately** (recommended): ```bash # Terminal 1 make dev-api # Terminal 2 make dev-web ``` 2. **Run only the API** for testing: ```bash make dev-api curl http://localhost:8000/health # Should show analytics_sql as healthy ``` 3. **Export variables explicitly before make**: ```bash export DATABRICKS_HOST=<your-host> export DATABRICKS_TOKEN=<your-token> export DATABRICKS_SQL_WAREHOUSE_HTTP_PATH=<your-path> make dev ``` ## Proposed Solutions 1. **Lazy initialization**: Move the settings singleton creation from module-level to inside the lifespan function or make it lazy-loaded 2. **Fix error message**: Update the error message to show the correct environment variable names 3. **Sequential startup**: Modify the Makefile to start servers sequentially instead of in parallel 4. **Environment check**: Add a pre-flight check in the Makefile to verify required env vars before starting ## Additional Notes - The Pydantic settings correctly use `validation_alias` to map the environment variables - The health endpoint shows the service as healthy when started correctly - This issue only occurs with parallel make execution (`make -j2`)
yindo closed this issue 2026-02-16 17:31:45 -05:00
Author
Owner

@simondmorias commented on GitHub (Sep 5, 2025):

lol - I'm not sure why it created the issue in this repo. Apologies!

@simondmorias commented on GitHub (Sep 5, 2025): lol - I'm not sure why it created the issue in this repo. Apologies!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#1614