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

227 lines
12 KiB
Python

"""Independent software-contract oracle; submitted code runs only in subprocesses."""
import random
import subprocess
import sys
import tempfile
from pathlib import Path
CANDIDATES = ['runtime.hpp', 'state.hpp', 'storage.cpp', 'notify.cpp', 'runtime.cpp']
COMMANDS = dict(C=2, X=1, A=3, K=2, S=3, R=1, D=2, F=1, M=2, V=1, E=1, I=1, N=1, G=0)
def histories():
events = []
def add(label, instance, *commands):
for command in commands:
events.append((label, instance, command.split()))
for instance in (0, 1):
add('fresh-instance', instance, 'G', 'I 1', 'E 65535', 'N 1')
for queue in range(4):
add('all-missing-apis', instance, f'V {queue}', f'X {queue}',
f'A {queue} 1 0', f'K {queue} 65535', f'S {queue} 0 0',
f'R {queue}', f'D {queue} 8', f'F {queue}', f'M {queue} 7', 'G')
# Public symptom: no second event without a new arm.
add('smoke-consume', 0, 'C 0 3', 'A 0 7 57005', 'S 0 17 10', 'S 0 18 20', 'E 7', 'D 0 8', 'S 0 19 30', 'E 7', 'V 0', 'G', 'X 0')
# Independent precise boundary: initial nonempty arm cannot publish, and survives to a later edge.
add('nonempty-arm', 0, 'C 0 2', 'S 0 5 99', 'A 0 65535 -2147483648', 'N 65535', 'I 65535', 'V 0', 'S 0 6 100', 'D 0 1', 'V 0', 'D 0 0', 'D 0 1', 'V 0', 'S 0 7 101', 'I 65535', 'N 65535', 'E 65535', 'V 0', 'G', 'X 0')
for instance in (0, 1):
add('initial-independent', instance, 'G', 'V 3', 'F 3', 'M 3 0', 'R 3', 'D 3 0', 'K 3 1', 'E 1', 'I 1', 'N 1')
# Domains: valid endpoints and one step beyond, tested on absent and occupied states.
for live in (False, True):
if live:
add('setup-domains', instance, 'C 3 8', 'A 3 1 0')
bad = ['C -1 1', 'C 4 1', 'C 0 0', 'C 0 9', 'C 3 0', 'C 3 9', 'A -1 1 0', 'A 4 1 0', 'A 3 0 0', 'A 3 65536 0', 'K -1 1', 'K 4 1', 'K 3 0', 'K 3 65536', 'S -1 0 0', 'S 4 0 0', 'S 3 -32769 0', 'S 3 32768 0', 'S 3 0 -1000001', 'S 3 0 1000001', 'D -1 0', 'D 4 0', 'D 3 -1', 'D 3 9', 'M -1 0', 'M 4 0', 'M 3 -1', 'M 3 8', 'X -1', 'X 4', 'R -1', 'R 4', 'F -1', 'F 4', 'V -1', 'V 4', 'E 0', 'E 65536', 'I 0', 'I 65536', 'N 0', 'N 65536']
for command in bad:
add('domain-and-atomicity', instance, command, 'G', 'V 3', 'I 1', 'N 1')
if live:
add('domain-cleanup', instance, 'X 3')
# Every queue, lower/upper capacity, repeated operations and FIFO at all valid indices.
for queue in range(4):
q = str(queue)
add('lifecycle-empty', instance, f'C {q} 1', f'C {q} 8', f'V {q}', f'R {q}', f'F {q}', f'M {q} 0', f'M {q} 7', f'D {q} 8', f'D {q} 0', f'K {q} 1', f'G', f'X {q}', f'X {q}', f'C {q} 8', f'V {q}')
add('owner-contention', instance, f'A {q} 1 2147483647', f'A {q} 1 2147483647', f'A {q} 1 -2147483648', f'A {q} 65535 0', f'K {q} 65535', f'V {q}', f'G', f'K {q} 1', f'K {q} 65535', f'V {q}', f'A {q} 65535 -2147483648')
for index in range(8):
ident = [-32768,32767,0,0,-1,1,3,2][index]
value = [-1000000,1000000,0,-1,1,2,3,4][index]
add('fifo-and-capacity', instance, f'S {q} {ident} {value}', f'F {q}', f'M {q} {index}', f'V {q}', 'G')
add('full-atomic', instance, f'A {q} 1 0', f'S {q} 100 100', f'S {q} 32768 100', f'V {q}', 'G', 'I 65535', 'I 65535', 'N 65535')
for index in range(8):
add('indexed-observation', instance, f'M {q} {index}')
add('drain-arm-survival', instance, f'D {q} 0', f'F {q}', f'D {q} 7', f'V {q}', f'F {q}', f'M {q} 1', f'S {q} 9 9', f'V {q}', f'D {q} 8', f'V {q}', f'S {q} 10 10', f'V {q}', 'I 1', 'E 1', 'E 65535', 'N 1', 'N 65535', f'D {q} 8', f'A {q} 1 -1', f'X {q}', 'G', f'V {q}', f'C {q} 1', f'V {q}', f'S {q} 11 11', 'I 1', f'X {q}')
# Pending records keep old cookie and survive cancel, close and queue recreation.
add('event-ownership-order', instance, 'C 0 2', 'C 1 2', 'A 0 1 13', 'A 1 65535 14', 'S 0 0 0', 'S 1 1 1', 'D 0 8', 'A 0 1 15', 'S 0 2 2', 'A 1 1 16', 'K 1 1', 'X 0', 'C 0 1', 'A 0 65535 17', 'S 0 3 3', 'X 1', 'C 1 1', 'N 1', 'N 65535', 'I 65535', 'I 65535', 'E 65535', 'I 1', 'E 1', 'E 1', 'E 1', 'E 65535', 'E 65535', 'N 65535', 'G', 'X 0', 'X 1')
add('receive-arm-survival', instance, 'C 2 1', 'S 2 -32768 1000000',
'A 2 2 2147483647', 'A 2 2 2147483647', 'S 2 0 0', 'D 2 0',
'F 2', 'M 2 0', 'V 2', 'I 2', 'N 2', 'G', 'R 2', 'V 2',
'I 2', 'N 2', 'G', 'R 2', 'S 2 32767 -1000000', 'V 2',
'I 2', 'I 2', 'N 2', 'R 2', 'S 2 1 2', 'E 2', 'E 2', 'X 2', 'G')
add('receive-fifo-duplicates', instance, 'C 2 8', 'S 2 7 31',
'S 2 -7 32', 'S 2 7 33', 'F 2', 'M 2 1', 'R 2', 'F 2',
'R 2', 'M 2 0', 'R 2', 'F 2', 'G', 'X 2')
# Same queue/owner in two live objects, interleaved before either is closed.
add('interleaved-isolation', 0, 'C 3 1', 'A 3 42 501', 'S 3 1 11')
add('interleaved-isolation', 1, 'C 3 2', 'A 3 42 502', 'S 3 2 22')
add('interleaved-isolation', 0, 'V 3', 'F 3', 'I 42', 'E 42', 'X 3', 'G')
add('interleaved-isolation', 1, 'V 3', 'F 3', 'I 42', 'N 42', 'E 42', 'X 3', 'G')
rng = random.Random(0xA11CE18)
for round_number in range(16):
for instance in (0, 1):
for queue in range(4):
add('random-start', instance, f'X {queue}', f'C {queue} {rng.choice([1,2,8])}')
for _ in range(220):
instance = rng.randrange(2)
queue = rng.choice([-1,0,1,2,3,4])
owner = rng.choice([0,1,2,7,65535,65536])
operation = rng.choice('CCCXAAKKSSSSRRDDFFMMVEEIINNGG')
args = {
'C':[queue,rng.choice([0,1,2,8,9])],
'X':[queue], 'A':[queue,owner,rng.choice([-2147483648,-1,0,57005,2147483647])],
'K':[queue,owner], 'S':[queue,rng.choice([-32769,-32768,0,17,32767,32768]),rng.choice([-1000001,-1000000,0,1000000,1000001])],
'R':[queue], 'D':[queue,rng.choice([-1,0,1,7,8,9])], 'F':[queue],
'M':[queue,rng.choice([-1,0,1,7,8])], 'V':[queue], 'E':[owner], 'I':[owner], 'N':[owner], 'G':[]
}[operation]
add('seeded-mixed', instance, operation + ''.join(' '+str(a) for a in args))
add('random-stats', 0, 'G')
add('random-stats', 1, 'G')
return events
class Model:
def __init__(self):
self.queues = [None]*4
self.epochs = [0]*4
self.events = []
self.counts = [0]*9
def apply(self, op, a):
# Status and zero payload are derived independently of the candidate's private layout.
zeros = {'R':[0,0], 'F':[0,0], 'M':[0,0], 'D':[0], 'V':[0]*5, 'E':[0]*4, 'I':[0]*4, 'N':[0]}
def error(code):
return [code] + zeros.get(op, [])
if op == 'G':
return self.counts[:]
if op in 'EIN':
owner, = a
if not 1 <= owner <= 65535:
return error(-1)
matches = [e for e in self.events if e[2] == owner]
if op == 'N':
return [0,len(matches)]
if not matches:
return error(-5)
event = matches[0]
if op == 'E':
self.events.remove(event)
self.counts[8] += 1
return [0]+event
queue = a[0]
valid = 0 <= queue < 4
if op == 'C': valid = valid and 1 <= a[1] <= 8
if op in 'AK': valid = valid and 1 <= a[1] <= 65535
if op == 'S': valid = valid and -32768 <= a[1] <= 32767 and -1000000 <= a[2] <= 1000000
if op == 'D': valid = valid and 0 <= a[1] <= 8
if op == 'M': valid = valid and 0 <= a[1] <= 7
if not valid:
return error(-1)
q = self.queues[queue]
if op == 'C':
if q is not None: return error(-3)
self.epochs[queue] += 1
self.queues[queue] = dict(cap=a[1], messages=[], arm=None)
self.counts[0] += 1
return [0]
if q is None:
return error(-2)
messages = q['messages']
if op == 'X':
self.counts[1] += 1
self.counts[4] += len(messages)
self.queues[queue] = None
elif op == 'A':
if q['arm'] is not None: return error(-3)
q['arm'] = a[1:]
self.counts[5] += 1
elif op == 'K':
if q['arm'] is not None:
if q['arm'][0] != a[1]: return error(-6)
q['arm'] = None
self.counts[6] += 1
elif op == 'S':
if len(messages) == q['cap']: return error(-4)
empty_before = not messages
messages.append(a[1:])
self.counts[2] += 1
if empty_before and q['arm'] is not None:
self.counts[7] += 1
self.events.append([self.counts[7],queue,*q['arm']])
q['arm'] = None
elif op in 'RFM':
index = a[1] if op == 'M' else 0
if index >= len(messages): return error(-5)
message = messages[index][:]
if op == 'R':
del messages[0]
self.counts[3] += 1
return [0]+message
elif op == 'D':
result = messages[:a[1]]
del messages[:a[1]]
self.counts[3] += len(result)
return [0,len(result)]+[v for m in result for v in m]
elif op == 'V':
return [0,self.epochs[queue],q['cap'],len(messages),*(q['arm'] or [0,0])]
return [0]
def expected(events):
models = [Model(), Model()]
lines = []
for label, instance, command in events:
op, *args = command
values = models[instance].apply(op, list(map(int,args)))
lines.append(f'{instance} {op} ' + ' '.join(map(str,values)))
return ('\n'.join(lines)+'\n').encode('ascii')
def main():
events = histories()
wanted = expected(events)
stdin = ''.join(str(i)+' '+' '.join(cmd)+'\n' for _,i,cmd in events).encode('ascii')
root = Path(__file__).resolve().parent
# Finish all trusted reads and scratch writes before the first child runs.
sources = {name:(Path(sys.argv[1])/name).read_bytes() for name in CANDIDATES}
sources['observer.cpp'] = (root/'observer.txt').read_bytes()
scratch = Path(tempfile.mkdtemp(prefix='message-notify-', dir=Path.cwd()))
for name, data in sources.items():
(scratch/name).write_bytes(data)
argv = ['c++','-std=c++17','-O2','-Wall','-Wextra','-pedantic','runtime.cpp','storage.cpp','notify.cpp','observer.cpp','-o','message-observer']
built = subprocess.run(argv,cwd=scratch,capture_output=True,timeout=35)
print('build_exit='+str(built.returncode),file=sys.stderr)
if built.returncode:
print('build failed: '+built.stderr[-2000:].decode('utf-8','replace'))
return 1
result = subprocess.run([str(scratch/'message-observer')],cwd=scratch,input=stdin,capture_output=True,timeout=25)
print('run_exit='+str(result.returncode)+'; observations='+str(len(events)),file=sys.stderr)
if result.returncode:
print('candidate exit='+str(result.returncode)+' stderr='+repr(result.stderr[-300:]))
return 1
if result.stderr:
print('stderr must be empty; got '+repr(result.stderr[:150]))
return 1
if result.stdout != wanted:
actual = result.stdout.split(b'\n')
answers = wanted.split(b'\n')
for index in range(max(len(actual),len(answers))):
got = actual[index] if index < len(actual) else b'<missing>'
want = answers[index] if index < len(answers) else b'<extra>'
if got != want:
label = events[index][0] if index < len(events) else 'byte-framing'
print('behavior mismatch step='+str(index+1)+' case='+label+' got='+repr(got[:170])+' expected='+repr(want[:170]))
break
return 1
print('PASS')
return 0
if __name__ == '__main__':
raise SystemExit(main())