Spaces:
Running
Running
File size: 3,393 Bytes
ef8334d | 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 | """Regenerate the packaged session activity fixture from the pinned source shard."""
import argparse
import hashlib
import io
import tempfile
from pathlib import Path
from urllib.request import urlopen
import ijson
SHA256 = "e73649253f159ae41cd5ebb10bf09927268e84342fc2f5a7378c66568b99e566"
PROJECTION_SHA256 = "d329d0ea419c4a475be6863607d7e551e24f8970858f95a5b7818793087e75eb"
URL = (
"https://huggingface.co/datasets/harvardMadsys/freeinference_agentic_trace/"
"resolve/bb26cf72c9c20f2b05f765d88548156a74d3c253/"
"release/2026-08-30_2026-09-05/traces/2026-09-01.jsonl.zst"
)
def project(source):
try:
from compression import zstd
reader = zstd.open(io.BytesIO(source), "rb")
except ImportError:
import zstandard
reader = io.BufferedReader(zstandard.ZstdDecompressor().stream_reader(io.BytesIO(source)))
# A single session can contain gigabytes of expanded prefix-block arrays.
# Parse scalar fields incrementally, retaining only this projection.
events = []
sessions = []
with reader:
for path, event, value in ijson.parse(reader, multiple_values=True):
if event in ("start_map", "end_map"):
if path == "" or path.endswith("tool_calls.item.subagent"):
if event == "start_map":
sessions.append({"rows": []})
else:
session = sessions.pop()
for timestamp, step in session["rows"]:
events.append((timestamp, session["id"], step))
elif event == "end_map" and path.endswith("requests.item"):
session = sessions[-1]
session["rows"].append((session.pop("end"), session.pop("step")))
elif event == "string" and (path == "session_id" or path.endswith("subagent.session_id")):
sessions[-1]["id"] = value
elif event == "number":
if path.endswith("requests.item.end_ms"):
sessions[-1]["end"] = value
elif path.endswith("requests.item.step"):
sessions[-1]["step"] = value
events.sort()
entities = {}
rows = []
for timestamp, session, _ in events:
entity = entities.setdefault(session, len(entities))
rows.append(f"{timestamp - events[0][0]}\t{entity}\n")
return "".join(rows).encode("ascii")
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--source", type=Path, help="Use an existing copy of the source .zst file.")
parser.add_argument("--output", type=Path, default=Path(__file__).with_name("activity.tsv"))
args = parser.parse_args()
if args.source:
source = args.source.read_bytes()
else:
with urlopen(URL, timeout=90) as response:
source = response.read()
if hashlib.sha256(source).hexdigest() != SHA256:
raise SystemExit("Source checksum mismatch")
data = project(source)
if hashlib.sha256(data).hexdigest() != PROJECTION_SHA256:
raise SystemExit("Projection checksum mismatch")
with tempfile.NamedTemporaryFile(dir=args.output.parent, delete=False) as tmp:
tmp.write(data)
Path(tmp.name).replace(args.output)
print(hashlib.sha256(data).hexdigest(), args.output)
if __name__ == "__main__":
main()
|