"""Codex audit U01 (distributed training control plane) -- confirmed-open findings. Each test is named after the incident it prevents and FAILED on the pre-fix code. Run: CUDA_VISIBLE_DEVICES= OMP_NUM_THREADS=2 PYTHONPATH=$PWD .venv/bin/python -m pytest -q tests/test_audit_u01_ctrlplane.py """ from __future__ import annotations import gc import glob import json import os import struct import weakref import zipfile import pytest import torch from test_model_parity import tiny_config from test_trainer import _tiny_trainer import align.train.trainer as trainer_mod from align.exit_codes import read_halt_marker from align.train.probes import GradNormTripwire, LengthDriftTripwire, LogpsChosenTripwire from align.train.trainer import HaltError @pytest.fixture def tiny(tiny_model_constants): return tiny_config(tiny_model_constants) def _ckpts(run_dir): return sorted(glob.glob(os.path.join(run_dir, "checkpoints", "micro_*"))) def _flip_payload_byte(path: str) -> None: """Same-size bit flip inside a stored tensor of a torch.save zip (the audit's r8).""" b = bytearray(open(path, "rb").read()) with zipfile.ZipFile(path) as z: info = [i for i in z.infolist() if "/data/" in i.filename and i.file_size > 8][0] off = info.header_offset n, m = struct.unpack("