From bea2562fc4b3b0e32e23a91b91809682cf6553e0 Mon Sep 17 00:00:00 2001 From: sprmn24 Date: Mon, 27 Apr 2026 22:55:44 +0300 Subject: [PATCH] fix(honcho): replace raw int() config parsing with safe helper Three int() calls in HonchoClient.from_global_config() parsed dialecticMaxChars, messageMaxChars, and dialecticMaxInputChars directly without guards. A malformed value in honcho.json would raise ValueError and abort provider initialization entirely. Add _parse_int_config() helper following the existing _parse_context_tokens() pattern, and replace all three raw int() calls with it. --- plugins/memory/honcho/client.py | 35 ++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/plugins/memory/honcho/client.py b/plugins/memory/honcho/client.py index 63e45b4628..7210c6071e 100644 --- a/plugins/memory/honcho/client.py +++ b/plugins/memory/honcho/client.py @@ -110,6 +110,17 @@ def _parse_context_tokens(host_val, root_val) -> int | None: return None +def _parse_int_config(host_val, root_val, default: int) -> int: + """Parse an integer config: host wins, then root, then default.""" + for val in (host_val, root_val): + if val is not None: + try: + return int(val) + except (ValueError, TypeError): + pass + return default + + def _parse_dialectic_depth(host_val, root_val) -> int: """Parse dialecticDepth: host wins, then root, then 1. Clamped to 1-3.""" for val in (host_val, root_val): @@ -463,10 +474,10 @@ class HonchoClientConfig: raw.get("dialecticDynamic"), default=True, ), - dialectic_max_chars=int( - host_block.get("dialecticMaxChars") - or raw.get("dialecticMaxChars") - or 600 + dialectic_max_chars=_parse_int_config( + host_block.get("dialecticMaxChars"), + raw.get("dialecticMaxChars"), + default=600, ), dialectic_depth=_parse_dialectic_depth( host_block.get("dialecticDepth"), @@ -487,15 +498,15 @@ class HonchoClientConfig: or raw.get("reasoningLevelCap") or "high" ), - message_max_chars=int( - host_block.get("messageMaxChars") - or raw.get("messageMaxChars") - or 25000 + message_max_chars=_parse_int_config( + host_block.get("messageMaxChars"), + raw.get("messageMaxChars"), + default=25000, ), - dialectic_max_input_chars=int( - host_block.get("dialecticMaxInputChars") - or raw.get("dialecticMaxInputChars") - or 10000 + dialectic_max_input_chars=_parse_int_config( + host_block.get("dialecticMaxInputChars"), + raw.get("dialecticMaxInputChars"), + default=10000, ), recall_mode=_normalize_recall_mode( host_block.get("recallMode")