Datasets:

Modalities:
Text
Languages:
English
Size:
< 1K
ArXiv:
Libraries:
Datasets
Harbor
License:
File size: 1,457 Bytes
0f1fe65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""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"))