Skip to content

hot_reload

hot_reload

Stdlib file watcher backing conductor config hot reload (#408).

Polls the config file and the instrument profile source directories for CONTENT changes (sha256, not bare mtime — survives editors' atomic rename-save and in-place rewrites that keep mtime granularity ambiguous) and funnels detected changes into the single reload path (DaemonProcess.reload_configuration → JobManager.reload_configuration).

Deliberately dependency-free (MN-005): an asyncio task on a short poll interval with a configurable debounce. Three watched directories do not justify watchdog/inotify.

Classes

ConfigWatcher

ConfigWatcher(*, config_file, profile_dirs, class_files=None, reload_fn, enabled_fn=None, debounce_fn=None, poll_interval=1.0)

Content-hash poller over the config file + profile directories.

Parameters:

Name Type Description Default
config_file Path | None

The conductor config file (None watches only profiles).

required
profile_dirs list[Path]

Instrument profile source directories — the same directories load_all_profiles reads (builtins, organization, venue). Missing directories are tracked so later creation fires.

required
reload_fn ReloadFn

Async reload entry — always the single reload path.

required
enabled_fn Callable[[], bool] | None

Live off-switch read every cycle (hot_reload.enabled).

None
debounce_fn Callable[[], float] | None

Live settle window in seconds read every cycle (hot_reload.debounce_seconds).

None
poll_interval float

Seconds between scans. Kept short so the debounce window, not the poll cadence, defines detection latency.

1.0
Source code in src/marianne/daemon/hot_reload.py
def __init__(
    self,
    *,
    config_file: Path | None,
    profile_dirs: list[Path],
    class_files: list[Path] | None = None,
    reload_fn: ReloadFn,
    enabled_fn: Callable[[], bool] | None = None,
    debounce_fn: Callable[[], float] | None = None,
    poll_interval: float = 1.0,
) -> None:
    self._config_file = config_file
    self._profile_dirs = list(profile_dirs)
    self._class_files = list(class_files or [])
    self._reload_fn = reload_fn
    self._enabled_fn = enabled_fn or (lambda: True)
    self._debounce_fn = debounce_fn or (lambda: 2.0)
    self._poll_interval = poll_interval
    self._task: asyncio.Task[None] | None = None
    self._snapshot: dict[Path, str] = {}
Methods:
start async
start()

Capture the baseline snapshot and start the poll loop.

Source code in src/marianne/daemon/hot_reload.py
async def start(self) -> None:
    """Capture the baseline snapshot and start the poll loop."""
    self._snapshot = self._scan()
    self._task = asyncio.create_task(self._run(), name="config-watcher")
stop async
stop()

Cancel the poll loop. Safe to call more than once.

Source code in src/marianne/daemon/hot_reload.py
async def stop(self) -> None:
    """Cancel the poll loop. Safe to call more than once."""
    task = self._task
    self._task = None
    if task is not None and not task.done():
        task.cancel()
        try:
            await task
        except asyncio.CancelledError:
            pass

Functions: