Files
zapret-autotune/RESOURCE_MONITOR.md
T
ZeusinaandGPT-6 Bot 4efc066625 feat: add guarded periodic resource monitoring
Add checks-only scheduling, read-only status, private authenticated persistence and guarded PID1 lifecycle. Keep strategy selection/recovery and remote fault acceptance out of scope.

Co-authored-by: GPT-6 <gpt-6@openai.com>
2026-10-13 23:33:31 +03:00

4.3 KiB

Periodic configured resource checks

managed monitor --resource-config FILE runs resource-config v1 periodically. PID 1 selects the same mode when ZAPRET_AUTOTUNE_RESOURCE_CONFIG is nonempty; unset preserves the existing YouTube monitor. The modes share one singleton lock. Supply an absolute container-visible config path (for example mount a read-only operator config directory using a Compose override). Configuration must be a regular root/runtime-owned, non-writable-by-others file without symlink/hardlink aliases. Environment references are resolved on every reload.

Each resource accepts interval_ms (default 300000) and cooldown_ms (default 30000), both integers in [100, 86400000]. Checks are sequential round robin with independent due times; tls: both requires both passes. Ordinary DNS, TLS, timeout or expectation failures mark only that resource DEGRADED and retry after its cooldown. There is no strategy selection, recovery or apply, and no no-strategy two-hour pause. HEALTHY means configured checks passed, not playback health, generic recovery or whole-production READY: HEALTHY is CHECKS_ONLY, never READY. The scheduling, status, persistence and lifecycle base is unit/fixture-verified; isolated remote fault acceptance remains pending.

Invalid resource JSON initially or after reload is BLOCKED, with no DNS or transfers until repaired. Bad static target role, proxy or DNS settings still fail startup validation; resource JSON is deliberately not part of target-config-check. Ownership and fresh source snapshots are checked before DNS and again before transfer; existing DNS/IP policy, pinned SOCKS transfers, TLS verification and private stdin are unchanged. No cached addresses bypass DNS policy. Existing zapret reconciliation remains mandatory and generic startup never consumes experimental apply requests.

State is independent of recovery SQL leases, fixed in the private target directory as .resource-monitor-state.json and .resource-monitor-key. Both are private 0600 files. Fingerprints HMAC the resolved configuration (including secrets); state is also authenticated and never contains URLs, headers, addresses or raw errors. Missing state initializes UNKNOWN. A missing key with existing state, corrupt or unsafe file is preserved and BLOCKED, never silently replaced. Restore the original key and a valid version-1 signed state from a trusted backup to repair it. The controller holds directory, key and state inode anchors: an identical signed replacement is still BLOCKED and preserved. Repair on the original held inode is reloaded only after version/MAC validation; replacing an inode requires deliberate operator repair/restart. A persistence failure pauses probes; deliberate repair requires a different valid authenticated snapshot, not just retrying a failed write. Never chmod/adopt unknown files to bypass validation. This is not isolation from a hostile same-UID actor: that actor can read the HMAC key and race filesystem publication; root/container administrators can also read private data. HMAC fingerprints protect stored secret values from unkeyed guessing, not from an actor with access to the key.

managed resource-status is read-only and reports BLOCKED or STALE explicitly (a check overdue by >65s, unknown state age >65s, or changed configuration). Idle reloads do not write a disk heartbeat: only configured state changes, BLOCKED transitions and completed checks are flushed. Cancelled checks join their children but do not change prior health, counts or completion/due times. It reads the config path from ZAPRET_AUTOTUNE_RESOURCE_CONFIG; use that environment setting also for manual monitor/status invocations. Status rows report only configured-check health.

TERM cancels/joins transfers before finalizing a completed snapshot and exits 0 on safe cleanup. PID 1 retains DNS through monitor/SS cleanup. In generic mode transient child restart-budget exhaustion pauses until the rolling window opens, rather than terminating the container. Unknown/unsafe cleanup stays BLOCKED pending operator repair/restart; no unsafe daemon sourcing is allowed. Generic cleanup shares an 80-second budget, including watchdog setup and command kill escalation, with bounded final reaping; it is designed to fit within a 90-second Docker stop limit (the supplied Compose grants 240 seconds). These changes do not claim to fix legacy YouTube exit 78.