commit 0f0a526afe4d2d8a86d1bdf494f5d1afec0df992
parent d76450d1faf5f7ab9a73d2072da5a2242dd84ef2
Author: triesap <tyson@radroots.org>
Date: Wed, 23 Sep 2026 18:48:49 +0000
H008: characterize exact retry wire attempt counts
- Pin retry-policy unit behavior for delay, attempt and budget bounds.
- Prove MaxLocal and Jev make exactly one counted attempt per explicit call.
- Characterize a retryable sequence and a non-retryable status via the fixture.
- Assert request and connection counters align with current HYF behavior.
Diffstat:
2 files changed, 143 insertions(+), 0 deletions(-)
diff --git a/tests/test_jev.mojo b/tests/test_jev.mojo
@@ -719,3 +719,91 @@ def test_jev_require_bearer_target_is_characterized_off() raises:
# which is the characterization surface the later step flips.
assert_true(not require_bearer_for("ok"))
assert_true(not require_bearer_for("echo_headers"))
+
+
+# ── H008 exact wire attempt counts ──────────────────────────────────────────
+
+
+def test_retry_policy_units_are_bounded() raises:
+ # H008: pin the existing HYF retry-policy unit behavior before any client
+ # change can introduce a hidden Flare retry.
+ var policy = retry_policy(2, 100, 500, 1000)
+ assert_equal(retry_delay_ms(policy, 0), 100)
+ assert_equal(retry_delay_ms(policy, 1), 200)
+ assert_equal(retry_delay_ms(policy, 2), 400)
+ assert_equal(retry_delay_ms(policy, 3), 500)
+ assert_equal(retry_delay_ms(policy, 9), 500)
+ assert_true(should_retry(policy, 0, 0, True))
+ assert_true(not should_retry(policy, 0, 0, False))
+ assert_true(not should_retry(policy, 2, 0, True))
+ assert_true(not should_retry(policy, 0, 900, True))
+ assert_true(should_retry(policy, 0, 899, True))
+ with assert_raises():
+ _ = retry_policy(-1, 100, 200, 1000)
+ with assert_raises():
+ _ = retry_policy(1, 0, 200, 1000)
+ with assert_raises():
+ _ = retry_policy(1, 300, 200, 1000)
+ with assert_raises():
+ _ = retry_policy(1, 100, 200, 0)
+
+
+def test_jev_wire_attempt_counts_for_retryable_then_success() raises:
+ # H008: a retryable status does not trigger a hidden retry. Each explicit
+ # call makes exactly one counted wire attempt, and applying the retry
+ # decision produces the next counted attempt.
+ var guard = CleanupGuard()
+ var scripts = List[ExchangeScript]()
+ scripts.append(
+ exchange_script(
+ "retryable_500", "POST", "/v1/systemone", 500, '{"error":"busy"}'
+ )
+ )
+ scripts.append(
+ exchange_script(
+ "retry_success", "POST", "/v1/systemone", 200, '{"ok":true}'
+ )
+ )
+ with spawn_jev_scripted_auto(scripts^, guard) as started:
+ var payload = _loads(
+ '{"model":"jev-1.13.0","state":"s","questions":{}}'
+ )
+ var url = "http://127.0.0.1:" + String(started.port)
+ var first = post_jev_systemone(url, payload, 3000)
+ assert_equal(first.status, 500)
+ var policy = retry_policy(1, 50, 200, 5000)
+ assert_true(retry_decision(policy, 0, 0, 500))
+ var second = post_jev_systemone(url, payload, 3000)
+ assert_equal(second.status, 200)
+ started.stub.wait()
+ assert_true(started.stub.ok())
+ assert_equal(started.stub.request_count(), 2)
+ assert_equal(started.stub.connection_count(), 2)
+ guard.assert_clean()
+
+
+def test_jev_wire_attempt_counts_for_non_retryable_failure() raises:
+ # H008: a non-retryable status is one wire attempt and the decision is
+ # false, so no later migration may silently retry it.
+ var guard = CleanupGuard()
+ var scripts = List[ExchangeScript]()
+ scripts.append(
+ exchange_script(
+ "auth_401", "POST", "/v1/systemone", 401, '{"error":"denied"}'
+ )
+ )
+ with spawn_jev_scripted_auto(scripts^, guard) as started:
+ var payload = _loads(
+ '{"model":"jev-1.13.0","state":"s","questions":{}}'
+ )
+ var outcome = post_jev_systemone(
+ "http://127.0.0.1:" + String(started.port), payload, 3000
+ )
+ assert_equal(outcome.status, 401)
+ var policy = retry_policy(2, 50, 200, 5000)
+ assert_true(not retry_decision(policy, 0, 0, 401))
+ started.stub.wait()
+ assert_true(started.stub.ok())
+ assert_equal(started.stub.request_count(), 1)
+ assert_equal(started.stub.connection_count(), 1)
+ guard.assert_clean()
diff --git a/tests/test_provider_adapter.mojo b/tests/test_provider_adapter.mojo
@@ -796,5 +796,60 @@ def test_provider_never_returning_call_is_stopped_and_reaped() raises:
guard.assert_clean()
+def test_maxlocal_wire_attempt_counts_are_exact() raises:
+ # H008: a retryable non-2xx does not trigger a hidden retry. Each explicit
+ # call makes exactly one counted wire attempt (request and connection).
+ var scripts = List[ExchangeScript]()
+ scripts.append(
+ exchange_script("ml_500", "POST", "/v1/chat/completions", 500, "{}")
+ )
+ scripts.append(
+ exchange_script(
+ "ml_ok", "POST", "/v1/chat/completions", 200, '{"choices":[]}'
+ )
+ )
+ var guard = CleanupGuard()
+ with spawn_max_local_scripted(0, scripts^, guard) as provider_stub:
+ var config = _bounded_timeout_provider_config(provider_stub.port, 3000)
+ var context = default_request_context()
+ var body = build_query_rewrite_request_body(
+ config, "eggs near me", context
+ )
+ var first = post_max_local_chat_completion(config, body)
+ assert_true(first.failure)
+ assert_equal(first.failure.value().kind, "http_status")
+ var second = post_max_local_chat_completion(config, body)
+ assert_true(not second.failure)
+ assert_equal(second.response.value().status, 200)
+ provider_stub.wait()
+ assert_true(provider_stub.ok())
+ assert_equal(provider_stub.request_count(), 2)
+ assert_equal(provider_stub.connection_count(), 2)
+ guard.assert_clean()
+
+
+def test_maxlocal_wire_attempt_counts_for_non_retryable_status() raises:
+ # H008: a non-2xx status that must not be retried is exactly one attempt.
+ var scripts = List[ExchangeScript]()
+ scripts.append(
+ exchange_script("ml_400", "POST", "/v1/chat/completions", 400, "{}")
+ )
+ var guard = CleanupGuard()
+ with spawn_max_local_scripted(0, scripts^, guard) as provider_stub:
+ var config = _bounded_timeout_provider_config(provider_stub.port, 3000)
+ var context = default_request_context()
+ var body = build_query_rewrite_request_body(
+ config, "eggs near me", context
+ )
+ var outcome = post_max_local_chat_completion(config, body)
+ assert_true(outcome.failure)
+ assert_equal(outcome.failure.value().kind, "http_status")
+ provider_stub.wait()
+ assert_true(provider_stub.ok())
+ assert_equal(provider_stub.request_count(), 1)
+ assert_equal(provider_stub.connection_count(), 1)
+ guard.assert_clean()
+
+
def main() raises:
TestSuite.discover_tests[__functions_in_module()]().run()