Failed `int("10.0")` pattern causes parsing errors, agent looping on `"majentik/Qwen3-Coder-Next-MLX-8bit"`
Author: essandessCreated Sep 24, 2026Updated Sep 24, 2026
I observe the regular parsing error warnings using the latest version of mlx-lm with "majentik/Qwen3-Coder-Next-MLX-8bit":
WARNING - Failed to parse tool call (ValueError: invalid literal for int() with base 10: '10.0') — tool text was likely truncated mid-generation.This issue is caused by unsafe text-to-int conversion in the function _convert_param_value in mlx_lm/tool_parsers/qwen3_coder.py (see below).
The fix is straightforward; I've pasted a suggested patch below included in https://github.com/macports/macports-ports/pull/34891:
diff -Naurd ./mlx_lm/tool_parsers/qwen3_coder.py ./mlx_lm/tool_parsers/qwen3_coder.py
--- ./mlx_lm/tool_parsers/qwen3_coder.py 2026-09-23 14:57:40
+++ ./mlx_lm/tool_parsers/qwen3_coder.py 2026-09-23 15:07:26
@@ -33,6 +33,33 @@
return {}
+# Handle mlx_lm.server errors observed on "majentik/Qwen3-Coder-Next-MLX-8bit"
+# E.g. `WARNING - Failed to parse tool call (ValueError: invalid literal for int() with base 10: '137.0') — tool text was likely truncated mid-generation.`
+# This issue is observed to cause agent looping and appears to be exacerbated by larger (~120k) token contexts on 128 GB machines
+def _safe_str_to_int(val: str) -> int:
+ """
+ Safely converts a string representation of a float or int (e.g., "50.0", "50")
+ into an integer. Returns a ValueError with a clean message if conversion fails.
+ """
+ if val is None:
+ raise ValueError("Input value cannot be None")
+
+ # Strip whitespace to prevent spacing issues
+ clean_val = str(val).strip()
+
+ try:
+ # First pass: try direct integer conversion (fastest for true ints)
+ return int(clean_val)
+ except ValueError:
+ try:
+ # Second pass: handle float strings like "50.0" or "50.7"
+ # Note: int(50.7) will truncate to 50.
+ # If you want to round instead, use int(round(float(clean_val)))
+ return int(float(clean_val))
+ except ValueError:
+ raise ValueError(f"Could not convert string to integer: {val}")
+
+
def _convert_param_value(param_value: str, param_name: str, param_config: dict) -> Any:
"""Convert parameter value based on its type in the schema."""
if param_value.lower() == "null":
@@ -54,7 +81,7 @@
or param_type.startswith("short")
or param_type.startswith("unsigned")
):
- return int(param_value)
+ return _safe_str_to_int(param_value)
elif param_type.startswith("num") or param_type.startswith("float"):
float_param_value = float(param_value)
int_param_value = int(float_param_value)Source: ml-explore/mlx-lm