Files
leleka/scripts
Pavlo RatushnyiandClaude Sonnet 5.5 55413eba07 Supervision for an unattended host: engine restarts with backoff, a hang detector, bounded logs, API limits, a hardened unit
`leleka run` restarted a crashed engine twice after a fixed 5 s and then ended the service; a hung engine, a growing log and a client
waiting on a dead engine had no answer. All of it is now in the supervisor and in what `leleka up` writes:

* Restart with backoff (config.rs RestartPolicy backoff_initial_s 5 / backoff_max_s 300, max_engine_restarts 6 in a row, reset after 600 s
  of ready): recover_engine() waits 5, 10, 20 ... s, counts a restart that fails (load refused, port taken) as an attempt and retries it
  instead of ending the service; only after the last attempt does the supervisor exit 1 and let systemd start everything afresh.
* Hang detector (watchdog.rs, pure and tested; HealthPolicy in leleka.json: interval 10 s, fail 120 s, max_request 3900 s): every 10 s the
  supervisor reads GET /metrics of the API (the control plane's own view; the engine's telemetry is not used, the API refreshes it only
  between requests). API unreachable 120 s: restart the API. Worker not ready 120 s (the API lost the engine): SIGKILL and restart the
  engine. A request active longer than 3900 s (generation_timeout 3600 + 300): the same. A stopped (SIGSTOP) or deadlocked engine ends this way.
* Requests get an error, not a hang: strata.json now carries runtime.stall_timeout_s 600 (no engine event for 10 min during a request cancels
  it with an error to the client) and generation_timeout_s 3600 (RequestLimits in leleka.json).
* Bounded logs (logs.rs): every 10 s the supervisor copy-truncates any STATE/logs/*.log past 16 MiB, keeps 3 generations (children keep
  their O_APPEND descriptors, nothing is told); <= 16 x 4 x 6 files; one 16 MiB copy per rotation. tail_of reads only the last 256 KiB.
* Status file: started_unix, restarts_total, last_restart_unix/reason, health, log_bytes; rewritten every 30 s as a heartbeat.
* units.rs (and scripts/ops/leleka.service, a test pins the file to the generator for the server layout): StartLimitIntervalSec=0 with
  RestartSteps/RestartMaxDelaySec (30 s growing to 10 min), LimitCORE=0 (a 100 GB core dump must not hit the root NVMe), LimitNOFILE,
  TasksMax, OOMScoreAdjust=-500 (system scope), journal rate limit, RequiresMountsFor, TimeoutStopSec 180, and ConditionPathExists=!STATE/lab-mode
  so the unit stays down while the GPU belongs to the lab queue.
* Tests (fake runtime, no GPU): a reported hang kills and replaces the engine; restarts back off, a start that fails twice and then works is
  just a slower restart, three failures in a row end the service with a message; an oversize log is rotated while the service runs; the
  existing lifecycle tests (SIGKILL of the engine, SIGTERM drain) still pass. 134 unit tests.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-02 20:55:25 +01:00
..