File size: 10,948 Bytes
6aa6c12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
"""File/metadata-only readiness capture; never imports or initializes the SIM.

Asset receipts establish archive/extraction provenance, not full live-asset
attestation. Selected task/robot files are independently rehashed at reset.
"""
import argparse
import hashlib
import importlib.metadata
import importlib.util
import json
import os
from pathlib import Path
import subprocess
import sys

from benchmarks.simBenchmarks.Behavior.bench_server.protocol import (
    ARCHIVE_DEPLOYMENT, LIVE_DEPLOYMENT, REVISION, TASK_METADATA_SHA256,
)

ARCHIVES = {
    "behavior-1k-assets": "09e9fce600f841dc611aa96c0b1b9f9074f56f0e67898b37b39bd00c38a0095e",
    "omnigibson-robot-assets": "3d813b2181e0581cf2300a40892de70f8475fe59346ceeea4fb9bf7ff21ce126",
    "2026-challenge-task-instances": "d4ac3d72dd585178e85d542f28d1b48233b886c80e196e2f9d3aa5993ba21f81",
}
ASSET_FILES = {
    "2026-challenge-task-instances/metadata/task.jsonl": TASK_METADATA_SHA256,
    "omnigibson-robot-assets/models/r1pro/r1pro.yaml": "63f841cffd5c499102416a797a22fa5b4cbaf146539df7dde8a4a1053e2326f1",
    "omnigibson-robot-assets/models/r1pro/urdf/r1pro.urdf": "b0d76760cbedfbcbe1ddc280380dd5f497bbca380313bc096d7239a2c50dae61",
    "2026-challenge-task-instances/scene_test/public/house_double_floor_lower/json/house_double_floor_lower_task_turning_on_radio_instances/house_double_floor_lower_task_turning_on_radio_0_301_template-tro_state.json": "30a0fe101da1cbf6eb3683d3f9da716399ccd7409974b459dc12a580d2c8ad13",
}
PACKAGES = ("omnigibson", "bddl", "joylo", "torch", "numpy", "isaacsim", "omegaconf", "hydra-core", "imageio", "imageio-ffmpeg")


def digest(path):
    result = hashlib.sha256()
    with Path(path).open("rb") as stream:
        for block in iter(lambda: stream.read(1024 * 1024), b""):
            result.update(block)
    return result.hexdigest()


def absolute(value):
    path = Path(value)
    if not path.is_absolute() or ".." in path.parts:
        raise ValueError("explicit absolute deployment paths required")
    return path


def source_identity(source):
    source = absolute(source)
    def git(*args):
        return subprocess.run(["git", "-c", "safe.directory=" + str(source), "-C", str(source), *args],
                              check=True, capture_output=True).stdout
    if git("rev-parse", "HEAD").decode().strip() != REVISION:
        raise ValueError("BEHAVIOR source revision differs")
    rows = []
    roots = ("OmniGibson/omnigibson", "bddl3/bddl", "joylo/gello")
    for entry in git("ls-tree", "-rz", REVISION, "--", *roots).split(b"\0"):
        if not entry:
            continue
        meta, name = entry.split(b"\t", 1)
        mode, kind, expected = meta.decode().split()
        relative = name.decode()
        path = source / relative
        if kind != "blob" or mode not in ("100644", "100755") or path.is_symlink() or not path.is_file():
            raise ValueError("unsupported or missing native source file")
        data = path.read_bytes()
        if hashlib.sha1(b"blob " + str(len(data)).encode() + b"\0" + data).hexdigest() != expected:
            raise ValueError("modified native source: " + relative)
        rows.append(relative)
    if not rows:
        raise ValueError("empty native source inventory")
    # -B only disables writes: stale or untracked bytecode may still be loaded.
    known = set(rows)
    for root in roots:
        for path in (source / root).rglob("*"):
            if path.is_symlink():
                raise ValueError("native source symlink is not part of this deployment")
            if path.is_file() and path.suffix in (".py", ".pyc", ".pyo", ".so", ".yaml", ".json") and path.relative_to(source).as_posix() not in known:
                raise ValueError("untracked executable/config native source: " + str(path))
    return {"revision": REVISION, "tracked_files_verified": len(rows), "roots": list(roots)}


def runtime_identity(source):
    source = absolute(source)
    origins = {}
    for name, relative in {"omnigibson": "OmniGibson/omnigibson/__init__.py", "bddl": "bddl3/bddl/__init__.py", "gello": "joylo/gello/__init__.py"}.items():
        spec = importlib.util.find_spec(name)  # top-level only: does not execute package
        if spec is None or spec.origin is None or Path(spec.origin).resolve() != (source / relative).resolve():
            raise ValueError("native module origin differs: " + name)
        origins[name] = str(Path(spec.origin).resolve())
    versions = {name: importlib.metadata.version(name) for name in PACKAGES}
    if not versions["isaacsim"].startswith("5.1.") or sys.version_info[:2] != (3, 11):
        raise ValueError("native runtime requires Python3.11 and Isaac Sim5.1")
    if not Path(sys.executable).is_file() or not Path(sys.base_prefix).is_dir():
        raise ValueError("runtime base or interpreter unavailable on current node")
    return {"python": sys.version.split()[0], "executable": str(Path(sys.executable).absolute()),
            "executable_sha256": digest(sys.executable), "base_prefix": sys.base_prefix,
            "versions": versions, "origins": origins}


