Scripts: coverage_gate.py ignores the sweep's exit code, so a failed sweep passes and --update can lower the baseline to match it #2260

Open
opened 2026-11-26 05:24:51 +00:00 by github-bot · 1 comment
Owner

@⁠itsonewi on GitHub · 2026-11-25 11:42 UTC · original

Summary

scripts/coverage_gate.py (426a5a7) runs the sweep and then reads only its stdout:

proc = subprocess.run(cmd, capture_output=True, text=True)
try:
    run = sweep_json(proc.stdout)
except ValueError as e:
    ...
    return 2

proc.returncode is never inspected. If the sweep exits non-zero but still printed a report line that parses - a worker that died after the summary, a panic or an OOM on the last programs, a sweep cut short with a partial count - the gate treats it as a complete sweep and compares it against the baseline.

Why it matters more with --update

--update writes the baseline before anything is compared, and from whatever the sweep reported:

if args.update:
    ...
    args.baseline.write_text(json.dumps({"stages": run["stages"]}, ...))
    print(f"baseline written: {args.baseline}")
    return 0

So a failed sweep does not just pass once: it can replace the committed reference with the lower counts of the build that failed, and every later run compares against that. The gate then reports "no regressions" for exactly the translation loss it exists to catch.

Not #2196, #2250 or #2099

  • #2196 is --validate never being passed, so validator_failed is always 0.
  • #2250 / #2253 are the empty sweep erasing the baseline.
  • #2099 is argument and error-path hardening: a missing --xcl/--rpf, an unreadable --run-json, malformed JSON, a spawn failure. A subprocess that starts, runs and exits non-zero is not one of those - that path has no check at all.

Suggested fix

if proc.returncode != 0:
    print(f"the sweep exited {proc.returncode}: {proc.stderr[-2000:]}", file=sys.stderr)
    return 2

right after subprocess.run, before sweep_json(proc.stdout). --run-json is unaffected (no process is started). Two tests in scripts/test_coverage_gate.py would cover it: a sweep fixture that exits 1 with a valid report line (expect 2, and the baseline byte-for-byte unchanged with --update).

Tested

  • Nothing run: read from 426a5a7 without a checkout. The claim is the absence of a read of proc.returncode in the file.

AI use

  • Claude (Opus 5.5) read scripts/coverage_gate.py and scripts/test_coverage_gate.py on 426a5a7 and wrote this report; the human account checked the lines against the file before opening it.
**@⁠itsonewi** on GitHub · 2026-11-25 11:42 UTC · [original](https://github.com/xcl-dev/xcl/issues/2260) ### Summary `scripts/coverage_gate.py` (`426a5a7`) runs the sweep and then reads only its stdout: ```python proc = subprocess.run(cmd, capture_output=True, text=True) try: run = sweep_json(proc.stdout) except ValueError as e: ... return 2 ``` `proc.returncode` is never inspected. If the sweep exits non-zero but still printed a report line that parses - a worker that died after the summary, a panic or an OOM on the last programs, a sweep cut short with a partial count - the gate treats it as a complete sweep and compares it against the baseline. ### Why it matters more with `--update` `--update` writes the baseline **before** anything is compared, and from whatever the sweep reported: ```python if args.update: ... args.baseline.write_text(json.dumps({"stages": run["stages"]}, ...)) print(f"baseline written: {args.baseline}") return 0 ``` So a failed sweep does not just pass once: it can replace the committed reference with the lower counts of the build that failed, and every later run compares against that. The gate then reports "no regressions" for exactly the translation loss it exists to catch. ### Not #2196, #2250 or #2099 - #2196 is `--validate` never being passed, so `validator_failed` is always 0. - #2250 / #2253 are the empty sweep erasing the baseline. - #2099 is argument and error-path hardening: a missing `--xcl`/`--rpf`, an unreadable `--run-json`, malformed JSON, a spawn failure. A subprocess that starts, runs and exits non-zero is not one of those - that path has no check at all. ### Suggested fix ```python if proc.returncode != 0: print(f"the sweep exited {proc.returncode}: {proc.stderr[-2000:]}", file=sys.stderr) return 2 ``` right after `subprocess.run`, before `sweep_json(proc.stdout)`. `--run-json` is unaffected (no process is started). Two tests in `scripts/test_coverage_gate.py` would cover it: a sweep fixture that exits 1 with a valid report line (expect 2, and the baseline byte-for-byte unchanged with `--update`). **Tested** - Nothing run: read from `426a5a7` without a checkout. The claim is the absence of a read of `proc.returncode` in the file. **AI use** - Claude (Opus 5.5) read `scripts/coverage_gate.py` and `scripts/test_coverage_gate.py` on `426a5a7` and wrote this report; the human account checked the lines against the file before opening it.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:24:51 +00:00
Author
Owner

@⁠Creaa on GitHub · 2026-11-25 11:48 UTC · original

I’m taking this. The fix and regression test are ready locally. I’m running the full workspace suite before opening the PR.

**@⁠Creaa** on GitHub · 2026-11-25 11:48 UTC · [original](https://github.com/xcl-dev/xcl/issues/2260#issuecomment-7161524211) I’m taking this. The fix and regression test are ready locally. I’m running the full workspace suite before opening the PR.
This discussion has been locked. Commenting is limited to contributors.
No description provided.