From f0754d4f2aac2e3a2882b5f6592e1b3d749286ae Mon Sep 17 00:00:00 2001 From: Hasan Basbunar Date: Thu, 24 Sep 2026 19:23:53 +0200 Subject: [PATCH] conc-check.py: the verdict is the exit status too; the docstring gives the real defaults It printed wrong answers, contamination and failed requests and exited 0 whatever it found: 0 is now all right, 1 a wrong or contaminated answer, 3 a failed request. Its usage line said 60 serial and 304 concurrent, the size of the published runs, while the defaults are 40 and 160. Found in review, 2026-09-24 (T24). Co-Authored-By: Claude Opus 5.5 (1M context) --- conc-check.py | 26 ++++++--- tests/test_conc_check_exit.py | 103 ++++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+), 7 deletions(-) create mode 100644 tests/test_conc_check_exit.py diff --git a/conc-check.py b/conc-check.py index 8c4a7c16..14e797db 100644 --- a/conc-check.py +++ b/conc-check.py @@ -12,9 +12,13 @@ Four deterministic ordering tasks, greedy, thinking off, exactly one right answe each. The serial pass proves the model can do them at all; the concurrent pass is the measurement. Any gap between the two is the engine, not the model. - python3 conc-check.py # 60 serial, 304 at concurrency 8 + python3 conc-check.py # 40 serial, 160 at concurrency 8 + python3 conc-check.py --serial 60 --conc-n 304 # the size of the runs below python3 conc-check.py --conc 4 --conc-n 96 +Exit status: 0 when every answer was right, 1 when one was wrong or carried another +request's answer, 3 when a request failed, so part of the run measured nothing. + Measured on the reference box, 2026-09-03, both heads, DFlash2 x8 and --max-running-requests 8, on the 1M unit (fp8 KV, mem fraction 0.70, chunk 8192): @@ -131,16 +135,17 @@ def run(n, conc, model, label, pad=0): print(f" {verdict.upper()} [{name}] {got!r}") for e in errs[:3]: print(f" ERR {e}") - return wrong + contam, contam + return wrong + contam, contam, len(errs) -if __name__ == "__main__": + +def main(argv=None): p = argparse.ArgumentParser() p.add_argument("--serial", type=int, default=40) p.add_argument("--conc-n", type=int, default=160) p.add_argument("--conc", type=int, default=8) p.add_argument("--pad", type=int, default=0, help="approximate filler tokens per request, unique to each request") - a = p.parse_args() + a = p.parse_args(argv) model = None for route in ("/model_info", "/get_model_info"): # the old one is deprecated upstream try: @@ -152,7 +157,14 @@ if __name__ == "__main__": raise print(f"modele: {model}\n") tag = f", {a.pad} tokens de contexte propre" if a.pad else "" - b1, c1 = run(a.serial, 1, model, f"serie (c=1, n={a.serial}{tag})", a.pad) - b2, c2 = run(a.conc_n, a.conc, model, f"concurrent (c={a.conc}, n={a.conc_n}{tag})", a.pad) + b1, c1, e1 = run(a.serial, 1, model, f"serie (c=1, n={a.serial}{tag})", a.pad) + b2, c2, e2 = run(a.conc_n, a.conc, model, f"concurrent (c={a.conc}, n={a.conc_n}{tag})", a.pad) print(f"\nverdict: serie {b1} faux/contamines, concurrent {b2} faux/contamines, " - f"{c1 + c2} contamination(s) croisee(s)") + f"{c1 + c2} contamination(s) croisee(s)" + (f", {e1 + e2} requete(s) en erreur" if e1 + e2 else "")) + # The verdict is the exit status too: it exited 0 whatever it found, wrong answers, + # contamination and failed requests included (found in review, 2026-09-24). + return 3 if e1 + e2 else (1 if b1 + b2 else 0) + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/tests/test_conc_check_exit.py b/tests/test_conc_check_exit.py new file mode 100644 index 00000000..dc4e0b61 --- /dev/null +++ b/tests/test_conc_check_exit.py @@ -0,0 +1,103 @@ +#!/usr/bin/env python3 +"""conc-check.py's verdict is its exit status too. + +It printed wrong answers, cross-request contamination and failed requests, and exited 0 +whatever it found (found in review, 2026-09-24), so no caller could gate on it. A fake +engine answers every task right, one wrong, or refuses. +""" +import contextlib +import http.server +import importlib.util +import io +import json +import os +import pathlib +import shutil +import tempfile +import threading +import unittest + +REPO = pathlib.Path(__file__).resolve().parents[1] +MODE = ["right"] + + +def load(): + home = tempfile.mkdtemp(prefix="conc-home-") + (pathlib.Path(home) / ".config" / "qwen38").mkdir(parents=True) + (pathlib.Path(home) / ".config" / "qwen38" / "api-key").write_text("test-key\n") + real = os.environ.get("HOME") + os.environ["HOME"] = home # the key is read at import + try: + spec = importlib.util.spec_from_file_location("conc_check_exit", REPO / "conc-check.py") + mod = importlib.util.module_from_spec(spec) + spec.loader.exec_module(mod) + return mod + finally: + if real is None: + os.environ.pop("HOME", None) + else: + os.environ["HOME"] = real + shutil.rmtree(home, ignore_errors=True) + + +cc = load() + + +class Fake(http.server.BaseHTTPRequestHandler): + protocol_version = "HTTP/1.1" + + def log_message(self, *a): + pass + + def send(self, code, obj): + raw = json.dumps(obj).encode() + self.send_response(code) + self.send_header("Content-Type", "application/json") + self.send_header("Content-Length", str(len(raw))) + self.end_headers() + self.wfile.write(raw) + + def do_GET(self): + self.send(200, {"model_path": "m"}) + + def do_POST(self): + body = json.loads(self.rfile.read(int(self.headers.get("Content-Length") or 0))) + prompt = body["messages"][0]["content"] + if MODE[0] == "error": + return self.send(500, {"error": "boom"}) + name, _, want = next(t for t in cc.TASKS if t[1] in prompt) + answer = "no idea" if (MODE[0] == "wrong" and name == cc.TASKS[0][0]) else want + self.send(200, {"choices": [{"message": {"content": answer}}]}) + + +class TheExitStatus(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.srv = http.server.ThreadingHTTPServer(("127.0.0.1", 0), Fake) + cls.srv.daemon_threads = True + threading.Thread(target=cls.srv.serve_forever, daemon=True).start() + cls.old_base, cc.BASE = cc.BASE, f"http://127.0.0.1:{cls.srv.server_port}" + + @classmethod + def tearDownClass(cls): + cc.BASE = cls.old_base + cls.srv.shutdown() + cls.srv.server_close() + + def status(self, mode): + MODE[0] = mode + with contextlib.redirect_stdout(io.StringIO()): + return cc.main(["--serial", "4", "--conc-n", "8", "--conc", "2"]) + + def test_every_answer_right_is_0(self): + self.assertEqual(self.status("right"), 0) + + def test_a_wrong_answer_is_1(self): + self.assertEqual(self.status("wrong"), 1) + + def test_a_failed_request_is_3(self): + self.assertEqual(self.status("error"), 3) + + +if __name__ == "__main__": + unittest.main()