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

352 lines
16 KiB
Python

"""Trusted independent model; candidate and raw observer run only in children."""
from pathlib import Path
import json
import random
import subprocess
import sys
import tempfile
LO = -(1 << 63)
HI = (1 << 63) - 1
SENTINEL = -777
class Model:
def __init__(self):
self.reset(8, 0, 0)
def reset(self, cap, mono, real):
self.cap, self.mono, self.real = cap, mono, real
self.cells = [0] * 8
self.records = {}
def now(self, domain):
return self.mono if domain == 0 else self.real
def predicate(self, r, value):
return [value == r[3], value >= r[3], value <= r[3]][r[2]]
def initial(self, r):
value = self.cells[r[1]]
if self.predicate(r, value):
r[6:8] = [1, value]
elif self.now(r[4]) >= r[5]:
r[6:8] = [2, 0]
else:
r[6:8] = [0, 0]
def publish(self, cell, value):
self.cells[cell] = value
for r in self.records.values():
if r[6] == 0 and r[1] == cell and self.predicate(r, value):
r[6:8] = [1, value]
def settle(self):
for r in self.records.values():
if r[6] == 0 and self.now(r[4]) >= r[5]:
r[6:8] = [2, 0]
def call(self, op, a):
if op == 'N':
cap, mono, real = a
if not 1 <= cap <= 32 or mono < 0:
return [1]
self.reset(cap, mono, real)
return [0]
if op == 'P':
cell, value = a
if not 0 <= cell <= 7:
return [1]
self.publish(cell, value)
return [0]
if op == 'B':
count, *data = a
items = list(zip(data[::2], data[1::2]))
if count > 64 or any(not 0 <= cell <= 7 for cell, _ in items):
return [1]
for cell, value in items:
self.publish(cell, value)
return [0]
if op == 'W':
id_, cell, relation, target, domain, deadline = a
if id_ < 1 or not 0 <= cell <= 7 or not 0 <= relation <= 2 or domain not in (0, 1) or (domain == 0 and deadline < 0):
return [1]
if id_ in self.records:
return [2]
if len(self.records) >= self.cap:
return [3]
r = list(a) + [0, 0]
self.initial(r)
self.records[id_] = r
return [0]
if op == 'A':
if a[0] < self.mono:
return [1]
self.mono = a[0]
self.settle()
return [0]
if op == 'J':
self.real = a[0]
self.settle()
return [0]
if op in ('I', 'D', 'C', 'E', 'U'):
id_ = a[0]
if op == 'U' and (a[1] not in (0, 1) or (a[1] == 0 and a[2] < 0)):
return [1]
r = self.records.get(id_)
if r is None:
if op == 'I':
return [4] + [SENTINEL] * 8
if op == 'D':
return [4, SENTINEL]
return [4]
if op == 'I':
return [0] + r
if op == 'D':
return [0, 0 if r[6] else min(HI, r[5] - self.now(r[4]))]
if op == 'C':
if r[6] != 0:
return [5]
r[6:8] = [3, 0]
elif op == 'E':
if r[6] == 0:
return [6]
del self.records[id_]
else:
if r[6] == 0:
return [5]
r[4:6] = a[1:3]
self.initial(r)
return [0]
if op == 'R':
return [0, self.cells[a[0]]] if 0 <= a[0] <= 7 else [1, SENTINEL]
if op == 'T':
return [0, self.now(a[0])] if a[0] in (0, 1) else [1, SENTINEL]
if op == 'S':
phases = [r[6] for r in self.records.values()]
return [self.cap, len(phases)] + [phases.count(i) for i in range(4)]
if op in ('L', 'G'):
phase, limit = a
if not -1 <= phase <= 3 or not 0 <= limit <= 32 or (op == 'G' and phase == 0):
return [1, 0]
selected = [r[:] for _, r in sorted(self.records.items()) if (phase == -1 or r[6] == phase) and (op == 'L' or r[6] != 0)][:limit]
result = [0, len(selected)] + [x for r in selected for x in r]
if op == 'G':
for r in selected:
del self.records[r[0]]
return result
raise ValueError(op)
def command(op, slot, *a):
return (op, slot, *a)
def watch(slot, id_, cell=0, relation=0, target=1, domain=0, deadline=30):
return command('W', slot, id_, cell, relation, target, domain, deadline)
def observations(slot, ids=()):
seq = [command('S', slot), command('L', slot, -1, 32)]
seq += [command('T', slot, domain) for domain in (0, 1)]
seq += [command('R', slot, cell) for cell in (0, 7)]
for id_ in ids:
seq += [command('I', slot, id_), command('D', slot, id_)]
return seq
def scenarios():
scenes = [('empty', [])]
default=[]
for slot in (0,1):
default += observations(slot,[0,HI])
default += [command('R',slot,cell) for cell in range(8)]
scenes.append(('default_queries',default))
smoke = [command('N',0,8,0,100),watch(0,11,3,1,7,0,20),watch(0,12,3,1,7,0,20),command('P',0,3,9),command('I',0,11),command('I',0,12),command('S',0)]
scenes.append(('public_smoke', smoke))
seq = [command('N',0,32,4,200)]
for id_, rel, target in [(9,0,0),(2,1,-1),(21,2,1),(6,0,11),(17,1,9),(1,2,-8)]:
seq.append(watch(0,id_,7,rel,target,0,40))
seq += [command('P',0,7,11)] + observations(0,[1,2,6,9,17,21])
seq += [command('P',0,7,-9)] + observations(0,[1,6,17])
scenes.append(('broadcast',seq))
seq=[]
for direction in (1,-1):
seq += [command('N',0,8,10,1000),watch(0,1,0,0,1,0,20),watch(0,2,0,0,1,1,1005),command('J',0,1000+direction*900)]
seq += observations(0,[1,2])
seq += [command('A',0,19)] + observations(0,[1])
seq += [command('A',0,20)] + observations(0,[1,2])
seq += [command('J',0,1005),command('P',0,0,1)] + observations(0,[1,2])
scenes.append(('clock_domains',seq))
seq=[command('N',0,8,3,-5),watch(0,4,0,0,1),watch(0,2,7,2,-1,1,10),watch(0,9,3,0,0,0,0)]
seq += [command('E',0,4),command('C',0,4),command('C',0,4),command('U',0,2,1,20),command('U',0,4,1,20)]
seq += observations(0,[2,4,9])
seq += [command('P',0,0,1),command('U',0,4,0,0),command('U',0,9,1,LO),command('G',0,1,1)] + observations(0,[4,9])
seq += [command('G',0,-1,32),command('E',0,4),watch(0,4),command('C',0,4),command('E',0,4),watch(0,4),command('N',0,1,0,HI)] + observations(0,[4])
scenes.append(('lifecycle',seq))
seq=[]
for cap in [LO,-1,0,1,32,33,HI]:
for mono in [LO,-1,0,HI]:
seq += [command('N',0,cap,mono,LO),command('S',0),command('T',0,0),command('T',0,1)]
for real in [LO,0,HI]:
seq += [command('N',0,8,0,real),command('T',0,1)]
seq += [command('N',0,32,0,0)]
for id_ in [LO,-1,0,1,HI]:
seq += [watch(0,id_),command('I',0,id_),command('D',0,id_),command('C',0,id_),command('E',0,id_)]
seq += [watch(0,HI),command('C',0,HI),command('U',0,HI,1,HI),command('I',0,HI),command('U',0,LO,1,HI),command('C',0,HI),command('E',0,HI)]
for cell in [LO,-1,0,7,8,HI]:
for value in [LO,0,HI]:
seq += [command('P',0,cell,value),command('R',0,cell),watch(0,10,cell,0,value),command('I',0,10),command('E',0,10)]
for rel in [LO,-1,0,1,2,3,HI]:
for target in [LO,0,HI]:
seq += [watch(0,20,0,rel,target),command('I',0,20),command('C',0,20),command('E',0,20)]
for dom in [LO,-1,0,1,2,HI]:
for deadline in [LO,-1,0,HI]:
seq += [watch(0,30,7,0,2,dom,deadline),command('T',0,dom),command('I',0,30),command('U',0,30,dom,deadline),command('D',0,30),command('C',0,30),command('U',0,30,dom,deadline),command('E',0,30)]
for value in [LO,-1,0,HI,HI,0]:
seq += [command('A',0,value),command('T',0,0),command('J',0,value),command('T',0,1)]
scenes.append(('integer_domains',seq))
seq=[]
for cap in (1,32):
seq.append(command('N',0,cap,0,0))
for i in range(cap):
seq.append(watch(0,cap-i,0,0,0 if i%2 else 1,0,20))
seq += [watch(0,1),watch(0,cap+1),watch(0,1,-1),command('S',0),command('L',0,-1,32)]
seq += [command('G',0,-1,0),command('G',0,-1,32),command('S',0),watch(0,cap+1)]
seq += [command('A',0,20),command('G',0,-1,32),watch(0,cap+1),command('S',0)]
scenes.append(('capacity',seq))
seq=[command('N',0,32,0,0),command('P',0,0,8),watch(0,1,0,0,0)]
seq += [command('B',0,1,0,0)] + observations(0,[1])
seq += [command('B',0,8,*[x for cell in range(8) for x in (cell,7)])]
seq += [command('B',0,8,*[x for cell in range(8) for x in (cell,0)])]
seq += [command('R',0,cell) for cell in range(8)]
for count in (0,1,64,65):
data=[]
for i in range(count):
data += [i%8,0 if i%2 else HI]
if count == 65:
seq += [command('P',0,0,LO),watch(0,501,0,0,HI)]
seq += [command('B',0,count,*data)] + observations(0,[1,501])
seq += [command('P',0,0,9),watch(0,2,0,0,4),command('B',0,3,0,4,7,0,8,12)] + observations(0,[2])
for invalid in (LO,HI):
seq += [command('B',0,2,0,4,invalid,0)] + observations(0,[2])
seq += [command('B',0,3,0,4,0,9,7,LO)] + observations(0,[2])
scenes.append(('batch',seq))
seq=[command('N',0,32,0,0),watch(0,1),watch(0,2,0,0,0),watch(0,3,0,0,1,0,0),watch(0,4),command('C',0,4)]
for op in ('L','G'):
for phase in [LO,-2,-1,0,1,2,3,4,HI]:
for limit in [LO,-1,0,1,32,33,HI]:
seq += [command(op,0,phase,limit),command('S',0)]
seq += [command('I',0,LO),command('D',0,HI),command('R',0,LO),command('T',0,HI)]
scenes.append(('list_queries',seq))
seq=[command('N',0,32,0,LO)]
for i,(domain,deadline) in enumerate([(0,HI),(1,HI),(1,0),(1,LO),(0,0)],1):
seq += [watch(0,i,0,0,HI,domain,deadline),command('D',0,i),command('I',0,i)]
seq += [command('J',0,-1)] + observations(0,range(1,6))
seq += [command('J',0,HI),command('A',0,HI)] + observations(0,range(1,6))
scenes.append(('remaining_extremes',seq))
seq=[command('N',0,32,0,0),watch(0,20,0,0,7,0,100),watch(0,10,0,1,7,1,100),watch(0,30,7,0,1,0,0),watch(0,40,7,0,1,0,100),watch(0,50,7,0,2,0,100),command('C',0,40),command('P',0,0,7),command('P',0,0,0)]
seq += observations(0,[10,20,30,40,50])
seq += [command('U',0,20,1,10),command('I',0,20),command('D',0,20),command('U',0,20,0,20),command('P',0,0,7),command('P',0,0,0),command('U',0,20,0,0),command('U',0,10,1,10),command('I',0,10),command('P',0,0,HI)]
seq += observations(0,[10,20,30,40,50])
for phase in (-1,1,2,3):
for limit in (0,1,32):
seq += [command('N',0,32,0,0),watch(0,5),watch(0,2,0,0,0),watch(0,9,0,0,1,0,0),watch(0,1),command('C',0,1)]
seq += [command('L',0,phase,limit),command('G',0,phase,limit),command('L',0,-1,32),command('S',0)]
scenes.append(('terminal_filters',seq))
seq=[]
for slot in (0,1):
seq += [command('N',slot,32,slot,100*slot),watch(slot,HI,7,0,LO,0,20)]
for slot in (1,0,1,0):
seq += [command('P',slot,7,LO if slot else HI),command('J',slot,HI if slot else LO),command('A',slot,20 if slot else 10)]
seq += observations(1-slot,[HI]) + observations(slot,[HI])
seq += [command('N',0,1,0,0)] + observations(1,[HI])
scenes.append(('two_instances',seq))
seq=[command('N',0,2,10,20),command('B',0,8,*[x for cell in range(8) for x in (cell,cell+10)]),watch(0,1,0,0,999,0,100),watch(0,2,7,0,999,1,100)]
rejected=[command('N',0,0,0,0),command('N',0,32,LO,HI),command('P',0,LO,999),command('P',0,HI,999),watch(0,1,8),watch(0,3),watch(0,1),command('A',0,9),command('A',0,LO),command('C',0,LO),command('E',0,1),command('E',0,HI),command('U',0,1,2,HI),command('U',0,1,0,HI),command('U',0,LO,1,HI),command('G',0,0,32),command('L',0,-1,HI),command('B',0,65,*[x for _ in range(65) for x in (0,999)]),command('B',0,2,0,999,LO,0)]
for row in rejected:
seq.append(row)
seq += observations(0,[1,2])
seq += [command('R',0,cell) for cell in range(8)]
scenes.append(('failure_atomicity',seq))
seq=[command('N',0,32,0,100),watch(0,1,0,1,1,0,30)]
while len(seq) < 20000:
index=len(seq)
if index % 1000 == 0:
seq.append(command('P',0,0,index//1000))
else:
op=('R','T','I','D','S','L')[index%6]
if op=='R': seq.append(command(op,0,index%8))
elif op=='T': seq.append(command(op,0,index%2))
elif op in ('I','D'): seq.append(command(op,0,1))
elif op=='L': seq.append(command(op,0,-1,32))
else: seq.append(command(op,0))
scenes.append(('command_limit',seq))
rng=random.Random(0xD0C10C)
seq=[command('N',0,32,0,100),command('N',1,32,0,-100)]
for _ in range(420):
slot=rng.randrange(2)
op=rng.choice('WWPPBAJCEUIDRTLGS')
id_=rng.choice([0,1,2,3,7,9,16,HI])
if op=='W': seq.append(watch(slot,id_,rng.randrange(8),rng.randrange(3),rng.choice([LO,-2,0,1,7,HI]),rng.randrange(2),rng.choice([LO,0,5,20,HI])))
elif op=='P': seq.append(command(op,slot,rng.randrange(8),rng.choice([LO,-2,0,1,7,HI])))
elif op=='B':
data=[x for _ in range(rng.randrange(5)) for x in (rng.randrange(8),rng.choice([LO,0,7,HI]))]
seq.append(command(op,slot,len(data)//2,*data))
elif op in 'AJ': seq.append(command(op,slot,rng.choice([LO,-10,0,3,7,20,HI])))
elif op in 'CEID': seq.append(command(op,slot,id_))
elif op=='U': seq.append(command(op,slot,id_,rng.randrange(2),rng.choice([LO,0,10,HI])))
elif op=='R': seq.append(command(op,slot,rng.randrange(8)))
elif op=='T': seq.append(command(op,slot,rng.randrange(2)))
elif op in 'LG': seq.append(command(op,slot,rng.randrange(-1,4),rng.randrange(33)))
else: seq.append(command('S',slot))
if rng.randrange(7)==0: seq+=observations(slot,[id_])
scenes.append(('seeded_combinations',seq))
return scenes
def compile_cases():
result=[]
for name, seq in scenarios():
stations=[Model(), Model()]
responses=[]
for op,slot,*args in seq:
responses.append(' '.join(map(str,[op,slot,*stations[slot].call(op,args)])))
input_=(''.join(' '.join(map(str,row))+'\n' for row in seq)).encode('ascii')
expected=(''.join(row+'\n' for row in responses)).encode('ascii')
result.append((name,input_,expected,len(seq)))
return result
def main():
candidate=Path(sys.argv[1])
# Finish trusted reads, generation and scratch writes before any compiler/candidate starts.
sources={name:(candidate/name).read_bytes() for name in ('wait_station.hpp','clock_book.cpp','station.cpp')}
observer=Path(__file__).with_name('observer.txt').read_bytes()
cases=compile_cases()
scratch=Path(tempfile.mkdtemp(prefix='clock-observe-',dir=Path.cwd()))
for name,data in sources.items(): (scratch/name).write_bytes(data)
(scratch/'observer.cpp').write_bytes(observer)
argv=['g++','-std=c++17','-O2','-Wall','-Wextra','-I.', 'clock_book.cpp','station.cpp','observer.cpp','-o','observe']
build=subprocess.run(argv,cwd=scratch,capture_output=True,timeout=35)
facts={'build':build.returncode,'build_stdout':len(build.stdout),'build_stderr':len(build.stderr),'runs':[]}
if build.returncode:
print('EVIDENCE '+json.dumps(facts,separators=(',',':')),file=sys.stderr)
print('build rejected')
return 1
failures=[]
for name,input_,expected,count in cases:
try:
run=subprocess.run([str(scratch/'observe')],cwd=scratch,input=input_,capture_output=True,timeout=8)
reason='exit' if run.returncode else 'stderr' if run.stderr else 'stdout' if run.stdout != expected else None
facts['runs'].append([name,run.returncode,len(run.stdout),len(run.stderr),reason,run.stdout == expected])
if reason: failures.append(name+':'+reason)
except subprocess.TimeoutExpired:
facts['runs'].append([name,'timeout',0,0,'timeout'])
failures.append(name+':timeout')
facts['first_reject']=failures[0] if failures else None
facts['commands']=sum(case[3] for case in cases)
print('EVIDENCE '+json.dumps(facts,separators=(',',':')),file=sys.stderr)
if failures:
print('behavior rejected '+', '.join(failures))
return 1
print('PASS')
return 0
if __name__=='__main__':
raise SystemExit(main())