fix: avoid io token false positives

This commit is contained in:
Brad Stein 2026-02-02 11:49:07 -03:00
parent be1df4dcd0
commit 78023ca956

View File

@ -590,7 +590,7 @@ class AnswerEngine:
reply = f"From the latest snapshot: {target}={count} ({nodes})." reply = f"From the latest snapshot: {target}={count} ({nodes})."
else: else:
reply = f"From the latest snapshot: {target}={count}." reply = f"From the latest snapshot: {target}={count}."
if ("io" in lowered_q or "i/o" in lowered_q) and ("node" in lowered_q or "nodes" in lowered_q): if _has_token(lowered_q, "io") and ("node" in lowered_q or "nodes" in lowered_q):
io_facts = _extract_hottest_facts(summary_lines, lowered_q) io_facts = _extract_hottest_facts(summary_lines, lowered_q)
io_line = next((fact for fact in io_facts if fact.startswith("hottest_io_node")), None) io_line = next((fact for fact in io_facts if fact.startswith("hottest_io_node")), None)
if io_line: if io_line:
@ -1193,6 +1193,14 @@ def _expand_hottest_line(line: str) -> list[str]:
return expanded return expanded
def _has_token(text: str, token: str) -> bool:
if not text or not token:
return False
if token == "io":
return "i/o" in text or re.search(r"\bio\b", text) is not None
return re.search(rf"\b{re.escape(token)}\b", text) is not None
def _extract_hottest_facts(lines: list[str], question: str) -> list[str]: def _extract_hottest_facts(lines: list[str], question: str) -> list[str]:
if not lines: if not lines:
return [] return []
@ -1222,17 +1230,17 @@ def _extract_hottest_facts(lines: list[str], question: str) -> list[str]:
if not facts: if not facts:
return [] return []
wanted = [] wanted = []
if ("io" in lowered or "i/o" in lowered) and ("disk" in lowered or "storage" in lowered): if _has_token(lowered, "io") and ("disk" in lowered or "storage" in lowered):
return [fact for fact in facts if fact.startswith("hottest_io_node")] return [fact for fact in facts if fact.startswith("hottest_io_node")]
if any(term in lowered for term in ("cpu", "processor")): if _has_token(lowered, "cpu") or "processor" in lowered:
wanted.append("hottest_cpu_node") wanted.append("hottest_cpu_node")
if any(term in lowered for term in ("ram", "memory")): if _has_token(lowered, "ram") or "memory" in lowered:
wanted.append("hottest_ram_node") wanted.append("hottest_ram_node")
if any(term in lowered for term in ("net", "network", "throughput")): if _has_token(lowered, "net") or "network" in lowered or "throughput" in lowered:
wanted.append("hottest_net_node") wanted.append("hottest_net_node")
if "io" in lowered or "i/o" in lowered: if _has_token(lowered, "io"):
wanted.append("hottest_io_node") wanted.append("hottest_io_node")
if "disk" in lowered or "storage" in lowered: if _has_token(lowered, "disk") or "storage" in lowered:
wanted.append("hottest_disk_node") wanted.append("hottest_disk_node")
if not wanted: if not wanted:
return facts return facts