Application startup and shutdown events.
(app: FastAPI)
| 119 | |
| 120 | @asynccontextmanager |
| 121 | async def lifespan(app: FastAPI): |
| 122 | """Application startup and shutdown events.""" |
| 123 | # Configure logging first |
| 124 | configure_logging() |
| 125 | intercept_standard_logging() |
| 126 | logger.info("[startup] Logging configured") |
| 127 | _log_bwrap_startup_status() |
| 128 | |
| 129 | # Warn about default JWT secrets in production |
| 130 | if "change-me" in settings.SECRET_KEY.lower() or "change-me" in settings.JWT_SECRET_KEY.lower(): |
| 131 | logger.warning( |
| 132 | "[startup] WARNING: SECRET_KEY or JWT_SECRET_KEY contains default 'change-me' value. " |
| 133 | "This is insecure for production. Set unique secrets in your .env file." |
| 134 | ) |
| 135 | |
| 136 | import asyncio |
| 137 | import sys |
| 138 | import os |
| 139 | from app.services.trigger_daemon import start_trigger_daemon |
| 140 | from app.services.tool_seeder import seed_builtin_tools |
| 141 | from app.services.template_seeder import seed_agent_templates |
| 142 | from app.services.feishu_ws import feishu_ws_manager |
| 143 | from app.services.dingtalk_stream import dingtalk_stream_manager |
| 144 | from app.services.wecom_stream import wecom_stream_manager |
| 145 | from app.services.wechat_channel import wechat_poll_manager |
| 146 | from app.services.discord_gateway import discord_gateway_manager |
| 147 | |
| 148 | if _role_enabled("all", "bootstrap"): |
| 149 | # ── Step 0: Ensure all DB tables exist (idempotent, safe to run on every startup) ── |
| 150 | try: |
| 151 | from app.database import Base, engine |
| 152 | # Import all models so Base.metadata is fully populated |
| 153 | import app.models.user # noqa |
| 154 | import app.models.agent # noqa |
| 155 | import app.models.task # noqa |
| 156 | import app.models.llm # noqa |
| 157 | import app.models.tool # noqa |
| 158 | import app.models.audit # noqa |
| 159 | import app.models.skill # noqa |
| 160 | import app.models.channel_config # noqa |
| 161 | import app.models.schedule # noqa |
| 162 | import app.models.plaza # noqa |
| 163 | import app.models.activity_log # noqa |
| 164 | import app.models.org # noqa |
| 165 | import app.models.system_settings # noqa |
| 166 | import app.models.invitation_code # noqa |
| 167 | import app.models.tenant # noqa |
| 168 | import app.models.tenant_setting # noqa |
| 169 | import app.models.participant # noqa |
| 170 | import app.models.chat_session # noqa |
| 171 | import app.models.trigger # noqa |
| 172 | import app.models.trigger_execution # noqa |
| 173 | import app.models.focus # noqa |
| 174 | import app.models.notification # noqa |
| 175 | import app.models.gateway_message # noqa |
| 176 | import app.models.agent_credential # noqa |
| 177 | import app.models.okr # noqa |
| 178 | import app.models.onboarding # noqa |
nothing calls this directly
no test coverage detected