Files
zapret-autotune/RESOURCE_MONITOR.md
T
ZeusinaandGPT-6 Bot cd05e75189 feat: add typed generic image and MP4 checks
Preserve strict v1 semantics and fingerprints; bind v2 typed expectations to a new proof namespace. Reuse bounded shared collection across checks, monitoring, qualification and apply health. Document prefix-only MP4 and deferred public GIF/plugin/runtime boundaries.

Co-authored-by: GPT-6 <gpt-6@openai.com>
2026-10-15 15:07:54 +03:00

93 lines
6.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Periodic configured resource checks
`managed monitor --resource-config FILE` runs resource-config v1 or v2 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 passed native full/race checks, independent security review and isolated
remote fault acceptance for `4efc066` plus ownership-status fix `5c85f3f`.
See [PROGRESS.md](PROGRESS.md) for supplied evidence and its narrow scope.
Both versions are bounded to 16 services / 64 resources with stable configured IDs;
valid configuration/state does not imply an automatic strategy assignment.
V1 remains HTTP GET/HEAD only, with explicit `kind: http`. See
`resource-check-v2.example.json` for v2: omitted kind defaults to `http`; all
expectations explicitly declare statuses/content_type/min_bytes/max_bytes.
`image` is GET-only, [200], PNG/JPEG with full bounded decode (5 MiB maximum,
16 MiPixels); public GIF is deferred pending an aggregate frame/pixel budget,
without changing legacy GIF adapters. `mp4_range` is GET-only, [206], audio/mp4
or video/mp4, 16–65536 bytes, checked Content-Range and ftyp. Range stays fixed
at 0-65535; a smaller max_bytes bounds the actual response, not the requested end.
Operator Range/Accept-Encoding headers remain forbidden in both versions.
Timeouts (100–30000 ms) and declared byte limits apply to every kind. Typed
wire-valid semantic failures degrade checks; malformed/unsafe execution cannot
qualify a candidate. V2 version/kind/expectations invalidate old HMAC rows/proofs;
historic v1 fingerprints remain unchanged. MP4 prefix health is not playback or
YouTube proof: three discovered CDNs, >=1024-byte producer samples, warmup,
suffix authorization and adaptive policy still belong to the legacy adapter.
Trusted compiled-in kind+version service modules remain a roadmap design, not an
implemented plugin API. Local v2 checks are covered by injected-wire tests;
Independent local source/closure review passed; managed remote acceptance is
still 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).
Bounded final reaps/worst-case cleanup were verified offline; measured remote
normal stops were 1.45s, 0.59s and 0.57s, not an 80-second runtime worst-case test.
These changes do not claim to fix legacy YouTube exit 78.