INNER CODE UNIT · Python
_detect_context_window
mouseart2025/AI-Reader-V2 · backend/src/api/main.py:86
async def _detect_context_window() -> None:
"""Detect model context window size after settings are restored."""
try:
from src.infra.context_budget import detect_and_update_context_window
await detect_and_update_context_window()
except Exception:
pass # Don't block startup on detection failure
@asynccontextmanager
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,供续跑