From 9da48ab0bd427276a686a4b0a45c554df6f2321a Mon Sep 17 00:00:00 2001 From: "E.G" <146701565+GlobalStar117@users.noreply.github.com> Date: Mon, 19 Jan 2026 15:46:06 +1100 Subject: [PATCH] fix: Handle NaN/Infinity values in ExeSQL JSON response (#12666) ## Summary Fixes #12631 When SQL query results contain NaN (Not a Number) or Infinity values (e.g., from division by zero or other calculations), the JSON serialization would fail because **NaN and Infinity are not valid JSON values**. This caused the agent interface to show 'undefined' error, as described in the issue where `EXAMINE_TIMES` became `NaN` and broke the JSON parsing. ## Root Cause The `convert_decimals` function in `exesql.py` was only handling `Decimal` types, but not `float` values that could be `NaN` or `Infinity`. When these invalid JSON values were serialized: ```json {"EXAMINE_TIMES": NaN} // Invalid JSON! ``` The frontend JSON parser would fail, causing the 'undefined' error. ## Solution Extended `convert_decimals` to detect `float` values and convert `NaN`/`Infinity` to `null` before JSON serialization: ```python if isinstance(obj, float): if math.isnan(obj) or math.isinf(obj): return None return obj ``` This ensures all SQL results can be properly serialized to valid JSON. --- This is a Gittensor contribution. gittensor:user:GlobalStar117 Co-authored-by: GlobalStar117 Co-authored-by: Jin Hai Co-authored-by: Zhichang Yu --- agent/tools/exesql.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/agent/tools/exesql.py b/agent/tools/exesql.py index 012b00d84..8f3f9dd17 100644 --- a/agent/tools/exesql.py +++ b/agent/tools/exesql.py @@ -86,6 +86,12 @@ class ExeSQL(ToolBase, ABC): def convert_decimals(obj): from decimal import Decimal + import math + if isinstance(obj, float): + # Handle NaN and Infinity which are not valid JSON values + if math.isnan(obj) or math.isinf(obj): + return None + return obj if isinstance(obj, Decimal): return float(obj) # 或 str(obj) elif isinstance(obj, dict):