feat: add candidate-bound domain qualification and planning
Co-authored-by: GPT-6 <gpt-6@openai.com>
This commit is contained in:
1 parent
2242643000
commit
573da3f797
15 files changed
+2486
-10
No files matched your search
@@ -18,6 +18,16 @@ dns_mode=$(/usr/local/bin/zapret-autotune dns-forwarder mode) || exit 64
|
||||
dns_address=$(/usr/local/bin/zapret-autotune dns-forwarder address) || exit 64
|
||||
generic_mode=0
|
||||
[ -z "${ZAPRET_AUTOTUNE_RESOURCE_CONFIG-}" ] || generic_mode=1
|
||||
qualification_mode=0
|
||||
qualification_attempted=0
|
||||
if [ -n "${ZAPRET_AUTOTUNE_QUALIFY_CONFIG-}${ZAPRET_AUTOTUNE_STRATEGY_CONFIG-}" ]; then
|
||||
[ -n "${ZAPRET_AUTOTUNE_QUALIFY_CONFIG-}" ] && [ -n "${ZAPRET_AUTOTUNE_STRATEGY_CONFIG-}" ] || {
|
||||
echo 'error: isolated qualification requires both config and strategy paths' >&2; exit 64;
|
||||
}
|
||||
qualification_mode=1
|
||||
generic_mode=1
|
||||
echo 'INTRUSIVE ISOLATED qualification target: do not route working traffic here' >&2
|
||||
fi
|
||||
case "$dns_mode" in doh|native) ;; *) exit 64 ;; esac
|
||||
config_dir=/run/zapret-autotune-ss
|
||||
awk '$2 == "/run/zapret-autotune-ss" && $3 == "tmpfs" { found=1 } END { exit !found }' /proc/mounts || {
|
||||
@@ -196,9 +206,15 @@ cleanup_cycle() {
|
||||
if [ -n "$monitor_pid" ]; then
|
||||
capture_monitor_session || cleanup_code=78
|
||||
kill -TERM "$monitor_pid" 2>/dev/null || true
|
||||
bounded_wait "$monitor_pid" 45
|
||||
if [ "$qualification_mode" -eq 1 ]; then bounded_wait "$monitor_pid" 75; else bounded_wait "$monitor_pid" 45; fi
|
||||
# Cancellation must restore safely even when SS failure requested retry.
|
||||
case "$waited_code" in 0|143) ;; *) echo "error: monitor cleanup status $waited_code" >&2; cleanup_code=78 ;; esac
|
||||
if [ "$qualification_mode" -eq 1 ]; then
|
||||
# Exit 78 is an outcome only with a producer-owned completed-cleanup
|
||||
# ACK and a fresh baseline/worker/nft check, while SS+DNS still live.
|
||||
cleanup_command 10 /usr/local/bin/zapret-autotune qualification-completion-check "$monitor_pid" "$waited_code" || cleanup_code=78
|
||||
else
|
||||
case "$waited_code" in 0|143) ;; *) echo "error: monitor cleanup status $waited_code" >&2; cleanup_code=78 ;; esac
|
||||
fi
|
||||
[ "$join_timed_out" -eq 0 ] || { echo 'error: monitor join timeout' >&2; cleanup_code=78; }
|
||||
# SIGTERM may have arrived before the launch acknowledgement was read.
|
||||
capture_monitor_session || cleanup_code=78
|
||||
@@ -310,6 +326,7 @@ start_dns() {
|
||||
done
|
||||
}
|
||||
run_cycle() {
|
||||
[ "$qualification_attempted" -eq 0 ] || return 78
|
||||
start_dns || return $?
|
||||
set -- ss-server -c "$config_dir/server.json"
|
||||
# DNS is not a secret. Native -d avoids assuming support for a JSON DNS key.
|
||||
@@ -338,8 +355,10 @@ fi
|
||||
# Never activate pending or unknown bytes. Any reconciliation failure is fatal,
|
||||
# not a transient (75) restart request. Reload restores known bytes first.
|
||||
timeout -k 5 45 /usr/local/bin/zapret-autotune managed reconcile || return 78
|
||||
if [ "$qualification_mode" -eq 0 ]; then
|
||||
zapret_started=1
|
||||
timeout -k 5 30 /opt/zapret2/init.d/sysv/zapret2 start || return 78
|
||||
fi
|
||||
|
||||
# Private operator request, consumed only after a successful guarded transaction.
|
||||
# Never suppress qualification gates globally or race the owned monitor.
|
||||
@@ -352,7 +371,13 @@ fi
|
||||
# startup before its cancellation handler exists. Clean this cycle directly.
|
||||
{ dns_alive && kill -0 "$server_pid" 2>/dev/null && kill -0 "$local_pid" 2>/dev/null; } || return 75
|
||||
rm -f "$config_dir/monitor-ready"
|
||||
setsid /bin/sh /opt/managed-target-supervision.sh --monitor "$config_dir" /usr/local/bin/zapret-autotune managed monitor 8<&- 9<&- &
|
||||
if [ "$qualification_mode" -eq 1 ]; then
|
||||
qualification_attempted=1
|
||||
set -- qualify --config "$ZAPRET_AUTOTUNE_QUALIFY_CONFIG" --strategies "$ZAPRET_AUTOTUNE_STRATEGY_CONFIG" --isolated
|
||||
else
|
||||
set -- managed monitor
|
||||
fi
|
||||
setsid /bin/sh /opt/managed-target-supervision.sh --monitor "$config_dir" /usr/local/bin/zapret-autotune "$@" 8<&- 9<&- &
|
||||
monitor_pid=$!
|
||||
monitor_ack_deadline=$(($(date +%s) + 5))
|
||||
while [ ! -e "$config_dir/monitor-ready" ]; do
|
||||
@@ -372,6 +397,18 @@ done
|
||||
if ! kill -0 "$monitor_pid" 2>/dev/null; then
|
||||
code=0
|
||||
wait "$monitor_pid" || code=$?
|
||||
if [ "$qualification_mode" -eq 1 ]; then
|
||||
if ! timeout -k 1 10 /usr/local/bin/zapret-autotune qualification-completion-check "$monitor_pid" "$code"; then
|
||||
generic_cleanup_failed=1
|
||||
fi
|
||||
monitor_pid=
|
||||
# One finite batch only, including negative/blocked completion. No live
|
||||
# daemon and no automatic retest. Keep owned SS/DoH alive for inspection.
|
||||
echo "isolated qualification finished (status $code); target safe-idle" >&2
|
||||
cleanup_session || return 78
|
||||
while dns_alive && kill -0 "$server_pid" && kill -0 "$local_pid"; do pause 1; done
|
||||
return 78
|
||||
fi
|
||||
monitor_pid=
|
||||
echo 'error: target managed monitor exited' >&2
|
||||
case "$code" in
|
||||
|
||||
Reference in new issue
Block a user