"""Fail-closed C-001 receipt join for the interactive HBM teaching path. This CPU-safe fixture defines the join. It does not claim that GLM-5.2 ran, that a GPU dispatched a kernel, or that power, cooling, water, or cost were measured. A live packet must replace every ``None`` field with an artifact carrying the same non-empty run_id. """ from __future__ import annotations from dataclasses import dataclass from typing import Any WORKLOAD = { "fixture_id": "C-001", "harness": "Hermes Agent", "model": "zai-org/GLM-5.2-FP8", "task": ( "Inspect the repository, make one bounded code change, use the declared " "tools, run the tests, and return a reviewable patch only after the " "named verifier passes." ), "prompt_parts": ( "system instructions", "tool schemas", "repository map and selected files", "prior turns and tool results", "current task and acceptance test", ), "tools": ("read_file", "search", "apply_patch", "terminal", "test_verifier"), "precision": { "checkpoint": "FP8", "activations": None, "kv_cache": None, "accumulation": None, "reason": "A checkpoint label does not prove every runtime dtype.", }, } TRACE_ORDER = ( "request", "context", "route", "prefix_lookup", "prefill", "attention_moe", "operator_and_kernel", "hbm_traffic", "kv_placement", "fabric_movement", "decode", "tool_and_verifier", "power_cooling_water_cost", ) REQUIRED_RECEIPTS = { "request": "prompt, task, tool schema, model and tokenizer identity", "software": "Hermes, engine, model revision, precision tuple and config", "kernel": "dispatch, executable, architecture, profiler and correctness", "hbm": "time-aligned read/write bytes and allocator state", "fabric": "link, source, target, bytes, direction and transfer interval", "power": "time-aligned device/node/facility meter samples", "cooling": "declared heat boundary, equipment mode and allocated energy", "water": "declared site boundary and measured or allocated consumed water", "cost": "tariff, GPU/capacity allocation, retries and accepted outcome", } @dataclass(frozen=True) class Receipt: kind: str run_id: str | None observation: str payload: dict[str, Any] def join_receipts(receipts: list[Receipt]) -> dict[str, Any]: """Join one run or fail closed without inventing downstream values.""" by_kind = {receipt.kind: receipt for receipt in receipts} run_ids = {receipt.run_id for receipt in receipts if receipt.run_id} missing = [kind for kind in REQUIRED_RECEIPTS if kind not in by_kind] if len(run_ids) != 1 or missing: return { "status": ( "INVALID / MIXED RUN IDS" if len(run_ids) > 1 else "ARCHITECTURE ONLY / RUN NOT CAPTURED" ), "run_id": None, "missing_receipts": missing, "hbm_bytes": None, "fabric_bytes": None, "device_energy_j": None, "facility_energy_kwh": None, "cooling_energy_kwh": None, "water_liters_consumed": None, "cost_per_accepted_patch_usd": None, } run_id = run_ids.pop() if any(receipt.run_id != run_id for receipt in receipts): raise ValueError("mixed run IDs are invalid") return { "status": "JOINED / NOT AUTOMATICALLY ACCEPTED", "run_id": run_id, "observations": {kind: receipt.observation for kind, receipt in by_kind.items()}, "values": {kind: receipt.payload for kind, receipt in by_kind.items()}, } if __name__ == "__main__": result = join_receipts([]) assert result["run_id"] is None assert result["water_liters_consumed"] is None print(result["status"])