Batch 24 (20261102-C-bos-seed-24) screened all 3078 Bos seed queries. Only 23 themes were in scope (pure user-space reliability, at most one task per theme); the rest were single operations or explanations, installs and networking, system administration, ROS2, board-only or GUI requests. Two finished drafts were withdrawn as too close to existing tasks. Seeds supply direction only: all sources, contracts and tests are new, and no task shares more than 14 characters with its seed text. Each task passed the local gate and the trace6 Docker gate (5 runs per sample class). Claude rebuilt the catalog from the calibration receipts: 23/23 USABLE. 16 of 23 are C/C++. Only the task directories are taken; the batch worktree's lowered disk floor in rollout/core.py stays out of main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
202 lines
6.2 KiB
Python
202 lines
6.2 KiB
Python
"""Parse and validate the public batch format before any result is built."""
|
|
|
|
from dataclasses import dataclass
|
|
from typing import Any, Dict, List, Tuple
|
|
|
|
|
|
class InputError(ValueError):
|
|
pass
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class Grid:
|
|
width: int
|
|
height: int
|
|
rows: Tuple[Tuple[int, ...], ...]
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class ImageSize:
|
|
width: int
|
|
height: int
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class Detection:
|
|
name: str
|
|
box: Tuple[int, int, int, int]
|
|
meta: Any
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class Frame:
|
|
name: str
|
|
grid: Grid
|
|
image: ImageSize
|
|
detections: Tuple[Detection, ...]
|
|
meta: Any
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class Batch:
|
|
frames: Tuple[Frame, ...]
|
|
meta: Any
|
|
|
|
|
|
def _object(value: Any, path: str) -> Dict[str, Any]:
|
|
if type(value) is not dict:
|
|
raise InputError(path + " must be an object")
|
|
return value
|
|
|
|
|
|
def _array(value: Any, path: str) -> List[Any]:
|
|
if type(value) is not list:
|
|
raise InputError(path + " must be an array")
|
|
return value
|
|
|
|
|
|
def _exact_keys(value: Dict[str, Any], keys: set, path: str) -> None:
|
|
if set(value) != keys:
|
|
raise InputError(path + " has missing or extra fields")
|
|
|
|
|
|
def _integer(value: Any, low: int, high: int, path: str) -> int:
|
|
if type(value) is not int:
|
|
raise InputError(path + " must be an integer")
|
|
if value < low or value > high:
|
|
raise InputError(path + " is outside its range")
|
|
return value
|
|
|
|
|
|
def _name(value: Any, path: str) -> str:
|
|
if type(value) is not str:
|
|
raise InputError(path + " must be a string")
|
|
if not value or len(value) > 48:
|
|
raise InputError(path + " has invalid length")
|
|
return value
|
|
|
|
|
|
def _meta(value: Any, path: str) -> Any:
|
|
if type(value) is not dict:
|
|
raise InputError(path + " must be an object")
|
|
_metadata_tree(value, path, 0)
|
|
return value
|
|
|
|
|
|
def _metadata_tree(value: Any, path: str, level: int) -> None:
|
|
kind = type(value)
|
|
if kind in (dict, list) and level > 16:
|
|
raise InputError(path + " is too deeply nested")
|
|
if kind is dict:
|
|
for key, child in value.items():
|
|
if type(key) is not str:
|
|
raise InputError(path + " has a non-string key")
|
|
_metadata_tree(child, path + "." + key, level + 1)
|
|
return
|
|
if kind is list:
|
|
for index, child in enumerate(value):
|
|
_metadata_tree(child, path + "[" + str(index) + "]", level + 1)
|
|
return
|
|
if kind in (str, int, bool, type(None)):
|
|
return
|
|
if kind is float:
|
|
if value == value and value != float("inf") and value != -float("inf"):
|
|
return
|
|
raise InputError(path + " contains a non-JSON value")
|
|
|
|
|
|
def _size(value: Any, path: str) -> ImageSize:
|
|
obj = _object(value, path)
|
|
_exact_keys(obj, {"width", "height"}, path)
|
|
width = _integer(obj["width"], 1, 64, path + ".width")
|
|
height = _integer(obj["height"], 1, 64, path + ".height")
|
|
return ImageSize(width, height)
|
|
|
|
|
|
def _depth(value: Any, path: str) -> Grid:
|
|
obj = _object(value, path)
|
|
_exact_keys(obj, {"width", "height", "values"}, path)
|
|
width = _integer(obj["width"], 1, 64, path + ".width")
|
|
height = _integer(obj["height"], 1, 64, path + ".height")
|
|
values = _array(obj["values"], path + ".values")
|
|
if len(values) != height:
|
|
raise InputError(path + ".values has wrong row count")
|
|
rows = []
|
|
for row_number, raw_row in enumerate(values):
|
|
row_path = path + ".values[" + str(row_number) + "]"
|
|
raw = _array(raw_row, row_path)
|
|
if len(raw) != width:
|
|
raise InputError(row_path + " has wrong column count")
|
|
row = []
|
|
for column, cell in enumerate(raw):
|
|
row.append(_integer(cell, 0, 10000,
|
|
row_path + "[" + str(column) + "]"))
|
|
rows.append(tuple(row))
|
|
return Grid(width, height, tuple(rows))
|
|
|
|
|
|
def _box(value: Any, image: ImageSize, path: str) -> Tuple[int, int, int, int]:
|
|
raw = _array(value, path)
|
|
if len(raw) != 4:
|
|
raise InputError(path + " must have four coordinates")
|
|
x0 = _integer(raw[0], 0, image.width, path + "[0]")
|
|
y0 = _integer(raw[1], 0, image.height, path + "[1]")
|
|
x1 = _integer(raw[2], 0, image.width, path + "[2]")
|
|
y1 = _integer(raw[3], 0, image.height, path + "[3]")
|
|
if x0 >= x1 or y0 >= y1:
|
|
raise InputError(path + " has no area")
|
|
return x0, y0, x1, y1
|
|
|
|
|
|
def _detection(value: Any, image: ImageSize, path: str) -> Detection:
|
|
obj = _object(value, path)
|
|
_exact_keys(obj, {"id", "box", "meta"}, path)
|
|
name = _name(obj["id"], path + ".id")
|
|
box = _box(obj["box"], image, path + ".box")
|
|
meta = _meta(obj["meta"], path + ".meta")
|
|
return Detection(name, box, meta)
|
|
|
|
|
|
def _detections(value: Any, image: ImageSize, path: str) -> Tuple[Detection, ...]:
|
|
raw = _array(value, path)
|
|
if len(raw) > 64:
|
|
raise InputError(path + " has too many detections")
|
|
found = set()
|
|
output = []
|
|
for index, item in enumerate(raw):
|
|
detection = _detection(item, image, path + "[" + str(index) + "]")
|
|
if detection.name in found:
|
|
raise InputError(path + " repeats an id")
|
|
found.add(detection.name)
|
|
output.append(detection)
|
|
return tuple(output)
|
|
|
|
|
|
def _frame(value: Any, path: str) -> Frame:
|
|
obj = _object(value, path)
|
|
_exact_keys(obj, {"frame_id", "image", "depth", "detections", "meta"}, path)
|
|
name = _name(obj["frame_id"], path + ".frame_id")
|
|
image = _size(obj["image"], path + ".image")
|
|
grid = _depth(obj["depth"], path + ".depth")
|
|
detections = _detections(obj["detections"], image, path + ".detections")
|
|
meta = _meta(obj["meta"], path + ".meta")
|
|
return Frame(name, grid, image, detections, meta)
|
|
|
|
|
|
def parse_batch(value: Any) -> Batch:
|
|
obj = _object(value, "batch")
|
|
_exact_keys(obj, {"frames", "meta"}, "batch")
|
|
meta = _meta(obj["meta"], "batch.meta")
|
|
raw = _array(obj["frames"], "batch.frames")
|
|
if len(raw) > 16:
|
|
raise InputError("batch.frames has too many frames")
|
|
frames = []
|
|
found = set()
|
|
for index, item in enumerate(raw):
|
|
frame = _frame(item, "batch.frames[" + str(index) + "]")
|
|
if frame.name in found:
|
|
raise InputError("batch.frames repeats a frame_id")
|
|
found.add(frame.name)
|
|
frames.append(frame)
|
|
return Batch(tuple(frames), meta)
|