commit 7ee211f6aec4dd5496fc00c518abeacbee3fa6d7
parent 6db6d9274edf6d58de398173f7c0c05f626fb706
Author: triesap <tyson@radroots.org>
Date: Mon, 15 Jun 2026 13:59:52 -0700
provider: make readiness probe deadline-aware
- gate query_rewrite provider execution on loaded config state without control-route health checks
- use the request-effective provider timeout for the single readiness probe
- cover health-probe timeout fallback and preserve one health plus one POST behavior
Diffstat:
3 files changed, 37 insertions(+), 21 deletions(-)
diff --git a/src/hyf_stdio/provider_execution.mojo b/src/hyf_stdio/provider_execution.mojo
@@ -40,8 +40,12 @@ from hyf_provider.max_local import (
execute_query_rewrite_via_max_local_provider,
max_local_provider_status,
)
+from hyf_runtime.config import (
+ HyfLoadedRuntimeConfig,
+ assisted_execution_enabled,
+ assisted_runtime_configured,
+)
from hyf_runtime.startup import RuntimeStartupContext
-from hyf_stdio.control.assisted_runtime import resolve_assisted_runtime_status
def _source_refs(
@@ -90,16 +94,16 @@ def _provider_meta(
)
-def _fallback_reason_for_runtime_state(state: String) -> String:
- if state == "disabled_by_runtime_config":
- return "disabled_by_runtime_config"
- if state == "unconfigured":
- return "provider_unconfigured"
- if state == "invalid_config":
- return "invalid_config"
- if state == "degraded":
- return "provider_degraded"
- return "provider_unavailable"
+def _provider_runtime_config_fallback_reason(
+ config: HyfLoadedRuntimeConfig,
+) -> Optional[String]:
+ if config.load_state == "invalid":
+ return Optional[String]("invalid_config")
+ if not assisted_execution_enabled(config):
+ return Optional[String]("disabled_by_runtime_config")
+ if not assisted_runtime_configured(config):
+ return Optional[String]("provider_unconfigured")
+ return Optional[String](None)
def _provider_execution_error_reason(message: String) -> String:
@@ -198,19 +202,15 @@ def _execute_query_rewrite_with_provider(
context: RequestContext,
runtime_context: RuntimeStartupContext,
) raises -> CapabilityResult:
- var runtime_status = resolve_assisted_runtime_status(
+ var config_fallback_reason = _provider_runtime_config_fallback_reason(
runtime_context.config
)
- if (
- runtime_status.state == "disabled_by_runtime_config"
- or runtime_status.state == "unconfigured"
- or runtime_status.state == "invalid_config"
- ):
+ if config_fallback_reason:
return _query_rewrite_fallback(
input,
context,
"provider_runtime",
- _fallback_reason_for_runtime_state(runtime_status.state),
+ String(config_fallback_reason.value()),
)
try:
diff --git a/tests/max_local_process_helper.mojo b/tests/max_local_process_helper.mojo
@@ -120,6 +120,8 @@ def _send(mut stream: TcpStream, status: Int, body: String) raises:
def _handle_health(mut stream: TcpStream, mode: String) raises:
if mode == "health_non_2xx":
_send(stream, 503, '{"status":"unavailable"}')
+ elif mode == "health_timeout":
+ usleep(1_000_000)
else:
_send(stream, 200, '{"status":"ok"}')
diff --git a/tests/test_stdio_contract.mojo b/tests/test_stdio_contract.mojo
@@ -94,12 +94,12 @@ def _semantic_rank_assisted_request_json(request_id: String) -> String:
)
-def _assert_query_rewrite_provider_fallback(
- mode: String, expected_reason: String, request_timeout_ms: Int
+def _assert_query_rewrite_provider_fallback_with_requests(
+ mode: String, expected_reason: String, request_timeout_ms: Int, requests: Int
) raises:
with TemporaryDirectory() as temp_dir:
var provider_port = reserve_loopback_port()
- var provider_stub = spawn_max_local_stub(provider_port, mode, 2)
+ var provider_stub = spawn_max_local_stub(provider_port, mode, requests)
var startup_config_path = Path(temp_dir) / "explicit-hyf-config.toml"
startup_config_path.write_text(
_max_local_runtime_config_toml_with_urls(
@@ -148,6 +148,14 @@ def _assert_query_rewrite_provider_fallback(
provider_stub.wait()
+def _assert_query_rewrite_provider_fallback(
+ mode: String, expected_reason: String, request_timeout_ms: Int
+) raises:
+ _assert_query_rewrite_provider_fallback_with_requests(
+ mode, expected_reason, request_timeout_ms, 2
+ )
+
+
def _assert_query_rewrite_runtime_config_fallback(
config_text: String, expected_reason: String, request_id: String
) raises:
@@ -1272,6 +1280,12 @@ def test_query_rewrite_falls_back_on_provider_timeout() raises:
)
+def test_query_rewrite_falls_back_when_provider_readiness_probe_times_out() raises:
+ _assert_query_rewrite_provider_fallback_with_requests(
+ "health_timeout", "timeout", 100, 1
+ )
+
+
def test_query_rewrite_falls_back_on_provider_invalid_json() raises:
_assert_query_rewrite_provider_fallback(
"query_rewrite_invalid_json", "provider_invalid_json", 15000