diff --git a/bin/fm-jev.sh b/bin/fm-jev.sh index 2ff9153b429..30cbdc2652c 100755 --- a/bin/fm-jev.sh +++ b/bin/fm-jev.sh @@ -98,13 +98,14 @@ # # Pauses. Two kinds, both in state/jev/disabled ("\t" or, for a timed # pause, "\t\t"). A DAY pause holds until the next local -# calendar day: on OpenRouter an API/transport error, a response without a +# calendar day: on OpenRouter an API error that came back as an HTTP response, a response without a # usage.cost, or reaching the daily spend cap (USD, default 1; override with a # decimal number in config/jev-daily-cap, summed from the usage.cost each # response reports); on either backend an invalid config/jev-endpoint, which is # a configuration mistake to surface, not a transient condition to retry. A -# TIMED pause covers timeouts, on either backend: the Nth consecutive timeout -# (config/jev-timeout-streak, default 3; any successful classification resets +# TIMED pause covers timeouts and transport failures (any curl failure with no +# HTTP response, such as a DNS or connection error), on either backend: the Nth +# consecutive one (config/jev-timeout-streak, default 3; any successful classification resets # the count, kept in state/jev/timeout-streak) pauses classification for # config/jev-timeout-pause minutes (default 60), then Jev tries again by # itself. A further pause with no success in between doubles (60, 120, 240 ... @@ -123,12 +124,12 @@ # skipped by a pause is logged with why=disabled. # # The local backend has no per-request cost and no monotonic quota to protect, -# so apart from the timed timeout pause and an invalid endpoint none of its own -# failure reasons ever pauses it: a 1-minute load average at or above -# config/jev-max-load (default 8; checked before each request) or an -# API/transport error each only skip that one row (why=load/api-error), and the -# very next drain tries again. A timeout also skips the rest of that same -# drain's rows (why=timeout) without dialing, so a stuck server costs one +# so apart from the timed pause (timeouts and transport failures) and an invalid +# endpoint none of its own failure reasons ever pauses it: a 1-minute load +# average at or above config/jev-max-load (default 8; checked before each +# request) or an HTTP API error each only skip that one row +# (why=load/api-error), and the very next drain tries again. A timeout also +# skips the rest of that same drain's rows (why=timeout) without dialing, so a stuck server costs one # timeout per drain rather than one per row (and counts once toward the # streak), and the classify lock is never held long enough for detached drains # to pile up behind it. The wake itself is untouched in every case because @@ -397,7 +398,7 @@ jev_clock() { # -> HH:MM local time (GNU date, then BSD date) } # state/jev/disabled is "\t" (a pause until the next local day: the -# spend cap, an API/transport error or a missing cost on OpenRouter, an +# spend cap, an HTTP API error or a missing cost on OpenRouter, an # invalid config/jev-endpoint) or "\t\t" (a timed pause # that clears itself). A "\ttimeout" record without an until time was # written when one timeout paused the whole day; that reason no longer pauses, @@ -704,7 +705,7 @@ jev_classify_row() { # "$out"; printf '500' ;; nocost) printf '{"answers":{"handling":{"type":"choice","choice":"absorbable","confidence":0.9}},"usage":{}}' > "$out"; printf '200' ;; ok) @@ -450,7 +451,7 @@ test_pause_state_command_prints_only_while_paused() { test_api_errors_pause_until_the_next_day() { local mode home - for mode in http500 refused nocost; do + for mode in http500 nocost; do home=$(jev_case "api-$mode" with-key) queue_row "$home" 1 heartbeat heartbeat heartbeat queue_row "$home" 2 stale default:w1:p1 'stale: default:w1:p1' @@ -459,7 +460,26 @@ test_api_errors_pause_until_the_next_day() { [ "$(cut -f2 "$home/state/jev/disabled")" = api-error ] || fail "$mode did not pause Jev" [ "$(calls "$home")" = 1 ] || fail "$mode: Jev kept calling after an API error" done - pass "HTTP errors, transport errors and a missing cost pause Jev until the next day" + pass "HTTP errors and a missing cost pause Jev until the next day" +} + +test_transport_errors_count_toward_the_timed_pause() { + local home now until + home=$(jev_case transport1 with-key) + timeout_drain "$home" 1 1 dns + jev_events "$home" 'select(.why == "api-error")' | grep -q . || fail "a transport error was not logged" + assert_absent "$home/state/jev/disabled" "one transport error paused Jev" + assert_contains "$(in_home "$home" "$JEV" status)" 'timeout streak: 1 of 3' "the transport error did not count in the streak" + home=$(jev_case transport3 with-key) + now=$(date +%s) + timeout_drain "$home" 1 3 refused + [ "$(calls "$home")" = 3 ] || fail "transport errors did not each dial" + [ "$(cut -f2 "$home/state/jev/disabled")" = timeout ] || fail "three transport errors did not start the timed pause" + until=$(pause_until "$home") + [ -n "$until" ] && [ "$until" -gt "$now" ] || fail "the timed pause carries no end time" + timeout_drain "$home" 4 1 refused + [ "$(calls "$home")" = 3 ] || fail "a paused Jev still dialed" + pass "transport errors count in the timeout streak and start the timed pause, never a day pause" } test_daily_cap_pauses_after_the_spend_is_reached() { @@ -1128,6 +1148,7 @@ test_every_pause_is_announced_once_through_a_check_wake test_resume_is_announced_only_for_an_announced_pause test_pause_state_command_prints_only_while_paused test_api_errors_pause_until_the_next_day +test_transport_errors_count_toward_the_timed_pause test_daily_cap_pauses_after_the_spend_is_reached test_local_backend_takes_priority_needs_no_key_and_records_the_answering_model test_local_backend_uncertain_maps_to_doubt