Datasets:

Modalities:
Text
Languages:
English
Size:
< 1K
ArXiv:
Libraries:
Datasets
Harbor
License:
lewtun's picture
lewtun HF Staff
s3-maze: 32 trees from seed 115, the maze service, the grader, the move budget (210) and the checks (huggingface/flock#115) (part 3)
0f1fe65 verified
Raw History Blame Contribute Delete
1.46 kB
"""Harbor's [[verifier.collect]] hook for s3-maze, run in this maze service once the agent is done
(its container already stopped): `python3 -I -S /app/export.py`.
Writes the service's own record of the walk to /evidence, which Harbor collects as artifacts
and hands to the grader in a fresh container: `final.json` (the state file, marked as exported
here) and `moves.jsonl` (the move log). Nothing in /evidence comes from the agent's container.
"""
import json
import os
STATE_DIR = os.environ.get("MAZE_STATE_DIR", "/var/lib/maze")
EVIDENCE = os.environ.get("MAZE_EVIDENCE_DIR", "/evidence")
LIMIT = 16 << 20
def read(name: str) -> bytes:
fd = os.open(os.path.join(STATE_DIR, name), os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK)
with os.fdopen(fd, "rb") as f:
return f.read(LIMIT)
def write(name: str, data: bytes) -> None:
path = os.path.join(EVIDENCE, name)
temp = path + ".tmp"
fd = os.open(temp, os.O_WRONLY | os.O_CREAT | os.O_TRUNC | os.O_NOFOLLOW, 0o644)
with os.fdopen(fd, "wb") as f:
f.write(data)
os.replace(temp, path)
os.makedirs(EVIDENCE, exist_ok=True)
state = json.loads(read("state.json"))
try:
moves = read("moves.jsonl")
except FileNotFoundError: # no move was ever asked for
moves = b""
write("moves.jsonl", moves)
write("final.json", json.dumps({**state, "exported_by": "maze"}).encode())
print("exported", state.get("moves"), "moves; exit reached:", state.get("reached"))