amos f611da1e57 Batch 24: add 23 calibrated tasks written from Bos seed directions
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>
2026-11-02 17:21:50 +08:00

330 lines
12 KiB
Python

"""Independent command oracle for the offline request admission contract."""
import random
import re
import subprocess
import sys
import tempfile
from pathlib import Path
HARNESS = r'''#include "admission.hpp"
#include <iostream>
#include <string>
int main() {
admission::Session session;
std::string line;
while (std::getline(std::cin, line)) {
const std::string observed = session.execute(line);
if (!observed.empty()) std::cout << observed << '\n';
}
return 0;
}
'''
def valid_key(value):
return 1 <= len(value) <= 24 and all(
ch in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-"
for ch in value
)
def number(value, maximum=(1 << 64) - 1):
if not value or (len(value) > 1 and value[0] == "0"):
return None
if any(ch not in "0123456789" for ch in value):
return None
bound = str(maximum)
if len(value) > len(bound) or (len(value) == len(bound) and value > bound):
return None
return int(value)
def tokens(raw):
stripped = raw.strip(" \t\r\v\f")
return re.split(r"[ \t\r\v\f]+", stripped) if stripped else []
def policy(args):
values = [number(args[0], (1 << 32) - 1), number(args[1]),
number(args[2], (1 << 32) - 1)]
if any(value is None for value in values):
return None
return tuple(values)
def valid_policy(value):
return 1 <= value[0] <= 1000 and 1 <= value[1] <= 1000000 and 1 <= value[2] <= 1000
class Oracle:
def __init__(self):
self.instances = {}
def execute(self, raw):
words = tokens(raw)
if not words or words[0].startswith("#"):
return None
op = words[0]
sizes = {"NEW": 5, "REQ": 4, "CFG": 5, "GET": 3, "DROP": 3,
"RESET": 2, "STATS": 2, "DEL": 2, "LIST": 1}
if op not in sizes or len(words) != sizes[op]:
return "ERR PARSE"
if op == "LIST":
return "LIST" + "".join(" " + name for name in sorted(self.instances))
name = words[1]
if op == "DEL":
if name not in self.instances:
return f"DEL {name} MISSING"
del self.instances[name]
return f"DEL {name} OK"
if op in {"NEW", "CFG"}:
value = policy(words[2:])
if value is None:
return "ERR NUMBER"
if op == "NEW":
if not valid_key(name) or not valid_policy(value):
return f"NEW {name} POLICY"
if name in self.instances:
return f"NEW {name} EXISTS"
self.instances[name] = {"policy": value, "clients": {}, "a": 0, "r": 0}
return f"NEW {name} OK"
if name not in self.instances:
return f"CFG {name} NO_INSTANCE"
state = self.instances[name]
if not valid_policy(value):
return f"CFG {name} POLICY"
if len(state["clients"]) > value[2]:
return f"CFG {name} TOO_MANY_CLIENTS"
state["policy"] = value
return f"CFG {name} OK"
if op == "REQ":
key = words[2]
tick = number(words[3])
if tick is None:
return "ERR NUMBER"
head = f"REQ {name} {key} "
if name not in self.instances:
return head + "NO_INSTANCE"
state = self.instances[name]
clients = state["clients"]
if not valid_key(key):
state["r"] += 1
return head + "BAD_KEY"
if key not in clients:
if len(clients) >= state["policy"][2]:
state["r"] += 1
return head + "CAPACITY"
clients[key] = {"start": tick, "last": tick, "used": 1,
"a": 1, "r": 0}
state["a"] += 1
return head + "ADMIT"
client = clients[key]
if tick < client["last"]:
client["r"] += 1
state["r"] += 1
return head + "BACKWARDS"
if tick - client["start"] >= state["policy"][1]:
client["start"] = tick
client["used"] = 0
client["last"] = tick
if client["used"] >= state["policy"][0]:
client["r"] += 1
state["r"] += 1
return head + "QUOTA"
client["used"] += 1
client["a"] += 1
state["a"] += 1
return head + "ADMIT"
if op in {"GET", "DROP"}:
key = words[2]
head = f"{op} {name} {key} "
if name not in self.instances:
return head + "NO_INSTANCE"
clients = self.instances[name]["clients"]
if op == "DROP":
if key not in clients:
return head + "MISSING"
del clients[key]
return head + "OK"
if key not in clients:
return head + "NONE"
client = clients[key]
return head + " ".join(str(client[field]) for field in
("start", "last", "used", "a", "r"))
if name not in self.instances:
return f"{op} {name} NO_INSTANCE"
state = self.instances[name]
if op == "RESET":
state["clients"] = {}
state["a"] = 0
state["r"] = 0
return f"RESET {name} OK"
value = state["policy"]
return (f"STATS {name} {len(state['clients'])} {state['a']} {state['r']} "
f"{value[0]} {value[1]} {value[2]}")
def traces():
groups = []
groups.append(("smoke", [
"NEW front 2 10 2", "REQ front a 5", "REQ front a 5",
"REQ front a 6", "GET front a", "STATS front", "REQ front a 15",
"GET front a", "LIST",
]))
groups.append(("backwards-preserve", [
"NEW clock 3 10 3", "REQ clock alpha 20", "REQ clock alpha 21",
"GET clock alpha", "REQ clock alpha 19", "GET clock alpha",
"REQ clock alpha 22", "GET clock alpha", "REQ clock alpha 20",
"REQ clock alpha 30", "GET clock alpha", "STATS clock",
]))
groups.append(("quota-no-consumption", [
"NEW quota 1 20 3", "REQ quota c 100", "REQ quota c 101",
"REQ quota c 102", "REQ quota c 101", "GET quota c", "CFG quota 2 20 3",
"REQ quota c 103", "GET quota c", "REQ quota c 104",
"GET quota c", "STATS quota",
]))
groups.append(("policy-capacity", [
"NEW manage 2 7 2", "REQ manage b 0", "REQ manage a 1",
"REQ manage c 2", "REQ manage ! 2", "STATS manage",
"CFG manage 3 7 1", "STATS manage", "CFG manage 0 7 2",
"CFG manage 1 3 2", "GET manage a", "REQ manage a 4",
"GET manage a", "DROP manage b", "DROP manage b",
"REQ manage c 4", "STATS manage", "RESET manage",
"STATS manage", "GET manage c", "REQ manage c 5",
]))
groups.append(("sessions-and-errors", [
"NEW z 2 10 1", "NEW a 1 1 1", "LIST", "NEW a 3 2 4",
"REQ z x 0", "REQ a x 0", "GET z x", "GET a x",
"DEL z", "LIST", "DEL z", "REQ z x 2", "CFG z 1 1 1",
"DROP z x", "RESET z", "STATS z", "GET z x", "NEW z 1 2 1",
"STATS z", "LIST", "NEW ! 1 2 1", "REQ a ! 1",
"GET a !", "DROP a !", "NEW broken 1001 2 1",
"CFG a 1 0 1", "STATS a", "REQ a x +2", "REQ a x 02",
"REQ a x 18446744073709551616", "NEW extra 01 2 1",
"REQ a x", "BOGUS a", "LIST extra", "", "# ignored",
]))
groups.append(("limits-and-regression", [
"NEW huge 2 1000000 1", "REQ huge x 18446744073709551610",
"REQ huge x 18446744073709551611", "REQ huge x 1",
"GET huge x", "REQ huge x 18446744073709551615",
"GET huge x", "REQ huge x 18446744073709551614",
"GET huge x", "STATS huge", "CFG huge 3 1 1",
"REQ huge x 18446744073709551615", "GET huge x",
]))
long_number = "9" * 5000
name24 = "n" * 24
name25 = "n" * 25
key24 = "k" * 24
key25 = "k" * 25
groups.append(("lexical-and-policy-bounds", [
f"NEW {name24} 1 1 1", f"REQ {name24} {key24} 0",
f"GET {name24} {key24}", f"REQ {name24} {key25} 1",
f"GET {name24} {key25}", f"NEW {name25} 1 1 1",
f"REQ {name25} x 0", f"STATS {name24}",
"NEW upper 1000 1000000 1000", "STATS upper",
"NEW zero-limit 0 1 1", "NEW zero-window 1 0 1",
"NEW zero-cap 1 1 0", "NEW over-limit 1001 1 1",
"NEW over-window 1 1000001 1", "NEW over-cap 1 1 1001",
"NEW unsigned32 4294967296 1 1",
"NEW unsigned64 1 18446744073709551616 1",
"NEW unsigned-long 1 " + long_number + " 1",
"NEW signed +1 1 1", "NEW leading 01 1 1",
"CFG upper 1000 1000000 1000", "CFG upper 1001 1 1",
"CFG upper 4294967296 1 1", "CFG upper 1 1 4294967296",
"CFG upper 1 18446744073709551616 1", "STATS upper",
"REQ upper x " + long_number, "REQ upper x 18446744073709551616",
"REQ upper x 00", "REQ upper x -1", "REQ upper x 0",
"REQ upper x 1", "GET upper x", "STATS upper",
]))
groups.append(("ascii-whitespace-and-shapes", [
" \tNEW\twhite\t2\t5\t1\t", "REQ\rwhite\vx\f0",
"GET\twhite x", " \t# comment after ASCII whitespace",
"\t\v\f\r ", "NEW\u00a0unicode 1 1 1", "LIST",
"REQ white x 1 trailing", "GET white", "CFG white 1 2",
"RESET white extra", "DEL white extra", "LIST extra",
"REQ white x 1", "STATS white", "GET white x",
"REQ ! x 1", "CFG ! 1 1 1", "GET ! x", "DROP ! x",
"RESET !", "STATS !", "DEL !", "LIST",
]))
rng = random.Random(72091)
commands = ["NEW random 4 13 7"]
keys = ["u", "v", "w", "x", "y", "z", "A"]
ticks = {key: rng.randrange(2, 12) for key in keys}
for index in range(210):
key = rng.choice(keys)
ticks[key] = min((1 << 64) - 1, ticks[key] + rng.randrange(-4, 9))
ticks[key] = max(0, ticks[key])
if index % 23 == 0:
commands.append(f"CFG random {rng.randrange(1, 7)} {rng.randrange(2, 21)} 7")
if index % 31 == 0:
commands.append("GET random " + key)
commands.append(f"REQ random {key} {ticks[key]}")
if index % 11 == 0:
commands.append("STATS random")
if index % 17 == 0:
commands.append("GET random " + key)
commands += ["STATS random"] + ["GET random " + key for key in keys]
groups.append(("mixed-replay", commands))
return groups
def main(candidate):
groups = traces()
oracle = Oracle()
input_lines = []
expected = []
owners = []
for group, lines in groups:
for line in lines:
input_lines.append(line)
result = oracle.execute(line)
if result is not None:
expected.append(result)
owners.append((group, line))
scratch = Path(tempfile.mkdtemp(prefix="request-grade-", dir=Path.cwd()))
harness = scratch / "observer.cpp"
stream = scratch / "commands.txt"
binary = scratch / "observer"
harness.write_text(HARNESS)
input_text = "\n".join(input_lines) + "\n"
stream.write_text(input_text)
harness.chmod(0o644)
stream.chmod(0o644)
compiler = ["g++", "-std=c++17", "-O2", "-Wall", "-Wextra", "-pedantic",
"-I", str(candidate), str(harness),
str(candidate / "admission.cpp"), str(candidate / "config.cpp"),
str(candidate / "wire.cpp"), "-o", str(binary)]
built = subprocess.run(compiler, capture_output=True, text=True, timeout=30)
if built.returncode:
print("FAIL compile")
return 1
played = subprocess.run([str(binary)], input=input_text.encode("utf-8"),
capture_output=True, timeout=12)
if played.returncode or played.stderr:
print("FAIL execution")
return 1
if not played.stdout.endswith(b"\n"):
print("FAIL final-LF")
return 1
try:
observed = played.stdout[:-1].decode("utf-8").split("\n")
except UnicodeDecodeError:
print("FAIL output-encoding")
return 1
if len(observed) != len(expected):
print(f"FAIL output-count {len(observed)} != {len(expected)}")
return 1
for index, (actual, want) in enumerate(zip(observed, expected)):
if actual != want:
group, command = owners[index]
print(f"FAIL {group} at {index} after {command!r}: {actual!r} != {want!r}")
return 1
print("PASS")
return 0
if __name__ == "__main__":
sys.exit(main(Path(sys.argv[1]).resolve()))