amos 2f32624d3b Batch 18 (20261026-C-hwe-codegen-18): add 100 calibrated HWE code-gen tasks; pause production for rollout
100 tasks from the HWE arm-linux code-gen pool (outside the lk/man/pth
range given to batch 22), each with at least one independent
contract-edge defect and plain public docs. Claude reviewed 100/100
USABLE against current digests; no ID or source overlap with main or
batch 22. Difficulty is unmeasured.

progress.md records the wrap-up: all Codex sessions and Qwen schedulers
stopped for the user's rollout, Qwen results so far (57 HARD of 373),
and what is left on each batch branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 17:52:13 +08:00

457 lines
19 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""Independent state machine; child receives operations and emits raw observations."""
import copy
import random
import re
import subprocess
import sys
import tempfile
from pathlib import Path
MAX = 10**12
TOP = 10**9
NAMES = {'define': ('d', 3), 'update': ('u', 3), 'erase': ('e', 1),
'post': ('p', 3), 'cancel': ('c', 1), 'retime': ('t', 2), 'advance': ('a', 1)}
class Model:
def __init__(self, capacity=8, now=0):
self.capacity, self.now, self.serial = capacity, now, 1
self.tasks, self.jobs = {}, {}
self.submitted = self.completed = self.cancelled = self.missed = self.executed = 0
def act(self, op, a):
if op == 'n':
cap, now = a
if not 1 <= cap <= 64: return -1
if not 0 <= now <= MAX: return -6
self.__init__(cap, now)
return 0
if op == 'a':
delta, = a
if not 0 <= delta <= MAX: return -1
if delta + self.now > MAX: return -6
self.now += delta
return 0
key = a[0]
if not 1 <= key <= TOP: return -1
if op in ('d', 'u'):
_, relative, budget = a
if not 1 <= relative <= TOP or not 1 <= budget <= TOP: return -1
if op in ('p', 't'):
if not 0 <= a[1] <= MAX: return -1
if op == 'p' and not 0 <= a[2] <= 2**32 - 1: return -1
if op == 'd':
if key in self.tasks: return -3
if len(self.tasks) == self.capacity: return -5
self.tasks[key] = (a[1], a[2])
return 0
if key not in self.tasks: return -2
if op in ('u', 'e', 'p') and key in self.jobs: return -4
if op in ('c', 't') and key not in self.jobs: return -7
if op == 'u': self.tasks[key] = (a[1], a[2])
elif op == 'e': del self.tasks[key]
elif op == 'c':
del self.jobs[key]
self.cancelled += 1
elif op in ('p', 't'):
release = self.now + a[1]
deadline = release + self.tasks[key][0]
if release > MAX or deadline > MAX or self.serial == 2**64-1: return -6
if op == 'p':
self.jobs[key] = dict(release=release, deadline=deadline, remaining=self.tasks[key][1],
tag=a[2], serial=self.serial)
self.submitted += 1
else:
self.jobs[key].update(release=release, deadline=deadline, serial=self.serial)
self.serial += 1
return 0
def run(self, cpu):
if not 0 <= cpu <= TOP: return -1, []
if cpu == 0: return 0, []
events = []
def emit(key, job, kind, begin, used):
events.append('F %d %d %d %d %d %d %d %d %d' %
(key, job['tag'], kind, begin, self.now, job['deadline'],
job['serial'], used, job['remaining']))
while True:
dead = sorted((j['deadline'], j['serial'], k) for k, j in self.jobs.items()
if j['deadline'] <= self.now)
for _, _, key in dead:
job = self.jobs.pop(key)
emit(key, job, 3, self.now, 0)
self.missed += 1
if cpu == 0 or not self.jobs: break
ready = [(j['deadline'], j['serial'], k) for k, j in self.jobs.items()
if j['release'] <= self.now]
if not ready:
self.now = min(j['release'] for j in self.jobs.values())
continue
key = min(ready)[2]
job = self.jobs[key]
bounds = [job['remaining'], cpu, job['deadline'] - self.now]
bounds += [j['release'] - self.now for j in self.jobs.values() if j['release'] > self.now]
work = min(bounds)
begin = self.now
self.now += work
self.executed += work
cpu -= work
job['remaining'] -= work
emit(key, job, 2 if job['remaining'] == 0 else 1, begin, work)
if job['remaining'] == 0:
del self.jobs[key]
self.completed += 1
return 0, events
def stats(self):
assert self.submitted == len(self.jobs) + self.completed + self.cancelled + self.missed
values = (self.capacity, self.now, len(self.tasks), len(self.jobs), self.submitted,
self.completed, self.cancelled, self.missed, self.executed)
return ['S ' + ' '.join(map(str, values))]
def views(self):
result = ['V %d' % len(self.tasks)]
for key, (relative, budget) in sorted(self.tasks.items()):
j = self.jobs.get(key)
fields = [j[name] if j else 0 for name in ('release', 'deadline', 'remaining', 'serial', 'tag')]
result.append('J ' + ' '.join(map(str, [key, relative, budget, int(j is not None)] + fields)))
return result
def plan(self, text):
if len(text.encode()) > 4096: return -9, 0
if not text: return 0, 0
instructions = []
for index, part in enumerate(text.split(';')):
if index == 32: return -9, 32
match = re.fullmatch(r'([a-z]+)\(([0-9]+(?:,[0-9]+)*)\)', part, re.ASCII)
if not match or match[1] not in NAMES: return -8, index
operation, count = NAMES[match[1]]
arguments = [int(x) for x in match[2].split(',')]
if len(arguments) != count or any(x > 2**63-1 for x in arguments): return -8, index
instructions.append((operation, arguments))
trial = copy.deepcopy(self)
for index, (operation, arguments) in enumerate(instructions):
code = trial.act(operation, arguments)
if code: return code, index
self.__dict__ = trial.__dict__
return 0, len(instructions)
class Suite:
def __init__(self):
self.objects = [Model(), Model()]
self.inputs, self.expected, self.labels = [], [], []
self.groups = {}
def send(self, group, op, slot=0, *args):
model = self.objects[slot]
line = '%s %d' % (op, slot)
if args: line += ' ' + ' '.join(map(str, args))
self.inputs.append(line)
if op == 's': output = model.stats()
elif op == 'v': output = model.views()
elif op == 'r':
code, events = model.run(args[0])
output = ['R %d %d' % (code, len(events))] + events
elif op == 'b':
code, index = model.plan(args[0] if args else '')
output = ['B %d %d' % (code, index)]
elif op == 'y':
self.objects[slot] = copy.deepcopy(self.objects[args[0]])
output = ['R 0']
else: output = ['R %d' % model.act(op, args)]
self.expected += output
self.labels += [group] * len(output)
self.groups[group] = self.groups.get(group, 0) + 1
def checked(self, group, op, slot=0, *args):
self.send(group, op, slot, *args)
self.send(group, 's', slot)
self.send(group, 'v', slot)
def generate():
s = Suite()
c = s.checked
c('origin', 'n', 0, 8, 100)
c('origin', 'd', 0, 1, 20, 3)
c('origin', 'p', 0, 1, 0, 71)
c('origin', 'r', 0, 3)
for origin in (0, 1, 19, 100003, MAX-100):
c('absolute-release', 'n', 0, 8, origin)
c('absolute-release', 'd', 0, 7, 30, 4)
c('absolute-release', 'p', 0, 7, 11, 2**32-1)
c('absolute-release', 'r', 0, 1)
c('absolute-release', 'r', 0, 20)
c('stable-tie', 'n', 0, 8, 0)
for key in (9, 2, 7): c('stable-tie', 'd', 0, key, 100, 2)
for key in (9, 2, 7): c('stable-tie', 'p', 0, key, 0, key+50)
c('stable-tie', 'r', 0, 1)
c('stable-tie', 'r', 0, 30)
c('retime-tie', 'n', 0, 8, 0)
for key in (12, 3):
c('retime-tie', 'd', 0, key, 100, 4)
c('retime-tie', 'p', 0, key, 0, key)
c('retime-tie', 't', 0, 12, 0)
c('retime-tie', 'r', 0, 20)
c('partial-retime', 'n', 0, 8, 0)
c('partial-retime', 'd', 0, 1, 100, 10)
c('partial-retime', 'p', 0, 1, 0, 90)
c('partial-retime', 'r', 0, 3)
c('partial-retime', 't', 0, 1, 5)
c('partial-retime', 't', 0, 1, 1)
c('partial-retime', 'r', 0, 30)
c('release-preemption', 'n', 0, 8, 0)
for key, relative, budget, delay in ((8, 50, 20, 0), (2, 2, 2, 5), (4, 100, 5, 10)):
c('release-preemption', 'd', 0, key, relative, budget)
c('release-preemption', 'p', 0, key, delay, key)
c('release-preemption', 'r', 0, 20)
c('release-preemption', 'r', 0, 100)
for order in ((5, 2, 8), (8, 5, 2)):
c('deadline-edges', 'n', 0, 8, 0)
for key, relative, budget in ((5, 3, 3), (2, 3, 9), (8, 1, 10)):
c('deadline-edges', 'd', 0, key, relative, budget)
for key in order: c('deadline-edges', 'p', 0, key, 0, key)
c('deadline-edges', 'r', 0, 3)
c('deadline-edges', 'r', 0, 100)
c('overdue-cancel-repost', 'n', 0, 1, 20)
c('overdue-cancel-repost', 'd', 0, TOP, 2, 3)
c('overdue-cancel-repost', 'p', 0, TOP, 0, 0)
c('overdue-cancel-repost', 'a', 0, 5)
c('overdue-cancel-repost', 'r', 0, 0)
c('overdue-cancel-repost', 'p', 0, TOP, 0, 1)
c('overdue-cancel-repost', 'c', 0, TOP)
c('overdue-cancel-repost', 'c', 0, TOP)
c('overdue-cancel-repost', 'u', 0, TOP, 100, 2)
c('overdue-cancel-repost', 'p', 0, TOP, 0, 2)
c('overdue-cancel-repost', 'r', 0, 10)
c('overdue-cancel-repost', 'e', 0, TOP)
c('overdue-cancel-repost', 'n', 0, 1, 10)
c('overdue-cancel-repost', 'd', 0, 1, 2, 10)
c('overdue-cancel-repost', 'p', 0, 1, 0, 7)
c('overdue-cancel-repost', 'r', 0, 1)
c('overdue-cancel-repost', 'a', 0, 2)
c('overdue-cancel-repost', 't', 0, 1, 5)
c('overdue-cancel-repost', 'r', 0, 3)
c('overdue-cancel-repost', 'c', 0, 1)
c('bounds-atomicity', 'n', 0, 1, MAX-10)
c('bounds-atomicity', 'd', 0, 1, 10, 1)
for op, args in [('p',(1,1,7)), ('p',(1,0,7)), ('t',(1,1)), ('a',(11,)),
('r',(0,)), ('n',(0,-1)), ('n',(65,0)), ('n',(1,MAX+1)),
('u',(1,0,0)), ('d',(1,0,0)), ('d',(2,1,1)), ('d',(1,1,1)),
('p',(1,MAX+1,-1)), ('u',(1,2,3)), ('e',(1,)), ('r',(1,)),
('a',(10,)), ('p',(1,0,0)), ('a',(0,))]:
c('bounds-atomicity', op, 0, *args)
for tag in (-1,2**32,2**63-1):
c('bounds-atomicity', 'p', 0, 1, 0, tag)
c('bounds-atomicity', 'p', 0, 99, 0, tag)
c('bounds-atomicity', 'n', 0, 1, -1)
for key in (-1,0,TOP+1,2**63-1):
for op, a in [('d',(key,1,1)), ('u',(key,1,1)), ('e',(key,)), ('c',(key,)),
('t',(key,0)), ('p',(key,0,0))]: c('invalid-id',op,0,*a)
for relative, budget in ((0,1),(-1,1),(TOP+1,1),(1,0),(1,-1),(1,TOP+1)):
c('invalid-definition', 'd', 0, 99, relative, budget)
c('invalid-definition', 'u', 0, 99, relative, budget)
for delay in (-1,MAX+1):
c('invalid-delay', 'p', 0, 99, delay, 0)
c('invalid-delay', 't', 0, 99, delay)
c('invalid-delay', 'a', 0, delay)
for cpu in (-1,TOP+1): c('invalid-run', 'r', 0, cpu)
c('capacity64', 'n', 0, 64, 0)
for key in range(64,0,-1): c('capacity64', 'd', 0, key, TOP, TOP)
c('capacity64', 'd', 0, 65, 1, 1)
for key in range(64,0,-1): c('capacity64', 'p', 0, key, 0, key)
c('capacity64', 'r', 0, TOP)
c('capacity64', 'r', 0, TOP)
c('capacity64', 'e', 0, 64)
c('capacity64', 'd', 0, 65, 1, 1)
c('capacity64', 'n', 0, 2, 0)
c('capacity64', 'd', 0, 1, TOP, TOP)
for tag in range(6):
c('capacity64', 'p', 0, 1, 0, tag)
c('capacity64', 'r', 0, TOP)
c('plans', 'n', 0, 8, 10)
plans = ['', 'define(2,9,3);update(2,10,2);post(2,0,1);cancel(2);erase(2)',
'define(7,100,10);post(7,5,12);advance(2)',
'retime(7,0);cancel(7);post(7,0,13)', 'cancel(7);erase(99)',
'erase(99);bad(1)', 'advance(1);define(2,0,4)', 'define(2,4,1);post(2,0,8)',
'advance(0);advance(0)', 'advance(0);', ';', 'define(1,2)', 'DEFINE(1,2,3)',
'advance(+1)', 'advance(-1)', 'advance( 1)', 'advance(1) ', 'advance(1);;advance(2)',
'advance(9223372036854775808)', 'advance(9223372036854775807)',
'advance(0000000000000000000000000000000000000000000000)',
'advance(1)\x00', 'advance(1)', 'cancel(0)',
';'.join(['advance(0)']*32), ';'.join(['advance(0)']*33),
'advance('+'0'*4087+')', 'advance('+'0'*4088+')']
for plan in plans: c('plans', 'b', 0, plan)
c('copy-isolation', 'y', 1, 0)
c('copy-isolation', 'y', 1, 1)
c('copy-isolation', 'r', 1, 1)
c('copy-isolation', 'c', 0, 7)
c('copy-isolation', 's', 1)
c('copy-isolation', 'v', 1)
c('copy-isolation', 'b', 1, 'advance(100);cancel(999)')
c('copy-isolation', 's', 0)
rng = random.Random(0xEDF18)
for wave in range(8):
for slot in (0,1):
c('random-reset', 'n', slot, rng.choice([1,4,8,16]), rng.choice([0,17,999,MAX-150]))
for _ in range(260):
slot = rng.randrange(2)
op = rng.choices(['d','u','e','p','c','t','a','r','b','y'], [8,3,2,12,4,6,4,12,5,1])[0]
key = rng.randint(1,18)
if op in ('d','u'): args = (key,rng.choice([1,2,7,25,99,TOP]),rng.choice([1,3,8,50,TOP]))
elif op in ('e','c'): args = (key,)
elif op == 'p': args = (key,rng.choice([0,0,1,5,100,MAX]),rng.randrange(2**32))
elif op == 't': args = (key,rng.choice([0,1,13,100,MAX]))
elif op == 'a': args = (rng.choice([0,1,2,9,100,MAX]),)
elif op == 'r': args = (rng.choice([0,1,2,6,20,TOP]),)
elif op == 'y': args = (rng.randrange(2),)
else:
args = ('define(%d,%d,%d);post(%d,%d,%d)' %
(key,rng.randint(1,40),rng.randint(1,20),key,rng.randint(0,20),rng.randrange(10000)),)
c('random-mixed',op,slot,*args)
return s
HARNESS = r'''#include "dispatch.hpp"
#include <array>
#include <charconv>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using edf::Dispatcher;
namespace {
bool integer(const std::string& token, std::int64_t& value) {
if (token.empty()) return false;
const char* begin = token.data();
const char* end = begin + token.size();
auto result = std::from_chars(begin, end, value, 10);
return result.ec == std::errc{} && result.ptr == end;
}
void print_stats(const edf::Stats& s) {
std::cout << "S " << s.capacity << ' ' << s.now << ' ' << s.defined << ' ' << s.active
<< ' ' << s.submitted << ' ' << s.completed << ' ' << s.cancelled
<< ' ' << s.missed << ' ' << s.executed << '\n';
}
void print_views(const std::vector<edf::View>& views) {
std::cout << "V " << views.size() << '\n';
for (const auto& v : views) {
std::cout << "J " << v.id << ' ' << v.relative << ' ' << v.budget << ' ' << v.active
<< ' ' << v.release << ' ' << v.deadline << ' ' << v.remaining
<< ' ' << v.serial << ' ' << v.tag << '\n';
}
}
void print_run(const edf::RunResult& result) {
std::cout << "R " << result.code << ' ' << result.events.size() << '\n';
for (const auto& e : result.events) {
std::cout << "F " << e.id << ' ' << e.tag << ' ' << e.kind << ' ' << e.start
<< ' ' << e.end << ' ' << e.deadline << ' ' << e.serial
<< ' ' << e.used << ' ' << e.remaining << '\n';
}
}
}
int main() {
std::array<Dispatcher, 2> objects;
std::string line;
while (std::getline(std::cin, line)) {
std::istringstream input(line);
std::string command_token;
std::string slot_token;
std::int64_t slot = -1;
if (!(input >> command_token >> slot_token) || command_token.size() != 1 ||
!integer(slot_token, slot) || slot < 0 || slot > 1) {
return 2;
}
char command = command_token[0];
auto& object = objects[static_cast<std::size_t>(slot)];
if (command == 'b') {
std::string plan;
std::getline(input, plan);
if (!plan.empty()) {
if (plan.front() != ' ') return 2;
plan.erase(plan.begin());
}
auto result = edf::apply_plan(object, plan);
std::cout << "B " << result.code << ' ' << result.index << '\n';
continue;
}
std::vector<std::int64_t> a;
std::string token;
while (input >> token) {
std::int64_t value = 0;
if (!integer(token, value)) return 2;
a.push_back(value);
}
int code = edf::Invalid;
if (command == 'n' && a.size() == 2) {
code = object.reset(a[0], a[1]);
} else if (command == 'd' && a.size() == 3) {
code = object.define(a[0], a[1], a[2]);
} else if (command == 'u' && a.size() == 3) {
code = object.update(a[0], a[1], a[2]);
} else if (command == 'e' && a.size() == 1) {
code = object.erase(a[0]);
} else if (command == 'p' && a.size() == 3) {
code = object.post(a[0], a[1], a[2]);
} else if (command == 'c' && a.size() == 1) {
code = object.cancel(a[0]);
} else if (command == 't' && a.size() == 2) {
code = object.retime(a[0], a[1]);
} else if (command == 'a' && a.size() == 1) {
code = object.advance(a[0]);
} else if (command == 'r' && a.size() == 1) {
print_run(object.run(a[0]));
continue;
} else if (command == 's' && a.empty()) {
print_stats(object.stats());
continue;
} else if (command == 'v' && a.empty()) {
print_views(object.inspect());
continue;
} else if (command == 'y' && a.size() == 1 && a[0] >= 0 && a[0] <= 1) {
object = objects[a[0]];
code = edf::Ok;
} else {
return 2;
}
std::cout << "R " << code << '\n';
}
return 0;
}
'''
def main():
candidate = Path(sys.argv[1])
suite = generate()
payload = '\n'.join(suite.inputs) + '\n'
scratch = Path(tempfile.mkdtemp(prefix='edf-observe-', dir=str(candidate.parent)))
for name in ('dispatch.hpp', 'dispatch.cpp', 'plan.cpp'):
(scratch/name).write_bytes((candidate/name).read_bytes())
(scratch/'console.cpp').write_text(HARNESS)
compiler = ['g++','-std=c++17','-O2','-Wall','-Wextra','-pedantic',
'dispatch.cpp','plan.cpp','console.cpp','-o','observe']
executable = str(scratch/'observe')
# All scratch filesystem access ends here, before the first untrusted compiler process.
# The wrapper owns UID handoff and final scratch cleanup; check never chmods/chowns it.
compiled = subprocess.run(compiler, cwd=str(scratch), capture_output=True, text=True, timeout=35)
if compiled.returncode:
print('compile failed')
return 1
result = subprocess.run([executable], cwd='/', input=payload, capture_output=True,
text=True, timeout=25)
if result.returncode:
print('observer exited %d' % result.returncode)
return 1
actual = result.stdout.splitlines()
for i, (got, wanted) in enumerate(zip(actual, suite.expected)):
if got != wanted:
print('mismatch %s observation=%d got=%r expected=%r' %
(suite.labels[i],i,got[:180],wanted[:180]))
return 1
if len(actual) != len(suite.expected):
print('observation count %d != %d' % (len(actual),len(suite.expected)))
return 1
print('validated %d observations in %d groups' % (len(actual),len(suite.groups)))
print('PASS')
return 0
if __name__ == '__main__':
raise SystemExit(main())