Skip to content

[BUG] HOST, PORT and UVICORN_WORKERS are ignored when set in .env #41

Closed

Description

@Nitjsefnie

Bug Description

HOST, PORT and UVICORN_WORKERS are read by cmd_serve in devops_agent/cli.py, but that module never calls load_dotenv(). The only load_dotenv() on the serve path lives in api/server.py, which uvicorn imports from the string "api.server:app" — i.e. after cmd_serve has already read the three values. So setting them in .env has no effect; they must be exported into the environment.

.env.example gives no hint of this, so the three read as ordinary configurable settings.

Steps to Reproduce

  1. Put HOST=203.0.113.7, PORT=7777 and UVICORN_WORKERS=9 in .env and nothing in the shell environment
  2. Run devops-agent serve
  3. Observe the address, port and worker count the server binds with

Expected Behavior

Values in .env are honoured, as they are for every other setting the project documents there.

Actual Behavior

All three are ignored and the hardcoded defaults win:

running: devops-agent serve

uvicorn.run() reached. The server would bind:
   host    = '127.0.0.1'
   port    = 8000
   workers = 2
(CLI exited with code 0)

os.environ['HOST'] after the serve path: None

--- control: import api.server, which DOES call load_dotenv() (line 35) ---
os.environ['HOST'] after importing api.server: '203.0.113.7'

The control matters: the same .env file is honoured the moment api.server is imported, so the file is well-formed and loadable and this is purely an import-ordering defect rather than a broken fixture.

Reproduced by driving the real devops_agent.cli.main() with real argv devops-agent serve; only uvicorn.run was stubbed. None of the three variables was set in the ambient shell — confirmed before the run.

Expected vs actual, by line (on main)

  • devops_agent/cli.py — no import dotenv and no load_dotenv anywhere in the file
  • devops_agent/cli.py:18-20 — the three os.getenv reads, inside cmd_serve (:14)
  • devops_agent/cli.py:26 — uvicorn.run(...), after the reads
  • api/server.py:13 imports load_dotenv, :35 calls it — too late for the three above

Environment

  • OS: Debian 13
  • Python Version: 3.13.14
  • Agent Version/Commit: ace3dc21ba2ee58ef748b39a31f7ec6049bd6d88 (main)
  • Deployment Method: local
  • Platform: n/a — reproduces from the CLI alone

Configuration

HOST=203.0.113.7
PORT=7777
UVICORN_WORKERS=9

Additional Context

Found while documenting environment variables for #15. That PR documents the caveat rather than changing behaviour, since a fix alters how the server starts.

Possible Solution

Unverified: calling load_dotenv() near the top of devops_agent/cli.py, before cmd_serve reads the environment, would make the three behave like every other documented setting. Worth checking it does not disturb the ordering api/server.py relies on.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions