From 619155f1e01457ee02da561200a571cbd5674055 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D1=81=D0=B8=D0=BB=D1=8C=D0=B5=D0=B2=20=D0=9D?= =?UTF-8?q?=D0=B8=D0=BA=D0=B8=D1=82=D0=B0?= Date: Fri, 6 Nov 2026 18:12:56 +0300 Subject: [PATCH] research: save repeatable experiment and sanitized environment manifest --- research/README.md | 4 +- research/run_local.py | 85 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 research/run_local.py diff --git a/research/README.md b/research/README.md index 15e5118e..2806242a 100644 --- a/research/README.md +++ b/research/README.md @@ -29,10 +29,10 @@ Durable intent до S3 PUT, row lock на время PUT/финализации ```sh # Исследование получает admin keys только в отдельном profile tools. # Создаёт отдельные БД и bucket, очищает только их в finally. -docker compose run --rm --no-deps research > evidence/reconcile-repeat-raw.txt 2>&1 +uv run --locked python research/run_local.py --output evidence/reconcile-repeat.json ``` -В строке `RESULT ` находится JSON с исходными счётчиками, проверками, хешами кода и результатами времени. Основная messenger БД и bucket не очищаются. +Контроллер сохраняет raw output, JSON со счётчиками, проверками, хешами кода, результатами времени и кратким host manifest; рядом создаётся summary.md. В исходном выводе контейнера JSON начинается со строки `RESULT `. Основная messenger БД и bucket не очищаются. Ошибки: настоящий trigger PostgreSQL после PUT; реальная ошибка подключения S3; успешный COMMIT с искусственно потерянным подтверждением; ошибка DELETE PostgreSQL после удаления bytes; ошибка S3 delete. Проверяются повтор, dry-run после сбоя, старый intent со свежим объектом, live row lock, missing used metadata и сохранность подтверждённого оригинала. diff --git a/research/run_local.py b/research/run_local.py new file mode 100644 index 00000000..edde11ba --- /dev/null +++ b/research/run_local.py @@ -0,0 +1,85 @@ +"""Run and save the isolated experiment, plus a small sanitized host manifest.""" + +import argparse +import json +import platform +import subprocess +import sys +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[1] + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("--output", default="evidence/reconcile-study.json") + args = parser.parse_args() + output = ROOT / args.output + output.parent.mkdir(parents=True, exist_ok=True) + run = subprocess.run( + ["docker", "compose", "run", "--rm", "--no-deps", "research"], + cwd=ROOT, + capture_output=True, + text=True, + ) + output.with_suffix(".raw.txt").write_text(run.stdout + run.stderr) + if run.returncode: + raise SystemExit(f"Experiment failed; inspect {output.with_suffix('.raw.txt')}") + marker = next( + (line[7:] for line in run.stdout.splitlines() if line.startswith("RESULT ")), None + ) + if marker is None: + raise SystemExit("Experiment did not emit RESULT") + result = json.loads(marker) + result["host_manifest"] = { + "system": platform.system(), + "machine": platform.machine(), + "release": platform.release(), + "git_revision": subprocess.check_output( + ["git", "rev-parse", "HEAD"], cwd=ROOT, text=True + ).strip(), + } + result["host_manifest"]["docker"] = json.loads( + subprocess.check_output( + [ + "docker", + "info", + "--format", + '{"version":"{{.ServerVersion}}","cpus":{{.NCPU}},"memory_bytes":{{.MemTotal}}}', + ], + text=True, + ) + ) + containers = subprocess.check_output( + ["docker", "compose", "ps", "-q"], cwd=ROOT, text=True + ).split() + result["host_manifest"]["containers"] = [] + for container in containers: + record = json.loads(subprocess.check_output(["docker", "inspect", container], text=True))[0] + result["host_manifest"]["containers"].append( + { + "service": record["Config"]["Labels"].get("com.docker.compose.service"), + "image": record["Image"], + "cpu_nano": record["HostConfig"]["NanoCpus"], + "memory_limit": record["HostConfig"]["Memory"], + } + ) + output.write_text(json.dumps(result, ensure_ascii=False, indent=2) + "\n") + subprocess.run( + [ + sys.executable, + "research/analyze.py", + str(output), + "--output", + str(output.with_suffix(".summary.md")), + ], + cwd=ROOT, + check=True, + ) + print( + f"Saved {len(result['checks'])} checks and {len(result['scan_cost'])} scan runs to {output}" + ) + + +if __name__ == "__main__": + main()