INNER CODE UNIT · Python
lifespan
mouseart2025/AI-Reader-V2 · backend/src/api/main.py:96
async def lifespan(app: FastAPI):
await init_db()
await _restore_persisted_settings()
await _detect_context_window()
await auto_import_samples()
# Recover tasks left in 'running' state from a previous server session
await recover_stale_tasks()
# 同理恢复二审 pass(multi-pass Epic 2): running → paused,供续跑
await recover_stale_passes()
yield
app = FastAPI(title="AI Reader V2", version=BACKEND_VERSION, lifespan=lifespan)
class SidecarAuthMiddleware:
"""V-01 修复:配置了 sidecar 令牌时,/api/* 与 /ws/* 一律要求鉴权。