From 3fe1188a4d23cd685fabee73a54f6b4e012218e9 Mon Sep 17 00:00:00 2001 From: Hasan Basbunar Date: Mon, 26 Oct 2026 18:39:06 +0100 Subject: [PATCH] cpu-hogs: no separator a reader splits on, cgroups read as bytes, and bench.sh says why it failed printable() let U+2028 and U+2029 through, which str.splitlines() in bench.sh takes for line ends: a busy process whose name held one vanished from the report, which then claimed a quiet box (code review, 2026-10-26). Anything not printable becomes a space now. cgroup() read /proc//cgroup as strict text, the failure fixed for stat in df39e91: it reads bytes too. bench.sh threw away a failing cpu-hogs.py's output, so a window out of 0.5 to 60 s or a crash read only as "cpu-hogs failed (exit 2)": its last line is given now. And tests/test_bench_median.py runs bench.sh with the docker that lists no container, as the other two do. Three checks fail on the previous code. Co-Authored-By: Claude Opus 5.5 --- bench.sh | 10 ++++++---- cpu-hogs.py | 10 ++++++---- tests/test_bench_lane.py | 6 ++++++ tests/test_bench_median.py | 9 ++++++++- tests/test_cpu_hogs.py | 5 +++++ 5 files changed, 31 insertions(+), 9 deletions(-) diff --git a/bench.sh b/bench.sh index 272ca606..71800538 100755 --- a/bench.sh +++ b/bench.sh @@ -19,13 +19,14 @@ HOGS_WINDOW="${HOGS_WINDOW:-3}" # A cpu-hogs that died must never read as a quiet box (revue 627, 2026-10-26): the # "2>/dev/null || true" used to swallow every failure (missing file, crash, a non-numeric # window from the caller) and the report then claimed nothing outside the engine held a core. +# Its last line says why it failed (a window out of 0.5 to 60 s, a crash), which the report gives. if HOGS="$(python3 "$(dirname "$0")/cpu-hogs.py" --window "$HOGS_WINDOW" 2>&1)"; then - HOGS_FAILED=0 + HOGS_FAILED=0; HOGS_ERR="" else - HOGS_FAILED=$?; HOGS="" + HOGS_FAILED=$?; HOGS_ERR="$(printf '%s\n' "$HOGS" | tail -n 1)"; HOGS="" fi -KEY="$(cat "$KEY_FILE")" PORT="$PORT" HOGS="$HOGS" HOGS_FAILED="$HOGS_FAILED" HOGS_WINDOW="$HOGS_WINDOW" python3 - <<'PYEOF' +KEY="$(cat "$KEY_FILE")" PORT="$PORT" HOGS="$HOGS" HOGS_FAILED="$HOGS_FAILED" HOGS_ERR="$HOGS_ERR" HOGS_WINDOW="$HOGS_WINDOW" python3 - <<'PYEOF' import json, os, statistics, time, urllib.request KEY, PORT = os.environ["KEY"], os.environ["PORT"] @@ -141,7 +142,8 @@ print(f"{reference}\n") # pid, share of a core, name and command line, tab-separated, from cpu-hogs.py HOGS = [line.split("\t") for line in os.environ.get("HOGS", "").splitlines() if line.count("\t") == 3] if os.environ.get("HOGS_FAILED", "0") != "0": - print(f"busy before the run: cpu-hogs failed (exit {os.environ['HOGS_FAILED']}), the quiet outside the engine is NOT proven, do not publish these numbers as clean\n") + why = "".join(c if c.isprintable() else " " for c in os.environ.get("HOGS_ERR", ""))[:200] + print(f"busy before the run: cpu-hogs failed (exit {os.environ['HOGS_FAILED']}{': ' + why if why else ''}), the quiet outside the engine is NOT proven, do not publish these numbers as clean\n") elif HOGS: print(f"busy before the run, outside the engine (half a core or more over {os.environ['HOGS_WINDOW']} s):") # its pid and name, never its command line: this report gets pasted in public, and a command line can diff --git a/cpu-hogs.py b/cpu-hogs.py index d5f95280..b0fc1f57 100644 --- a/cpu-hogs.py +++ b/cpu-hogs.py @@ -56,8 +56,8 @@ def engine_ids(): def cgroup(pid, proc="/proc"): try: - with open(f"{proc}/{pid}/cgroup") as f: - return f.read() + with open(f"{proc}/{pid}/cgroup", "rb") as f: # bytes, as stat: a path is not always UTF-8 + return f.read().decode(errors="replace") except OSError: return "" @@ -100,8 +100,10 @@ def hogs(window=3.0, floor=0.5, proc="/proc"): def printable(text): """A field of the tab-separated output: no tab or newline to split the line (bench.sh keeps lines of four fields, and a busy process with a tab in its argv vanished from its report), and no control character a - terminal would act on (an argv can carry an escape sequence) (verification, 2026-10-26).""" - return "".join(" " if ord(c) < 32 or 127 <= ord(c) < 160 else c for c in text) + terminal would act on (an argv can carry an escape sequence) (verification, 2026-10-26). Nothing that is + not printable: U+2028 and U+2029 end a line for splitlines() too, and a name holding one hid its busy + process from bench.sh's report (code review, 2026-10-26).""" + return "".join(c if c.isprintable() else " " for c in text) def main(argv): diff --git a/tests/test_bench_lane.py b/tests/test_bench_lane.py index be42d125..b7f45044 100644 --- a/tests/test_bench_lane.py +++ b/tests/test_bench_lane.py @@ -183,6 +183,12 @@ def main(): out = run_bench("qwen3.8-27b", window="not-a-number") if "cpu-hogs failed" not in out: fails.append(f"a failing cpu-hogs did not say so:\n{out[:400]}") + # and why: its error was thrown away with its output (code review, 2026-10-26) + if "invalid float value" not in out: + fails.append(f"a failing cpu-hogs did not say why:\n{out[:400]}") + out = run_bench("qwen3.8-27b", window="0.3") + if "must be 0.5 to 60 s" not in out or "cpu-hogs failed (exit 2" not in out: + fails.append(f"a window under 0.5 s did not fail with its reason:\n{out[:400]}") if "nothing outside the engine held half a core" in out: fails.append("a failing cpu-hogs still let the quiet-box claim through") diff --git a/tests/test_bench_median.py b/tests/test_bench_median.py index 576d8658..0a5cbdf7 100644 --- a/tests/test_bench_median.py +++ b/tests/test_bench_median.py @@ -62,9 +62,16 @@ class TheMedian(unittest.TestCase): os.makedirs(os.path.join(home, ".config", "qwen38")) with open(os.path.join(home, ".config", "qwen38", "api-key"), "w") as f: f.write("test-key\n") + # cpu-hogs.py asks docker which containers are the engine's: the offline suite asks no docker + # (TESTING.md), so a docker that lists none comes first on PATH (code review, 2026-10-26) + os.makedirs(os.path.join(home, "bin")) + with open(os.path.join(home, "bin", "docker"), "w") as f: + f.write("#!/bin/sh\nexit 0\n") + os.chmod(os.path.join(home, "bin", "docker"), 0o755) try: r = subprocess.run(["bash", str(BENCH)], capture_output=True, text=True, timeout=120, - env={**os.environ, "PORT": str(srv.server_port), "HOME": home}) + env={**os.environ, "PORT": str(srv.server_port), "HOME": home, + "PATH": os.path.join(home, "bin") + os.pathsep + os.environ.get("PATH", "")}) finally: srv.shutdown() srv.server_close() diff --git a/tests/test_cpu_hogs.py b/tests/test_cpu_hogs.py index 26fcb149..6331f2b6 100644 --- a/tests/test_cpu_hogs.py +++ b/tests/test_cpu_hogs.py @@ -127,6 +127,11 @@ class OnThisMachine(unittest.TestCase): self.assertEqual(len(mine[0]), 4, mine) self.assertNotIn("\x1b", r.stdout) + def test_no_line_or_paragraph_separator_reaches_the_output(self): + # U+2028 and U+2029 end a line for str.splitlines(), which bench.sh reads with: a name holding one + # hid its busy process from the report (code review, 2026-10-26) + self.assertEqual(hogs.printable("spin\u2028x\u2029y\x85z\tw"), "spin x y z w") + def test_a_window_too_short_or_long_is_refused(self): # a window of 0 turned one clock tick into several cores: ghosts above 100 % (code review, 2026-10-26) for window in ("0", "0.1", "nan", "inf", "61"):