Skip to content

Use Claude Code, Codex, VSCode, Pi, and OpenCode (and 6 other harnesses) for free (1.3B+ free tokens) from your terminal, app, IDE, or phone, and now from the browser with native browser sessions (multi-harness + multi-model) like OpenClaw (voice supported + ToS friendly)

Python

Log startup model validation failures clearly

Alishahryar185232a3ccb9e
diff --git a/api/runtime.py b/api/runtime.py
index 1a179b60..698e9ee3 100644
--- a/api/runtime.py
+++ b/api/runtime.py
@@ -11,6 +11,7 @@ from fastapi import FastAPI
from loguru import logger
from config.settings import Settings, get_settings
+from providers.exceptions import ServiceUnavailableError
from providers.registry import ProviderRegistry
if TYPE_CHECKING:
@@ -61,6 +62,20 @@ def warn_if_process_auth_token(settings: Settings) -> None:
)
+def log_startup_failure(settings: Settings, exc: Exception) -> None:
+ """Log startup failures without traceback noise unless verbose diagnostics are enabled."""
+ if isinstance(exc, ServiceUnavailableError):
+ message = exc.message.strip() or "Server startup failed."
+ logger.error("Startup failed:\n{}", message)
+ return
+
+ if settings.log_api_error_tracebacks:
+ logger.error("Startup failed: {}: {}", type(exc).__name__, exc)
+ return
+
+ logger.error("Startup failed: exc_type={}", type(exc).__name__)
+
+
@dataclass(slots=True)
class AppRuntime:
"""Own optional messaging, CLI, session, and provider runtime resources."""
@@ -89,7 +104,8 @@ class AppRuntime:
await self._provider_registry.validate_configured_models(self.settings)
await self._start_messaging_if_configured()
self._publish_state()
- except Exception:
+ except Exception as exc:
+ log_startup_failure(self.settings, exc)
await best_effort(
"provider_registry.cleanup",
self._provider_registry.cleanup(),
diff --git a/tests/api/test_app_lifespan_and_errors.py b/tests/api/test_app_lifespan_and_errors.py
index 4225caa4..6c050126 100644
--- a/tests/api/test_app_lifespan_and_errors.py
+++ b/tests/api/test_app_lifespan_and_errors.py
@@ -378,6 +378,7 @@ async def test_runtime_startup_validation_blocks_messaging_and_cleans_up(tmp_pat
with (
patch.object(ProviderRegistry, "validate_configured_models", new=validation),
patch.object(ProviderRegistry, "cleanup", new=cleanup),
+ patch.object(api_runtime_mod.logger, "error") as log_error,
patch(
"messaging.platforms.factory.create_messaging_platform"
) as create_platform,
@@ -388,6 +389,12 @@ async def test_runtime_startup_validation_blocks_messaging_and_cleans_up(tmp_pat
validation.assert_awaited_once_with(settings)
cleanup.assert_awaited_once()
create_platform.assert_not_called()
+ logged = " ".join(
+ str(arg) for call in log_error.call_args_list for arg in call.args
+ )
+ assert "Startup failed" in logged
+ assert "bad model" in logged
+ assert "Traceback" not in logged
def test_app_lifespan_messaging_import_error_no_crash(tmp_path, caplog):