main
md 62 lines 3.68 KB
Rendered Raw
1 # server_startup.py DOX
2
3 ## Purpose
4
5 - Own the `server_startup.py` helper module.
6 - This module runs Uvicorn startup with health checks and retry tracking.
7 - Keep this file-level DOX profile synchronized with `server_startup.py` because this directory is intentionally flat.
8
9 ## Ownership
10
11 - `server_startup.py` owns the runtime implementation.
12 - `server_startup.py.dox.md` owns durable notes about responsibilities, contracts, side effects, and verification for that implementation.
13 - Classes:
14 - `StartupConfig` (no explicit base class)
15 - `from_env(cls) -> 'StartupConfig'`
16 - `StartupStageRecord` (no explicit base class)
17 - `StartupMonitor` (no explicit base class)
18 - `mark(self, stage: str, detail: str | None=...) -> None`
19 - `stage(self, stage: str, detail: str | None=...) -> Iterator[None]`
20 - `lifespan(self)`
21 - `attach_server(self, server: uvicorn.Server) -> None`
22 - `start_watchdog(self) -> None`
23 - `mark_ready(self, source: str=...) -> None`
24 - `is_ready(self) -> bool`
25 - `close(self) -> None`
26 - `_UvicornServerWrapper` (no explicit base class)
27 - `shutdown(self) -> None`
28 - Top-level functions:
29 - `_env_int(name: str, default: int, minimum: int=...) -> int`
30 - `_env_float(name: str, default: float, minimum: float=...) -> float`
31 - `get_health_probe_host(bind_host: str) -> str`
32 - `run_uvicorn_with_retries(host: str, port: int, build_asgi_app: Callable[[StartupMonitor], object], flush_callback: Callable[[str], None], access_log: bool=..., log_level: str=..., ws: str=..., startup_config: StartupConfig | None=...) -> None`
33 - `_run_server_attempt(host: str, health_host: str, port: int, startup_monitor: StartupMonitor, build_asgi_app: Callable[[StartupMonitor], object], flush_callback: Callable[[str], None], access_log: bool, log_level: str, ws: str) -> bool`
34 - `wait_for_health(host: str, port: int, startup_monitor: StartupMonitor) -> None`
35 - `_serve_uvicorn(server: uvicorn.Server) -> None`
36
37 ## Runtime Contracts
38
39 - Helper modules own reusable framework APIs and must preserve public callers unless all callers, tests, and docs are updated together.
40 - Update this file whenever public functions, classes, persistence behavior, path/security assumptions, side effects, or cross-module contracts change.
41 - Observed side-effect areas: filesystem writes, network calls, subprocess/runtime control, settings/state persistence.
42 - Imported dependency areas include: `asyncio`, `collections`, `contextlib`, `dataclasses`, `faulthandler`, `helpers`, `helpers.print_style`, `os`, `sys`, `threading`, `time`, `typing`, `urllib.request`, `uvicorn`.
43
44 ## Key Concepts
45
46 - Important called helpers/classes observed in the source: `dataclass`, `get_health_probe_host`, `PrintStyle.debug`, `RuntimeError`, `startup_monitor.start_watchdog`, `server.config.get_loop_factory`, `cls`, `time.monotonic`, `deque`, `threading.Event`, `threading.RLock`, `self.mark`, `threading.Thread`, `self._watchdog_thread.start`, `self._ready.is_set`, `self.snapshot`, `PrintStyle.error`, `join`, `StartupConfig.from_env`, `StartupMonitor`.
47 - Keep request/response, tool, or helper semantics documented here at the same time as source changes.
48
49 ## Work Guidance
50
51 - Preserve public helper APIs used by core code and plugins unless every caller is updated.
52 - Keep path, auth, secret, persistence, network, and subprocess behavior explicit and bounded.
53 - Prefer adding cohesive helper functions here only when behavior is reused across modules.
54
55 ## Verification
56
57 - Run targeted tests for changed helper behavior; run security regressions for auth, filesystem, WebSocket, tunnel, upload, or secret-handling helpers.
58 - No direct test reference was found by name search; choose the nearest behavioral test or perform a focused smoke check.
59
60 ## Child DOX Index
61
62 No child DOX files.