Files
kdm-re/tools/wave/constants.py
T

51 lines
2.0 KiB
Python

"""Compute ceilings from docs/reconstruction-loop.md section 3b, as typed constants.
Every cap here cites the line in that section it encodes, so changing the
wave's compute budget means editing this file, never re-deriving a number
inline inside a dispatcher.
"""
# /// script
# requires-python = ">=3.11"
# dependencies = []
# ///
from __future__ import annotations
import os
from dataclasses import dataclass
from typing import Final
BUILD_ONCE_PER_WAVE: Final[bool] = True
"""3b: "Build recon.exe once per wave, not once per function... Rebuild only
when a source file in the wave changes." """
CONCURRENT_WINE_CAP: Final[int] = os.cpu_count() or 1
"""3b: "cap concurrent wine processes ... at roughly the core count to avoid
thrashing." Falls back to 1 when the host cannot report its core count."""
PER_FUNCTION_WALL_CLOCK_TIMEOUT_SECONDS: Final[float] = 30.0
"""3b: "Set a per-function wall-clock ceiling; a case that does not return
cleanly ... is a reconstruction or harness bug ... and should fail fast
rather than hang the wave." The section names the requirement, not a number;
this is the dispatcher's documented default and a wave may override it."""
CHEAP_FIRST_ORDERING: Final[bool] = True
"""3b: "Order a wave cheap-functions-first so a shard that blows its time
budget is one expensive function, not the whole batch." """
WINE_ENV_OVERRIDES: Final[dict[str, str]] = {"WINEDEBUG": "-all"}
"""3b: "WINEDEBUG=-all keeps per-call overhead down." """
@dataclass(frozen=True, slots=True)
class ComputeBudget:
concurrent_wine_cap: int = CONCURRENT_WINE_CAP
per_function_timeout_seconds: float = PER_FUNCTION_WALL_CLOCK_TIMEOUT_SECONDS
build_once_per_wave: bool = BUILD_ONCE_PER_WAVE
cheap_first_ordering: bool = CHEAP_FIRST_ORDERING
def __post_init__(self) -> None:
if self.concurrent_wine_cap < 1:
raise ValueError("concurrent_wine_cap must be at least 1")
if self.per_function_timeout_seconds <= 0:
raise ValueError("per_function_timeout_seconds must be positive")