From 6fd80541c5a8307bb9cd1fc9674b189d9fb1cacf Mon Sep 17 00:00:00 2001 From: John Menke Date: Sun, 1 Nov 2026 14:22:10 -0500 Subject: [PATCH] Fail the listen check when a LISTEN address cannot be parsed. That row was dropped, so the check warned that Ollama was down instead of failing closed. Co-authored-by: Cursor --- src/local_coding_slm/safety.py | 5 ++--- tests/test_safety.py | 9 +++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/local_coding_slm/safety.py b/src/local_coding_slm/safety.py index cd75ce1..e7de07a 100644 --- a/src/local_coding_slm/safety.py +++ b/src/local_coding_slm/safety.py @@ -218,9 +218,8 @@ def parse_proc_net_listen_ports(text: str) -> list[tuple[str, int]]: port = int(port_hex, 16) except ValueError: continue - ip = _hex_ip(addr_hex) - if ip is not None: - found.append((ip, port)) + ip = _hex_ip(addr_hex) or "unparsed" + found.append((ip, port)) return found diff --git a/tests/test_safety.py b/tests/test_safety.py index 70c04c6..4538105 100644 --- a/tests/test_safety.py +++ b/tests/test_safety.py @@ -159,6 +159,15 @@ def test_missing_listener_warns(self) -> None: result = classify_local_listeners([]) self.assertEqual(result.status, "warn") + def test_unparsed_listen_address_fails(self) -> None: + """A LISTEN row whose address cannot be parsed is not 'Ollama is down'.""" + text = ( + " sl local_address rem_address st\n" + " 0: GGGGGGGG:2CAA 00000000:0000 0A 00000000:00000000\n" + ) + result = classify_local_listeners(parse_proc_net_listen_ports(text)) + self.assertEqual(result.status, "fail", result.message) + class TestHygiene(unittest.TestCase): def test_placeholder_ips_pass(self) -> None: