iflytek/astron-agent · error · ValueError

LOG_PATH_KEY is not set

Error message

LOG_PATH_KEY is not set

What it means

spark_link_app reads const.LOG_PATH_KEY from the environment and raises ValueError when it is unset or empty, because the log file path is required to configure logging (via configure(...)) before the app and database are initialized.

Solutions

  1. Set LOG_PATH_KEY's underlying env var (e.g. LOG_PATH=logs/spark_link.log) before starting the server
  2. Ensure the path is writable relative to the app root (log_path is joined with Path(__file__).parent.parent)
  3. Add the variable to the deployment env_file / k8s env section
  4. Optionally provide a default log path in code if unset logging is acceptable

Example fix

// before
# container env has no LOG_PATH
ValueError: LOG_PATH_KEY is not set
// after
# docker-compose.yml
environment:
  - LOG_PATH=logs/link.log
  - LOG_LEVEL=INFO
Defensive patterns

Strategy: validation

Validate before calling

import os
assert os.getenv('LOG_PATH'), 'LOG_PATH must be set before starting the app'

Try / catch

try:
    application = spark_link_app()
except ValueError as e:
    print(f'App factory failed: {e}; ensure LOG_PATH is configured')
    raise SystemExit(1)

Prevention

When it happens

Trigger: Creating the FastAPI app (start_uvicorn -> spark_link_app, or importing `app`) while LOG_PATH_KEY is missing from the environment — uvicorn's app factory fails during startup.

Common situations: Deploying without the logging env var defined in the manifest; .env not loaded before uvicorn starts; a typo/renamed log-path variable; empty string set in container config which passes os.getenv but not the truthiness check.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12). Data as JSON: /api/errors/c9f6bde578cafb4c. Report an issue: GitHub.

Appendix: source

Thrown at core/plugin/link/app/start_server.py:143

            port=int(service_port),
            workers=20,
            reload=False,
            log_config=None,
        )
        uvicorn_server = uvicorn.Server(uvicorn_config)
        uvicorn_server.run()


def spark_link_app() -> FastAPI:
    """
    Create Spark Link app.

    Returns:
        FastAPI: The configured FastAPI application instance
    """
    log_path = os.getenv(const.LOG_PATH_KEY)
    if not log_path:
        raise ValueError("LOG_PATH_KEY is not set")
    configure(
        os.getenv(const.LOG_LEVEL_KEY),
        Path(__file__).parent.parent / log_path,
    )

    init_data_base()

    # Run database migration before starting the service
    from extensions.database_migration import run_database_migration

    run_database_migration()

    load_create_tool_schema()
    load_update_tool_schema()
    load_http_run_schema()
    load_tool_debug_schema()
    load_mcp_register_schema()
    spark_link_init_sid()

View on GitHub (pinned to 5e758547a8)