hyf

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

commit 610921c1760665d53ec05d4fc6311fc20a1a58a4
parent b38e595d7d2641858b77db043929791162104a1d
Author: triesap <tyson@radroots.org>
Date:   Fri, 19 Jun 2026 04:10:23 -0700

runtime: harden max route config scan

- scan inline max-local tables with quote-aware delimiter handling
- keep removed route keys rejected when quoted values contain commas
- allow quoted inline values that only mention route text
- verify the stdio contract suite remains green

Diffstat:
Msrc/hyf_runtime/config.mojo | 69+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------
Mtests/test_stdio_contract.mojo | 25+++++++++++++++++++++++++
2 files changed, 86 insertions(+), 8 deletions(-)

diff --git a/src/hyf_runtime/config.mojo b/src/hyf_runtime/config.mojo @@ -213,24 +213,77 @@ def _normalize_toml_key_path(key: String) -> String: return normalized^ +def _toml_delimiter_index_outside_quotes( + text: String, delimiter: UInt8, start_index: Int +) -> Int: + var bytes = text.as_bytes() + var index = start_index + var in_basic_string = False + var in_literal_string = False + var escaped = False + while index < text.byte_length(): + var byte = bytes[index] + if in_basic_string: + if escaped: + escaped = False + elif byte == UInt8(ord("\\")): + escaped = True + elif byte == UInt8(ord('"')): + in_basic_string = False + elif in_literal_string: + if byte == UInt8(ord("'")): + in_literal_string = False + else: + if byte == UInt8(ord('"')): + in_basic_string = True + elif byte == UInt8(ord("'")): + in_literal_string = True + elif byte == delimiter: + return index + index += 1 + return -1 + + def _inline_table_contains_route_key(value: String) -> Bool: var table = String(String(value).strip()) - var open_index = table.find("{") + var open_index = _toml_delimiter_index_outside_quotes( + table, UInt8(ord("{")), 0 + ) if open_index < 0: return False - var close_index = table.find("}") + var close_index = _toml_delimiter_index_outside_quotes( + table, UInt8(ord("}")), open_index + 1 + ) if close_index < 0 or close_index <= open_index: close_index = table.byte_length() var body = String(table[byte=open_index + 1:close_index]) - for raw_field in body.split(","): - var field = String(String(raw_field).strip()) - var equals_index = field.find("=") + var field_start = 0 + while field_start <= body.byte_length(): + var comma_index = _toml_delimiter_index_outside_quotes( + body, UInt8(ord(",")), field_start + ) + var field_end = comma_index + if field_end < 0: + field_end = body.byte_length() + + var field = String(String(body[byte=field_start:field_end]).strip()) + var equals_index = _toml_delimiter_index_outside_quotes( + field, UInt8(ord("=")), 0 + ) if equals_index < 0: + if comma_index < 0: + break + field_start = comma_index + 1 continue - var key = String(String(field[byte=0:equals_index]).strip()) - if _normalize_toml_key_path(key) == "route": - return True + else: + var key = String(String(field[byte=0:equals_index]).strip()) + if _normalize_toml_key_path(key) == "route": + return True + + if comma_index < 0: + break + field_start = comma_index + 1 return False diff --git a/tests/test_stdio_contract.mojo b/tests/test_stdio_contract.mojo @@ -1350,6 +1350,17 @@ def test_status_rejects_invalid_max_local_runtime_config() raises: + 'assisted.max_local = { enabled = true, ' + 'base_url = "http://127.0.0.1:8000/v1", ' + 'health_url = "http://127.0.0.1:8000/health", ' + + 'model = "max-local-query-rewrite, route = quoted literal", ' + + 'route = "provider_runtime.query_rewrite.max_local", ' + + 'request_timeout_ms = 15000 }\n', + "assisted.max_local.route", + ) + _assert_invalid_runtime_config_load_error( + prefix + + provider + + 'assisted.max_local = { enabled = true, ' + + 'base_url = "http://127.0.0.1:8000/v1", ' + + 'health_url = "http://127.0.0.1:8000/health", ' + 'model = "max-local-query-rewrite", ' + "'route' = \"provider_runtime.query_rewrite.max_local\", " + 'request_timeout_ms = 15000 }\n', @@ -1384,6 +1395,20 @@ def test_status_allows_non_route_toml_mentions() raises: _assert_valid_runtime_config_load(config) +def test_status_allows_inline_table_quoted_route_mentions() raises: + var config = ( + '[service]\ntransport = "stdio"\n\n' + + '[runtime]\ndefault_execution_mode = "deterministic"\nallow_assisted = true\n\n' + + '[assisted]\nprovider = "max_local"\n\n' + + 'assisted.max_local = { enabled = true, ' + + 'base_url = "http://127.0.0.1:8000/v1", ' + + 'health_url = "http://127.0.0.1:8000/health", ' + + 'model = "max-local-query-rewrite, route = quoted literal", ' + + 'request_timeout_ms = 15000 }\n' + ) + _assert_valid_runtime_config_load(config) + + 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"