def asset_identity(data_root, receipts):
    root = absolute(data_root)
    if set(receipts) != set(ARCHIVES):
        raise ValueError("all three archive extraction receipts required")
    result = {}
    for name, expected in ARCHIVES.items():
        path = absolute(receipts[name])
        receipt = json.loads(path.read_text())
        if (receipt.get("archive_sha256") != expected or receipt.get("source_commit") != REVISION
                or Path(receipt.get("target", "")).resolve() != (root / name).resolve()
                or not (root / name).is_dir()):
            raise ValueError("asset extraction receipt differs: " + name)
        result[name] = {"path": str(path), "sha256": digest(path)}
    for name, expected in ASSET_FILES.items():
        if digest(root / name) != expected:
            raise ValueError("selected native asset differs: " + name)
    return result


def live_asset_identity(data_root):
    """Verify selected current bytes, without asserting archive/download origin."""
    root = absolute(data_root).resolve(strict=True)
    for name in ARCHIVES:
        directory = root / name
        if directory.is_symlink() or not directory.is_dir():
            raise ValueError("missing real native asset directory: " + name)
    files = {}
    for name, expected in ASSET_FILES.items():
        path = root / name
        if (path.is_symlink() or not path.is_file()
                or not path.resolve(strict=True).is_relative_to(root)
                or digest(path) != expected):
            raise ValueError("selected live native asset differs: " + name)
        files[name] = {"sha256": expected, "size_bytes": path.stat().st_size}
    return {"selected_files": files, "archive_origin_verified": False,
            "complete_asset_inventory_verified": False}


def verify_track(recorded, deployment_track):
    """Bind the public deployment choice before creating a native worker."""
    if deployment_track == ARCHIVE_DEPLOYMENT:
        if recorded.get("schema") != "behavior2026-deployment/v1" or "deployment_track" in recorded:
            raise ValueError("archive deployment manifest/track differs")
    elif deployment_track == LIVE_DEPLOYMENT:
        if (recorded.get("schema") != "behavior2026-live-deployment/v1"
                or recorded.get("deployment_track") != LIVE_DEPLOYMENT):
            raise ValueError("live deployment manifest/track differs")
    else:
        raise ValueError("unknown BEHAVIOR deployment track")


def capture(source_root, data_root, receipts=None, *, deployment_track=ARCHIVE_DEPLOYMENT):
    if deployment_track not in (ARCHIVE_DEPLOYMENT, LIVE_DEPLOYMENT):
        raise ValueError("unknown BEHAVIOR deployment track")
    if deployment_track == LIVE_DEPLOYMENT and receipts is not None:
        raise ValueError("live deployment does not accept archive receipts")
    if deployment_track == ARCHIVE_DEPLOYMENT and receipts is None:
        raise ValueError("archive deployment requires extraction receipts")
    source = source_identity(source_root)
    runtime = runtime_identity(source_root)
    if deployment_track == LIVE_DEPLOYMENT:
        assets = live_asset_identity(data_root)
        return {"schema": "behavior2026-live-deployment/v1", "deployment_track": LIVE_DEPLOYMENT,
                "source_root": str(absolute(source_root)), "data_root": str(absolute(data_root)),
                "source": source, "runtime": runtime, "live_assets": assets,
                "selected_asset_files": ASSET_FILES,
                "asset_attestation_scope": "current selected task/robot bytes only; no archive origin or complete asset inventory attestation"}
    assets = asset_identity(data_root, receipts)
    return {"schema": "behavior2026-deployment/v1", "source_root": str(absolute(source_root)),
            "data_root": str(absolute(data_root)), "source": source, "runtime": runtime,
            "asset_receipts": assets, "selected_asset_files": ASSET_FILES,
            "asset_attestation_scope": "verified archive extraction receipts and selected files; not all live asset bytes"}


def verify(path, expected_sha256, *, deployment_track=ARCHIVE_DEPLOYMENT):
    path = absolute(path)
    if digest(path) != expected_sha256:
        raise ValueError("deployment manifest hash differs")
    recorded = json.loads(path.read_text())
    verify_track(recorded, deployment_track)
    receipts = ({name: row["path"] for name, row in recorded["asset_receipts"].items()}
                if deployment_track == ARCHIVE_DEPLOYMENT else None)
    current = capture(recorded["source_root"], recorded["data_root"], receipts,
                      deployment_track=deployment_track)
    if current != recorded:
        raise ValueError("native deployment changed since capture")
    return current


def main():
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("--source-root", required=True)
    parser.add_argument("--data-root", required=True)
    parser.add_argument("--deployment-track", choices=(ARCHIVE_DEPLOYMENT, LIVE_DEPLOYMENT),
                        default=ARCHIVE_DEPLOYMENT)
    parser.add_argument("--receipts", help="JSON mapping asset directory name to extraction receipt path (archive track only)")
    parser.add_argument("--output", required=True)
    args = parser.parse_args()
    if (args.deployment_track == ARCHIVE_DEPLOYMENT) != (args.receipts is not None):
        parser.error("--receipts is required only for archive-receipts/v1")
    receipts = json.loads(Path(args.receipts).read_text()) if args.receipts else None
    record = capture(args.source_root, args.data_root, receipts, deployment_track=args.deployment_track)
    with absolute(args.output).open("x") as stream:
        json.dump(record, stream, indent=2, allow_nan=False)
    print(digest(args.output))


if __name__ == "__main__":
    main()