Root cause: ensure_structured_column() executed a synchronous blocking
engine.connect().execute(SELECT information_schema.columns ...) inside the
async request path (_build_chat_history / _maybe_compress_history), freezing
the uvicorn event loop and hanging all endpoints (~200s, recovered only by
docker restart).
Fix:
- chat_context.py: remove per-request ensure_structured_column() calls; run
once idempotently at app startup (main.py lifespan). Use CURRENT_DATABASE()
for PostgreSQL compatibility.
- main.py: add startup-only ensure_structured_column() hook (try/except).
- llm_client.py: trust_env=False + bounded httpx.Timeout/wait_for so broken
endpoints fail fast instead of hanging the event loop.
- chat_service.py: run media generation in a background daemon thread with its
own event loop (_launch_media_task_bg) so SSE end does not cancel image/video
tasks (#811); remove TEMP faulthandler diagnostic.
Safe-align: persist accumulated live container changes (admin/*, knowledge,
market, models, config, observability, mcp_client, platform_knowledge,
im_bot_platform, chat_media, capability_registry, requirements) and add
workflow_templates.
Verified: live failover test (model-006 -> conn-refused) returns in ~1.9s with
concurrent login 0.83s/200; event-loop responsiveness restored (sub-second).
Recovers 7 model classes (UserStorageQuota, AutomatedTask, ExternalKBService,
KnowledgeDocumentChunk, MCPServer, OSSStorageConfig, TaskExecutionLog) and the
gen_uuid helper that were lost in the mass file-deletion (5d7f32d). These are
required by the restored admin modules (storage_admin/asset_admin/etc). Verified
at runtime: /health=200 and all restored admin routers serve 200.
Backend:
- Add OSSStorageConfig model (models.py)
- Create storage_admin.py API (9 endpoints): stats, CRUD, toggle, set-default, test connection
- Register route /app/api/admin/storage in main.py
- Create oss_storage_configs table in MySQL
Frontend:
- Add Storage.tsx admin page (713 lines) with stats, table, create/edit modal
- Register /admin/storage route in App.tsx
- Add nav item and icon in AdminLayout.tsx
- Add 9 API methods in api/index.ts