hyf

Context-aware query service for Radroots
git clone https://radroots.dev/git/hyf.git
Log | Files | Refs | README | LICENSE

commit f5475c71335c7aa8d3f69525b60ac7848c639ce7
parent 45e3775e5c9e92756b649e045abf9af540e081e7
Author: triesap <tyson@radroots.org>
Date:   Sun, 14 Jun 2026 16:38:50 -0700

provider: harden max local health coverage

Diffstat:
Msrc/hyf_assist/contract.mojo | 1+
Msrc/hyf_provider/max_local.mojo | 5+----
Msrc/hyf_provider/result.mojo | 71+++++++++++++++++++++++++++++++++++++++++++++--------------------------
Msrc/hyf_stdio/control/assisted_runtime.mojo | 121++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------
Msrc/hyf_stdio/provider_execution.mojo | 18+++++++++++++++++-
Mtests/max_local_http_stub.py | 5++++-
Mtests/test_stdio_contract.mojo | 423++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
7 files changed, 582 insertions(+), 62 deletions(-)

diff --git a/src/hyf_assist/contract.mojo b/src/hyf_assist/contract.mojo @@ -29,5 +29,6 @@ struct AssistedRuntimeStatus(Copyable, Movable): var configured: Bool var reachable: Bool var state: String + var reason: String var fallback_contract: String var supported_business_capabilities: List[String] diff --git a/src/hyf_provider/max_local.mojo b/src/hyf_provider/max_local.mojo @@ -41,10 +41,7 @@ def execute_query_rewrite_via_max_local_provider( ) var latency_ms = Int((perf_counter_ns() - start_ns) // 1_000_000) if not response.ok(): - raise Error( - "max_local provider returned HTTP " - + String(response.status) - ) + raise Error("provider_non_2xx") return MaxLocalQueryRewriteResult( analysis=parse_query_analysis_from_chat_completion( diff --git a/src/hyf_provider/result.mojo b/src/hyf_provider/result.mojo @@ -53,18 +53,26 @@ def _first_validation_error(value: Value) raises -> String: def extract_chat_completion_text(response: Value) raises -> String: if not response.is_object(): - raise Error("max_local response must be a JSON object") + raise Error("provider_invalid_response") + if _has_key(response, "error"): + raise Error("provider_error_payload") if not _has_key(response, "choices"): - raise Error("max_local response must contain choices") + raise Error("provider_empty_choices") if ( not response["choices"].is_array() or len(response["choices"].array_items()) == 0 ): - raise Error("max_local response choices must be a non-empty array") + raise Error("provider_empty_choices") - var message = response["choices"][0]["message"].clone() + var choice = response["choices"][0].clone() + if not choice.is_object() or not _has_key(choice, "message"): + raise Error("provider_missing_content") + + var message = choice["message"].clone() if not message.is_object(): - raise Error("max_local response choice message must be an object") + raise Error("provider_missing_content") + if not _has_key(message, "content"): + raise Error("provider_missing_content") var content = message["content"].clone() if content.is_string(): @@ -86,36 +94,47 @@ def extract_chat_completion_text(response: Value) raises -> String: if collected != "": return collected^ - raise Error("max_local response contained no text content") + raise Error("provider_missing_content") def parse_query_analysis_json(value: Value) raises -> QueryAnalysis: if not value.is_object(): - raise Error("query_rewrite structured output must be an object") + raise Error("provider_schema_invalid") var validation_error = _first_validation_error(value.clone()) if validation_error != "": - raise Error(validation_error) - - var filters = value["extracted_filters"].clone() - return QueryAnalysis( - original_text=value["original_text"].string_value(), - normalized_text=value["normalized_text"].string_value(), - rewritten_text=value["rewritten_text"].string_value(), - query_terms=_string_array(value["query_terms"], "query_terms"), - normalization_signals=_string_array( - value["normalization_signals"], "normalization_signals" - ), - ranking_hints=_string_array(value["ranking_hints"], "ranking_hints"), - extracted_filters=ExtractedFilters( - local_intent=filters["local_intent"].bool_value(), - fulfillment=filters["fulfillment"].string_value(), - time_window=filters["time_window"].string_value(), - ), - ) + raise Error("provider_schema_invalid") + + try: + var filters = value["extracted_filters"].clone() + return QueryAnalysis( + original_text=value["original_text"].string_value(), + normalized_text=value["normalized_text"].string_value(), + rewritten_text=value["rewritten_text"].string_value(), + query_terms=_string_array(value["query_terms"], "query_terms"), + normalization_signals=_string_array( + value["normalization_signals"], "normalization_signals" + ), + ranking_hints=_string_array( + value["ranking_hints"], "ranking_hints" + ), + extracted_filters=ExtractedFilters( + local_intent=filters["local_intent"].bool_value(), + fulfillment=filters["fulfillment"].string_value(), + time_window=filters["time_window"].string_value(), + ), + ) + except: + raise Error("provider_schema_invalid") def parse_query_analysis_from_chat_completion( response: Value, ) raises -> QueryAnalysis: - return parse_query_analysis_json(loads(extract_chat_completion_text(response))) + var text = extract_chat_completion_text(response) + try: + return parse_query_analysis_json(loads(text)) + except e: + if String(e).find("provider_schema_invalid") >= 0: + raise Error("provider_schema_invalid") + raise Error("provider_invalid_json") diff --git a/src/hyf_stdio/control/assisted_runtime.mojo b/src/hyf_stdio/control/assisted_runtime.mojo @@ -13,34 +13,116 @@ from hyf_runtime.config import ( assisted_runtime_configured, assisted_execution_enabled, ) +from hyf_provider.config import max_local_provider_config_from_runtime +from hyf_provider.max_local import max_local_provider_status -def resolve_assisted_runtime_status( - config: HyfLoadedRuntimeConfig, +def _base_status( + configured: Bool, + transport: String, + endpoint: String, + backend_kind: String, + provider: String, + route: String, + model: String, + reachable: Bool, + state: String, + reason: String, ) -> AssistedRuntimeStatus: - var configured = assisted_runtime_configured(config) - var state = "disabled_by_runtime_config" - if assisted_execution_enabled(config): - state = "unavailable" if configured else "unconfigured" - return AssistedRuntimeStatus( id=provider_runtime_id(), kind="provider_runtime", contract_version=assisted_runtime_contract_version(), - transport="deferred", - endpoint="", - backend_kind="deferred", - provider="", - route="", - model="", + transport=String(transport), + endpoint=String(endpoint), + backend_kind=String(backend_kind), + provider=String(provider), + route=String(route), + model=String(model), configured=configured, - reachable=False, - state=state, + reachable=reachable, + state=String(state), + reason=String(reason), fallback_contract="deterministic_baseline_preserved", supported_business_capabilities=assisted_runtime_supported_business_capabilities(), ) +def resolve_assisted_runtime_status( + config: HyfLoadedRuntimeConfig, +) -> AssistedRuntimeStatus: + if config.load_state == "invalid": + return _base_status( + configured=False, + transport="deferred", + endpoint="", + backend_kind="max_local", + provider="max_local", + route="", + model="", + reachable=False, + state="invalid_config", + reason="invalid_config", + ) + + if not assisted_execution_enabled(config): + return _base_status( + configured=False, + transport="deferred", + endpoint="", + backend_kind="deferred", + provider="", + route="", + model="", + reachable=False, + state="disabled_by_runtime_config", + reason="disabled_by_runtime_config", + ) + + if not assisted_runtime_configured(config): + return _base_status( + configured=False, + transport="deferred", + endpoint="", + backend_kind="deferred", + provider="", + route="", + model="", + reachable=False, + state="unconfigured", + reason="not_checked", + ) + + try: + var provider_config = max_local_provider_config_from_runtime(config) + var status = max_local_provider_status(provider_config) + return _base_status( + configured=True, + transport="http", + endpoint=String(provider_config.health_url), + backend_kind=String(status.backend_kind), + provider=String(status.provider), + route=String(status.route), + model=String(status.model), + reachable=status.reachable, + state=String(status.state), + reason=String(status.reason), + ) + except e: + return _base_status( + configured=True, + transport="http", + endpoint="", + backend_kind="max_local", + provider="max_local", + route="", + model="", + reachable=False, + state="invalid_config", + reason="invalid_config", + ) + + def assisted_execution_state_for_capability( status: AssistedRuntimeStatus, capability_id: String ) -> String: @@ -54,7 +136,7 @@ def assisted_execution_state_for_capability( def assisted_backend_available_for_capability( status: AssistedRuntimeStatus, capability_id: String ) -> Bool: - return False + return capability_id == "query_rewrite" and status.state == "ready" def serialize_assisted_runtime_status_value( @@ -71,6 +153,13 @@ def serialize_assisted_runtime_status_value( value.set("configured", Value(status.configured)) value.set("reachable", Value(status.reachable)) value.set("state", Value(String(status.state))) + value.set("reason", Value(String(status.reason))) + if status.provider != "": + value.set("provider", Value(String(status.provider))) + if status.route != "": + value.set("route", Value(String(status.route))) + if status.model != "": + value.set("model", Value(String(status.model))) value.set("fallback_contract", Value(String(status.fallback_contract))) var capabilities = loads("[]") diff --git a/src/hyf_stdio/provider_execution.mojo b/src/hyf_stdio/provider_execution.mojo @@ -103,8 +103,24 @@ def _fallback_reason_for_runtime_state(state: String) -> String: def _provider_execution_error_reason(message: String) -> String: var lower = message.lower() - if lower.find("http") >= 0: + if lower.find("timeout") >= 0 or lower.find("timed out") >= 0: + return "timeout" + if lower.find("connection") >= 0: + return "connection_failed" + if lower.find("provider_non_2xx") >= 0 or lower.find("http") >= 0: return "provider_non_2xx" + if lower.find("provider_error_payload") >= 0: + return "provider_error_payload" + if lower.find("provider_invalid_json") >= 0: + return "provider_invalid_json" + if lower.find("provider_schema_invalid") >= 0: + return "provider_schema_invalid" + if lower.find("provider_empty_choices") >= 0: + return "provider_empty_choices" + if lower.find("provider_missing_content") >= 0: + return "provider_missing_content" + if lower.find("provider_invalid_response") >= 0: + return "provider_invalid_response" if lower.find("choices") >= 0: return "provider_empty_choices" if lower.find("content") >= 0 or lower.find("message") >= 0: diff --git a/tests/max_local_http_stub.py b/tests/max_local_http_stub.py @@ -52,7 +52,10 @@ class Handler(BaseHTTPRequestHandler): self.send_header("content-type", content_type) self.send_header("content-length", str(len(body))) self.end_headers() - self.wfile.write(body) + try: + self.wfile.write(body) + except (BrokenPipeError, ConnectionResetError): + return def do_GET(self): if self.path == "/health": diff --git a/tests/test_stdio_contract.mojo b/tests/test_stdio_contract.mojo @@ -65,14 +65,79 @@ def _max_local_runtime_config_toml_with_urls( ) -def _max_local_runtime_config_toml() -> String: +def _unavailable_max_local_runtime_config_toml() raises -> String: + var provider_port = reserve_loopback_port() return _max_local_runtime_config_toml_with_urls( - "http://127.0.0.1:8000/v1", - "http://127.0.0.1:8000/health", - 15000, + "http://127.0.0.1:" + String(provider_port) + "/v1", + "http://127.0.0.1:" + String(provider_port) + "/health", + 250, ) +def _query_rewrite_assisted_request_json(request_id: String) -> String: + return ( + '{"version":1,"request_id":"' + + request_id + + '","trace_id":"' + + request_id + + '","capability":"query_rewrite","context":{"execution_mode_preference":"assisted","return_provenance":true},"input":{"query":"apples near me with weekend pickup"}}' + ) + + +def _assert_query_rewrite_provider_fallback( + mode: String, expected_reason: String, request_timeout_ms: 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 startup_config_path = Path(temp_dir) / "explicit-hyf-config.toml" + startup_config_path.write_text( + _max_local_runtime_config_toml_with_urls( + "http://127.0.0.1:" + String(provider_port) + "/v1", + "http://127.0.0.1:" + String(provider_port) + "/health", + request_timeout_ms, + ) + ) + with ScopedEnvVar(HYF_PATHS_PROFILE_ENV, "repo_local"): + with ScopedEnvVar(HYF_PATHS_REPO_LOCAL_ROOT_ENV, temp_dir): + var response = run_stdio_entrypoint( + "src/main.mojo", + _query_rewrite_assisted_request_json( + "rewrite-assisted-" + mode + ), + "--config", + startup_config_path.__fspath__(), + ) + + assert_true(response["ok"].bool_value()) + assert_equal( + response["meta"]["execution_mode"].string_value(), + "deterministic", + ) + assert_equal( + response["meta"]["backend"].string_value(), + "heuristic", + ) + assert_true(not _has_key(response["meta"], "provider")) + assert_equal( + response["meta"]["provenance"]["fallback"][ + "fallback_kind" + ].string_value(), + "provider_runtime", + ) + assert_equal( + response["meta"]["provenance"]["fallback"]["reason"] + .string_value(), + expected_reason, + ) + assert_equal( + response["output"]["rewritten_text"].string_value(), + "apples", + ) + + provider_stub.wait() + + def _assert_invalid_runtime_config_load_error( config_text: String, expected_error_fragment: String ) raises: @@ -330,7 +395,9 @@ def test_status_reports_repo_local_runtime_truth() raises: def test_status_loads_valid_runtime_config_truthfully() raises: with TemporaryDirectory() as temp_dir: var startup_config_path = Path(temp_dir) / "explicit-hyf-config.toml" - startup_config_path.write_text(_max_local_runtime_config_toml()) + startup_config_path.write_text( + _unavailable_max_local_runtime_config_toml() + ) with ScopedEnvVar(HYF_PATHS_PROFILE_ENV, "repo_local"): with ScopedEnvVar(HYF_PATHS_REPO_LOCAL_ROOT_ENV, temp_dir): var response = run_stdio_entrypoint( @@ -359,6 +426,11 @@ def test_status_loads_valid_runtime_config_truthfully() raises: "unavailable", ) assert_equal( + response["output"]["assisted_runtime"]["reason"] + .string_value(), + "connection_failed", + ) + assert_equal( response["output"]["assisted_runtime"]["id"] .string_value(), "hyf_provider_runtime", @@ -371,7 +443,32 @@ def test_status_loads_valid_runtime_config_truthfully() raises: assert_equal( response["output"]["assisted_runtime"]["transport"] .string_value(), - "deferred", + "http", + ) + assert_equal( + response["output"]["assisted_runtime"]["backend_kind"] + .string_value(), + "max_local", + ) + assert_equal( + response["output"]["assisted_runtime"]["provider"] + .string_value(), + "max_local", + ) + assert_equal( + response["output"]["assisted_runtime"]["route"] + .string_value(), + "provider_runtime.query_rewrite.max_local", + ) + assert_equal( + response["output"]["assisted_runtime"]["model"] + .string_value(), + "max-local-query-rewrite", + ) + assert_equal( + response["output"]["assisted_runtime"]["reachable"] + .bool_value(), + False, ) assert_equal( response["output"]["backend_reachability"][ @@ -499,12 +596,17 @@ def test_status_reports_invalid_runtime_config_without_crashing() raises: response["output"]["execution_mode_request_behavior"][ "assisted" ].string_value(), - "disabled_by_runtime_config", + "invalid_config", ) assert_equal( response["output"]["assisted_runtime"]["state"] .string_value(), - "disabled_by_runtime_config", + "invalid_config", + ) + assert_equal( + response["output"]["assisted_runtime"]["reason"] + .string_value(), + "invalid_config", ) assert_equal( response["output"]["runtime"]["config"][ @@ -544,6 +646,175 @@ def test_status_reports_invalid_runtime_config_without_crashing() raises: ) +def test_status_reports_unconfigured_assisted_runtime_truthfully() raises: + with TemporaryDirectory() as temp_dir: + var startup_config_path = Path(temp_dir) / "explicit-hyf-config.toml" + startup_config_path.write_text( + '[service]\ntransport = "stdio"\n\n' + + '[runtime]\ndefault_execution_mode = "deterministic"\nallow_assisted = true\n\n' + + '[assisted]\nprovider = "max_local"\n' + ) + with ScopedEnvVar(HYF_PATHS_PROFILE_ENV, "repo_local"): + with ScopedEnvVar(HYF_PATHS_REPO_LOCAL_ROOT_ENV, temp_dir): + var response = run_stdio_entrypoint( + "src/main.mojo", + load_scenario_request_json("scenarios/status_ok.json"), + "--config", + startup_config_path.__fspath__(), + ) + + assert_true(response["ok"].bool_value()) + assert_equal( + response["output"]["execution_mode_request_behavior"][ + "assisted" + ].string_value(), + "provider_unconfigured", + ) + assert_equal( + response["output"]["assisted_runtime"]["state"] + .string_value(), + "unconfigured", + ) + assert_equal( + response["output"]["assisted_runtime"]["reason"] + .string_value(), + "not_checked", + ) + assert_equal( + response["output"]["assisted_runtime"]["transport"] + .string_value(), + "deferred", + ) + assert_equal( + response["output"]["assisted_runtime"]["configured"] + .bool_value(), + False, + ) + + +def test_status_reports_non_2xx_max_local_health_truthfully() raises: + with TemporaryDirectory() as temp_dir: + var provider_port = reserve_loopback_port() + var provider_stub = spawn_max_local_stub( + provider_port, "health_non_2xx", 1 + ) + var startup_config_path = Path(temp_dir) / "explicit-hyf-config.toml" + startup_config_path.write_text( + _max_local_runtime_config_toml_with_urls( + "http://127.0.0.1:" + String(provider_port) + "/v1", + "http://127.0.0.1:" + String(provider_port) + "/health", + 15000, + ) + ) + with ScopedEnvVar(HYF_PATHS_PROFILE_ENV, "repo_local"): + with ScopedEnvVar(HYF_PATHS_REPO_LOCAL_ROOT_ENV, temp_dir): + var response = run_stdio_entrypoint( + "src/main.mojo", + load_scenario_request_json("scenarios/status_ok.json"), + "--config", + startup_config_path.__fspath__(), + ) + + assert_true(response["ok"].bool_value()) + assert_equal( + response["output"]["assisted_runtime"]["state"] + .string_value(), + "unavailable", + ) + assert_equal( + response["output"]["assisted_runtime"]["reason"] + .string_value(), + "non_2xx", + ) + assert_equal( + response["output"]["assisted_runtime"]["reachable"] + .bool_value(), + False, + ) + + provider_stub.wait() + + +def test_status_reports_ready_max_local_provider_truthfully() raises: + with TemporaryDirectory() as temp_dir: + var provider_port = reserve_loopback_port() + var provider_stub = spawn_max_local_stub( + provider_port, "query_rewrite_ok", 1 + ) + var startup_config_path = Path(temp_dir) / "explicit-hyf-config.toml" + startup_config_path.write_text( + _max_local_runtime_config_toml_with_urls( + "http://127.0.0.1:" + String(provider_port) + "/v1", + "http://127.0.0.1:" + String(provider_port) + "/health", + 15000, + ) + ) + with ScopedEnvVar(HYF_PATHS_PROFILE_ENV, "repo_local"): + with ScopedEnvVar(HYF_PATHS_REPO_LOCAL_ROOT_ENV, temp_dir): + var response = run_stdio_entrypoint( + "src/main.mojo", + load_scenario_request_json("scenarios/status_ok.json"), + "--config", + startup_config_path.__fspath__(), + ) + + assert_true(response["ok"].bool_value()) + assert_equal( + response["output"]["execution_mode_request_behavior"][ + "assisted" + ].string_value(), + "execute", + ) + assert_equal( + response["output"]["backend_reachability"][ + "assisted_backend" + ].string_value(), + "ready", + ) + assert_equal( + response["output"]["assisted_runtime"]["state"] + .string_value(), + "ready", + ) + assert_equal( + response["output"]["assisted_runtime"]["reason"] + .string_value(), + "ready", + ) + assert_equal( + response["output"]["assisted_runtime"]["transport"] + .string_value(), + "http", + ) + assert_equal( + response["output"]["assisted_runtime"]["backend_kind"] + .string_value(), + "max_local", + ) + assert_equal( + response["output"]["assisted_runtime"]["provider"] + .string_value(), + "max_local", + ) + assert_equal( + response["output"]["assisted_runtime"]["route"] + .string_value(), + "provider_runtime.query_rewrite.max_local", + ) + assert_equal( + response["output"]["assisted_runtime"]["model"] + .string_value(), + "max-local-query-rewrite", + ) + assert_equal( + response["output"]["assisted_runtime"]["reachable"] + .bool_value(), + True, + ) + + provider_stub.wait() + + def test_status_rejects_invalid_max_local_runtime_config() raises: var prefix = ( '[service]\ntransport = "stdio"\n\n' @@ -629,7 +900,9 @@ def test_status_rejects_invalid_max_local_runtime_config() raises: def test_capabilities_reports_configured_provider_runtime_truthfully() raises: with TemporaryDirectory() as temp_dir: var startup_config_path = Path(temp_dir) / "explicit-hyf-config.toml" - startup_config_path.write_text(_max_local_runtime_config_toml()) + startup_config_path.write_text( + _unavailable_max_local_runtime_config_toml() + ) with ScopedEnvVar(HYF_PATHS_PROFILE_ENV, "repo_local"): with ScopedEnvVar(HYF_PATHS_REPO_LOCAL_ROOT_ENV, temp_dir): var response = run_stdio_entrypoint( @@ -647,6 +920,12 @@ def test_capabilities_reports_configured_provider_runtime_truthfully() raises: "unavailable", ) assert_equal( + response["output"]["business_capabilities"][0][ + "assisted_backend_available" + ].bool_value(), + False, + ) + assert_equal( response["output"]["assisted_runtime_capabilities"][0][ "id" ].string_value(), @@ -666,21 +945,95 @@ def test_capabilities_reports_configured_provider_runtime_truthfully() raises: ) assert_equal( response["output"]["assisted_runtime_capabilities"][0][ + "reason" + ].string_value(), + "connection_failed", + ) + assert_equal( + response["output"]["assisted_runtime_capabilities"][0][ "backend_kind" ].string_value(), - "deferred", + "max_local", + ) + + +def test_capabilities_reports_ready_max_local_provider_truthfully() raises: + with TemporaryDirectory() as temp_dir: + var provider_port = reserve_loopback_port() + var provider_stub = spawn_max_local_stub( + provider_port, "query_rewrite_ok", 1 + ) + var startup_config_path = Path(temp_dir) / "explicit-hyf-config.toml" + startup_config_path.write_text( + _max_local_runtime_config_toml_with_urls( + "http://127.0.0.1:" + String(provider_port) + "/v1", + "http://127.0.0.1:" + String(provider_port) + "/health", + 15000, + ) + ) + with ScopedEnvVar(HYF_PATHS_PROFILE_ENV, "repo_local"): + with ScopedEnvVar(HYF_PATHS_REPO_LOCAL_ROOT_ENV, temp_dir): + var response = run_stdio_entrypoint( + "src/main.mojo", + load_scenario_request_json("scenarios/capabilities_ok.json"), + "--config", + startup_config_path.__fspath__(), ) + assert_true(response["ok"].bool_value()) + assert_equal( + response["output"]["business_capabilities"][0][ + "assisted_execution" + ].string_value(), + "ready", + ) + assert_equal( + response["output"]["business_capabilities"][0][ + "assisted_backend_available" + ].bool_value(), + True, + ) + assert_equal( + response["output"]["business_capabilities"][2][ + "assisted_execution" + ].string_value(), + "unsupported_capability", + ) + assert_equal( + response["output"]["assisted_runtime_capabilities"][0][ + "state" + ].string_value(), + "ready", + ) + assert_equal( + response["output"]["assisted_runtime_capabilities"][0][ + "reason" + ].string_value(), + "ready", + ) + assert_equal( + response["output"]["assisted_runtime_capabilities"][0][ + "backend_kind" + ].string_value(), + "max_local", + ) + + provider_stub.wait() + def test_query_rewrite_falls_back_deterministically_when_provider_is_unavailable() raises: with TemporaryDirectory() as temp_dir: var startup_config_path = Path(temp_dir) / "explicit-hyf-config.toml" - startup_config_path.write_text(_max_local_runtime_config_toml()) + startup_config_path.write_text( + _unavailable_max_local_runtime_config_toml() + ) with ScopedEnvVar(HYF_PATHS_PROFILE_ENV, "repo_local"): with ScopedEnvVar(HYF_PATHS_REPO_LOCAL_ROOT_ENV, temp_dir): var response = run_stdio_entrypoint( "src/main.mojo", - '{"version":1,"request_id":"rewrite-assisted-fallback-1","trace_id":"rewrite-assisted-fallback-1","capability":"query_rewrite","context":{"execution_mode_preference":"assisted","return_provenance":true},"input":{"query":"apples near me with weekend pickup"}}', + _query_rewrite_assisted_request_json( + "rewrite-assisted-fallback-1" + ), "--config", startup_config_path.__fspath__(), ) @@ -699,12 +1052,12 @@ def test_query_rewrite_falls_back_deterministically_when_provider_is_unavailable response["meta"]["provenance"]["fallback"][ "fallback_kind" ].string_value(), - "assisted_execution", + "provider_runtime", ) assert_equal( response["meta"]["provenance"]["fallback"]["reason"] .string_value(), - "deferred_bootstrap_runtime", + "connection_failed", ) assert_equal( response["output"]["rewritten_text"].string_value(), @@ -793,6 +1146,48 @@ def test_query_rewrite_uses_max_local_provider_when_ready() raises: provider_stub.wait() +def test_query_rewrite_falls_back_on_provider_non_2xx() raises: + _assert_query_rewrite_provider_fallback( + "query_rewrite_non_2xx", "provider_non_2xx", 15000 + ) + + +def test_query_rewrite_falls_back_on_provider_timeout() raises: + _assert_query_rewrite_provider_fallback( + "query_rewrite_timeout", "timeout", 100 + ) + + +def test_query_rewrite_falls_back_on_provider_invalid_json() raises: + _assert_query_rewrite_provider_fallback( + "query_rewrite_invalid_json", "provider_invalid_json", 15000 + ) + + +def test_query_rewrite_falls_back_on_provider_schema_invalid_json() raises: + _assert_query_rewrite_provider_fallback( + "query_rewrite_schema_invalid", "provider_schema_invalid", 15000 + ) + + +def test_query_rewrite_falls_back_on_provider_empty_choices() raises: + _assert_query_rewrite_provider_fallback( + "query_rewrite_empty_choices", "provider_empty_choices", 15000 + ) + + +def test_query_rewrite_falls_back_on_provider_missing_content() raises: + _assert_query_rewrite_provider_fallback( + "query_rewrite_missing_content", "provider_missing_content", 15000 + ) + + +def test_query_rewrite_falls_back_on_provider_error_payload() raises: + _assert_query_rewrite_provider_fallback( + "query_rewrite_error_payload", "provider_error_payload", 15000 + ) + + def test_status_reports_configured_but_deferred_custody_truthfully() raises: with TemporaryDirectory() as temp_dir: var identity_dir = Path(temp_dir) / "secrets" / "services" / "hyf"