Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions python/packages/kagent-adk/src/kagent/adk/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
kagent_url_override = os.getenv("KAGENT_URL")
sts_well_known_uri = os.getenv("STS_WELL_KNOWN_URI")
propagate_token = os.getenv("KAGENT_PROPAGATE_TOKEN")
uvicorn_log_level = os.getenv("UVICORN_LOG_LEVEL", os.getenv("LOG_LEVEL", "info")).lower()
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uvicorn_log_level is derived from LOG_LEVEL/UVICORN_LOG_LEVEL without sanitizing/normalizing beyond .lower(). If LOG_LEVEL is set to a numeric value (which Python logging accepts) or either env var is set but empty/whitespace, this will pass an invalid log_level through to uvicorn.run(). Consider .strip() plus handling numeric levels (e.g., map 20→"info") and falling back to "info" when the value is empty/invalid.

Suggested change
uvicorn_log_level = os.getenv("UVICORN_LOG_LEVEL", os.getenv("LOG_LEVEL", "info")).lower()
_raw_uvicorn_log_level = os.getenv("UVICORN_LOG_LEVEL")
if _raw_uvicorn_log_level is None:
_raw_uvicorn_log_level = os.getenv("LOG_LEVEL")
if _raw_uvicorn_log_level is None:
_raw_uvicorn_log_level = "info"
_raw_uvicorn_log_level = _raw_uvicorn_log_level.strip()
allowed_uvicorn_levels = {"critical", "error", "warning", "info", "debug", "trace"}
if not _raw_uvicorn_log_level:
uvicorn_log_level = "info"
elif _raw_uvicorn_log_level.isdigit():
# Map numeric logging levels (e.g., 20) to their textual names (e.g., "info")
numeric_level = int(_raw_uvicorn_log_level)
level_name = logging.getLevelName(numeric_level)
if isinstance(level_name, str):
level_name = level_name.lower()
uvicorn_log_level = level_name if level_name in allowed_uvicorn_levels else "info"
else:
uvicorn_log_level = "info"
else:
level_name = _raw_uvicorn_log_level.lower()
uvicorn_log_level = level_name if level_name in allowed_uvicorn_levels else "info"

Copilot uses AI. Check for mistakes.


def create_sts_integration() -> Optional[ADKTokenPropagationPlugin]:
Expand Down Expand Up @@ -90,6 +91,7 @@ def root_agent_factory() -> BaseAgent:
port=port,
workers=workers,
reload=reload,
log_level=uvicorn_log_level,
)


Expand Down Expand Up @@ -204,6 +206,7 @@ def root_agent_factory() -> BaseAgent:
host=host,
port=port,
workers=workers,
log_level=uvicorn_log_level,
)


Expand Down
Loading